Skip to content

Move checker: partial (field) move on a divergent branch wrongly poisons the fall-through #695

Closed

Description

@ehartford

Pre-existing latent precision bug in the move/borrow checker, found while inventorying #691 (it surfaces at ~140 compiler-source sites once POD Vecs need drop, but reproduces on the shipped compiler with any Drop-bearing field).

Repro (shipped compiler, exit 1)

type D { id: i32 }
impl Drop for D:
    fn drop(move self: Self): ()
type B { d: D, n: i32 }
fn pick(cond: bool) -> D:
    var b = B { d: D { id: 1 }, n: 0 }
    if cond:
        return b.d       // moves b.d ONLY on the returning (divergent) branch
    b.d                  // ERROR: use of moved value  — but this path never took the move
fn main:
    print_i32(pick(false).id)

error: use of moved value at the fall-through b.d.

Root cause

The checker handles whole-value divergent moves correctly — the identical shape with a local (return v then use v) compiles and runs. It's specifically partial (field) moves through a divergent branch: return b.d inside if cond: marks b.d moved, and the move is (incorrectly) considered live on the fall-through even though the branch that performed it returns (diverges). A precise analysis knows the move cannot reach past a divergent terminator.

Why it matters

Fix direction

In the move/borrow dataflow, a move performed on a path that ends in a divergent terminator (return/break-out/panic/unreachable) must not propagate the moved-state to the join with the non-diverging paths. Same treatment the whole-value case already gets — extend it to projected (field/index) place moves. Repro becomes a behavior fixture; add the whole-value control case alongside so the two stay pinned together.

Activity

  1. ehartford commented on Jul 21, 2026

    @ehartford
    ContributorAuthor

    Follow-up landed in ee4e5f4: beyond the original divergent-branch poisoning, the branch-merge of the partial-move set (set_moved_field_union) concatenated instead of dedup'ing — a field moved on both arms was re-added at every merge, growing the moved-field arrays ~2^N across nested branches (~100 GB compile under the #691 flip). Fixed with a membership check before union; pinned by test/behavior/behav_nested_branch_field_moves.w and guarded by the new tools/move_audit.w matrix.

  2. ehartford commented on Aug 31, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-08-31: CLOSE (overcome by events). Fixed by 2f330e5 "divergence-aware branch merge for the partial-move set (#695)" + ee4e5f4. The D32-legal respelling (explicit move b.d on the divergent branch and fall-through) compiles and runs correctly; the original repro's implicit spelling is separately a D32 §2.2 compile error now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions