mebassett
2017-2-8 14:42:24

hey, I’m having some trouble moving from racket 6.5 to 6.8. On racket 6.5 I can do the following: Welcome to Racket v6.5. -> (require typed/json) -> (struct my-test ()) -> (jsexpr? (my-test)) - : Boolean #fbut in 6.8 things go awry:Welcome to Racket v6.8. > (require typed/json) > (struct my-test ()) > (my-test) - : my-test #<my-test> > (jsexpr? (my-test)) ; jsexpr?: contract violation ; any-wrap/c: Unable to protect opaque value passed as `Any` ; value: #<my-test> ; in: the 1st argument of ; a part of the or/c of ; (or/c ; struct-predicate-procedure?/c ; (-> Any boolean?)) ; contract from: (interface for jsexpr?) ; blaming: <pkgs>/typed-racket-more/typed/json.rkt ; (assuming the contract is correct) ; at: <pkgs>/typed-racket-more/typed/json.rkt:11.24 ; [,bt for context]`


mebassett
2017-2-8 14:43:46

any idea why the predicate from (require/typed/provide json …) is throwing contract violations on structs ?


pnwamk
2017-2-8 14:51:23

@mebassett I think I can provide a high level answer, others may be able to give you a more precise answer and suggestion with how to proceed


pnwamk
2017-2-8 14:52:14

basically, the Typed Racket developers realized that things like predicates imported from untyped code with the type (->Any Boolean) need to be careful to ensure soundness


pnwamk
2017-2-8 14:52:47

that predicate could totally muck with the data it is given, and so to prevent any mucking, a thin wrapper is placed around the data being tested by the imported predicate to ensure it is not abused


pnwamk
2017-2-8 14:53:02

that’s the any-wrap/c contract that is failing


pnwamk
2017-2-8 14:53:11

it can’t protect the opaque struct my-test


pnwamk
2017-2-8 14:53:14

solutions?


pnwamk
2017-2-8 14:53:19
  1. don’t make the struct opaque

pnwamk
2017-2-8 14:53:42
  1. if it’s too burdonsome to have the added safety of the any-wrap/c contract on values passed to jsexpr?

pnwamk
2017-2-8 14:53:59

and you trust that jsexpr? isn’t going to muck with values passed to it


pnwamk
2017-2-8 14:54:02

you could do the following:


pnwamk
2017-2-8 14:54:19
#lang typed/racket

(require (except-in typed/json jsexpr?)
         typed/racket/unsafe)

(unsafe-require/typed json [jsexpr? (-> Any Boolean)])

(struct my-test () #:transparent)

(jsexpr? (my-test))

pnwamk
2017-2-8 14:55:03

here, we’re unsafely importing the jsexpr? predicate, telling the type system “just trust me! don’t worry about things I pass to it! you don’t need to wrap them! I promise!”


pnwamk
2017-2-8 14:55:23

(we’re also telling the type system to assume the result is always a Boolean)


pnwamk
2017-2-8 14:55:52

anyway, there’s probably a crappy description of the precise issue at hand, and some potential solutions


pnwamk
2017-2-8 14:56:06

maybe someone else can provide some sage advice w.r.t. the “best” solution for something like this


mebassett
2017-2-8 14:57:48

Thanks for the response. I do remember something like this being a warning in 6.6. It is vexing that this crops up as a runtime error, rather than a compile-time error. In some cases I don’t have control over using an opaque structure or not. Say if I require/typed/provide Gregor, and then pass a gregor-date-struct into jsexpr?. Code compiles but throws a runtime error, which violates my naive understanding of “safe”.


pnwamk
2017-2-8 14:58:25

I believe one of the releases made it a compile time warning


pnwamk
2017-2-8 14:58:34

and then it was made an error in a later version


pnwamk
2017-2-8 14:59:09

well safe code in any language can throw runtime errors


pnwamk
2017-2-8 14:59:25

well, any language within reason


pnwamk
2017-2-8 14:59:39

but yes, this was a nasty surprise, sorry for the inconvenience


pnwamk
2017-2-8 15:00:01

@samth or some of the other TR devs might be able to provide better answer(s) as well


mebassett
2017-2-8 15:00:48

your answer matched with my prior reasoning of what was going on. I was more hoping I was wrong. :slightly_smiling_face:


mebassett
2017-2-8 15:00:54

thanks for the help.


samth
2017-2-8 15:01:48

I think the unsafe-require is the best option, and we should make a typed/json library that does that


mebassett
2017-2-8 15:03:51

while I have you both here - is there a public roadmap for typed/racket? It would be nice to know what y’all are working on and where its going.


pnwamk
2017-2-8 15:05:14

I don’t think there is currently a clean, consolidated public roadmap


pnwamk
2017-2-8 15:05:37

you might be able to infer one from various sources… but having an explicit public roadmap would be nice


pnwamk
2017-2-8 15:12:09

(me personally, I just finished internal improvements so TR is more performant and less bloated time/space wise, and I’m starting to finally add in the refinement types extension I’ve already prototyped)


mebassett
2017-2-8 15:12:42

refinement types are super useful.


pnwamk
2017-2-8 15:13:52

my goal is to get them added before the summer (when I’ll likely be off at an internship)


pnwamk
2017-2-8 15:14:31

(and there’s no longer any TR “to do’s” before adding refinements in my hopper)


lexi.lambda
2017-2-8 17:48:35

@stchang: Thanks for the PRs. Let me know when I should merge.


stchang
2017-2-8 18:26:53

@lexi.lambda i just merged


stchang
2017-2-8 18:27:23

though it looks like you could have merged at any time, since my changes are compatible with the old version


stchang
2017-2-8 18:28:02

@lexi.lambda a lot of the most recent changes were from your feedback so thanks for that


lexi.lambda
2017-2-8 21:58:40

@stchang: I’m glad to hear it :)


lexi.lambda
2017-2-8 21:59:01

we’re using the aws cloudformation dsl for production services now :)


lexi.lambda
2017-2-8 21:59:35

biggest worry currently is package management, which is still imo the biggest barrier to me feeling comfortable with racket in production


lexi.lambda
2017-2-8 21:59:52

specifically, versioning


lexi.lambda
2017-2-8 22:33:07

@mflatt @samth: what is the status of the sandboxing stuff mentioned in this PR? https://github.com/racket/racket/pull/1206 I think it would be important for fixing the package management issues I currently have


mflatt
2017-2-8 22:34:55

@lexi.lambda “tethering” is in place, and that’s intended to make raco sandbox init easy, but I never tried to build that sandbox layer


mflatt
2017-2-8 22:36:21

See http://docs.racket-lang.org/raco/dirs.html?q=tether#%28def._%28%28lib._setup%2Fdirs..rkt%29._find-addon-tethered-console-bin-dir%29%29 and between those docs and the PR conversation, maybe you’ll be able to infer what I had in mind


lexi.lambda
2017-2-8 22:46:28

@mflatt: I admit, I don’t really understand… if tethering is to avoid having to set PLTADDONDIR, why do both those functions require (find-system-path 'addon-dir)? I’m sure I’m misunderstanding their intent.


mflatt
2017-2-8 22:52:03

Maybe that was the wrong place to point to, and the end of http://docs.racket-lang.org/raco/config-file.html is better


mflatt
2017-2-8 22:55:13

The idea is that you create a configuration that chains to your regular installation, but also defines config-tethered-console-bin-dir and config-tethered-gui-bin-dir; then run racket -G <new-config-dir> -l- raco setup to get binaries that have the <new-config-dir> configuration built in


mflatt
2017-2-8 22:56:36

To use the sandbox, you’d use the executables that have <new-config-dir> wired in


lexi.lambda
2017-2-8 22:58:15

I see, that makes sense. I think maybe I don’t fully understand how addon-dir itself works… if I install a package into the addon directory, then specify the right incantation in the configuration, will racket load those packages?


lexi.lambda
2017-2-8 22:58:50

Similarly, if I set the configuration properly, will raco pkg install install packages into that directory?


lexi.lambda
2017-2-8 22:59:02

Or is that the stuff that still needs to be implemented?


mflatt
2017-2-8 22:59:46

User-scope packages are installed/found within the addon directory


lexi.lambda
2017-2-8 23:01:24

Ok, that makes sense. For that reason, if I wanted to use that feature for sandboxing, then I should really probably avoid installing any packages in installation scope (since packages can’t be installed in both user and installation scope)?


mflatt
2017-2-8 23:02:54

Right; if I understand your goal, then you want a minimal Racket installation to use for creating sandboxes


lexi.lambda
2017-2-8 23:03:48

Yeah, pretty much. This isn’t very important right now, but I’m imagining a future world where the package system supports multiple versions of packages and raco pkg install does constraint solving.


lexi.lambda
2017-2-8 23:04:44

In that world, sandboxes would be extremely important to avoid dependency hell, since you couldn’t have multiple versions of the same package installed globally, but you would want different projects to use different versions.


lexi.lambda
2017-2-8 23:08:32

A small weirdness here: does this mean I would need to install and recompile DrRacket in every project I want to use it with?


mflatt
2017-2-8 23:15:50

Yes, as long as you want to be able to have different installations of anything DrRacket depends on (otherwise, you could start with a base Racket installation that includes DrRacket, instead of a minimal Racket installation)


lexi.lambda
2017-2-8 23:16:49

Right, yeah. That might be ok, but DrRacket depends on a lot (especially since racket-doc depends on a lot).