Repository navigation
A generator's yielded value and its temporaries before a yield are given back - #620
Merged
Merged
Conversation
…ven 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>
…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>
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.
Follow-up to #619. That PR left three cases leaking. This handles them:
const n = ("b"+i).length; if (n > 0) { yield n; }), 500000 runsyield "a" + iyield new C(i)own/own_generator.tsChanges (all in
OwnedReturnConsumptionPassunless noted)releaseRangeEndnow stops at the first op that is a yield or resume point, or that has one inside it. The release goes in front of that op.retainYieldedRecordsretains the{value, done}record before eachts.YieldReturnVal, the way a return statement does (§9.24). The record then owns its fields, and a fresh value made for it is an ordinary temporary released before the yield. Under own the value still moves into the record, and the store rule (escapesThroughStore) stays for every model except rc.functionReturnsOwnedclassifies a generator'snextlike any function, with yields counted as returns.calleeNameOfresolvesnextread out of a field of the state object that only ever holds it. The map isown_facts::FieldFunctions, moved out ofOwnershipSignaturePass(own's behavior is unchanged), so the caller takes the record over.Side effect worth a look
Under rc, a module with a generator (including any
.map/.filter, which MLIRGen builds as generators) used to count as having an unclassified owning return. That kept the whole-module rule (closedWorld) off for it. Now it can be on, so calls through plain values in those modules take over their results, following the +1 convention. The full suite agrees.Tests
00generator_temporaries.tsgainsitems(yield new Item),next()called by hand and kept past the next call, and a declared C function, so the whole-module rule can't stand in for the field resolution.generator-temporaries.cmakechecks:ifinbranchYield;nextcall inmainwhose record holds a heap value takes it over. This fails when the field resolution is turned off (checked).stringsstill keeps the concatenation and passes the verifier.ctest -C Release -j 16: 4767/4767 pass.Not done: no DefaultLib rc rebuild with this compiler. Nothing about how calls cross a library boundary changes: the caller's takeover needs the state object's constant in its own module, which an imported generator never has, so such a call leaks as before rather than being freed early.
Separate bug found:
("a" + i) + (yield 1)crashes the compiler in every model (proposed as its own task).🤖 Generated with Claude Code