builtin: reclaim captured closure contexts#18
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e3c1b6c869
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
e3c1b6c to
cc9e5b6
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc9e5b6381
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
cc9e5b6 to
1ca0da1
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ca0da1cd4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
1ca0da1 to
f558787
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f558787b1a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
60f52df to
6c0a119
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
6c0a119 to
70ad17d
Compare
|
@codex review |
|
@GGRei Have you checked out fat closures as an alternative to this? |
|
@MartenH Yes, I looked at the fat-closures RFC. I agree it is the cleaner long-term direction: make pure V closures GC-visible and keep trampolines only for C ABI coercions. I do not think it is a drop-in alternative for this PR, though. This PR intentionally fixes the leak under the existing closure representation. Fat closures would require changing fn value representation/calling convention, Cgen call lowering, C FFI coercions, -gc none/-autofree ownership, bootstrap, and eventually native backend support. Given where the V1/C backend is in its lifecycle, I would prefer not to block this scoped fix on a much larger closure ABI/codegen redesign. My preference would be land the current fix as an interim unblocker, and treat fat closures as a separate staged RFC/implementation, probably aligned with future V2 ownership/autofree work. If/when fat closures land, the manual lifetime/reclaim API can be removed or deprecated. |
Summary
This rescues the closure leak fix from vlang#27446 with a smaller, scoped patch.
Captured closure contexts now use collectable
memdupinstead ofmemdup_uncollectable, while the closure runtime keeps live contexts reachable through a scanned table. Local captured closures that do not escape are cleaned up when their scope is left, including normal scope exit,return, and labeled/non-labeledbreak/continue.The cleanup is conservative: closures are not destroyed when they escape through return values, copies, function arguments, struct fields, globals, defer blocks,
spawn, orgo.Changes
closure_create_with_data.Tests