You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Move checker: value moved BEFORE a loop is wrongly flagged at the loop's back-edge #696
Pre-existing latent move-checker imprecision (the loop sibling of #695), found inventorying #691's flip. Reproduces on the shipped compiler with any Drop-bearing value.
Repro (exit 1)
type D { id: i32 }
impl Drop for D:
fn drop(move self: Self): ()
fn consume(d: D): ()
fn f(n: i32):
let fresh = D { id: 1 }
consume(move fresh) // moved BEFORE the loop, never used inside it
for i in 0..n:
if i > 0:
continue // ERROR: `fresh` is moved inside a loop and not reinitialized
let _x = 0
error: use of moved value: fresh is moved inside a loop and not reinitialized before the loop repeats at the continue.
Root cause
The loop move-state check (finalize_loop_move_state) flags any variable that is MOVED-and-not-reinitialized at a loop back-edge (continue / end-of-body). But fresh is moved before the loop and is neither used nor moved inside it — it is not loop-carried, so it has no bearing on iteration. The check must only consider variables that are moved WITHIN the loop body (or live-and-moved across the back-edge), not values already moved on entry to the loop.
Why it matters
Correctness on the shipped compiler: a legal "move a value, then loop" pattern is rejected.
Dominant cluster of the Campaign: the wide flip — containers own their buffers (POD-element drop elaboration) #691 wide-flip migration: the compiler's own codegen (mir_emit_function etc.) sets up let fresh_x = Vec.new(); self.x = fresh_x before per-parameter loops with continue. Once the flip makes Vec need drop, ~105 of the flip's ~127 error sites are exactly this false positive. Fixing it here dissolves that cluster.
Fix direction
At the loop back-edge move-state check, restrict the "moved-not-reinitialized" diagnostic to variables whose move occurred inside the loop body (loop-carried), excluding those already in the moved state at loop entry. Repro becomes a behavior fixture; add a genuine loop-carried-move case that MUST still error, to pin the boundary.
Root cause (proven at the instruction level, not inferred). The move checker computes "moved across this edge without reinit?" separately at each loop back-edge, and the two implementations had drifted:
check_loop_continue_carried_move (continue back-edge): fired on cur[i]==MOVED && needs_drop — missing the entry==LIVE guard.
The continue check never had the loop-entry snapshot, so it could not distinguish "moved before the loop" from "moved inside it." A WITH_TRACE_MOVE run on the repro confirmed it directly: for fresh, entry=MOVED(1) at_continue=MOVED(1) → old_verdict=1 (fired) new_verdict=0 (suppressed).
This shipped in #613 (1ee372c) with zero tests for the diagnostic. It is not flip-specific — a plain Drop struct moved before a for/while/loop with a continue reproduces it on the shipped seed, no Vec involved.
Fix. Capture the loop-entry move-state per frame (loop_entry_flat, parallel to loop_break_flat, sharing label_break_off) at alloc_loop_break_region, and apply the same entry==LIVE guard in the continue check. One change covers all three loop constructs (they share the continue path).
Regression coverage.
test/behavior/behav_loop_move_before_continue.w — the false positive now compiles.
test/behavior/loop_carried_move_via_continue.w — a genuine continue-carried move still errors.
Activity
ehartford commentedon Jul 21, 2026
Fixed in ee4e5f4.
Root cause (proven at the instruction level, not inferred). The move checker computes "moved across this edge without reinit?" separately at each loop back-edge, and the two implementations had drifted:
finalize_loop_move_state(fall-through back-edge): fires onentry[i]==LIVE && cur[i]==MOVED && needs_drop✓check_loop_continue_carried_move(continueback-edge): fired oncur[i]==MOVED && needs_drop— missing theentry==LIVEguard.The continue check never had the loop-entry snapshot, so it could not distinguish "moved before the loop" from "moved inside it." A
WITH_TRACE_MOVErun on the repro confirmed it directly: forfresh,entry=MOVED(1) at_continue=MOVED(1) → old_verdict=1 (fired) new_verdict=0 (suppressed).This shipped in #613 (1ee372c) with zero tests for the diagnostic. It is not flip-specific — a plain Drop struct moved before a
for/while/loopwith acontinuereproduces it on the shipped seed, noVecinvolved.Fix. Capture the loop-entry move-state per frame (
loop_entry_flat, parallel toloop_break_flat, sharinglabel_break_off) atalloc_loop_break_region, and apply the sameentry==LIVEguard in the continue check. One change covers all three loop constructs (they share the continue path).Regression coverage.
test/behavior/behav_loop_move_before_continue.w— the false positive now compiles.test/behavior/loop_carried_move_via_continue.w— a genuine continue-carried move still errors.tools/move_audit.w(with build :move-audit, e8faa1a) — a move-checker verdict matrix that flags exactly this class of per-edge drift; it caught that the bug hit for/while/loop and would have caught it the day Loop maybe-init dataflow: accept reinit (§2.4) and move-then-break; reject only genuine use-after-move #613 landed.Verified: full battery green (build, fixpoint, audit:all, move-audit, drop-audit, test, test-green, last-green).
Sema: correct loop-carried move checking — continue back-edge guard (#…
Build: move-checker verdict audit matrix (:move-audit) + fix drop-aud…
Sema: single loop back-edge carried-move predicate (kills the #696 cl…