Skip to content

[soundness] Field/index stores (h.m = m), projections in composite literals (holder{m: h1.m}), and intermediate-copy rebinds sever may_share and bypass O5.2 freeze with 0 diagnostics #92

Closed

Description

@yodakkak

Revision (git rev-parse HEAD)

8fb92385a54f3934959c1ff059cb13f2ffe2e78d (origin/main)

Summary (Bounty Track #5 — Soundness P0)

PR #35 (fixing #27) introduced the undirected FnState.may_share graph so shallow copies, projections, and composite literals sharing mutable GC storage freeze together under O5.2 (A1b). However, three distinct omissions in how may_share is populated and maintained in compiler/crates/hy-check/src/loans.rs and compiler/crates/hy-check/src/model.rs allow pure Tier-0 .hy programs (zero managed blocks, let, const, or new) to pass hyb check with OK (0 diagnostics) while sharing mutable map[string]int storage across concurrent tasks (fatal error: concurrent map writes):

  1. Field and index stores (h.m = m, xs[0] = m, mm["a"] = m) never record may_share edges:
    In loans.rs (process_assign, lines 759–806), record_may_share is only invoked when the assignment target is a bare PlaceKind::Ident(name). When assigning a reference-bearing value into a struct field (h.m = m) or slice/map index (xs[0] = m), process_assign skips record_may_share completely, even though composite literal initialization (h := holder{m: m}) is tracked and rejected. Moving m into a spawned task (task worker(move m, done)) leaves h (or xs) unfrozen in main.
  2. record_literal_ref ignores projections (h1.m, arr[0]), slices (s1[:]), and calls (same(m)) inside composite literals (h2 := holder{m: h1.m}):
    In loans.rs (record_literal_ref, lines 473–499), composite literal sub-expressions only match Expr::Ident and nested composite literals. Embedding a field/index projection (holder{m: h1.m}), re-slice (holder{s: s1[:]}), or call result (holder{m: same(m)}) inside a composite literal drops the sharing edge to h1 / s1 / m, whereas the two-step local form (tmp := h1.m; h2 := holder{m: tmp}) is rejected.
  3. FnState::share_clear severs transitive sharing paths on bridge rebind (h2 := h1; h3 := h2; h2 = fresh) and inner-block shadowing (if true { h2 := 1 }):
    In model.rs (FnState::share_clear, lines 287–295), removing vertex name from st.may_share deletes all incident edges {name, p} without connecting name's former neighbors (clique closure on vertex elimination), and FnState.may_share is unscoped across scope_push / scope_pop. Consequently:
    • In h1 := holder{...}; h2 := h1; h3 := h2, may_share is a 2-hop chain h1 — h2 — h3. Rebinding the intermediate copy (h2 = holder{m: map[string]int{"fresh": 0}}) calls st.share_clear("h2"), severing the path between h1 and h3 even though h1.m and h3.m still point to the exact same map header.
    • Shadowing h2 inside an inner block (if true { h2 := 1 }) calls define_binding -> st.share_clear("h2"), permanently wiping outer h2's sharing edge to h1 after the block exits.

Minimal .hy Reproducer 1 — Field/index store into composite (repro_field_assign_share.hy)

struct holder {
    m map[string]int
}

fn worker(m map[string]int, done chan<- bool) {
    for i in 0..10000 {
        m["k"] = i
    }
    done <- true
}

fn main() {
    m := map[string]int{"k": 0}
    h := holder{m: map[string]int{"init": 0}}
    h.m = m
    done := make(chan bool, 1)
    task worker(move m, done)
    for i in 0..10000 {
        h.m["k"] = i
    }
    <-done
}

Minimal .hy Reproducer 2 — Projection/slice/call inside composite literal (repro_literal_projection_share.hy)

struct holder {
    m map[string]int
}

fn worker(h holder, done chan<- bool) {
    for i in 0..10000 {
        h.m["k"] = i
    }
    done <- true
}

fn main() {
    h1 := holder{m: map[string]int{"k": 0}}
    h2 := holder{m: h1.m}
    done := make(chan bool, 1)
    task worker(move h1, done)
    for i in 0..10000 {
        h2.m["k"] = i
    }
    <-done
}

Minimal .hy Reproducer 3 — Rebinding intermediate copy severs transitive may_share component (repro_bridge_rebind_share.hy)

struct holder {
    m map[string]int
}

fn worker(h holder, done chan<- bool) {
    for i in 0..10000 {
        h.m["k"] = i
    }
    done <- true
}

fn main() {
    h1 := holder{m: map[string]int{"k": 0}}
    h2 := h1
    h3 := h2
    h2 = holder{m: map[string]int{"fresh": 0}}
    done := make(chan bool, 1)
    task worker(move h1, done)
    for i in 0..10000 {
        h3.m["k"] = i
    }
    <-done
}

What the checker should say

Reject all three programs with HYB-E3003 (tier0_rule: "A1b", O5.2: write through a live alias of a moved value).

What it actually said

repro_field_assign_share.hy: OK (0 diagnostics)
repro_literal_projection_share.hy: OK (0 diagnostics)
repro_bridge_rebind_share.hy: OK (0 diagnostics)

Emitted Go (hyb build --emit-go) spawns go worker(...) mutating the shared map[string]int while main mutates the same map through h.m["k"] = i / h2.m["k"] = i / h3.m["k"] = i, crashing with fatal error: concurrent map writes / WARNING: DATA RACE.

Negative Controls (already rejected on origin/main @ 8fb9238)

  • h := holder{m: m}; task worker(move m, done); h.m["k"] = i (composite literal instead of h.m = m) -> Rejected with HYB-E3003 (A1b).
  • tmp := h1.m; h2 := holder{m: tmp}; task worker(move h1, done); h2.m["k"] = i -> Rejected with HYB-E3003 (A1b).
  • h1 := holder{...}; h2 := h1; h3 := h2; task worker(move h1, done); h3.m["k"] = i (without rebinding h2) -> Rejected with HYB-E3003 (A1b).

Claimed severity

P0 — data race reachable in the checked subset

Payout Wallet (USDC on Base)

0x59622Fe8f9b438eF1CD5dB4e91f1230fe6239AC9

Activity

  1. added 6 commits that reference this issue on Oct 15, 2026
    e316768
    226672a
    bd8f386
    cbf5ba3
    36797d8
    483c3d5
  2. limitlessprojects commented on Oct 18, 2026

    @limitlessprojects
    Owner

    Verified against main @ 0706813 — all three omissions are closed by successor landings:

    Closing as fixed-by-successors — thanks @yodakkak for the precise three-omission breakdown; the clique model that landed follows exactly the shape you described.

  3. yodakkak commented on Oct 18, 2026

    @yodakkak
    ContributorAuthor

    Verified against main (c5126b0): #181 and #183 fixed simple identifier field stores (h.m = p) and block shadowing, while the non-Ident (PlaceKind::Field / PlaceKind::Index) arms of
    ebind_assign_targets in compiler/crates/hy-check/src/loans.rs still dropped
    on_owned_origin (HYB-E3004), const roots (HYB-E3006), and live A3 map-slot loans (HYB-E3102) on h.m = move p / xs[0] = move p / p, h.m = fresh, p /
    , h.m = pair(move p). Rebased and narrowed #93 (3b423f5) strictly to those remaining live gaps with 6 reproducer tests.

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