Skip to content

validate-ownership: a statement move of an already-moved place is rejected; the drop-state lattice keeps "maybe moved" apart from "maybe uninitialized" (#1414) - #1525

Merged
ehartford merged 1 commit into
fix-1429-emit-c-global-typefrom
fix-1414-move-of-moved-place
Sep 23, 2026
Merged

ehartford merged 1 commit into
fix-1429-emit-c-global-typefrom
fix-1414-move-of-moved-place

Conversation

@ehartford

@ehartford ehartford commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

A failed match guard's arm bound _5 = move _3<as v0>.f0, dropped _5,
and the next arm bound _12 = move _3<as v0>.f0 again: run --debug-alloc
reported DOUBLE FREE (size=512 origin=Vec) and --validate-all said ok
(#1394 fixed the lowering; the validator still had no rule). The natural
rule — reject an OK_MOVE of a drop-bearing place whose state is Moved or
Maybe — was tried in #1394 and reverted: Maybe was the join of any two
different states, so "moved on some path" and "never written on some path"
were one state, and every match result temp (_16 = move _18 in one arm,
the unreachable no-arm path leaving _16 Uninit, _14 = move _16 at the
join) looked like a double move.

The lattice gains MaybeMoved: the join of two different states where one
of them is Moved or MaybeMoved. Maybe keeps meaning "paths disagree and
none moved it". Consumers that read Maybe treat MaybeMoved alike: the drop
plan still says conditional, and the vacated-sub-place rule (#1394)
ranks both 1, so its verdicts do not move. mir_elaborate_dead_drops keys
only on Moved and is unchanged; codegen reads none of these states, so no
generated code changes.

The rule (mir_move_of_moved_place, run on every Assign's rvalue operands
before the transfer): an OK_MOVE whose place is Moved or MaybeMoved, and
whose type is drop-bearing (sema_moved_drop_types, which now snapshots
every moved place's type, not only projected ones), is "move of X, which a
path reaching it already moved out (state) and nothing re-initialized: two
owners free one value". A place that is only Maybe is not judged; moves of
Copy values are not judged.

Call arguments are not judged yet. As first written the rule judged them
too, and rejected three legal programs: spec_ss09_9_the_in_operator (ch in s), behav_index_place_user (IndexPlace get/set in g[i] += 100) and
spec_ss13_4_no_references_across_yield (a generator's next()). Each
lowering passes a receiver the callee borrows as an OK_MOVE argument, and
each runs clean under the debug allocator; the MIR says move where the ABI
borrows (#1505). The terminator arm waits for that.

Sweep: check --validate-all over test/, examples/ and lib/std (3188
files), base stage2 (main f1e3bd2) vs this stack's stage2. The rule
rejects two files that passed, both real: behav_for_comprehension.w and
spec_ss13_6a_option_and_result_for_comprehensions.w, whose
for-comprehension over Result moves the failed carrier twice (_14 = move _8; _15 = move _8, then drop(_15)); with a heap Err payload run --debug-alloc reports DOUBLE FREE (#1504). Nothing else is newly rejected.

Unit fixture (MirValidationTests.mir_test_move_of_moved_place,
test/internals/mir_move_of_moved_place_test.w), a two-arm body:
moved on one arm, moved again at the join -> MaybeMoved, rejected
moved on one arm and re-initialized there -> ok
moved twice on one path (the failed-guard shape) -> Moved, rejected
written on one arm only, moved at the join -> Maybe, ok
moved on one arm, passed by move to a call -> not judged (#1505)
the first shape with a value that has no drop glue -> ok
mir_test_vacated_payload_drop's expectation names the child's state
MaybeMoved, which is what it is.

Closes #1414

Stack #1528, bottom to top: #1522 (#1411) → #1523 (#1413) → #1524 (#1429) → #1525 (#1414) → #1526 (#1372) → #1527 (#1417). Each layer holds only its own commit.

Verification (iterate tier; no battery yet — draft until the seed-driven battery is green): stage1 and stage2 built from the stack top on darwin-aarch64 (SDKROOT CLT 15.4) and on native Windows 10 x64; fixtures below pass on both; check --validate-all swept over test/, examples/, lib/std (3188 files) with base stage2 (main f1e3bd2) vs the stack's stage2.

@ehartford

Copy link
Copy Markdown
Contributor Author

Stack #1528 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main + #1522 → … → #1527 (head 33e6ba5; every PR head is a tested commit): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Merges cleanly into main. Merge the stack: gh stack merge 1527 --squash.

@ehartford
ehartford marked this pull request as ready for review September 23, 2026 16:45
…ected; the drop-state lattice keeps "maybe moved" apart from "maybe uninitialized" (#1414)

A failed match guard's arm bound `_5 = move _3<as v0>.f0`, dropped `_5`,
and the next arm bound `_12 = move _3<as v0>.f0` again: `run --debug-alloc`
reported DOUBLE FREE (size=512 origin=Vec) and `--validate-all` said ok
(#1394 fixed the lowering; the validator still had no rule). The natural
rule — reject an OK_MOVE of a drop-bearing place whose state is Moved or
Maybe — was tried in #1394 and reverted: `Maybe` was the join of any two
different states, so "moved on some path" and "never written on some path"
were one state, and every match result temp (`_16 = move _18` in one arm,
the unreachable no-arm path leaving `_16` Uninit, `_14 = move _16` at the
join) looked like a double move.

The lattice gains MaybeMoved: the join of two different states where one
of them is Moved or MaybeMoved. Maybe keeps meaning "paths disagree and
none moved it". Consumers that read Maybe treat MaybeMoved alike: the drop
plan still says `conditional`, and the vacated-sub-place rule (#1394)
ranks both 1, so its verdicts do not move. mir_elaborate_dead_drops keys
only on Moved and is unchanged; codegen reads none of these states, so no
generated code changes.

The rule (mir_move_of_moved_place, run on every Assign's rvalue operands
before the transfer): an OK_MOVE whose place is Moved or MaybeMoved, and
whose type is drop-bearing (sema_moved_drop_types, which now snapshots
every moved place's type, not only projected ones), is "move of X, which a
path reaching it already moved out (state) and nothing re-initialized: two
owners free one value". A place that is only Maybe is not judged; moves of
Copy values are not judged.

Call arguments are not judged yet. As first written the rule judged them
too, and rejected three legal programs: spec_ss09_9_the_in_operator (`ch in
s`), behav_index_place_user (IndexPlace get/set in `g[i] += 100`) and
spec_ss13_4_no_references_across_yield (a generator's `next()`). Each
lowering passes a receiver the callee borrows as an OK_MOVE argument, and
each runs clean under the debug allocator; the MIR says move where the ABI
borrows (#1505). The terminator arm waits for that.

Sweep: `check --validate-all` over test/, examples/ and lib/std (3188
files), base stage2 (main f1e3bd2) vs this stack's stage2. The rule
rejects two files that passed, both real: behav_for_comprehension.w and
spec_ss13_6a_option_and_result_for_comprehensions.w, whose
for-comprehension over Result moves the failed carrier twice (`_14 = move
_8; _15 = move _8`, then `drop(_15)`); with a heap Err payload `run
--debug-alloc` reports DOUBLE FREE (#1504). Nothing else is newly rejected.

Unit fixture (MirValidationTests.mir_test_move_of_moved_place,
test/internals/mir_move_of_moved_place_test.w), a two-arm body:
  moved on one arm, moved again at the join        -> MaybeMoved, rejected
  moved on one arm and re-initialized there         -> ok
  moved twice on one path (the failed-guard shape)  -> Moved, rejected
  written on one arm only, moved at the join        -> Maybe, ok
  moved on one arm, passed by move to a call        -> not judged (#1505)
  the first shape with a value that has no drop glue -> ok
mir_test_vacated_payload_drop's expectation names the child's state
MaybeMoved, which is what it is.
@ehartford
ehartford force-pushed the fix-1414-move-of-moved-place branch from 7659953 to 0b18174 Compare September 23, 2026 19:40
@ehartford
ehartford removed this pull request from stack #1528 September 23, 2026 19:43
@ehartford
ehartford added this pull request to stack #1563 September 23, 2026 19:43
@ehartford
ehartford merged commit be46ccd into main Sep 23, 2026
@ehartford
ehartford deleted the fix-1414-move-of-moved-place branch September 24, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

validate-ownership is silent on a move out of an already-moved place (guarded match arm double free passed)

1 participant