Repository navigation
A generator body's temporaries are released before the yield - #619
Merged
Merged
Conversation
OwnedReturnConsumptionPass skipped whole generators when releasing discarded owned
temporaries, so under rc and own `yield ("a" + i).length` leaked the number's string
and the concatenation on every call (500000 runs: 165 MB; now 4.4 MB).
A temporary in a generator is now released right before the first yield after it in
its block, when no resume point is nested between it and that yield, every user comes
before it, and neither it nor a view of it is stored (the yielded record's field store
takes no count, so `yield "a" + i` stays as it was). Everything else still leaks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Oct 19, 2026
…ven back (#620) * A generator's yielded value and its temporaries before a yield are given back Two leaks left after #619: - A temporary made in front of a statement with a yield inside it (`const n = ("b" + i).length; if (n > 0) { yield n; }`) was never released, under rc and own: 165 MB over 500000 runs, now 4.4 MB. The release now goes in front of the first yield, resume point or statement holding one, where the definition still dominates. - Under rc a yielded value (`yield "s" + i`, `yield new C(i)`) kept the reference it was born with: 50 MB over 500000 runs, now 4.4 MB. A yield now retains its `{ value, done }` record the way a return does, a generator's `next` is classified as returning owned, and its caller takes the record over: `next` is resolved through the state object's field that only ever holds it (own_facts::FieldFunctions, moved out of OwnershipSignaturePass). own already moved the value into the record. A temporary used after a yield cannot occur: MLIRGen keeps a generator's locals in its state object. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Generator temporaries test: the caller's takeover is checked through the field, not the closed world A declared C function in the file keeps a call through a plain value from being taken as owned by the whole-module rule, so the main check fails when the field resolution is turned off (checked). Comments and the own spec's found-not-fixed list updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OwnedReturnConsumptionPassskipped whole generators when it released discarded owned temporaries (spec 18.5), so under-mm=rcand-mm=ownevery temporary in a generator body leaked.yield ("a" + i).length, iterated 500000 times, grew by about 165 MB. The same code in a plain function stays flat.Fix
A temporary in a generator is now released right before the first
ts.YieldReturnValafter it in its block. That release runs before the state machine's cut, so it stays dominated by the definition. It applies only when:ts.StateLabelis nested in a statement between the temporary and that yield,ts.Store. The yielded{value, done}record's field store takes no count, soyield "s" + imust keep its +1.Every other case still leaks, as before.
Results
tests/00generator_temporaries.ts(default jit/compile, rc/none corpus, own jit/compile) and the IR checktest-rc-generator-temporaries. The IR check fails on the old compiler, and it also runs--verify-ownershipunder own.ctest -C Release -j 16: 4757/4757 pass, including own_generator*.🤖 Generated with Claude Code