Skip to content

hy-check: instantiate generic call return shapes and keep block-exit outer aliases (refs #73, #313) - #1216

Closed
dancerdan15 wants to merge 2 commits into
limitlessprojects:mainfrom
dancerdan15:fix/hy-check-loop-backedge-range-vars-313
Closed

dancerdan15 wants to merge 2 commits into
limitlessprojects:mainfrom
dancerdan15:fix/hy-check-loop-backedge-range-vars-313

Conversation

@dancerdan15

@dancerdan15 dancerdan15 commented Oct 22, 2026 •

Copy link
Copy Markdown

Refs #73 (residual generic variants)
Refs #313

What this fixes

The original #73 repros (alias_holder(h1) and id(m) / id(s)) are already rejected on main (see tests/call_share.rs). This PR closes the generic gaps that are still open, plus one block-exit alias hole:

  • Generic alias chain: m2 := id(m); m3 := m2; move m; write m3. Main accepted this, and the emitted Go races at runtime (concurrent map writes). It is now rejected with HYB-E3003.
  • Struct projection through a generic identity: h2 := id(h1); inner := h2.m; move h1; write inner. Main accepted this. It is now rejected with HYB-E3003.
  • Multi-return chain: _, m2 := pair_id(1, m); m3 := m2; move m; write m3. Main accepted this. It is now rejected with HYB-E3003.
  • False reject removed: m2 := id(move m); task worker(move m2) is valid. Main rejected it with HYB-E3005. It is now accepted.
  • Shadowed block alias ([soundness] Loop back-edge check (check_loop_backedge) fails to propagate moved alias state across iterations, allowing double-move data races #313-style): if true { m := m; alias = m; m = fresh }; task worker(move m); alias[k] = 3. Main accepted this, and the emitted Go races at runtime. It is now rejected with HYB-E3003. FnState::scope_pop now keeps outer alias links and shadow links when a block exits.

Implementation

  • shape.rs: generic type parameters are instantiated at call sites (infer_call_type_shapes, infer_call_type_args, subst_call_type_params, call_result_tys_with_args, call_result_shapes_with_args).
  • loans.rs: value_reads_storage_of and expr_has_borrow_shape now use the instantiated result shapes.
  • model.rs: scope_pop keeps outer aliases and shadow links. Cycles are checked, and the change only makes the checker stricter.
  • freeze.rs: after check_loop_backedge reports, it clears the whole alias chain, so the same chain is not reported twice.

Tests

These tests fail on base 7d63d5f and pass with this PR:

  • generic_call_freeze_73_a (alias chain, struct projection)
  • generic_call_freeze_73_b (owned move chain, the E3005 false reject)
  • generic_multi_return_73
  • scope_pop_outer_alias_313 (shadow sub-case)

loop_backedge_range_vars_313 passes on main as well. It is a regression guard and does not prove a fix.

cargo test -p hy-check: 1369 passed, 0 failed.

Out of scope / known limitations

  • Generic struct field instantiation (b := box[map]{val: m}; m2 := unbox(b)) is not handled. It is still accepted and needs a separate issue. Its test case was removed from this PR.
  • I removed the closure-slice (wrap_slice(f)) and copy(dst, id_slice(src)) cases from the tests. Main already rejects both, so they are not fixes from this PR.

@sonson0910

Copy link
Copy Markdown
Contributor

Prior-Art & First-Reporter Cross-Reference (#105 / PR #106)

For maintainer Wave-2 triage cross-reference:

@github-actions github-actions Bot added the bot:stale-base Shepherd: behind main beyond threshold label Oct 23, 2026
…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)
@dancerdan15
dancerdan15 force-pushed the fix/hy-check-loop-backedge-range-vars-313 branch from 2dd3c74 to 7a9b538 Compare October 23, 2026 05:44
@github-actions github-actions Bot added the bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify()) label Oct 23, 2026
@dancerdan15 dancerdan15 changed the title hy-check: instantiate generic call return shapes and preserve block-exit outer aliases (#73, #313) hy-check: instantiate generic call return shapes and keep block-exit outer aliases (refs #73, #313) Oct 23, 2026
@dancerdan15

Copy link
Copy Markdown
Author

Thanks @sonson0910. Our three generic-call tests (generic_call_freeze_73_a, generic_call_freeze_73_b, generic_multi_return_73) pass on #106 (b3541f5), so #105/#106 has priority on the generic call return-shape part.
The model.rs scope_pop fix (scope_pop_outer_alias_313, refs #313) fails on #106 and on main, and passes here, so it is independent of #106.
If #106 lands first, or whenever the maintainer prefers, we'll drop the generic-call hunks and reduce this PR to the scope_pop (#313) fix.

@limitlessprojects

Copy link
Copy Markdown
Owner

Queue-reset sweep: this repo now runs a rolling conveyor, and open PRs
outside the active review window are being closed as not planned to keep the
queue honest — a stale queue wastes every contributor's time, including yours.

This is not a verdict on the work. If this change still matters:

  1. rebase against current main (main has landed a lot since this PR opened),
  2. confirm the diff still applies and the affected verdicts still hold,
  3. reopen — the triage board picks reopened PRs up as fresh arrivals.

Wildcard holds (verdict window 2026-11-01) and Pareto land candidates are
unaffected. Thanks for the effort — high-volume repos only stay reviewable
with a queue that actually drains.

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

Labels

bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify()) bot:stale-base Shepherd: behind main beyond threshold

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants