-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for local state in meta programs #2948
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Aseem, this looks good to me. I have one question though.
In interpreted mode, we use e_any
, so the reference points to a term
, even if it's a tref int
or whatever. But in native tactics, a tref int
will be exactly ref int
, and use the native alloc/read/write. So they cannot interoperate, right? A reference can only be used in the "mode" it's created.
I don't think it's terrible. We could fix this by deprecating e_any
and instead trying to generate an embedding for the type of the reference, but that requires some plumbing.
src/tactics/FStar.Tactics.Basic.fst
Outdated
let write (r:tref 'a) (x:'a) : tac unit = | ||
r := x; | ||
ret () | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be better to "thunk" these to prevent them from reducing before being applied to a proofstate, like so:
let alloc (x:'a) : tac (tref 'a) =
idtac;!
ret (BU.mk_ref x)
let read (r:tref 'a) : tac 'a =
idtac;!
ret (!r)
let write (r:tref 'a) (x:'a) : tac unit =
idtac;!
r := x;
ret ()
Come to think of it, since there is no embedding for |
Could this be used to store state across meta-program calls, e.g. to memoize typeclass resolution? |
What's the status of this? I would find it convenient to use a bit of local state in the Pulse checker. |
fa42456
to
94ba4c0
Compare
I think we can merge this. I updated it to the current master and pushed to this branch. |
This a squashed version of Aseem's branch updated to work with current F*.
94ba4c0
to
e86a220
Compare
This PR adds support for local state in metaprograms. In particular, it adds three primitives:
Metaprograms can use these to maintain local state during execution.
Under the hood we use native OCaml heap to allocate these references.