Skip to content

Async lowering types an async call's result local as T while projecting Task.fiber_id (.f0) off it #1305

Closed

Description

@ehartford

Found by the audit:codegen place-type check (PR #1301) on test/behavior/behav_fn_abi_async.w's fixture. The audit's detail line (branch audit-place-types-followup) names the shape exactly:

violation: place 6 in main: projection could not be typed by codegen but its MIR type 3 (i32) is kind 8; base _6: Unit (ty 14) proj[0]=kind0:0
violation: place 15 in main: projection could not be typed by codegen but its MIR type 3 (i32) is kind 8; base _14: i64 (ty 4) proj[0]=kind0:0
violation: place 34 in main: projection lowers to LLVM type kind 8 but its MIR type 3 (i32) is kind 8; base _28: Payload (ty 88) proj[0]=kind0:0 got-int-width=64 want-int-width=32

--dump-mir of the fixture (async fn empty: (), async fn number(n: i64), async fn aggregate(value: Payload), all .awaited):

_1: ty14 [mut]            // Unit — the result of `call const fn sym225()` (empty())
...
_6 = copy _1;
call const ()(copy _6.f0) -> ...   // FIBER_WAS_CANCELLED_RETURN(fiber_id)

lower_single_await (src/MirLower.w:8286) and the FIBER_IS_DONE/FIBER_WAS_CANCELLED_RETURN method path (src/MirLower.w:10768) build new_field_place(task_place, 0, ty_i32) — Task.fiber_id, correctly typed — but the base local was created for the async call with the awaited result type T, not Task[T] (sema types the call as Task[T]). Codegen only survives because its FIBER_AWAIT lowering (src/CodegenDispatch.w:10199) treats that local's MIR type as the RESULT type and derives the Task struct itself, so the two sides agree by convention rather than by the MIR. On Payload the projection walk resolves .f0 to Payload.a (i64) — the same field-0-of-the-wrong-aggregate shape as #1280, here masked because the real load path takes a different route.

Expected: the async call's result local is Task[T], .f0 types as i32 on every walk, and FIBER_AWAIT reads T from the Task's generic argument. Until then audit_codegen_place_types skips places that feed a fiber intrinsic — a stated exclusion citing this issue, not a weakened check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions