Repository navigation
MIR: a yield drops its statement temporaries before suspending; the next-body transform keeps a Drop's place (#1412) - #1555
Merged
ehartford merged 1 commit intoSep 24, 2026
Conversation
Contributor
Author
|
Audits on this layer's stage1 (candidate = stack top before the rebase onto 3cda6eb; baseline = pinned seed): drop-audit 201 cells, 0 non-PASS, 0 regressions vs baseline (generator_yield_{full,stop} FIXED: DOUBLE-FREE on the seed, PASS here; async_await_inferred FIXED); move-audit 105 cells, 0 vs-expected FAIL. All 20 new fixtures of the stack pass on the rebased top's stage1. |
…ext-body transform keeps a Drop's place (#1412) §13.4: a `gen fn` suspends at each `yield`; lower_generator_next_body saves the generator's named locals into its state and returns, and a later next() restores them and resumes. Two lines put drops on the wrong path or the wrong place. 1. lower_generator_yield lowered the yielded expression and terminated with TK_YIELD, leaving the yield statement's temporaries to the statement's own flush — which runs after the yield, on the resume path of the next call, where nothing initialized them. `--validate-ownership` on the issue's nebula shape: "drop of _9 reaches a path that never initialized it (Uninit)"; `--dump-mir`: the resume target block `bb11: drop(_9) @ drop#10 scope-exit _8` for `fmt_to_str(i)`'s part of `f"dev-{i}"`. At runtime `yield f"n{i}"` in a while loop was a DOUBLE FREE under the debug allocator. Fix: the yield expression is lowered in its own statement-temp frame; the value moves into a local of its own, then the frame's temps drop and its reset-on-move blanks flush on the suspending path, before the state is saved (so a `let w … yield w` saves a blank, not a second owner of the str the caller received). 2. lower_generator_next_body remapped a Drop statement's operand through the local map (`sd0 = mir_gen_remap_local(&local_map, sd0)` for StorageLive, StorageDead AND Drop). A Drop names a PLACE; places are copied one for one with their base locals remapped, so every Drop in a generator body dropped whichever place came next: `_5 = move _10; drop(_10) @ drop#6 scope-exit _7` — the origin names the temp `_7` the drop was for, the statement frees `_10`, the str the yield hands to the caller (`let w = f"w{i}"; yield w`: DOUBLE FREE; the temp leaked). Only StorageLive/StorageDead are remapped now. Matrix (12 shapes, base = origin/main ba2d5d1 stage1 -> fixed, all `--validate-ownership: ok` fixed): while + `yield f"n{i}"` DOUBLE FREE -> 6 clean; struct yield with an f-string field 15 (validator error -> ok); `yield label(i) ++ "-" ++ label(i+1)` (validator error -> ok); `let w = f"…"; yield w` DOUBLE FREE -> w0 w1 w2; two yields per iteration "code generation failed" -> a0 b0! a1 b1!; yields in both arms of an if DOUBLE FREE -> e0! o1 e2! o3; early `break` in the consumer DOUBLE FREE -> clean; int yields unchanged (14, 5); the existing §13.4 fixtures pass. Still wrong, filed: #1534 — a `for` loop in a generator loses its counter at the yield (the nebula generator, `for i in 0..count`, still panics with integer overflow on resume: no local but the named lets is carried); #1548 — a named owned local that stays live across the yield is freed by the body's scope exit and again by the state's drop; #1539 — the ownership validator accepts a drop of a Moved place (it said ok over line 2's double free). Fixtures: behav_generator_yield_temps.w (exact stdout; base fails to build), da_generator_yield_temps.w (base DOUBLE FREE). Drop audit gains generator_yield_{full,stop} (an R yielded beside an f-string temp; base DOUBLE FREE, fixed 3 and 1).
ehartford
force-pushed
the
fix-1412-generator-yield-temps
branch
from
September 23, 2026 21:39
f455efa to
77368cf
Compare
Contributor
Author
|
Battery green — ownership stack #1549 → #1555 (top 77368cf, rebased onto main 02301f8, no diff change), driven by the pinned seed with a cold c_import cache: Ready to merge: |
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.
Draft: layer 7 of 7 in the ownership/leaks stack (batch battery pending; iterate tier +
:drop-audit/:move-auditon the layer's stage1 done locally). Closes #1412. Filed on the way: #1534, #1539, #1548.Audits (tools/drop_audit.w + tools/move_audit.w, candidate = this layer's stage1, baseline = the pinned seed): drop-audit/move-audit running on this layer's stage1 (results posted when done); generator_yield_{full,stop} verified by hand (base DOUBLE FREE, fixed 3/1).
MIR: a yield drops its statement temporaries before suspending; the next-body transform keeps a Drop's place (#1412)
§13.4: a
gen fnsuspends at eachyield; lower_generator_next_body savesthe generator's named locals into its state and returns, and a later
next() restores them and resumes. Two lines put drops on the wrong path or
the wrong place.
lower_generator_yield lowered the yielded expression and terminated with
TK_YIELD, leaving the yield statement's temporaries to the statement's
own flush — which runs after the yield, on the resume path of the next
call, where nothing initialized them.
--validate-ownershipon theissue's nebula shape: "drop of _9 reaches a path that never initialized
it (Uninit)";
--dump-mir: the resume target blockbb11: drop(_9) @ drop#10 scope-exit _8forfmt_to_str(i)'s part off"dev-{i}".At runtime
yield f"n{i}"in a while loop was a DOUBLE FREE under thedebug allocator. Fix: the yield expression is lowered in its own
statement-temp frame; the value moves into a local of its own, then the
frame's temps drop and its reset-on-move blanks flush on the suspending
path, before the state is saved (so a
let w … yield wsaves a blank,not a second owner of the str the caller received).
lower_generator_next_body remapped a Drop statement's operand through
the local map (
sd0 = mir_gen_remap_local(&local_map, sd0)forStorageLive, StorageDead AND Drop). A Drop names a PLACE; places are
copied one for one with their base locals remapped, so every Drop in a
generator body dropped whichever place came next:
_5 = move _10; drop(_10) @ drop#6 scope-exit _7— the origin names the temp_7thedrop was for, the statement frees
_10, the str the yield hands to thecaller (
let w = f"w{i}"; yield w: DOUBLE FREE; the temp leaked).Only StorageLive/StorageDead are remapped now.
Matrix (12 shapes, base = origin/main ba2d5d1 stage1 -> fixed, all
--validate-ownership: okfixed): while +yield f"n{i}"DOUBLE FREE ->6 clean; struct yield with an f-string field 15 (validator error ->
ok);
yield label(i) ++ "-" ++ label(i+1)(validator error -> ok);let w = f"…"; yield wDOUBLE FREE -> w0 w1 w2; two yields per iteration"code generation failed" -> a0 b0! a1 b1!; yields in both arms of an if
DOUBLE FREE -> e0! o1 e2! o3; early
breakin the consumer DOUBLE FREE ->clean; int yields unchanged (14, 5); the existing §13.4 fixtures pass.
Still wrong, filed: #1534 — a
forloop in a generator loses its counterat the yield (the nebula generator,
for i in 0..count, still panics withinteger overflow on resume: no local but the named lets is carried);
#1548 — a named owned local that stays live across the yield is freed by
the body's scope exit and again by the state's drop; #1539 — the
ownership validator accepts a drop of a Moved place (it said ok over
line 2's double free).
Fixtures: behav_generator_yield_temps.w (exact stdout; base fails to
build), da_generator_yield_temps.w (base DOUBLE FREE). Drop audit gains
generator_yield_{full,stop} (an R yielded beside an f-string temp; base
DOUBLE FREE, fixed 3 and 1).