Repository navigation
Description
Summary
In hy-check (compiler/crates/hy-check/src/lib.rs, shape.rs, and loans.rs), user-defined methods (fn (r T) method(...)) are discarded during table construction and method receivers (callee = Expr::Field { base, .. }) / reference-bearing composite arguments (holder{m: map[string]int}) / ?-unwrapped calls (Expr::Try) are ignored by record_may_share and record_alias.
As a result, extracting or returning a reference-bearing value via a user-defined method (m = h.data(), var m map[string]int = h.data(), n, m := h.pair(), m := h.try_data()?) or via a top-level function taking a reference-bearing struct (m := extract(h)) leaves zero may_share or aliases edge between m and h (and fails to propagate non_owned_origin when h is a method receiver or function parameter). Moving m into a spawned task (task worker(move m, done)) and concurrently mutating h.m in the parent task is accepted by hyb check with 0 diagnostics and 0 managed blocks, producing an immediate Go -race data race (exit status 66).
Minimal Reproducer (method_repro.hy, 26 lines, 0 managed blocks)
import "fmt"
import "time"
struct holder {
m map[string]int
}
fn (h holder) data() map[string]int {
return h.m
}
fn worker(m map[string]int, done chan<- bool) {
m["worker"] = 1
done <- true
}
fn main() {
h := holder{m: map[string]int{"init": 0}}
m := map[string]int{}
m = h.data()
done := make(chan bool, 1)
task worker(move m, done)
h.m["main"] = 2
<-done
time.sleep(10 * time.millisecond)
fmt.println(h.m["worker"], h.m["main"])
}Additional Bypass Variants
- Ascribed define from user-defined method (
var m map[string]int = h.data()):h.data()resolves toTypeShape::Unknownbecausebuild_tablesdiscardedfn (h holder) data(), and thevar m map[string]intascription suppliesTypeShape::Map(Str, Primitive).- Neither
record_may_sharenorrecord_aliasinspects the method receiverhinsidecallee = Expr::Field { base: h, name: "data" }.
- Top-level function extracting a map/slice from a struct (
m := extract(h)):fn extract(h holder) map[string]int { return h.m }- In
record_alias(loans.rsline 530), the argument loop checksif b.shape.is_reference_alias(), which isfalseforh(TypeShape::Struct(Some("holder"))), even thoughself.binding_may_share(st, "h")istrue!
- Non-owned receiver/parameter extraction (
fn (h holder) leak(...) { m := h.data(); task worker(move m, done) }):- Because
mis not linked tohand does not inherith.non_owned_origin,move mbypassesHYB-E3004(check_non_owned_move) and moves caller-owned storage across a task boundary.
- Because
?-unwrapped calls (m := h.try_data()?/m2 := same_ok(m1)?) and multi-return method calls (n, m := h.pair()):record_may_shareandrecord_aliasonly peeledExpr::Paren(unwrap_parens) and notExpr::Try(?), so any?-unwrapped call hit_ => {}with zero alias/may-share tracking.
Proof of Acceptance & Go -race Failure on main (651dc42)
1. hyb check accepts with 0 diagnostics
$ hyb check method_repro.hy
OK (0 diagnostics)
2. go run -race reports a fatal data race (exit status 66)
$ HYB_ALLOW_TOOLCHAIN_DRIFT=1 CC=gcc CGO_ENABLED=1 go run -race main.go
==================
WARNING: DATA RACE
Write at 0x00c0000741b0 by goroutine 7:
runtime.mapassign_faststr()
/usr/local/go/src/runtime/map_faststr.go:223 +0x0
main.worker()
main.go:19 +0x50
main.main.gowrap1()
main.go:29 +0x58
Previous write at 0x00c0000741b0 by main goroutine:
runtime.mapassign_faststr()
/usr/local/go/src/runtime/map_faststr.go:223 +0x0
main.main()
main.go:30 +0x1d8
Goroutine 7 (running) created at:
main.main()
main.go:29 +0x1b8
==================
1 2
Found 2 data race(s)
exit status 66
Root Cause in hy-check
build_tables(compiler/crates/hy-check/src/lib.rs, line 170) discards all user-defined methods:if f.receiver.is_none() { ck.fns.insert(f.name.clone(), f); }prevented methods from overwriting top-level functions inck.fns, but never storedf.receiver.is_some()declarations in a method table.- Consequently,
call_shape,ty_of_expr,multi_value_shapes, andmulti_value_tys(shape.rs) could only look up foreign methods viaforeign::method_result, resolving every user-defined method call toTypeShape::Unknown.
record_may_shareandrecord_alias(compiler/crates/hy-check/src/loans.rs) ignore method receivers, struct-to-reference arguments, multi-value unpacks, andExpr::Try(?):record_aliasonly inspectedargsofExpr::Call(never the receiverbaseincallee = Expr::Field { base, .. }) and requiredb.shape.is_reference_alias()on the source binding (rejectingStruct/Arraybindings withbinding_may_share == true).record_may_sharehad noExpr::Callarm and was not called in the multi-value define/assign branches (l.values.len() == 1 && l.names.len() > 1), and neither function unwrappedExpr::Try(?).
Expected Behavior
hyb check method_repro.hy must reject the program with HYB-E3003 (tier0_rule: "A1b"):
error[HYB-E3003]: write through a live alias of a moved value
--> method_repro.hy:23:9
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
Activity
fix(hy-check): track user-defined methods and multi-return/ascribed c…
sonson0910 commentedon Oct 15, 2026
Update: Rebased the fix onto
main(c09e992/pr-162) and opened replacement PR #197 (#197), since PR #121 was accidentally auto-closed by GitHub when commit6344d496(Merge pr-122) includedfixes #121in its commit message.fix(hy-check): track user-defined methods and multi-return/ascribed c…
fix(hy-check): track user-defined methods and multi-return/ascribed c…
fix(hy-check): track user-defined methods and multi-return/ascribed c…
fix(hy-check): track user-defined methods and multi-return/ascribed c…
fix(hy-check): track user-defined methods and multi-return/ascribed c…
fix(hy-check): track user-defined methods and multi-return/ascribed c…
fix(hy-check): track user-defined methods and multi-return/ascribed c…
fix(hy-check): track user-defined methods and multi-return/ascribed c…
fix(hy-check): track user-defined methods and multi-return/ascribed c…
limitlessprojects commentedon Oct 18, 2026
Verified against main @ 0706813 — the full scenario set from this report (shared with PR #197's test block) now rejects with the exact expected codes:
obj.fieldcallee)?-unwrapped call sharingMethod/receiver tracking, struct-to-reference extraction edges, and
?-unwrapped call sharing are all populated intorecord_may_share/record_aliasby successor landings. Note: PR #197's ownmodel.rshunk was stale (it deletes thecollect_ref_rootsFnLit arm the current machinery needs) and was credit-closed rather than merged — the behavior this issue asks for is enforced on main.Closing as fixed — thanks @sonson0910 (who also authored much of the successor work).
STATUS: session-21 — old-wave recons + wave triage #248-#336 + const-…