Repository navigation
fix(hy-check): preserve generic struct type args in TypeShape::Struct across all soundness passes (Fixes #775) - #792
Conversation
…Fixes limitlessprojects#775) Preserve full generic instantiation names in named_shape_depth and substitute struct type parameters via struct_fields_for_sname / struct_fields_for_type across shape_may_share, field_shape, shape_holds_closure, shape_holds_unmovable_leaf, shape_is_const_sendable, field_borrow_kind, ty_of_expr, and place_target_ty. Fixes limitlessprojects#775 Author: @huynhnhatquandongnai-source Wallet (USDC/USDT BEP20/EVM): 0xb9f3765aeb1974c27a193463f655a1a57b3aec94
Duplicate / Copied PR & Regression Notice — Reported & Fixed 99 Hours Earlier in #105 / PR #106For maintainer triage: this PR (
1. Regression Introduced by
|
Fixes #775
Summary
In
compiler/crates/hy-check/src/shape.rs,Checker::named_shape_depthpreviously stripped generic type arguments viabase_named_type_str(name)and returnedTypeShape::Struct(Some(base.to_string())), while field lookups acrosssendability.rs,shape.rs,loans.rs,closures.rs,emit_guard.rs, andfreeze.rsqueriedself.structs.get(...)without substituting the struct's declared type parameters (struct_type_params).As a result, any generic struct field typed as a type parameter
Tresolved toTypeShape::Unknown, causing multiple Tier-0 soundness checks (and completeness checks acrossemit_guard.rs,closures.rs, andfreeze.rs) to silently bypass:shape_may_share_at):b1 := box[[]int]{...}; b2 := b1; task worker(move b1); b2.v[0] = 42was accepted withoutHYB-E3003and caused a concurrent data race.field_shape&ty_of_expr):s := b.vresolved toTypeShape::Unknown, droppingmay_share,non_owned_origin, andimmutable(const) propagation (HYB-E3003/HYB-E3004/HYB-E3006).shape_holds_closure,shape_holds_unmovable_leaf,shape_is_const_sendable):box[fn()],box[sync.Mutex], andconst box[[]int]bypassedHYB-E3004/HYB-E3001.field_borrow_kind,emit_guard.rs,closures.rs,freeze.rs): Generic struct instantiations carrying pointers or borrow handles (box[*int],box[serde_json.view]), incomparable generic structs (box[[]int] == box[[]int]), and constant overflow on generic struct literals (box[int8]{v: 200}) are now properly checked (HYB-E3103,HYB-E6003,HYB-E6002).Changes
sendability.rs: AddChecker::struct_fields_for_sname(with alias resolution andstruct_type_paramssubstitution) and updateshape_holds_closure,shape_holds_unmovable_leaf,shape_is_const_sendable,spawn_param_shapes,shape_may_be_elem, andcheck_composite_nils.shape.rs: Preserve full generic instantiation name innamed_shape_depth(TypeShape::Struct(Some(name.to_string()))), preserve index type args incall_shape("new"), and usestruct_fields_for_sname/struct_fields_for_typeinshape_may_share_at,shape_carries_handle_at,struct_has_mutex_field,field_shape,ty_of_expr, andno_zero_value_reason.loans.rs&closures.rs: MakeChecker::field_borrow_kindrecurse into instantiatedTypeShape::Struct(Some(sname))fields with cycle protection, normalize receiver base names in method lookups, and substitute generic fields inplace_target_ty.emit_guard.rs&freeze.rs: Check generic struct type arguments and A6 stored-borrow invariants incheck_type_expr_with_state(HYB-E3103), usestruct_fields_for_snameinExpr::StructLitandincomparable_rec, and normalizebase_named_type_strinshape_is_proven_pure_value.tests/generic_struct_type_shape_issue_775.rs: Add regression test suite coveringHYB-E3003,HYB-E3004,HYB-E3006,HYB-E3001,HYB-E3103, and positive controls (Verdict::Accept).Author / Payout Attribution:
@huynhnhatquandongnai-source0xb9f3765aeb1974c27a193463f655a1a57b3aec94