Skip to content

Sema: a join arm typed as a bare generic (Vec.new()) records the join's type (#1393) - #1418

Merged
ehartford merged 1 commit into
mainfrom
fix-1393-ref-default-join
Sep 23, 2026
Merged

ehartford merged 1 commit into
mainfrom
fix-1393-ref-default-join

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #1393. Stacked on #1398 (branch fix-1363-unwrap-or-str). Sibling of #1404 (#1378): both add the same type_is_generic_base_of helper and both extend the same completion loop in resolve_contextual_join, so whichever lands second has a trivial conflict.

Root cause

say(&o.unwrap_or(Vec.new())) failed with [mir-lower-fail] kind=27 at the Vec.new() span. So did o.unwrap_or(Vec.new()).len(), &r.unwrap_or(Vec.new()) and (o ?? Vec.new()).len(). let v = o.unwrap_or(Vec.new()) compiled.

  • lldb, breakpoint on MirBuilder.mark_unsupported. The call path is: lower_un_op (the &) → lower_expr_place → lower_unwrap_or_method → lower_method_call → lower_intrinsic_call → mark_unsupported.
  • In lower_intrinsic_call, a static constructor whose result type is the bare struct takes its type from self.expected_type, but only when that is the matching generic instance. Under & the expected type is &Vec[i32], and as a receiver there is none. So ret_type stays the bare TY_STRUCT and hits mark_unsupported.
  • with analyze repro.w explain:node:577319 (the Vec.new()), base: type=Vec. The join settled on Vec[i32] but never recorded it on the arm. The let form only worked because let happened to supply the right expectation.
  • Exact line: the completion loop in resolve_contextual_join (src/SemaCheck.w) completed an arm only when its type was 0 (variant shorthands).

Fix

Per §3.8/§10, the join decides the arm's type. An EXPR arm whose type is the bare generic base of the final type now records the final type, both on the node and on the recorded arm. After the fix, the same query reads type=Vec[i32] and the repro prints 0.

Matrix

test/debug_alloc/da_join_default_bare_generic_any_context.w (leak count 0, exact stdout):

  • unwrap_or on Option/Result × both paths, under & and as a method receiver
  • ?? as a receiver and under &
  • HashMap, an owned call argument
  • if / match arms

On the base it fails MIR lowering.

Local evidence (iterate tier, stage1 from this branch)

  • with check src/main.w: ok
  • 92 d22 / §10 / §3.8 / carrier-eliminator fixtures: every failure (test/non_compliant/d22/*, two phase dumps) also fails on the base.

This changes typing only. It does not change drop scheduling or ownership lowering. Full battery not run, so this stays a draft.

@ehartford

Copy link
Copy Markdown
Contributor Author

Batch battery X2 (seed-driven, NEW seed, with :drop-audit/:move-audit) on main 977e667 + #1404 → #1418 → #1419 → #1425 (head ee4e2e4, including the #1404/#1418 join-arm merge resolution): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. #1424's four repros run clean on this build. Branches hold exactly the tested chain; merge in order #1404, #1418, #1419, #1425 — then batch Y (#1405 … #1360), then #1428.

@ehartford

Copy link
Copy Markdown
Contributor Author

Back to draft: this ships inside the combined battery with #1425/#1428 (rebased on main with batch Y). When that battery is green, the whole chain lands as ONE PR (#1425) and this PR closes into it.

@ehartford
ehartford force-pushed the fix-1393-ref-default-join branch from 4b8b601 to 777fb39 Compare September 23, 2026 05:16
@ehartford
ehartford added this pull request to stack #1437 September 23, 2026 05:17
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery (seed-driven, new seed, with :drop-audit/:move-audit) on main 05b674e (incl. batch Y) + #1418 → #1419 → #1425 → #1428 (head eea9017): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds — including #1422's da_option_filter_observes_payload, so this clears main's #1424 red), :test-green ok, :last-green ok. Merges cleanly into main 1c76062. Now GitHub stack #1437 (gh stack link); merge the whole stack: gh stack merge 1428 --squash.

@ehartford
ehartford marked this pull request as ready for review September 23, 2026 05:17
…in's type (#1393)

Route: MIR lowering failure — WITH_MIR_AUDIT, lldb on mark_unsupported,
analyze facts for the arm node.

`say(&o.unwrap_or(Vec.new()))` failed: `[mir-lower-fail] kind=27 fn=main
span=118..127` (the `Vec.new()`), `error: code generation failed`. So did
`o.unwrap_or(Vec.new()).len()`, `&r.unwrap_or(Vec.new())` and
`(o ?? Vec.new()).len()`; `let v = o.unwrap_or(Vec.new())` compiled.

Evidence:
- lldb, breakpoint on MirBuilder.mark_unsupported: lower_un_op (the `&`)
  -> lower_expr_place -> lower_method_call -> lower_unwrap_or_method ->
  lower_method_call -> lower_intrinsic_call -> mark_unsupported. In
  lower_intrinsic_call a static constructor (VEC_NEW) whose
  method_call_result_type is the bare struct borrows the type from
  `self.expected_type` only when that is the matching GENERIC_INST; under
  `&` it is `&Vec[i32]` (as a receiver, nothing), so ret_type stays the
  bare TY_STRUCT and MirLower.w's `ret_tk2 == TypeKind.TY_STRUCT` branch
  calls mark_unsupported.
- `with analyze repro.w explain:node:577319` (the `Vec.new()` node), base
  stage1: `type=Vec`. The join had settled `Vec[i32]` but never recorded it
  on the arm; the `let` form only worked because lower_let's expectation
  happened to be `Vec[i32]`.

Exact line: SemaCheck.resolve_contextual_join completes an arm after the
final type is known only when the arm's type is 0 (variant shorthands). An
EXPR arm typed as the bare generic base of the final type kept that type.

Fix (§3.8/§10: the join fixes the arm's type): the completion loop
records the final type on an EXPR arm whose type is the bare generic base
of it (typed_expr_types and the recorded arm type), so lowering the arm no
longer depends on the surrounding expectation. After: explain:node:577319
reads `type=Vec[i32]`; the repro prints 0.

Matrix (test/debug_alloc/da_join_default_bare_generic_any_context.w, leak
count 0, exact stdout): unwrap_or on Option / Result × both paths, under
`&` and as a method receiver; `??` as a receiver and under `&`; HashMap;
an owned call argument; `if` and `match` arms under `&` / bound. Base
stage1 (fix-1363-unwrap-or-str): MIR lowering failed. The 92 d22 / §10 /
§3.8 / carrier-eliminator fixtures: every failure also fails on the base
(test/non_compliant/d22/*, two phase dumps).

Typing change only: no drop scheduling or ownership lowering changed.
Shares type_is_generic_base_of with #1378's branch (same helper text).

Fixes #1393.
@ehartford
ehartford force-pushed the fix-1393-ref-default-join branch from 777fb39 to 9b05af8 Compare September 23, 2026 09:57
@ehartford
ehartford removed this pull request from stack #1437 September 23, 2026 09:58
@ehartford
ehartford added this pull request to stack #1466 September 23, 2026 09:58
@ehartford

Copy link
Copy Markdown
Contributor Author

Stack #1466 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main 1c76062 + #1418 → #1419 → #1425 → #1428 → #1449 → #1377 → #1459 → #1460 → #1461 → #1462 (head cf36211, including the #1449/#1462 Codegen resolution and the fixed #1460): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Each branch holds exactly its tested commits on the layer below. Merge the whole stack: gh stack merge 1462 --squash.

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.

say(&o.unwrap_or(Vec.new())): MIR lowering fails — Vec.new() gets no expected type under &

1 participant