Repository navigation
Description
Summary
Checker::check_loop_backedge (compiler/crates/hy-check/src/freeze.rs, compiler/crates/hy-check/src/lib.rs, and compiler/crates/hy-check/src/closures.rs) has three soundness bypasses where loop-carried ownership moves (O5.1 / O5.2 / O13) pass hyb check with 0 diagnostics and trigger real go run -race data races (exit code 66) at runtime:
-
Gap 1 (
lib.rs+closures.rs+freeze.rs—pre_movedandreported_backedgetrack bare variable namesHashSet<String>instead of(scope_depth, name)):- At loop entry (
lib.rs:472–478andclosures.rs:971–977),pre_movedcollects bare binding namesk.clone()acrossst.envandst.scopeswithout their scope depth (0forst.env,i + 1forst.scopes[i]). - When an outer binding
m(e.g. inst.env, depth0) is moved before an enclosing scope (if, block{ ... }, outer loop, or closure) that shadowsmwith a fresh bindingm := map[string]int{...}(st.scopes[d], depthd + 1 <= outer_depth),pre_movedcontains"m". - When the inner shadowed
m(or an alias of the same name) is moved inside a subsequent loop (for i in 0..2 { m["main"] = i; task worker(move m, done) }),check_loop_backedge(freeze.rs:639) andhas_continue_after_loop_move(freeze.rs:801) seepre_moved.contains("m") == true, clearb.moved = Noneon the shadowed binding, and skip the back-edge check completely. - Similarly,
reported_backedgetracks bareStringinstead of(usize, String), so reporting a back-edge diagnostic on an earlier binding suppresses back-edge reporting on a distinct shadowed binding of the same name in another scope.
- At loop entry (
-
Gap 2 (
freeze.rs— Labeledcontinue loop(SPEC LX14) inside a nested finiteforloop (ForKind::Range,ForKind::Iterate,ForKind::While) bypassesstmt_has_continue_for_loop,stmt_can_reach_backedge, andstmt_move_can_reach_backedge):- By SPEC LX14 (and
hy-emit/src/stmt.rs:1674–1675, 1932–1938), labeledcontinue loop(Stmt::Continue { label: Some(_) }) binds ONLY to the nearest enclosingloop(ForKind::Infinite), skipping any intermediatefor(Range,Iterate,While). - However, in
freeze.rs:stmt_has_continue_for_loop(freeze.rs:1245–1247) unconditionally returnsfalseonStmt::For { .. }, missingcontinue loopinside a nested finiteforwhen checking an enclosingloop.stmt_can_reach_backedge(freeze.rs:884–886) returnsafter_reachdirectly on a finiteFor, ignoring that its body can jump directly to the enclosingloopback-edge viacontinue loopeven whenafter_reachisfalse(before trailingbreakorreturn).stmt_move_can_reach_backedge(freeze.rs:987–1000) overwritescontinue_reachwithloop_exits, losinglabeled_continue_reachforcontinue loopinside a finiteFor.
- By SPEC LX14 (and
-
Gap 3 (
freeze.rs— Labeledbreak loop(SPEC LX14) inside a nested finiteforloop enclosed in an innerloopbypassesstmt_can_reach_backedgeandstmt_move_can_reach_backedge):- By SPEC LX14, labeled
break loop(Stmt::Break { label: Some(_) }) binds to the nearest enclosingloop(ForKind::Infinite), skipping any intermediate finiteforandselect. - Because
stmt_can_reach_backedgereturnsafter_reachon any finiteForandstmt_move_can_reach_backedgeoverwritesloop_break_reachwithafter_reachon anyFor, an innerloop { for j in 0..1 { if step == 0 { step = 1; break loop } }; return }followed in the outerloopbyif step == 1 { continue }; breakis misclassified as unable to reach the outerloopback-edge.
- By SPEC LX14, labeled
Minimal Reproducers & go run -race Verification
Reproducer 1 (Gap 1: Shadowed pre_moved binding moved inside loop)
package main
fn worker(m map[string]int, done chan bool) {
for i in 0..1000 {
m["w"] = i
}
done <- true
}
fn main() {
m := map[string]int{"outer": 0}
done := make(chan bool, 3)
task worker(move m, done)
if true {
m := map[string]int{"inner": 1}
for i in 0..2 {
m["main"] = i
task worker(move m, done)
}
}
<-done
<-done
<-done
}- Actual on
main(aa4a9d9):hyb check->OK (0 diagnostics),go run -race->WARNING: DATA RACE(exit code 66) betweenmainand both spawnedworkergoroutines on the inner mapm. - Expected: Reject with
HYB-E3003(m is used after ownership was moved away).
Reproducer 2 (Gap 2: continue loop inside nested finite for before trailing break)
package main
fn worker(m map[string]int, done chan bool) {
for i in 0..1000 {
m["w"] = i
}
done <- true
}
fn main() {
m := map[string]int{"init": 0}
done := make(chan bool, 2)
step := 0
loop {
m["main"] = step
task worker(move m, done)
for j in 0..1 {
if step == 0 {
step = 1
continue loop
}
}
break
}
<-done
<-done
}- Actual on
main(aa4a9d9):hyb check->OK (0 diagnostics),go run -race->WARNING: DATA RACE(exit code 66). - Expected: Reject with
HYB-E3003.
Reproducer 3 (Gap 3: break loop inside nested finite for exiting inner loop to outer continue)
package main
fn worker(m map[string]int, done chan bool) {
for i in 0..1000 {
m["w"] = i
}
done <- true
}
fn main() {
m := map[string]int{"init": 0}
done := make(chan bool, 2)
step := 0
loop {
m["main"] = step
task worker(move m, done)
loop {
for j in 0..1 {
if step == 0 {
step = 1
break loop
}
}
return
}
if step == 1 {
continue
}
break
}
<-done
<-done
}- Actual on
main(aa4a9d9):hyb check->OK (0 diagnostics),go run -race->WARNING: DATA RACE(exit code 66). - Expected: Reject with
HYB-E3003.
Payout Wallet
- USDC / ETH (Base / Ethereum):
0x3018577736ebcdd3ddca916Bef44e7dC6E27e33E
Activity
dancerdan15 commentedon Oct 23, 2026
/attempt #739
fix(hy-check): handle shadowed loop-carried moves and LX14 jumps. Fixes