Skip to content

fix(hy-check): scope aliases across blocks, break alias cycles, and reject same-stmt double moves (#31) - #32

Merged
limitlessprojects merged 1 commit into
limitlessprojects:mainfrom
carelessdept:fix/scoped-aliases-and-double-move-soundness
Oct 15, 2026
Merged

limitlessprojects merged 1 commit into
limitlessprojects:mainfrom
carelessdept:fix/scoped-aliases-and-double-move-soundness

Conversation

@carelessdept

Copy link
Copy Markdown
Contributor

Fixes #31
Participates in #5

Problem

  1. Unscoped FnState.aliases wiped by block shadowing: Commit 2e79213 ([soundness] inner block shadowing hides an outer map from the task sendability check #14) scoped FnState.env via FnState.scopes, but FnState.aliases remained a flat HashMap<String, String>. An inner shadow if true { m2 := 1 } called st.aliases.remove("m2"), permanently erasing the outer m2 -> m alias link so moving m afterward left outer m2 unfrozen.
  2. Mutual alias rebind cycle (m2 := m; m = m2): process_assign inserted "m" -> "m2" while "m2" -> "m" was still present. Because resolve_alias stepped a fixed 16 iterations, resolve_alias(st, "m") == "m" and resolve_alias(st, "m2") == "m2", causing mark_move to miss m2 when m was moved.
  3. Same-statement double-move / move+read (task both(move m, move m), a, b := move m, move m, a, b := move m, m): check_uses ran once before statement move marking and did not track intra-statement moves on the same alias group, allowing a single statement to duplicate or concurrently share a moved map with 0 diagnostics.

Fix

  • compiler/crates/hy-check/src/model.rs:
    • Add alias_scopes: Vec<HashMap<String, String>> to FnState (saved on scope_push, restored on scope_pop with freeze synchronization across restored alias groups).
    • Add FnState::detach_alias_binding to cleanly re-parent dependent aliases when a binding is shadowed or rebound.
  • compiler/crates/hy-check/src/freeze.rs:
    • Make resolve_alias cycle-canonical and track intra-statement move transfers in check_uses so double-moves and same-statement move+read emit HYB-E3003 (A1b).
  • compiler/crates/hy-check/src/loans.rs:
    • Canonicalize alias roots on define/assign, call detach_alias_binding, and propagate prior moved state across multi-defines/rebinds.
  • compiler/crates/hy-check/src/lib.rs:
    • Pop remaining scopes via scope_pop() at function exit and add regression tests (shadow_scope_does_not_wipe_outer_alias_e3003, mutual_alias_rebind_cycle_still_freezes_on_move_e3003, same_statement_double_move_and_move_plus_read_reject_e3003).

Verification

  • cargo test -p hy-check — 53/53 unit tests + 2/2 spike6 tests pass.
  • python3 tools/corpus_harness.py --bin compiler/target/debug/hyb — 24/24 verdict agreement, tripwire not fired.

@limitlessprojects

Copy link
Copy Markdown
Owner

PR #32 (issue #31: shadowed outer alias roots survive block scope) — triage update:

Verified on current main (b4c6a68): the repro still accepts with 0 diagnostics, so the underlying gap is REAL and this report stands.

Why it is not merged yet: main's alias/freeze machinery moved substantially since this PR's base (record_alias for call-return aliases #38, may-share edges for #27, the non-owned-move guard, parallel pre-state assignment evaluation, multi-event scoping). The PR now conflicts in every touched region of loans.rs/model.rs, and merging it as-is would silently revert those seams.

Path forward (maintainer): rebase onto current main and re-apply the fix on top of the new recorders — the repro tests are the acceptance bar, plus cargo/corpus/differential green. The report keeps its bounty standing; this is a rebase ask, not a rejection.

@carelessdept

Copy link
Copy Markdown
Contributor Author

@limitlessprojects Updated (71518b1) so the branch merges cleanly (MERGEABLE, 0 conflicts) onto current main (8fb9238).

  • Composes with main's ScopeEvent push/pop and record_alias: scope_push/scope_pop now snapshot and restore aliases across block boundaries (preventing shadowed inner variables from polluting outer alias graphs), record_alias avoids self-loop edges and records symmetric edges for mutual alias cycles, and record_moves rejects same-statement duplicate moves (f(move m, move m) / f(move m, move m2)) with HYB-E3003 (A1b).
  • Verified on merged main: cargo test --manifest-path compiler/Cargo.toml -p hy-check (104/104 tests green) and python3 tools/corpus_harness.py (27/27 corpus agreement, tripwire not fired).

…, and reject same-statement double moves (limitlessprojects#31)

Maintainer-assisted rebase onto 8fb9238 (the pr-35/pr-49/pr-56/pr-59/pr-61 seam).

Verified on main before the rebase — three of the four holes still reproduce:
shadowed-define wipes the outer alias link (u1: if { m2 := 1 } unfixes m2->m),
same-statement double-move (u3: task both(move m, move m) accepts), and
same-statement move-plus-read (u4: a, b := move m, m accepts). The mutual-
rebind cycle (u2) already rejects on main via the pr-35 may-share edges, and
the shadowed-root variant (u5) likewise — the PR's tests now pin both.

Seam resolution: the PR's machinery applies as authored (alias_scopes
snapshots, scope-pop move propagation, cycle-canonical resolve_alias,
same-statement stmt_moves in check_uses), extended symmetrically for the
seam's SECOND freeze map — may_share gets the same snapshot/restore
discipline (share_scopes), because main's freeze verdicts ride pr-35's
share edges and the shadow-define's share_clear must not survive the block
either.

Tests: +3 (shadow-scope alias survival, cycle freeze, same-statement moves
incl. the shadowed-root variant); verified on the rebased commit: cargo
293/0, clippy 0, corpus 27/27, differential FULL, examples 10/10.
@limitlessprojects
limitlessprojects force-pushed the fix/scoped-aliases-and-double-move-soundness branch from 71518b1 to 249f253 Compare October 15, 2026 03:53
@limitlessprojects

Copy link
Copy Markdown
Owner

Maintainer-assisted rebase landed — the branch now sits on current main (8fb9238) as commit 249f253, force-pushed so CI runs against the real seam.

Verified on main before the rebase — three of your four holes still reproduce:

  1. shadowed define wipes the outer alias link (if true { m2 := 1 } unfixes m2 -> m and the later move m leaves m2 live) — silent accept
  2. same-statement double-move (task both(move m, move m)) — silent accept
  3. same-statement move-plus-read (a, b := move m, m) — silent accept

The mutual-rebind cycle (m2 := m; m = m2) and the shadowed-root variant already reject on main — the pr-35 may-share edges catch them — and your tests now pin both behaviors.

Seam resolution: your machinery applies as authored (alias-scope snapshots, scope-pop move propagation, cycle-canonical resolve_alias, the same-statement stmt_moves pass in check_uses), extended symmetrically for the seam's second freeze map — may_share now gets the same snapshot/restore discipline (share_scopes), since main's freeze verdicts ride pr-35's share edges and a shadowing define's share_clear must not survive the block either.

Verified on the rebased commit: cargo 293/0 · clippy 0 · corpus 27/27 · differential FULL (10/10 + 17/17) · examples 10/10.

The report remains bounty-standing — confirmed at triage, now closed by your work.

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.

[soundness] Unscoped FnState.aliases wiped by block shadowing, mutual alias rebind cycles, and same-statement double moves bypass O5.1/O5.2 freeze

2 participants