Skip to content

§14.10: a channel receive as a select await arm (the spec's example) is refused: "select await arm requires a Task value" #2956

Closed

Description

@ehartford

Conformance audit 2026-11-02. §14.10's first example:

select await
    msg = rx_fast.recv() => print(f"fast: {msg}")
    msg = rx_slow.recv() => print(f"slow: {msg}")
    _ = timeout(1.secs()) => print("timeout")

Installed compiler (main 038c50c), with let (tx, rx) = chan[i64](4):

    select await:
        v = rx.recv() => print(f"got {v}")
        _ = p => print("producer first")
error: select await arm requires a Task value

rx.recv() is a fiber-aware runtime operation (§14.3 lists channel receive among the operations that yield the fiber), not a Task, so the one thing the spec shows select await racing cannot be raced. Either an arm accepts any may-suspend expression (the spec's "async expressions"), or Receiver.recv returns a Task. (timeout does not exist at all: #2955 item 1.) Arms over Task values work, and behav_async_select_cancels_parked_send covers a parked send, so the gap is the arm's accepted shape.

Activity

  1. added
    bug
    spec-gap
    on Nov 2, 2026
  2. ehartford commented on Nov 3, 2026

    @ehartford
    ContributorAuthor

    Mechanism, from the code as of main 7083214 (conformance campaign, item 3 of bridge-the-impl-gap):

    • select await lowers to FIBER_SELECT over Task operands (MirLower.w ~18376); each arm's expression must already be a Task (expr_is_awaitable_task_value, SemaCheck ~12706). A Task exists only from a call of a fn in sema.task_fns: codegen routes such a call to emit_async_fn_spawn_task_value (CodegenDispatch ~18816), which packs the arguments into a heap env, makes a per-fn trampoline, allocates a result buffer and calls with_fiber_spawn.
    • The channel runtime already cuts a parked recv short when the fiber is cancelled (rt/channel_runtime.w ~167), so a loser arm blocked in rx.recv() unwinds on FIBER_CANCEL as a losing Task does.

    So "a non-Task arm expression" = "spawn the expression as a fiber":

    1. Sema: an arm whose expression is not a Task is recorded (select_arm_spawn_nodes) and typed as its own value; the arm binding takes that type. Captures of the expression are summarized as a gen-loop body's are (closure_capture_summary_* keyed by the arm node), by place.
    2. MIR: for a recorded arm, synthesize an anonymous body from the expression the way begin_gen_loop_closure does (captures as leading params, no item param, the expression's value returned), and lower the arm's task operand as a call of that body marked spawnable (a MIR-side set codegen consults beside sema.task_fns), so the existing select/await/cancel/cleanup protocol sees a Task.
    3. Codegen: the spawn emitter takes any callee value and arg list; the anonymous body is declared as a function with its capture params, so no new trampoline shape.
    4. Fixture: test/conformance/open_s14_10_channel_select_arm.w moves to test/behavior; a second one races two receivers; select await biased unchanged.

    Worktree ~/.local/with-staging/select-arm (branch s14-10-select-recv-arm, on main) is open for it.

  3. added a commit that references this issue on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugspec-gap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions