Repository navigation
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 intoSep 23, 2026
Conversation
This was referenced Sep 23, 2026
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: |
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
force-pushed
the
fix-1414-move-of-moved-place
branch
from
September 23, 2026 19:40
7659953 to
0b18174
Compare
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.
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>.f0again:run --debug-allocreported DOUBLE FREE (size=512 origin=Vec) and
--validate-allsaid 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:
Maybewas the join of any twodifferent states, so "moved on some path" and "never written on some path"
were one state, and every match result temp (
_16 = move _18in one arm,the unreachable no-arm path leaving
_16Uninit,_14 = move _16at thejoin) 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 ing[i] += 100) andspec_ss13_4_no_references_across_yield (a generator's
next()). Eachlowering 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-allover test/, examples/ and lib/std (3188files), 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, thendrop(_15)); with a heap Err payloadrun --debug-allocreports 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-allswept over test/, examples/, lib/std (3188 files) with base stage2 (main f1e3bd2) vs the stack's stage2.