You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
§14.10: a channel receive as a select await arm (the spec's example) is refused: "select await arm requires a Task value" #2956
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.
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":
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.
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.
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.
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.
Activity
ehartford commentedon Nov 3, 2026
Mechanism, from the code as of main 7083214 (conformance campaign, item 3 of bridge-the-impl-gap):
select awaitlowers toFIBER_SELECTover 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 insema.task_fns: codegen routes such a call toemit_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 callswith_fiber_spawn.recvshort when the fiber is cancelled (rt/channel_runtime.w~167), so a loser arm blocked inrx.recv()unwinds onFIBER_CANCELas a losing Task does.So "a non-Task arm expression" = "spawn the expression as a fiber":
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.begin_gen_loop_closuredoes (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 besidesema.task_fns), so the existing select/await/cancel/cleanup protocol sees a Task.test/conformance/open_s14_10_channel_select_arm.wmoves to test/behavior; a second one races two receivers;select await biasedunchanged.Worktree
~/.local/with-staging/select-arm(branch s14-10-select-recv-arm, on main) is open for it.§14.10 (#2956): a select await arm races any async expression (#3018)