Repository navigation
Description
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):
- Field and index stores (
h.m = m,xs[0] = m,mm["a"] = m) never recordmay_shareedges:
Inloans.rs(process_assign, lines 759–806),record_may_shareis only invoked when the assignment target is a barePlaceKind::Ident(name). When assigning a reference-bearing value into a struct field (h.m = m) or slice/map index (xs[0] = m),process_assignskipsrecord_may_sharecompletely, even though composite literal initialization (h := holder{m: m}) is tracked and rejected. Movingminto a spawned task (task worker(move m, done)) leavesh(orxs) unfrozen inmain. record_literal_refignores projections (h1.m,arr[0]), slices (s1[:]), and calls (same(m)) inside composite literals (h2 := holder{m: h1.m}):
Inloans.rs(record_literal_ref, lines 473–499), composite literal sub-expressions only matchExpr::Identand 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 toh1/s1/m, whereas the two-step local form (tmp := h1.m; h2 := holder{m: tmp}) is rejected.FnState::share_clearsevers transitive sharing paths on bridge rebind (h2 := h1; h3 := h2; h2 = fresh) and inner-block shadowing (if true { h2 := 1 }):
Inmodel.rs(FnState::share_clear, lines 287–295), removing vertexnamefromst.may_sharedeletes all incident edges{name, p}without connectingname's former neighbors (clique closureon vertex elimination), andFnState.may_shareis unscoped acrossscope_push/scope_pop. Consequently:- In
h1 := holder{...}; h2 := h1; h3 := h2,may_shareis a 2-hop chainh1 — h2 — h3. Rebinding the intermediate copy (h2 = holder{m: map[string]int{"fresh": 0}}) callsst.share_clear("h2"), severing the path betweenh1andh3even thoughh1.mandh3.mstill point to the exact same map header. - Shadowing
h2inside an inner block (if true { h2 := 1 }) callsdefine_binding->st.share_clear("h2"), permanently wiping outerh2's sharing edge toh1after the block exits.
- In
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 ofh.m = m) -> Rejected withHYB-E3003(A1b).tmp := h1.m; h2 := holder{m: tmp}; task worker(move h1, done); h2.m["k"] = i-> Rejected withHYB-E3003(A1b).h1 := holder{...}; h2 := h1; h3 := h2; task worker(move h1, done); h3.m["k"] = i(without rebindingh2) -> Rejected withHYB-E3003(A1b).
Claimed severity
P0 — data race reachable in the checked subset
Payout Wallet (USDC on Base)
0x59622Fe8f9b438eF1CD5dB4e91f1230fe6239AC9
Activity
fix(hy-check): track field/index store sharing, composite literal pro…
fix(hy-check): track field/index store sharing, composite literal pro…
fix(hy-check): track field/index store sharing, composite literal pro…
fix(hy-check): track field/index store sharing, composite literal pro…
fix(hy-check): track field/index store sharing, composite literal pro…
fix(hy-check): track field/index store sharing, composite literal pro…
limitlessprojects commentedon Oct 18, 2026
Verified against main @ 0706813 — all three omissions are closed by successor landings:
h.m = m,m["k"] = vinto shared storage): landed via pr-398 (13df097, @G0st13, fixes [soundness] P0: field store of a reference-typed value does not materialize may_share - accepted program races #392) with corpus 54/55 successor pins; share-clear clique closure via 314b748 (fixes [soundness] scope_pop propagates freeze only over aliases, not may_share: shadowed struct-embedded map escapes the move of its holder (follow-up gap in #14/#31's fixes) #195).O5.2/A1b).Closing as fixed-by-successors — thanks @yodakkak for the precise three-omission breakdown; the clique model that landed follows exactly the shape you described.
STATUS: session-21 — old-wave recons + wave triage #248-#336 + const-…
fix(hy-check): propagate non-owned origin, const roots, and A3 loans …
yodakkak commentedon Oct 18, 2026
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.
fix(hy-check): propagate non-owned origin, const roots, and A3 loans …