-
Notifications
You must be signed in to change notification settings - Fork 14
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
Naive state #235
Naive state #235
Conversation
… new state evidence)
The PR is starting to look solid. I implemented the new local state for all backends, except LLVM (and machine for that matter). It would be very valuable to get feedback from @marzipankaiser, @serkm, and @phischu on how to proceed with machine. You don't have to look at the whole PR, the essential change is this in - case State(id: Id, init: Expr, region: Symbol, ev: Evidence, body: Stmt)
+ // allocates into a (type-monomorphic?) region.
+ // e.g. var x in r = init; body
+ case Alloc(id: Id, init: Expr, region: Id, ev: Evidence, body: Stmt)
+
+ // creates a fresh state handler to model local (backtrackable) state.
+ // e.g. state(init) { (ev){x: Ref} => ... }
+ case Var(init: Expr, body: Block.BlockLit) For now, I changed the test files to use an explicit region instead of local mutable state. -def main() = {
- var n = 0
+def main() = region r {
+ var n in r = 0 but this is only a temporary fix, since I do not translate local mutable state to machine: Any feedback on how to proceed with machine is very welcome! You can also look at how the other backends implement it, of course. |
@serkm I have yet another idea for the implementation of local mutable state. It crucially relies on going back to the "copy-on-share" strategy. This means that Now when we want to create a local mutable reference we push a frame that contains the value. References are offsets from the bottom of the stack. Getting the content of a reference means finding the correct stack using evidence and then reading the value at the offset. Setting the content of a reference finds the location in the same way and directly writes to it on the stack. For arenas we could do the same except that the frame contains a reference to the arena and A corner case is allocating into the global region which would create a reference on the heap. This could also fix #244. |
Here I am experimenting with a different representation of state that is easier to monomorphize.