-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Comments
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. |
As part of #776 I have the foundations in place for stack allocating closures. The current issue is that when a method defines an argument of type |
Not only do we need to specialize closures similar to generics, but we also need to make sure that capture information is propagated across inferred types and type signatures. Consider this example:
For Another challenge is that if we infer a whole bunch of types according to a closure, they should all be specialized to the same closure type. In the above example that means We also can't generate type parameters and then turn closures into some sort of special trait requirement, as this wouldn't work for return types. Consider this:
If we use generated parameters, we'd turn that into something like this:
The problem here is that we never end up assigning I'm not sure yet how to approach these challenges, so I'll postpone this until 0.19.0 as I suspect it will take some time to figure all this out. We can however use the foundations provided by #798 to implement the |
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 datainline
typesFor 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
The text was updated successfully, but these errors were encountered: