Repository navigation
Closed
Description
The smallest .hy program that demonstrates it
// defer_repro.hy (main @ 8fb9238)
// Commands:
// hyb check defer_repro.hy
// hyb build defer_repro.hy -o defer_repro_bin
import "fmt"
import "time"
fn audit(m map[string]int) {
for i in 0..5000 {
m["defer"] = i
}
}
fn worker(m map[string]int, done chan<- bool) {
for i in 0..5000 {
m["worker"] = i
}
done <- true
}
fn run() {
m := map[string]int{"init": 0}
done := make(chan bool, 1)
// `defer` evaluates `m` (copying the map header) here, but executes
// `audit(m)` at function exit — AFTER `task worker(move m, done)`
// transfers ownership of `m` to the spawned task.
defer audit(m)
task worker(move m, done)
time.sleep(1 * time.millisecond)
}
fn main() {
run()
time.sleep(50 * time.millisecond)
fmt.println("done")
}Additional affected forms in the same root cause:
- Alias use in
deferbeforemove(ordeferbefore aliasing +move):m := map[string]int{"init": 0} m2 := m defer audit(m2) task worker(move m, done)
- Use in
deferbefore a consuming API call (O13 / rule A7):import "rust/flate2" fn main() { w := flate2.new_writer(1, 6) defer w.write("late") w.finish() }
moveinsidedefer(defer cleanup(move m)) and inside call arguments (m2 := id(move m),eat(move m)):
walk::own_usesmarksExpr::Moveoperands asvia_move: true(exempting them fromcheck_uses), butStmt::DeferandStmt::Exprnever invokedmark_move_in_value/check_non_owned_move, andcollect_move_operandsdid not recurse intoExpr::Callarguments. As a result,defer cleanup(move m); m["after"] = 1,fn run(p map[string]int) { defer cleanup(move p) }, andm2 := id(move m); task worker(move m2); m["main"] = 2all passed with0 diagnostics.- Non-lexical loan window truncation on
defer(O7 / rule A2 & O8 / rule A3):
walk::flattenrecordedlast_useof bindings referenced insideStmt::Deferat the lexical index of thedeferstatement rather than function exit (fn_end), andStmt::Defercalls passedloop_end: Nonetoprocess_call/lend_handle_args. Consequently,s := &m["a"]; defer bump(s); m["b"] = svc{count: 2}(map rehash whiledeferholds slot pointers) anddefer serde_json.to_string_pretty(doc); doc.set("k", 1)passed with0 diagnostics.
What the checker should say
- Reject (
HYB-E3003, ruleA1b):m(or its aliasm2) is captured bydefer audit(...), which executes at function exit after ownership ofmleaves viatask worker(move m, done). - Reject (
HYB-E3003, ruleA7):wis used bydefer w.write(...)at function exit afterw.finish()consumes ownership ofw. - Reject (
HYB-E3003/HYB-E3004, ruleA1b):moveinsidedeferor call arguments must freeze the moved binding and reject non-owned bindings (parameters/receivers/captures/range vars). - Reject (
HYB-E3102ruleA3/HYB-E3101ruleA2): Map-slot loans (&m[k]) and boundary-handle borrow loans referenced or opened bydeferremain live until function exit (fn_end).
What it actually said
$ hyb check defer_repro.hy
OK (0 diagnostics)
When lowered by hyb and executed under go run -race, the program immediately triggers a data race / concurrent map write between the spawned worker goroutine and the deferred audit(m) call at function exit:
==================
WARNING: DATA RACE
Write at 0x00c0000941b0 by goroutine 7:
runtime.mapassign_faststr()
/home/son/anaconda3/src/runtime/map_faststr.go:223 +0x0
main.worker()
defer_repro_bin.go:19 +0x58
Previous write at 0x00c0000941b0 by main goroutine:
runtime.mapassign_faststr()
/home/son/anaconda3/src/runtime/map_faststr.go:223 +0x0
main.audit()
defer_repro_bin.go:13 +0x4d
main.run.deferwrap1()
defer_repro_bin.go:28 +0x33
main.run()
defer_repro_bin.go:31 +0x125
==================
Found 1 data race(s)
exit status 66
Claimed severity
P0 — data race reachable in the checked subset
Anything else
- Rules involved: SPEC-LANGUAGE §9 O5.1 / O5.2 / O5.4 (
A1b,HYB-E3003/HYB-E3004), O13 (A7,HYB-E3003), O7 (A2,HYB-E3101), and O8 (A3,HYB-E3102). - Root cause in
hy-check:walk::flattenincompiler/crates/hy-check/src/walk.rsassignedlast_usefor bindings insideStmt::Deferto thedeferstatement's lexical index instead offn_end.check_fnincompiler/crates/hy-check/src/lib.rs(andclosures.rs) only rancheck_usesat the lexical position ofStmt::Defer(before subsequentmoveorconsumestatements) and had noStmt::Defer/Stmt::Exprmove handling.collect_move_operandsincompiler/crates/hy-check/src/model.rsdid not recurse intoExpr::Callarguments.process_call/lend_handle_argsincompiler/crates/hy-check/src/loans.rscreated single-statement (last: idx) handle loans forStmt::Defercalls instead of extending them tofn_end.
Payout / Wallet Addresses (Bounty Track #5)
- USDT (TRC20):
TCQwxbpYVdRWYNDs1JbnKyVHNRVaRJg1io - USDT / USDC (ERC20 / BEP20):
0x76d1c4283a2ff662ccf85c1f57655c29b4256756 - Self-Custody EVM Wallet (ETH / USDC / USDT / any EVM chain or token):
0x6Cf7Fc00857f2bbd12fBF2E11BC5AacEF0e97985 - USDC (Solana):
6dX8oqvvHj6Q936PVyTjVYKVk45soNpJ234aVqMm6ZJm
Metadata
Metadata
Assignees
Labels
No labels
Activity
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): A3 events cross frames, share-peers, and closure call …
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(limitlessprojects#98): defer/call-arg moves freeze the source; de…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
gelismarvel commentedon Oct 17, 2026
/claim #98
Fixes #98
Submitting verified fix PR for #98.
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
fix(hy-check): enforce freeze and loan windows across defer and call-…
limitlessprojects commentedon Oct 18, 2026
Verified against main @ 0706813 — every scenario class in this report now rejects with the expected codes:
defer_repro.hy)defer w.write; w.finish()defer cleanup(move m); m["after"]=1)m2 := id(move m))s := &m["a"]; defer bump(s); m["api"]=…)Landing evidence: pr-421 (2defedf, @exantiv, fixes #415/#438 — value-precise deferred-binding freeze), pr-395 (1ed45d5, @sonson0910 — mark moves in non-assignment statement expressions), pr-288 (5317e70 — defer-operand E2001), test pins spliced at 1980a40.
Closing as fixed — thanks @sonson0910; the deferred-freeze precision landed essentially as this report asked.
STATUS: session-21 — old-wave recons + wave triage #248-#336 + const-…