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

Find a way to stack allocate closures #786

Open
yorickpeterse opened this issue Dec 10, 2024 · 1 comment
Open

Find a way to stack allocate closures #786

yorickpeterse opened this issue Dec 10, 2024 · 1 comment
Labels
compiler Changes related to the compiler feature New things to add to Inko, such as a new standard library module

Comments

@yorickpeterse
Copy link
Collaborator

yorickpeterse commented Dec 10, 2024

Description

In #783 we're introducing the ability to define stack allocated types capable of storing both heap and stack allocated types. We should find a way to extend such functionality to also work for closures.

Stack allocating closures poses a few challenges:

  • fn types are currently assumed to be pointers, not stack allocated data
  • stack allocated closures don't have a uniform layout, as their size is dictated by the variables they capture
  • closures may assign captured variables new values, which won't work reliably if we copy the stack data similar to inline types

For closures to be stack allocated, we most likely need to treat them similarly as generic type arguments and generate specialized versions. This however is likely to require extensive changes to how we specialize types and methods, so I'm not sure about this yet.

Related issues

Related work

@yorickpeterse yorickpeterse added compiler Changes related to the compiler feature New things to add to Inko, such as a new standard library module labels Dec 10, 2024
@yorickpeterse
Copy link
Collaborator Author

yorickpeterse commented Dec 10, 2024

For closures it might make more sense to keep their memory layout the same, but use escape analysis to allocate them on the stack. Most closures aren't likely to outlive the method they're defined in, so this might be good enough. This also removes the need for complex specialization changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Changes related to the compiler feature New things to add to Inko, such as a new standard library module
Projects
None yet
Development

No branches or pull requests

1 participant