Skip to content

checker: freeze all may-share aliases on move (fix #27) - #35

Merged
limitlessprojects merged 1 commit into
limitlessprojects:mainfrom
Ratanlavate:fix/27-shallow-copy-aliases-freeze
Oct 14, 2026
Merged

limitlessprojects merged 1 commit into
limitlessprojects:mainfrom
Ratanlavate:fix/27-shallow-copy-aliases-freeze

Conversation

@Ratanlavate

Copy link
Copy Markdown
Contributor

What

Fixes #27 — a move now freezes every binding that may share mutable GC storage with the moved value, not just the single-parent alias chain.

Three soundness gaps closed:

  • is_reference_alias() only classified Map/Slice/Pointer as aliases. A struct or array that carries a reference field/element is copied by value in Go, but the reference interior is shared — the freeze rule missed it.
  • Alias recording only matched a bare Expr::Ident RHS, so shallow copies / re-slices / projections / composite literals were never recorded.
  • mark_move froze only the old single-parent aliases component, leaving those peers live.

Changes

  • model.rs — FnState::may_share (undirected graph) + share_edge / share_clear / share_group; cleared on redefine/rebind.
  • shape.rs — Checker::shape_may_share(): true for map/slice/pointer (via is_reference_alias), recurses transitively into Struct/Array; bounded depth.
  • loans.rs — binding_may_share / record_may_share / record_literal_ref, called from process_local and process_assign. Handles all four reported forms:
    1. h2 := h1 — shallow struct/array copy of a reference-bearing value
    2. (shared), s2 := s1[:] — parenthesized / re-sliced RHS
    3. m2 := h1.m, m2 := arr[i] — field/index projection
    4. h := holder{m: agg} — composite literal capturing a live binding
  • freeze.rs — mark_move unions the may-share component; emit_use_after_move treats a use as an alias if it is in aliases or may_share.

Why this is safe

  • Additive: the old aliases path is unchanged for plain reference-typed ident copies, so existing diagnostics/wording and all current corpus verdicts are preserved.
  • Conservative depth guard (16) for pathological/recursive struct shapes; no claim made for Unknown.
  • Only locals/params seed edges (no const involvement).

Verification

Repro (from the issue): h2 := h1; task worker(move h1); h2.m["k"] = ...

case before after
struct shallow copy (d01) accept → Go -race: DATA RACE + concurrent map writes reject HYB-E3003 (frozen alias)
slice-field struct copy (d03) accept → -race: DATA RACE reject HYB-E3003
projection / re-slice / composite / paren accept (bypass) reject HYB-E3003
d04 no-move control reject HYB-E3001 reject HYB-E3001 (unchanged)
d05 direct use-after-move control reject HYB-E3003 reject HYB-E3003 (unchanged)
  • cargo test workspace: green — hy-check lib 50/50, hy-syntax 87, hy-emit 77, hy-diag 8, spike6 2/2.
  • Checker corpus verdict agreement: 25/25 OK (no verdict flips on existing rows, incl. 19/20 freeze rows).
  • Differential loop: FULL AGREEMENT — accept-side 10/10 build+run, reject-side 15/15 checker.
  • hyb rebuilds clean.

Notes

  • Uses A1b for the frozen-alias diagnostic (consistent with existing move freeze).
  • No change to A6/A7 or any other rule.

- extend freeze to union may-share component from aliases so struct/array shallow copies, reslices, projections, and composite-literal captures freeze peers
- record may-share edges on local/assign for Ident/shallow copies, Expr::Slice (s1[:]), Field/Index projections (including when they carry reference interior), and composite literals
- add shape_may_share (Map/Slice/Pointer true + transitively Struct/Array); keep is_reference_alias used as base
- union may-share in mark_move; is_alias true if aliases or may_share has name
- clear may_share on rebind/redefine; avoid recording consts
- fixes P0: struct/array shallow copy bypassing O5.2 freeze; rejects limitlessprojects#27 repros and keeps corpus/CI green
@limitlessprojects
limitlessprojects merged commit b4c6a68 into limitlessprojects:main Oct 14, 2026
2 checks passed
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] Shallow struct/array copy and non-bare-ident aliases bypass O5.2 move freeze (h2 := h1, m2 := (agg), s2 := s1[:], holder{m: agg})

2 participants