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

Implement closure conversion #1254

Closed
1 task done
jfecher opened this issue Apr 28, 2023 · 0 comments · Fixed by #1959
Closed
1 task done

Implement closure conversion #1254

jfecher opened this issue Apr 28, 2023 · 0 comments · Fixed by #1959
Assignees
Labels
enhancement New feature or request

Comments

@jfecher
Copy link
Contributor

jfecher commented Apr 28, 2023

Problem

Currently the compiler does no form of closure conversion. Code such as

let x = 2;
let f = |y| x + y;
f(3);

Is represented quite literally after monomorphization leading to functions in SSA referring to a closure's environment from outside of the function, without taking in the environment as a parameter. This leads to odd bugs such as #1088. The new ssa refactor is also more stringent and panics when a closure environment is used this way.

Proposed solution

Going forward we should implement proper closure conversion to solve both these issues. This means translating the above code into the following before/during monomorphisation:

let x = 2;
let f = (x, |x2, y| x2 + y);
f.1(f.0, 3);

Alternatives considered

No response

Additional context

No response

Submission Checklist

  • Once I hit submit, I will assign this issue to the Project Board with the appropriate tags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants