Repository navigation
Description
Summary
Under SPEC-LANGUAGE.md §9.3 O5 (O5.1 / O5.2, rule A1b) and §9.1 O8, move x at a task spawn or channel send must freeze the moved binding and every live alias or sharing peer, and O8 index/field loans (slot := &m[k], f := &h.field) lower to a copy-read plus a synthetic block-exit store-back (m[k] = slot, h.field = f) at the end of their declaring block.
Four interconnected pointer-borrow (&x) and O8 block-exit store-back seams in hy-check + hy-syntax currently allow programs to pass hyb check with OK (0 diagnostics) and crash at runtime (fatal error: concurrent map writes) or trigger go run -race data races:
- Pointer-borrow + composite-literal / may-share composition (
p := &h; xs := []*holder{p}; task worker(move xs, done); h.m["k"] = iand directxs := []*holder{&h}):record_local_borrow_aliases(loans.rs) recordedp -> honly inst.aliases(notst.may_share), whilemark_moveandcheck_non_owned_move(freeze.rs) expandedst.aliasesonly once beforest.share_group(name)and never took the transitive closure ofaliases ∪ may_share. Movingxstherefore frozexsandpviamay_share, but left the underlying pointeehunfrozen.- Furthermore,
record_literal_refandrecord_may_sharehad no arm foras_addr_of(...)(&h), soxs := []*holder{&h}recorded no sharing edge tohat all.
- Pointer-borrow argument passed to a call (
p := id_ptr(&h); task worker(move p, done); h.m["k"] = i):Expr::root_ident()(compiler/crates/hy-syntax/src/ast.rs:745-754) did not recurse throughExpr::AddrOforExpr::Unary { op: UnOp::Addr }, returningNoneon&h. Consequently,record_aliasandrecord_may_shareignored&harguments inExpr::Call, leavingpunlinked toh.
- Scalar-struct borrow via explicit
&sorhy-emitauto-addressed pointer parameter (s := stats{count: 0}; p := id_ptr(s); task worker(move p, done); s.count = i):hy-emit/src/expr.rs:626-647automatically rewrites a value argumentsto&swhen the callee parameter is a pointer (fn id_ptr(p *stats) *stats). Meanwhile,record_aliasandrecord_may_sharecheckedb.shape.is_reference_alias()/binding_may_share(st, src)ons(TypeShape::Structwith scalar fields ->false), ignoring that taking&s(explicitly or via pointer-parameter auto-addressing) creates shared mutable*statsstorage.- Similarly,
record_local_borrow_aliases(p := ¶m) did not propagateparam'snon_owned_originontop, allowingtask worker(move p, done)on a borrowed value parameterparamto bypassHYB-E3004.
- O8 slot/field-loan block-exit store-back after
move(if true { slot := &m["k"]; slot.n = 1; task worker(move m, start, done) }):hy-emit/src/stmt.rs:221-235, 898-901lowersslot := &m["k"](andf := &h.field) to a copy-readslot := m["k"]plus a synthetic store-backm["k"] = slotemitted at the end of the declaring block — i.e., aftergo worker(m, start, done).hy-checkended the loan window atlast_use["slot"](slot.n = 1) and never checked whetherm(orh) was moved before the declaring block exited, emitting an unsynchronized writem["k"] = slotto the moved map concurrently withworker.
- Tested commit (
main):f99d6d0 - Violated guarantees:
GUARANTEES.mdRow 1 (No value reaches a spawned task or channel send through an unproven path) & Row 6 (move/ freeze: a moved value cannot be used by the sender afterwards)SPEC-LANGUAGE.md§9.3 O5.1 & O5.2 (HYB-E3003/HYB-E3004, ruleA1b) and §9.1 O8
Minimal Reproducers
Reproducer 1 — Pointer borrow embedded in composite literal (repro1_ptr_borrow_composite.hy)
struct holder {
m map[string]int
}
fn worker(xs []*holder, done chan<- bool) {
for i in 0..10000 {
xs[0].m["k"] = i
}
done <- true
}
fn main() {
h := holder{m: map[string]int{"k": 0}}
p := &h
xs := []*holder{p}
done := make(chan bool, 1)
task worker(move xs, done)
for i in 0..10000 {
h.m["k"] = i
}
<-done
}Reproducer 2 — Pointer borrow passed through a call (repro2_ptr_borrow_call.hy)
struct holder {
m map[string]int
}
fn id_ptr(p *holder) *holder {
return move p
}
fn worker(p *holder, done chan<- bool) {
for i in 0..10000 {
p.m["k"] = i
}
done <- true
}
fn main() {
h := holder{m: map[string]int{"k": 0}}
p := id_ptr(&h)
done := make(chan bool, 1)
task worker(move p, done)
for i in 0..10000 {
h.m["k"] = i
}
<-done
}Reproducer 3 — Auto-addressed pointer parameter on a scalar struct (repro3_auto_addr_ptr_param.hy)
struct stats {
count int
}
fn id_ptr(p *stats) *stats {
return move p
}
fn worker(p *stats, done chan<- bool) {
for i in 0..10000 {
p.count = i
}
done <- true
}
fn main() {
s := stats{count: 0}
p := id_ptr(s)
done := make(chan bool, 1)
task worker(move p, done)
for i in 0..10000 {
s.count = i
}
<-done
}Reproducer 4 — O8 map-slot loan block-exit store-back after move m (repro4_slot_storeback_after_move.hy)
struct item {
n int
}
fn worker(m map[string]item, start <-chan bool, done chan<- bool) {
<-start
for i in 0..10000 {
m["k"] = item{n: i}
}
done <- true
}
fn main() {
m := map[string]item{"k": item{n: 0}}
start := make(chan bool, 1)
done := make(chan bool, 1)
if true {
slot := &m["k"]
slot.n = 1
task worker(move m, start, done)
start <- true
for i in 0..10000 {
slot.n = i
}
}
<-done
}Actual vs. Expected Behavior
Actual (main @ f99d6d0)
$ hyb check repro1_ptr_borrow_composite.hy
OK: repro1_ptr_borrow_composite.hy (0 diagnostics)
$ hyb run repro1_ptr_borrow_composite.hy
fatal error: concurrent map writes
$ hyb check repro2_ptr_borrow_call.hy
OK: repro2_ptr_borrow_call.hy (0 diagnostics)
$ hyb run repro2_ptr_borrow_call.hy
fatal error: concurrent map writes
$ hyb check repro3_auto_addr_ptr_param.hy
OK: repro3_auto_addr_ptr_param.hy (0 diagnostics)
$ hyb check repro4_slot_storeback_after_move.hy
OK: repro4_slot_storeback_after_move.hy (0 diagnostics)
(In repro4, hyb build --keep-go emits m["k"] = slot at the end of the if true block after go worker(m, start, done), racing with worker's map writes.)
Expected
All four programs must be rejected by hyb check with HYB-E3003 (tier0_rule: "A1b"), and moving a pointer borrow of a non-owned parameter (p := ¶m; task worker(move p, done)) must be rejected with HYB-E3004 (tier0_rule: "A1b").
Activity
fix(check): track transitive pointer-borrow share chains and auto-add…
gelismarvel commentedon Oct 17, 2026
/attempt #131
Implemented and verified the fix for
#131acrosshy-syntax(Expr::root_ident) andhy-check(freeze.rs,shape.rs,loans.rs), with 7 integration tests incompiler/crates/hy-check/tests/pointer_borrow_chains_issue_131.rs(7/7 PASS,25/25 pointer_borrow_composites PASS,129/129 hy-check --lib PASS).ocakciomursel-pixel commentedon Oct 17, 2026
Note for maintainers: As the original reporter of #131 (filed 2026-10-15), companion fix PR #132 (#132) was already triaged and queued in Wave 1/Wave 2 with bounty standing preserved, and is rebased cleanly on latest
main(compiler+quickgreen).Merge pr-484 (exantiv, fixes limitlessprojects#131): transitive point…