-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Compiler: turn proc pointer into proc literal in some cases #9824
Compiler: turn proc pointer into proc literal in some cases #9824
Conversation
b807d13
to
22e9a25
Compare
else | ||
call_self = @last | ||
end | ||
call_self = @last |
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.
Why is the "If obj is a primitive like ..." no longer needed?
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.
Because if obj
is a Var
thenh this was turned into a ProcLiteral
, so a proc pointer at this point never has a Var
as its obj
.
if proc_pointer = arg.proc_pointer | ||
case proc_pointer.obj | ||
when Var | ||
arg.raise "#{message} (closured vars: #{proc_pointer.obj})" |
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.
This condition seems new. The previous var.join ", "
was moved a couple of lines below. Is there a spec missing to stress this error?
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.
Without this, existing specs would fail. So there are already specs covering this. I just had to adjust the logic for the new behavior.
Fixes #8584
This essentially makes the compiler transform this:
To this:
The effect is the same: it captures the value at the point of creating the proc/closure. However, the compiler has already logic for closuring
tmp
so it remains in the heap.