Repository navigation
fix(hy-check): instantiate generic type parameters on call result shapes and types (#73) - #408
gelismarvel wants to merge 2 commits into
Conversation
|
Reviewed the patch. The core idea — threading a One thing that should be fixed before merge: the diff re-encodes existing comment text. I checked the file at The original U+2014
So roughly 20 lines of pre-existing documentation were rewritten by an encoding round-trip. It is not a correctness problem, but it inflates the diff with changes that have nothing to do with #73 and makes the real hunks harder to review — and once merged the corruption is in A smaller note on For what it is worth I did the same check I ran on #410: your branch builds, and the real question for #73 is whether the generic instantiation now freezes correctly ( |
…ced/nested type-arg test (limitlessprojects#73)
|
Thanks for the thorough review @G0st13! Addressed both points in e91032b:
|
|
Validation (agent session-15/2-a3, worktree = PR head merged with main @ c53978b): VALIDATED — READY TO LAND. Status note: the two headline repros from #73 (
Negative controls unchanged: non-generic Battery on the merged worktree: One observation for the author/maintainer: the false-reject family in (3) is worth a corpus fixture — "checker cannot verify because the type did not resolve" is exactly the class of fail-closed-but-wrong rejection that drives users away from generic helpers. Thanks @exantiv — substituting |
|
Thank you for validating @limitlessprojects! Happy to add a corpus fixture for the generic owned-move chain ( |
|
Closing as same-fix with credit - maintainer re-verification on current main (0c0ef74, after #312/#319/#234 landed): your transitive-call shape (m3 := m2 := id(m)) and the projection shape (inner := b.m) both reject E3003 on main now, and the false-reject case (m2 := id(move m); task worker(move m2)) ACCEPTS on main - the E3005 fail-closed was refined by later landings. All three of this PR's behaviors are covered; the generic-parameter instantiation machinery you built remains a solid reference for the future generics work. |
|
Thank you for the credit @limitlessprojects! Quick heads-up from testing against current
I rebased the branch cleanly onto |
…xit outer aliases Instantiate generic function and method return shapes and TypeExprs from call-site arguments across single-value and multi-value calls so shallow-copied references, struct field projections, slice element copies, and closure slices cannot escape O5.2 freeze tracking. Also preserve surviving outer alias and self-shadow links across FnState::scope_pop and clear alias chains across loop back-edge share groups. Fixes limitlessprojects#73 Fixes limitlessprojects#313 Sibling-take credit: @Visional-Dev (limitlessprojects#408), @Andrrewss (limitlessprojects#401)
Fixes #73
Participates in #5
Root Cause Analysis (RCA)
In
compiler/crates/hy-check/src/shape.rs,call_shape,ty_of_expr,multi_value_shapes, andmulti_value_tysresolved the declared return type of top-level functions (self.fns) directly throughshape_of_type(&r.ty)without instantiating generic type parameters (FnDecl::type_params) against call-site arguments (or explicit[T, ...]type arguments).Because any generic type parameter
tfell throughnamed_shape_depthtoTypeShape::Unknown(and remained an un-substitutedTypeExpr::Named { name: "t" }inty_of_expr), generic call results lost their concrete reference/container shape and source type:m2 := id(m); m3 := m2):m2receivedTypeShape::Unknownand missedrecord_alias(other_shape.is_reference_alias() == false). A subsequent copym3 := m2then skipped bothrecord_may_share(binding_may_share("m2") == falseonUnknown) andrecord_alias, leavingm3completely unfrozen aftertask worker(move m)(0 diagnostics, runtimefatal error: concurrent map writes).h2 := id(h1); inner := h2.m):h2receivedTypeShape::Unknowninstead ofTypeShape::Struct(Some("holder")), soinner := h2.mresolved toUnknownand skippedrecord_may_share(shape_may_share(&h2.shape) == false), allowinginner["k"] = 2aftertask worker(move h1)with0 diagnostics.fn id_slice[t any](s []t) []t,fn wrap_slice[t any](x t) []t): Return type[]tresolved toTypeShape::Slice(Box::new(TypeShape::Unknown)), erasing element shapes needed byrecord_copy_may_share(copy(dst, src)skipped linkingdstandsrc) and by the closure-container spawn guard (shape_carries_closure).m2 := id(move m); task worker(move m2)): Becausem2degraded toTypeShape::Unknown, honest owned move chains were falsely rejected withHYB-E3005.Changes
compiler/crates/hy-check/src/shape.rs:shape_of_type_with_params,infer_fn_type_params,match_param_shape,match_param_ty, andsubstitute_type_paramsto unifyFnDecl::type_paramsagainst call-site argument shapes/types (and explicit folded[T, ...]type arguments) and substitute them into single-return (call_shape,ty_of_expr) and multi-return (multi_value_shapes,multi_value_tys) result types.id(m), struct field projections ofid(h1),copy(dst, src)on generic slice results, closure-carrying slices returned by generic helpers, and the positive control (m2 := id(move m); task worker(move m2)).Verification
cargo test --manifest-path compiler/Cargo.toml -p hy-check: 126/126 unit tests PASS + 86/86 integration tests PASS (0 failed).