Skip to content

fix(hy-check): track generic structs, prelude set[T], and associated generic calls (#105) - #106

Open
sonson0910 wants to merge 1 commit into
limitlessprojects:mainfrom
sonson0910:fix/generic-struct-and-set-soundness
Open

sonson0910 wants to merge 1 commit into
limitlessprojects:mainfrom
sonson0910:fix/generic-struct-and-set-soundness

Conversation

@sonson0910

@sonson0910 sonson0910 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #105 (Bounty Track #5).

Summary

Closes the generic and prelude type-table omissions in hy-check that allowed mutable reference-bearing state to cross task boundaries un-frozen (A1b) or un-classified (A1c):

  1. Generic struct instantiations (box[map[string]int], lru_cache[string, int]):
    • build_tables (lib.rs) records struct_type_params: HashMap<String, Vec<TypeParam>> alongside self.structs.
    • shape.rs adds split_generic_name and resolved_struct_fields, substituting type arguments across generic struct fields in shape_may_share_at, field_shape, and struct_has_mutex_field.
    • Shallow copies (b2 := b1) of generic structs instantiated with reference-bearing type arguments now record a may_share edge and are frozen on move b1 (HYB-E3003), while field projections (m := b1.v) resolve to their substituted TypeShape. Generic structs instantiated with purely sendable types (box[int]) remain non-sharing.
  2. Prelude set[T] (set.new[string]()):
    • hy-emit lowers set[T] to type set[t comparable] struct { m map[t]struct{} }, so a shallow struct copy shares the underlying Go map m.
    • shape.rs recognizes set / set[T] in named_shape_at, call_shape (set.new[T](), .insert / .contains / .len), and shape_may_share_at (true).
  3. Associated and explicit-type-arg generic function calls (lru_cache.new[string, int](2), box.new[map[string]int](m)):
    • shape.rs adds resolve_hy_fn_call to resolve direct and Type.method associated Hybrid function calls (with explicit [type_args] or argument-inferred type parameters) across call_shape, ty_of_expr, multi_value_shapes, and multi_value_tys (plus sendability.rs and loans.rs), alongside Decl::TypeAlias resolution and call-return may_share propagation.

Verification

  • Added 4 regression test suites in compiler/crates/hy-check/src/lib.rs:
    • set_prelude_shallow_copy_and_unmoved_spawn_reject
    • generic_struct_instantiation_tracks_may_share_and_field_projection
    • generic_and_associated_fn_calls_preserve_return_shape_and_arg_sharing
    • type_alias_resolves_underlying_shape_for_aliases_and_boundaries
  • cargo test --workspace — all unit and integration tests pass.
  • cargo clippy --workspace --all-targets -- -D warnings — 0 warnings.
  • python3 tools/corpus_harness.py — 27/27 verdict agreement, tripwire not fired.
  • python3 tools/managed_gate.py — PASS (2 block(s), baseline 2).
  • python3 tools/differential_loop.py — 10/10 accept, 17/17 reject (FULL AGREEMENT).
  • All 10 examples/*/program.hy pass hyb check with 0 diagnostics.

@sonson0910 sonson0910 changed the title fix(hy-check): resolve generic structs, prelude set[T], generic calls, and type aliases (#105) fix(hy-check): track generic structs, prelude set[T], and associated generic calls (#105) Oct 15, 2026
@sonson0910
sonson0910 force-pushed the fix/generic-struct-and-set-soundness branch from d3c3f15 to 4ec24cb Compare October 15, 2026 04:51
@limitlessprojects

Copy link
Copy Markdown
Owner

Triage (2026-10-15, AI maintainer): generic struct instantiations + prelude set[T] (#105) is the largest remaining known soundness gap and your writeup is the most complete we have. This one is genuinely big — it gets its own review slot rather than the conveyor: expect a design note from the maintainer side first (the shape machinery's generic-story is uncommitted today), then a maintainer-assisted rebase. Thank you for the depth here.

@sonson0910
sonson0910 force-pushed the fix/generic-struct-and-set-soundness branch from 4ec24cb to 0f85670 Compare October 15, 2026 12:57
@sonson0910

Copy link
Copy Markdown
Contributor Author

Thank you for the kind words and dedicated review slot! Proactively rebased fix/generic-struct-and-set-soundness onto latest main (c09e992, commit 0f85670), composing cleanly with pr-162's collect_ref_roots. All 201 hy-check tests pass. Happy to adapt anything once your design note on generic shapes lands!

@limitlessprojects

Copy link
Copy Markdown
Owner

Triage (2026-10-15, AI maintainer, post-CI-repair): unchanged from last session: generic struct instantiations + prelude set[T] (issue #105) keeps its own design-note-first review slot — the maintainer-side shape-machinery note is due with the next review pass. Queued as its own slot, not the conveyor.

@sonson0910
sonson0910 force-pushed the fix/generic-struct-and-set-soundness branch 2 times, most recently from 417b144 to 6825571 Compare October 17, 2026 03:02
@limitlessprojects

Copy link
Copy Markdown
Owner

Wave-2 triage: queued — next tier (carried from wave 1). Fixes #105 (generic structs box[T]/lru_cache, prelude set[T], associated generic calls) — the largest single soundness surface left; lands after a fresh rebase.

@sonson0910
sonson0910 force-pushed the fix/generic-struct-and-set-soundness branch from 6825571 to ed47037 Compare October 17, 2026 05:44
@sonson0910

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto latest main (cad1375, ed47037), resolving the shape.rs merge conflict with #343/#355 while preserving both user-struct/alias precedence (#326) and generic struct / set[T] / associated generic call resolution (#105). Full cargo test --workspace passes with 0 failures.

@sonson0910
sonson0910 force-pushed the fix/generic-struct-and-set-soundness branch 4 times, most recently from 599613b to c910c58 Compare October 17, 2026 15:11
@sonson0910
sonson0910 force-pushed the fix/generic-struct-and-set-soundness branch 5 times, most recently from ac8fa92 to 61d6a1c Compare October 18, 2026 23:39
@sonson0910
sonson0910 force-pushed the fix/generic-struct-and-set-soundness branch from 61d6a1c to 5ea48d1 Compare October 19, 2026 03:48
@sonson0910

Copy link
Copy Markdown
Contributor Author

Rebased cleanly on aa4a9d9 (5ea48d1, MERGEABLE / CLEAN, 178/178 unit tests passing in hy-check). Also verified that this PR resolves all repros in later duplicate issues #772 and #775 (filed on 2026-10-19T03:18Z–03:26Z, 97.5 hours after #105 / #106).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[soundness] Generic struct instantiations (box[T], lru_cache[K, V]), prelude set[T], and associated generic calls bypass A1b freeze

2 participants