-
Notifications
You must be signed in to change notification settings - Fork 28
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
Class Lifter #266
base: hkmc2
Are you sure you want to change the base?
Class Lifter #266
Conversation
What's the intended scheme regarding mutable local variables? FWIW, we should distinguish mutable from immutable variables. I intend to let When there are only immutable variables being captured, the scheme can be simpler. |
I don't distinguish between local variables that are mutated / not mutated for now. I intend to move every local variable that's referenced inside a nested class / function into a closure. Would it be better to add the immutable local variables to each class/function directly? P.S. seems I accidentally marked this PR as ready earlier, but it's definitely not. It's now marked as a draft. |
Added much more into to the the first comment. |
As discussed in the meeting, it would be nice to emit a warning if lifted classes are used in instance tests or as first-class values, which is not supported yet. And please add this test to the PR: fun foo1(x, n) =
class C()
print(x is C)
if n > 0 do foo1(C(), n - 1)
:lift
fun foo2(x, n) =
class C()
print(x is C)
if n > 0 do foo2(C(), n - 1)
foo1(0, 1)
//│ > false
//│ > false
foo2(0, 1)
//│ > false
//│ > true |
Lifts classes and nested functions to the top-level.
Method
General idea: when functions have to capture local variables, we need to rewrite their parameter lists. For example:
is transformed into
Variables which are not mutated will be passed as a parameter directly.
TODO
Instantiate
does not work at allg(unused)
is symbolically replaced.("lifting" curried functions is much easier than the lifting in general, so it can be done later)