Repository navigation
Description
The smallest .hy program that demonstrates it
// Commit: aa4a9d9 (latest main)
// Command: hyb check repro.hy && hyb build repro.hy
// Original Finder & Bounty Claimant: @huynhnhatquandongnai-source
// Payout Wallet (USDC/USDT - BEP20/EVM): 0xb9f3765aeb1974c27a193463f655a1a57b3aec94
struct box[t] {
v t
}
fn worker(b box[[]int], done chan bool) {
b.v[0] = 1
done <- true
}
fn main() {
done := make(chan bool, 1)
b1 := box[[]int]{v: []int{0}}
b2 := b1
task worker(move b1, done)
b2.v[0] = 2
<-done
}
What the checker should say
Reject with HYB-E3003 (tier0_rule: "A1b", O5.2 — write through a live alias of a moved value: b2 is a shallow copy of b1 := box[[]int]{v: []int{0}} sharing the underlying []int backing array, so moving b1 into task worker(move b1, done) must freeze b2 in main).
Negative Control (Monomorphic equivalent is correctly rejected with HYB-E3003):
struct int_box { v []int }
fn worker(b int_box, done chan bool) { b.v[0] = 1; done <- true }
fn main() {
done := make(chan bool, 1)
b1 := int_box{v: []int{0}}
b2 := b1
task worker(move b1, done)
b2.v[0] = 2
<-done
}
Additional P0 Soundness Bypasses from the Same Root Cause (All Accepted with 0 Diagnostics & Race at Runtime):
- O5.1 Non-owned parameter move bypass (HYB-E3004): Copying local_b := param_b (where param_b: box[[]int]) drops non_owned_origin and share_edge, allowing task worker(move local_b, done) while caller mutates b.v[0].
- T22 Deep const immutability bypass (HYB-E3006): Copying c := k from const k = box[[]int]{v: []int{0}} drops shadowed_const and const_write_root, allowing concurrent tasks to mutate c.v[0] on the shared const slice.
- A5 / O4 Closure-in-generic-struct move bypass (HYB-E3001): b := box[fn()]{v: fn() { shared = 1 }}; task run_box(move b, done) is accepted with 0 diagnostics, racing on captured local shared.
- O12 / O2 Borrow-in-generic-struct & loan-escape bypass (HYB-E3103 / HYB-E3104): fn escape() box[*node] { n := node{x: 1}; b := box[*node]{v: &n}; return b } is accepted with 0 diagnostics, escaping stack borrow &n.
What it actually said
OK (0 diagnostics) — Verdict::Accept. Compiles cleanly under hyb build / go build and immediately triggers WARNING: DATA RACE under go run -race between worker writing b.v[0] = 1 and hyMain writing b2.v[0] = 2.
Claimed severity
P0 — data race reachable in the checked subset
Anything else
Root Cause in hy-check
Commit 4a17528 (#722) enabled generic struct declarations (struct box[t] { v t }) to emit valid Go (type box[t any] struct { v t }) and added type-argument substitution (OpKind::Struct(Some(full_name)), struct_type_arg_map, kind_of_ty_with_subst) only inside compiler/crates/hy-check/src/buildable.rs:1231-1390.
However, the Tier-0 ownership, sendability, freeze, loan, and const-immutability passes in shape.rs, sendability.rs, and loans.rs still strip generic type arguments:
compiler/crates/hy-check/src/shape.rs:80-84(Checker::named_shape_depth) &shape.rs:269-275:
CallsSelf::base_named_type_str(name)and returnsTypeShape::Struct(Some("box")), discarding[[]int].compiler/crates/hy-check/src/shape.rs:116-143(Checker::shape_may_share_at):
Looks upself.structs.get("box"), whose uninstantiated field type isTypeExpr::Named { name: "t" }.self.shape_of_type(ty)returnsTypeShape::Unknown, soshape_may_share_atreturnsfalsefor every generic struct whose reference-bearing field comes from a type parametert.compiler/crates/hy-check/src/sendability.rs:157-212(shape_holds_closure&shape_holds_unmovable_leaf) andcompiler/crates/hy-check/src/loans.rs:2006-2042, 7760-7860(field_borrow_kind&expr_has_borrow_shape):
All evaluate uninstantiated field type"t"->TypeShape::Unknown->false.
Original Reporter & Bounty Claimant: @huynhnhatquandongnai-source
Payout Wallet (USDC/USDT — BNB Smart Chain BEP20 / EVM): 0xb9f3765aeb1974c27a193463f655a1a57b3aec94
(Note: Per BOUNTY.md rules, the first reporter of this unique root cause holds the bounty claim. I am also preparing the regression test and fix PR under @huynhnhatquandongnai-source.)
Activity
sonson0910 commentedon Oct 19, 2026
Prior-Art & First-Reporter Notice (Duplicate of
#105/PR #106, filed 97.5 hours earlier)For maintainer triage reference (
@limitlessprojects), the root cause and soundness surface reported here —TypeShapegeneric type-argument erasure on generic structs (box[T],lru_cache[K, V]) acrossshape.rs,sendability.rs, andloans.rs— was originally reported and fixed 4 days (97.5 hours) earlier by@sonson0910in:2026-10-15T01:51:53Z5ea48d1,MERGEABLE / CLEANonaa4a9d9) — opened2026-10-15T01:52:46Z#772(@aazminu) — filed2026-10-19T03:18:57Z(+97 hours 27 minutes later)#775(@huynhnhatquandongnai-source) — filed2026-10-19T03:26:51Z(+97 hours 35 minutes later)PR #106already implementsChecker::resolved_struct_fields,struct_fields_for_name, andshape_field_borrow_kindacrossshape.rs,sendability.rs, andloans.rs, rejecting all repros (HYB-E3003,HYB-E3004,HYB-E3006,HYB-E3001/HYB-E3002,HYB-E3102,HYB-E3104,HYB-E4001, andHYB-E4002) with regression tests incompiler/crates/hy-check/src/lib.rs.huynhnhatquandongnai-source commentedon Oct 19, 2026
Fix PR Submitted: #792 (Covers
emit_guard.rs,closures.rs, andfreeze.rssurfaces omitted by #106)Fix PR: #792 (
2f5fb14,MERGEABLE: true)For maintainer triage (
@limitlessprojects): in addition toshape.rs,sendability.rs, andloans.rs, PR #792 also closes the remaining generic-structTypeShapesoundness & completeness gaps inemit_guard.rs,closures.rs, andfreeze.rsthat were not touched by PR #106:emit_guard.rs(check_type_expr_with_state— O12 / A6HYB-E3103): Rejects generic struct instantiations carrying non-atomic pointers or borrow handles (box[*int]{v: &x},box[serde_json.view]) withHYB-E3103, which otherwise slip pastcheck_struct_declsbecause the uninstantiated declarationtype box[T any] struct { v T }hasTypeShape::UnknownforTat struct-decl check time.emit_guard.rs(incomparable_rec&Expr::StructLit— B2HYB-E6003&HYB-E6002): Substitutes generic type parameters when checking struct comparability (box[[]int]{} == box[[]int]{}) and constant integer overflow on generic struct literal fields (box[int8]{v: 200}).closures.rs(A6HYB-E3103inside closure bodies): Uses recursiveck.field_borrow_kind(&shape)on field assignments inside closure bodies.freeze.rs(shape_is_proven_pure_value): NormalizesSelf::base_named_type_str(sname)when checking generic struct declarations inshape_is_proven_pure_value.Author / Payout Attribution:
@huynhnhatquandongnai-source0xb9f3765aeb1974c27a193463f655a1a57b3aec94sonson0910 commentedon Oct 19, 2026
Duplicate / Copied PR & Regression Notice — Reported & Fixed 99 Hours Earlier in #105 / PR #106
For maintainer triage: this PR (
#792, opened2026-10-19T05:09:20Z) is a duplicate of our earlier issue and pull request opened more than 4 days (99 hours 16 minutes) earlier, and was opened 80 minutes after we posted a prior-art link to PR #106 on#775:2026-10-15T01:51:53Z(99 hours 17 minutes before#792).fix/generic-struct-and-set-soundness) — opened2026-10-15T01:52:46Z(99 hours 16 minutes before#792).#775: #775 (comment) — posted2026-10-19T03:48:53Z(80 minutes before#792was opened).1. Regression Introduced by
#792(tests/const_overflow.rs::type_alias_struct_literal_overflow_is_rejectedFails)In
compiler/crates/hy-check/src/emit_guard.rs:413-419,#792deleted thewhile let Some(TypeExpr::Named { name: target, .. }) = self.type_aliases.get(&sname) { sname = target.clone(); }loop before callingself.struct_fields_for_sname(&sname). Becausestruct_fields_for_snameonly looks upself.structs.get(sname), any struct literal constructed through a type alias (type MyLimit = Limit; MyLimit{limit: 300}) returnsNoneand breaks existing testtests/const_overflow.rs::type_alias_struct_literal_overflow_is_rejected:2. Direct Code Overlap & Strict Superset Comparison (
PR #106vs#792)#792was already implemented inPR #106on Oct 15:TypeShape::Struct(Some(name.to_string()))inshape.rs:231instead of stripping[T1, T2].Decl::Struct.type_paramsacross field types viastruct_fields_for_name/parse_generic_type_args/substitute_type_paramsinsendability.rsandshape.rs.shape_field_borrow_kind/emit_struct_field_borrow_diag) and generic receiver base-name stripping acrossloans.rs,closures.rs,emit_guard.rs(while preservingself.type_aliasesresolution soconst_overflowpasses94/94), andfreeze.rs.PR #106additionally covers that#792omits:set[T]sendability and share-edge tracking (HYB-E3001/HYB-E3003),resolve_hy_fn_for_call),Pair[K, V]), chained type aliases to generic structs (type Alias = Box[map[string]int]), and nested generic struct fields (Outer[Inner[[]int]]),mainwith 100% of unit and integration tests passing (includingtests/const_overflow.rs94/94 okand 27 dedicated generic-struct/set regression tests).Recommend closing
#792and#775as duplicates of #105 / PR #106.Dimank92 commentedon Oct 26, 2026
Opened PR #1806 to fix this issue by preserving full generic type arguments in TypeShape::Struct and substituting type parameters during struct field shape lookups.
fix(hy-check): preserve generic struct type arguments for soundness p…