You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[soundness] walk_stmt_param_stores walks a loop body once, so a loop-carried param store in a helper is missed (HYB-E3003 bypass, go run -race data race) #2308
Template: soundness.yml Claimed severity: P0, data race reachable in the checked subset
The smallest .hy program that demonstrates it
Commit: 1f0ff97 (main), built with rust 1.99.0 / go1.26.9.
package main
fn link(dst []map[string]int, src map[string]int, other map[string]int) {
tmp := other
for i in0..2 {
dst[0] = tmp
tmp = src
}
}
fn worker(s []map[string]int, done chan int) {
s[0]["race"] = 1
done <- 1
}
fn main() {
m := map[string]int{"a": 1}
o := map[string]int{"b": 1}
dst := []map[string]int{{}}
link(dst, m, o)
done := make(chan int, 1)
task worker(move dst, done)
m["a"] = 2
<-done
}
Commands: hyb check loop_carried.hy, then hyb build loop_carried.hy -o out --emit-go and go run -race on the emitted file.
What the checker should say
HYB-E3003 at m["a"] = 2 (line 21). After link returns, dst[0] is m: iteration 1 stores other, then tmp = src, and iteration 2 stores src. Moving dst into the task therefore moves m's map, and the write through m races with the worker. The straight-line equivalent (tmp = src; dst[0] = tmp) and the same loop written inline in main are both rejected with HYB-E3003 on this commit.
What it actually said
loop_carried.hy: OK (0 diagnostics)
Emitted Go under go run -race: DATA RACE in 10/10 runs (exit status 66):
WARNING: DATA RACE
Write at 0x00c0000a0000 by goroutine 7:
runtime.mapassign_faststr()
main.worker() main.go:12
Previous write at 0x00c0000a0000 by main goroutine:
runtime.mapassign_faststr()
main.main() main.go:23
The same program written with i := 0; for i < 2 { ...; i = i + 1 } is also accepted and races 10/10.
Anything else
Root cause: in compiler/crates/hy-check/src/loans.rs, the Stmt::For arm of walk_stmt_param_stores (lines 3382-3424) walks the body exactly once. The (dst, src) store pair only appears on the second iteration, when tmp already carries src's slot, so collect_callee_param_stores never records it and the caller never links dst to m.
Local check: re-walking the body until aliases and out stop changing makes this program (and the while form) reject with HYB-E3003, and cargo test --workspace stays green (1800 passed, 0 failed).
Relation to #854: different mechanism. #854 case 1 is the aliases.contains_key(&k) merge filter at line 3420. Removing only that filter fixes the #854 repro but this program is still accepted, because tmp is already in aliases here. Closed PR #858 (a fix proposed for #854, not merged) did include a two-pass loop walk that also rejects this program, but no issue describes the loop-carried case and main still accepts it. Related ideas: #1714 (SCC fixpoint summaries, wildcard). Not covered by #788, #829, #831, #739 (check_loop_backedge), #799.
Tier-0 rule: O5.2 freeze of live aliases at a move (GUARANTEES rows 1 and 6).
Activity
fix(hy-check): walk loop bodies to a fixpoint in walk_stmt_param_stor…
Merge PR limitlessprojects#2727: hy-check — walk loop bodies to a fix…
Merge PR #3173: hy-check rejects elided struct literals in interface …