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

Can we make @defer inferrable? #4

Open
c42f opened this issue Jul 30, 2021 · 0 comments
Open

Can we make @defer inferrable? #4

c42f opened this issue Jul 30, 2021 · 0 comments

Comments

@c42f
Copy link
Owner

c42f commented Jul 30, 2021

It seems that context passing and cleanup has a similar structure to reverse mode AD: we accumulate a bunch of actions wrapped inside closures which must be run at the exit of a scope.

Currently ResourceContexts generates kind of bad code for the cleanup because everything becomes boxed. It's not a disaster if you're cleaning up heavy weight resources, but perhaps there's some way to use opaque closures to give the compiler insight into the list of cleanup actions?

A difficulty here is that @defer may be called within a loop to defer cleanup of a collection of objects, so the cleanup list is currently of dynamic length. It's unclear whether this is a good pattern, but if it is, maybe we should try to encapsulate the list of closures as a concrete list of zero-argument thunks which can be called with minimal overhead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant