-
Notifications
You must be signed in to change notification settings - Fork 52
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
Variables in a local monadic binder escape to outer scopes #681
Comments
I was trying to do a |
Yikes, good job figuring this one out @byorgey. 👍 Maybe we could make the example a unit test, to make it easier to debug/fix? 🙂 I don’t know how the binder machinery works, so this is just a guess on my part, but could we fix this by renaming variables internally? For example the inner variable could be named |
Yes, good idea.
I mean, that's a reasonable idea, but I think it would just be a band-aid, and would probably lead to other bugs. In theory, we should be able to fix it simply by managing environments in such a way that the dynamic semantics (i.e. which values flow where) matches the static semantics (the scopes etc. enforced by the type checker). |
It's actually a pretty good error, in the sense that it really is a fatal error and a bug in swarm, and the machine state at least gives us a bit of info about what's going wrong. |
Current progress: so when a Evaluating a delayed expression should never cause names to get bound, however, so maybe we can just change the way that happens? Tried wrapping evaluation of delayed things in a new I guess the real issue is that whenever we're executing something and we look up the value of a variable, we should discard any environment generated by whatever the variable resolves to, because it came from some nested or non-local scope. Even that is tricky though... we have to know when such a value looked up as the value of a variable meets an |
Wrapping all variables, period, is problematic, because then we have a |
Just wanted to share that the error messages have improved: def repeat = \c. c; repeat c end;
repeat ( c <- scan down; case c (\_. say "Hi") (\_. return ()) ) def f = a <- scan down end;
let a = 2 in f; return (a+1) Thanks, @byorgey! 👍 |
Optimistic we can actually get this fixed soon after we clean up and merge #991 , which I hope to get to soon. This past week was the first week of classes so not much extra time for me, but things should soon settle into more normal patterns... |
- Closes #990 Values of type `Syntax` are as before: parsed syntax, with each node annotated with `SrcLoc`. Values of type `Syntax' Polytype`, however, have each node annotated with *both* a `SrcLoc` *and* a `Polytype`. (`Syntax` is really just a synonym for `Syntax' ()`.) Type inference takes a `Syntax` and outputs a `TModule`, which now contains a `Syntax' Polytype`, in other words, a new version of the AST where every node has been annotated with the inferred type of the subterm rooted there. --- Why is this useful? 1. It will enable us to do type-specific elaboration/rewriting. For example I think this will allow us to solve #681 , because we only want to apply a rewrite to variables with a command type. 2. It makes type information for any specific subterm easily available. For example I hope we will be able to use this to enhance the `OnHover` LSP handler, e.g. to show the type of the term under the mouse. I imagine the code changes might look kind of intimidating but I don't think it's really that bad once you understand what is going on, so I'm happy to answer any questions or explain anything.
i.e. #681. Doesn't work yet; fixes one test case but still fails others, and strangely seems to cause an unrelated test case to fail...
This bug is so interesting and so irritating. I am learning a lot. My latest realization (thanks to #1033) is that it's not enough to just wrap variables with a I am beginning to think the real problem is that we treat names defined via a |
@byorgey the I am interested what your super secret final solution will be. 😄 |
The export strategy is a promising way to solve the wrong problem. 😄 |
Figured out what's causing the bug. Basically the
b <- ...
in the definition ofuntil
is overriding the definition ofb
inhanoi
, which absolutely should not happen.Originally posted by @byorgey in #669 (comment)
To reproduce, put the following in a
.sw
file and--run
it in Creative mode:The binding of the variable
a
from the definition off
is escaping into the outer scope from whichf
is called, so thata
is now bound toinl ()
instead of2
, which obviously causes a runtime crash when the+
operator is applied to a non-number.Edited to add: we should keep the below discussion around for reference, but see #1087 for my latest thinking on the issue.
The text was updated successfully, but these errors were encountered: