Skip to content
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

Merged
merged 2 commits into from
Oct 23, 2020

Conversation

asterite
Copy link
Member

Fixes #8584

This essentially makes the compiler transform this:

->foo.bar(X, Y)

To this:

tmp = foo
->(x : X, y : Y) { tmp.bar(x, y) }

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.

@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Oct 13, 2020
@asterite asterite force-pushed the compiler/turn-proc-pointer-into-proc-literal branch from b807d13 to 22e9a25 Compare October 13, 2020 16:08
else
call_self = @last
end
call_self = @last
Copy link
Member

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?

Copy link
Member Author

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})"
Copy link
Member

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?

Copy link
Member Author

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.

@bcardiff bcardiff added this to the 1.0.0 milestone Oct 23, 2020
@asterite asterite merged commit 442952f into master Oct 23, 2020
@asterite asterite deleted the compiler/turn-proc-pointer-into-proc-literal branch October 23, 2020 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid memory access (signal 11) at address 0x841f13
2 participants