- spec 04 §40: mutex<T> always linear, never copyable; mutex.take is the only way to dismantle it and needs no live borrow (hence no guard and no waiter); no unlock or destructor - P3-10 (async buffer claims, E4303) moved to P7-10 with task-aware I/O; E4303 stays reserved; Phase 3 scope closed - RFC 0012 erratum: consumption after send is E2002, use is E2001 - tests: take while borrowed (E2101), use after take (E3001)
32 KiB
RFC 0012: Channels, Mutex, Select and Cancellation Points
Status: Accepted (revision 2, after owner review: D1–D3 decided; task.wait gated by cancellation; values and handles returned as block parameters)
Scope: AIR format 0, features cancellation, channels, sync
Language version: 0.1
Measured Agent Reference Bundle growth on integration: +15.8 % tokens (estimate: 12–16 %).
Integrated into: spec 04 §37–§41; spec 04 §35; spec 05 §9; spec 07 §8.11; spec 07a; spec 08 §14; spec 11 §8; reference/air-features.md, effects.md, error-codes.md; docs/design/decisions.md DD-014; docs/agent/bundle.txt
Supersedes: —
Erratum (owner decision after implementation): rejected example 3 corrected to E2002 (consumption after send); E2001 is a non-consuming use. mutex<T> is always linear (spec 04 §40).
Resolves: Q-013 (deterministic select and the scheduler's choice points). Realizes spec 04 §7–§9, §12, §14–§16 for AIR. Builds on RFC 0011 (spec 04 §33–§36).
Scope boundary:
RFC 0011: who may execute concurrently?
RFC 0012: how do concurrent tasks communicate, wait and coordinate?
Out of scope: RwLock (deferred, reserved feature rwlock), atomics (own RFC: after atomics the "every native outcome is an interleaving" model no longer suffices, spec 04 §36.1), timers, task-aware I/O and async buffer claims (E4303), several receivers (channels are MPSC).
Motivation
After RFC 0011 tasks can only exchange data at spawn and join. Stage B of the evaluation (spec 14, docs/evaluation/protocol.md) needs the next two steps of spec 04 §1: ownership transfer between running tasks (channels) and synchronized shared state (mutex). It also needs waits that can be cancelled and a reproducible select.
The design goal is a concurrency core that a weaker model can use safely. So the RFC chooses rules that remove whole classes of failure, even where they are stricter than Rust or Go:
- every wait can end only in a listed outcome (
ok,closed,cancelled) on its own CFG edge. There is no error enum, no exception and no trap; - a channel never drops a value: a receiver can close only after it has drained the channel;
- a task never waits while it holds a lock guard. So mutexes alone cannot deadlock, and lock ordering never needs reasoning (§4.4);
- every scheduler-visible choice, including which ready
selectarm runs, comes from one seeded stream.schedules: Nexplores both.
Invariants
- Explicit outcomes. Every waiting operation completes on exactly one of its declared edges. Cancellation is never a trap.
- Ownership transfer. A value sent on a channel is owned by the sending operation until the operation completes. On
okit belongs to the channel and then to the receiver. Onclosedorcancelledit is handed back to the sender as a block parameter of the target. A value is never observable by two tasks. - No silent drop. A value is removed from a channel only by
channel.recvor aselectreceive arm. A receiver is consumed only when the channel is empty and no more values can enter it. - No wait under a lock. While a task holds a
guard<T>, it executes no waiting operation. This is checked statically, including through calls. - Cooperative cancellation. Cancellation is observed only at the cancellation points of §2.2. An operation that can complete without waiting completes, even if cancellation is pending. Inside a shield, cancellation is never observed. Shields nest properly.
- Reproducibility. Task choices and choices among ready
selectarms are drawn from the single schedule generator (spec 04 §36.2). Equal schedule seeds give equal runs. - No hidden cleanup. No guard is unlocked, no endpoint closed and no value dropped implicitly. A trap while holding a guard terminates the whole execution (spec 04 §33.2).
1. Features and dependencies
All three features are new to this RFC. channels and sync were reserved with dependencies [ownership]; their semantics cannot be stated without the task model, effects and, for channels, allocation budgets.
Rule for reserved dependencies (D1). While a feature is reserved, no valid module can use it, so its dependency set MAY change. When the feature is published, its dependencies become part of the frozen semantics of AIR 0. This is a general registry rule (reference/air-features.md, DD-014), not an exception for these two features.
| Feature | Depends on | Semantic block |
|---|---|---|
cancellation |
effects, tasks |
effect task.wait and its gated requirement (§2.4); the waiting-operation rule (§2); shield, task.shield.*; task.check_cancel; task.join.cancel |
channels |
cancellation, heap |
sender<T>, receiver<T>, channel.*, select |
sync |
cancellation |
mutex<T>, guard<T>, mutex.*, the critical-section rule (E4304) |
Reserved by this RFC (all unscheduled):
| Feature | Depends on | Semantic block |
|---|---|---|
rwlock |
sync |
rwlock<T>, read and write guards (only read_lock, write_lock and unlock; no upgrade or downgrade) |
channel_transfer |
channels |
sender<…>/receiver<…> inside channel elements or mutex contents |
receiver_dup |
channels |
several receivers of one channel (MPMC) |
guard_transfer |
sync |
guard<T> as a parameter, a return type or an aggregate member |
The published feature tasks is not changed (spec 07 §8.7). The plain task.join is never a cancellation point, and task.cancelled keeps returning the raw request flag. The only rule that touches a tasks instruction, the task.wait effect of task.join, applies only in modules declaring cancellation (§2.4). A module that does not declare it keeps the RFC 0011 semantics exactly.
2. Waiting and cancellation (feature cancellation)
2.1 The waiting-operation rule
A waiting operation is one of task.join.cancel, channel.send, channel.recv, select and mutex.lock. Each has a ready condition that may hold now or later. One rule covers all of them:
1. If the operation is ready, it completes with that outcome (ok or closed).
Pending cancellation is not consulted.
2. Otherwise, if cancellation is observable, it completes on its cancelled edge.
3. Otherwise the task waits. It becomes runnable when the operation becomes ready
or cancellation becomes observable. When it resumes, go to 1.
Cancellation is observable in a task when its cancellation-request flag (set by task.cancel, spec 04 §33.2) is set and its shield depth is 0.
A waiting operation is a scheduling point when it completes and when it begins to wait. Fuel is paid once, when it first begins (spec 04 §36.3). A waiting task counts as waiting for global quiescence (spec 11 §8). If every unfinished task waits and none can become runnable, the run ends blocked. A cancellation request wakes a waiting task only if it makes cancellation observable for that task.
The plain task.join and the I/O intrinsics (net.accept, reads on streams) are not cancellation points in format 0.
2.2 Cancellation points
| Point | Observes cancellation |
|---|---|
task.check_cancel |
always when observable |
task.join.cancel, channel.send, channel.recv, select, mutex.lock |
only when it would otherwise wait (§2.1 step 2) |
2.3 Instructions
| Instruction | Operands → result | Effect | Verifier | Runtime |
|---|---|---|---|---|
task.check_cancel, ok -> @ok, cancelled -> @c (terminator) |
— ; both targets have no parameters | — | — | @c if cancellation is observable, else @ok; a scheduling point |
task.join.cancel %t, ok -> @ok, cancelled -> @c (terminator) |
task<T> (consumed on both edges); @ok(T), @c(task<T>) |
task.wait |
ok edge: as task.join — the task is joined and its loans end. cancelled edge: the same task comes back as the parameter of @c; it is not joined, and its loans stay LOANED, now owned by the new handle value |
waiting operation; ready when the task has returned |
%sh = task.shield.begin |
→ shield |
— | pushes %sh on the function's shield stack |
increments the task's shield depth |
task.shield.end %sh |
shield (consumed) |
— | %sh must be the innermost live shield (E4305) |
decrements the shield depth |
shield is linear, function-bound (as scope in spec 04 §33.1) and Local. The stack of live shields is part of the verifier state and must be identical on every edge into a block (E3002, like other linear state). Together with the innermost-first rule this makes shields properly nested regions. The depth is dynamic per task, so a function called inside a shield runs shielded.
task.join.cancel is a new instruction, not a form of task.join. Its loan state machine extends spec 04 §34:
task<T> --task.join.cancel--+-- ok --------> joined; loans end; result T
+-- cancelled -> same task<T> as a block parameter;
not joined; loans stay LOANED
If the child has already returned, the join completes on ok even when cancellation is pending (§2.1 step 1). The usual reaction on cancelled forwards the request and then waits:
cancelled(%t2: task<u64>):
task.cancel %t2
%r = task.join %t2
Downward propagation is not automatic: changing task.cancel would change the published tasks feature.
Shield invariant. task.shield.begin pushes a token; task.shield.end accepts only the innermost live token:
%a = task.shield.begin
%b = task.shield.begin
task.shield.end %a ; E4305
task.shield.end %b ; ok
task.shield.end %a ; ok
Every shield token is ended before ret (E3002). A trap needs no cleanup.
2.4 Effect task.wait
The new effect task.wait (no capability) says in a function's public contract that it may wait for another task. §4.4 needs that.
Gated requirement. In a module declaring cancellation, every operation that may suspend requires task.wait: task.join (from tasks), task.join.cancel, channel.send, channel.recv, select and mutex.lock. It is checked like every effect (spec 05 §9; E3101).
A module that does not declare cancellation is unaffected. A published tasks module whose function joins without declaring task.wait stays valid with the same run record. Only modules that opt into the new feature get the extended effect semantics, and channels and sync imply it. This is an addition under spec 07 §8.7, because the stricter rule is attached to a feature that older modules do not declare.
A separate verifier-level "may suspend" analysis was rejected: it would add a second transitive property next to effects.
3. Channels (feature channels)
3.1 Types
| Type | Meaning | Class | Send | Share |
|---|---|---|---|---|
sender<T> |
sending endpoint | linear | yes | no |
receiver<T> |
the receiving endpoint (exactly one per channel) | linear | yes | no |
Endpoints are ordinary linear values. They may be block arguments, function parameters and return values, and may be moved into tasks. In format 0 they may not be aggregate members (reserved linear_aggregates) or heap contents (spec 03 §18: own<T> holds value types).
Element type T must satisfy:
T: Send(E4001);Tcontains no borrow (E1001) and noscope,task<…>,shieldorguard<…>(E1001);Tcontains nosender<…>orreceiver<…>; that is the reservedchannel_transfer(E0006).
Linear element types such as own<T>, file<…> and stream are allowed. Moving them between tasks is what channels are for.
3.2 Instructions
send and recv take a mut borrow of the endpoint, dup takes a ref, and the close operations consume it.
| Instruction | Operands → targets | Effect | Verifier | Runtime |
|---|---|---|---|---|
channel.make T, %n, %mem, ok -> @ok, err -> @err (terminator) |
%n: usize capacity, %mem: cap<mem.alloc>; @ok(sender<T>, receiver<T>), @err(alloc_error) |
mem.alloc |
element rules of §3.1 | charges %n × size(T) bytes to %mem (spec 03 §19); a capacity of 0 creates a rendezvous channel. Never waits |
%tx2 = channel.sender.dup %txr |
ref<sender<T>> → sender<T> |
— | — | a new, separately linear sender of the same channel; open_senders += 1; the original stays live |
channel.send %txb, %v, ok -> @ok, closed -> @closed, cancelled -> @c (terminator) |
mut<sender<T>>, T (consumed on every edge); @ok(), @closed(T), @c(T) |
task.wait |
on closed and cancelled the value comes back as the target's parameter; on ok it is gone |
waiting operation (§3.3) |
channel.recv %rxb, ok -> @ok, closed -> @closed, cancelled -> @c (terminator) |
mut<receiver<T>>; @ok(T) |
task.wait |
— | waiting operation (§3.3) |
channel.close_sender %tx |
sender<T> (consumed) |
— | — | open_senders -= 1; at 0 no new value can ever enter; a scheduling point |
channel.close_receiver %rx, ok -> @ok, pending -> @pending (terminator) |
receiver<T> (consumed on both edges); @pending(receiver<T>) |
— | — | §3.4; a scheduling point |
select … (terminator) |
§3.5 | task.wait |
§3.5 | §3.5 |
3.3 Channel states and ready conditions
A channel has a FIFO buffer, a count open_senders of live senders and a receiver state:
| State | Meaning |
|---|---|
OPEN |
the receiver is open and open_senders > 0: sends are accepted |
RECEIVER_CLOSING |
the receiver has started closing (§3.4): no send is accepted; buffered values remain and must be received |
DRAINED |
no future value can arrive (open_senders = 0, or RECEIVER_CLOSING) and the buffer is empty: recv reports closed, close_receiver takes ok |
CLOSED |
the receiver has been consumed; sends report closed |
New values stop arriving in exactly two ways: the last sender closes, or the receiver starts closing. In both cases values already buffered are received, never destroyed: the runtime never silently drops an owned value.
| Operation | ok-ready |
closed-ready |
|---|---|---|
send, capacity n > 0 |
OPEN and fewer than n values buffered |
RECEIVER_CLOSING or CLOSED |
| send, capacity 0 | OPEN and the receiver is waiting in channel.recv or in a select with a receive arm on this channel |
RECEIVER_CLOSING or CLOSED |
recv, capacity n > 0 |
a value is buffered | DRAINED |
| recv, capacity 0 | OPEN and a sender is waiting in channel.send or in a select with a send arm on this channel |
DRAINED |
closed takes precedence for a send: a send to a closed receiver is closed even if there is space. For a receive, buffered values take precedence: closed is reported only after the channel is drained. This is the RFC's answer to "last sender closed → recv after the queue is drained → closed". It is a concurrency state, not an io_error.
On a rendezvous channel, a sender waiting in channel.send holds its value until a receiver takes it. A sender that leaves on cancelled or closed gets the value back as a block parameter. Waiting rendezvous senders are matched in the order they began to wait. When a send completes against a waiting select, that select resumes on the matched arm without a draw.
A synchronization edge runs from a successful send to the receive that obtains the value (spec 04 §12). In the cooperative interpreter this is immediate; native backends must provide acquire/release ordering.
3.4 Closing the receiver
channel.close_receiver never drops a value:
- if the buffer is empty, the receiver is consumed and the channel becomes
CLOSED. Waiting and future sends endclosed. The program continues at@ok; - otherwise the channel enters
RECEIVER_CLOSING. Sends endclosedfrom now on, and waiting rendezvous senders also endclosed. The receiver comes back on@pending. The program drains it withchannel.recvuntilclosed(buffered values first) and then closes it again, which now takes@ok.
Because the closing state admits no new values, the drain loop terminates. A receiver can therefore stop early without leaking linear values, and the verifier needs no knowledge of the buffer contents.
The channel's memory is returned to the mem.alloc budget when the channel is CLOSED and open_senders = 0, at whichever of those closes comes last. That is an explicit instruction, so there is no hidden destructor.
3.5 select
select [recv %rxb1, ok -> @a, closed -> @a_done],
[send %txb, %v, ok -> @sent, closed -> @gone],
cancelled -> @c
select is written on one line. The line breaks above are for readability.
-
Arms are channel operations, nothing else:
[recv %rxb, ok -> @x, closed -> @y]with@x(T), and[send %txb, %v, ok -> @x, closed -> @y]. Aselecthas at least one arm and exactly onecancelledtarget. The arm targets have the parameters of the correspondingchannel.recv/channel.sendtargets. -
Readiness. An arm is ready when its operation is
ok-ready orclosed-ready (§3.3). Theselectas a whole is a waiting operation (§2.1) whose ready condition is "at least one arm is ready". -
Choice. If exactly one arm is ready, it is taken. If
k ≥ 2arms are ready, the scheduler drawsx = next()from the schedule generator and takes the ready arm numberx mod k, in textual order. The draw counts as a scheduler choice. It is not "first in text", so schedule exploration covers alternative ready branches. Withschedules: N, task scheduling and arm selection vary together, from one stream. -
Ownership along edges. Let
Vbe the distinct values named by the send arms, in order of first appearance. Theselectconsumes every value ofVon every edge. Each target receives, after its own parameters (the receivedTon a receive arm'sok), the values ofVthat were not sent on that edge, in the order ofV. So ownership is visible in the CFG; nothing is restored implicitly:select [send %tx1, %x, ok -> @to1, closed -> @c1], [send %tx2, %x, ok -> @to2, closed -> @c2], cancelled -> @c ; V = (%x) ; @to1() @to2() %x was sent ; @c1(%x) @c2(%x) @c(%x) %x comes backThe same value may appear in several send arms, because only one arm runs. This is the branch-edge ownership rule (spec 06 §6.3) applied per arm. A plain
channel.sendis the one-arm case. -
Borrows. Arms may name the same endpoint borrow more than once. Only one arm runs.
4. Mutex (feature sync)
4.1 Types
| Type | Meaning | Class | Send | Share |
|---|---|---|---|---|
mutex<T> |
mutual exclusion around a value of type T |
move-only; linear if T is linear |
if T: Send |
if T: Send |
guard<T> |
proof that the current task holds the lock | linear, function-bound, Local |
no | no |
T must satisfy the element rules of §3.1. A mutex<T> is opaque: no borrow.field, load or store reaches its contents. That makes it the verifier-known interior-mutability abstraction of spec 04 §8. Tasks share a mutex by a ref<mutex<T>> loan (spec 04 §34). Its Share property comes from the lock, not from immutability.
guard<T> is function-bound in the sense of spec 04 §33.1. Using it as a parameter, a return type or an aggregate member is the reserved guard_transfer (E0006). So the critical section is always visible in one function.
4.2 Instructions
| Instruction | Operands → result | Effect | Verifier | Runtime |
|---|---|---|---|---|
%m = mutex.make %v |
T (consumed) → mutex<T> |
— | element rules | an unlocked mutex holding %v; no allocation |
%v = mutex.take %m |
mutex<T> (consumed) → T |
— | ordinary move rules (no live borrow of the place holding it) | — |
mutex.lock %mr, ok -> @ok, cancelled -> @c (terminator) |
ref<mutex<T>>; @ok(guard<T>), @c() |
task.wait |
the guard is a child of %mr: ending %mr while the guard is live is E2102; critical-section rule (§4.4) |
waiting operation; ready when unlocked; acquire |
%p = mutex.borrow %g |
guard<T> (not consumed) → mut<T> |
— | %p is a child borrow of %g; it must be ended before mutex.unlock %g (E2102) |
— |
mutex.unlock %g |
guard<T> (consumed) |
— | — | release; every task waiting in mutex.lock on this mutex becomes runnable, and the first one scheduled takes the lock; a scheduling point |
No fairness is promised (spec 04 §32). Because waiters are woken together and the schedule generator picks the order, schedule exploration covers the possible acquisition orders.
4.3 No poisoning, no implicit unlock
A trap terminates the whole execution (spec 04 §33.2), so there is no state where another task could observe a mutex abandoned mid-update. Nothing is unlocked implicitly. A guard<T> that is not consumed on some path is E3002.
4.4 The critical-section rule (E4304)
On every path where a guard<T> is live, the function MUST NOT execute:
- an instruction that requires the effect
task.waitortask.spawn(in asyncmodule these are every suspending operation of §2.4,task.joinincluded, andtask.spawn); - a
call(or an indirect call) of a function whose declared effects includetask.waitortask.spawn.
Violations are E4304 (sync.wait_while_locked), naming the guard and the instruction.
Consequences, by construction:
- a task holds at most one guard at a time, since
mutex.lockrequirestask.wait:lock A; lock BisE4304, and the classic lock-order deadlock cannot be expressed in safe AIR 0; - the holder of a lock never waits for another task. Every wait in
mutex.lockends when the holder runs to itsmutex.unlock, unless the holder runs forever (fuel bounds that) or traps (which ends the run). Mutexes alone cannot deadlock, and no lock-ordering discipline is needed; - a critical section may call ordinary functions and pass them the
mut<T>frommutex.borrow. Their effect sets say whether they may wait.
The check reads only the caller's guard state and the callees' declared effects, so it stays intraprocedural (spec 04 §33 invariant 6). sync depends on cancellation, so callee effect sets are always available and task.join carries task.wait. This is stricter than common runtimes. A future feature may relax it if evaluation shows the need. It is deliberately not reserved now.
5. Scheduler and run record (resolves Q-013)
- Choice points: (a) the choice of the next task among
n ≥ 2runnable tasks (spec 04 §36.2), and (b) the choice amongk ≥ 2readyselectarms (§3.5). Both draw from the schedule generator. No draw is made when there is only one candidate. "schedule":{"seed","quantum","choices"}counts both kinds of choice. The record is emitted when tasks were spawned or aselectdrew.- The
hostedprofile uses the same rule. - The conformance runner's
schedules: Nneeds no change. Stress modes (P3-12) add cancellation during waits and slow consumers.
Valid examples
Producer/consumer. The receiver stops after the sender closes, and the drain protocol is visible:
fn @produce(%tx: sender<u64>) -> u8
effects [task.wait]
entry:
%txb = borrow.mut %tx
%v = const.u64 7
channel.send %txb, %v, ok -> @done, closed -> @back, cancelled -> @back
back(%w: u64): ; the value comes back; u64 needs no cleanup
br @done
done:
borrow.end %txb
channel.close_sender %tx
%z = const.u8 0
ret %z
fn @main(%heap: cap<mem.alloc>) -> u64
effects [mem.alloc, task.spawn, task.wait]
entry:
%two = const.usize 2
channel.make u64, %two, %heap, ok -> @made, err -> @no_memory
made(%tx: sender<u64>, %rx: receiver<u64>):
%sc = task.scope.begin
%t = task.spawn %sc, @produce(%tx) ; sender moved into the task
%rxb = borrow.mut %rx
channel.recv %rxb, ok -> @got, closed -> @empty, cancelled -> @empty
got(%v: u64):
borrow.end %rxb
... ; join, close_receiver (handle pending), scope.end, ret %v
A counter shared through a mutex. The critical section contains no wait:
fn @bump(%mr: ref<mutex<u64>>) -> u8
effects [task.wait]
entry:
mutex.lock %mr, ok -> @locked, cancelled -> @stop
locked(%g: guard<u64>):
%p = mutex.borrow %g
%x = load %p
%one = const.u64 1
%y = add.checked.u64 %x, %one
store %p, %y
borrow.end %p
mutex.unlock %g
...
select with the same value in two send arms:
select [send %a, %job, ok -> @sent_a, closed -> @a_gone], [send %b, %job, ok -> @sent_b, closed -> @b_gone], cancelled -> @stop
; @sent_a() @sent_b() — %job went to one worker
; @a_gone(%j: own<@Job>) @b_gone(%j: own<@Job>) @stop(%j: own<@Job>) — the job comes back
Rejected examples
locked(%g: guard<u64>):
channel.recv %rxb, ok -> @got, closed -> @end, cancelled -> @end ; E4304: waits while %g is live
%s1 = task.shield.begin
%s2 = task.shield.begin
task.shield.end %s1 ; E4305: %s2 is the innermost live shield
channel.send %txb, %v, ok -> @sent, closed -> @closed, cancelled -> @c
sent:
%w = own.take %v ; E2002: %v was already consumed by the send
; (a non-consuming use, e.g. borrow.ref %v, is E2001)
channel.make ref<u64>, %n, %heap, ok -> @ok, err -> @err ; E1001: channel elements contain no borrow
Expected diagnostic of the first example:
{"code":"E4304","kind":"sync.wait_while_locked","severity":"error","function":"worker","block":"locked","inst":0,"guard":"%g","op":"channel.recv","message":"waiting operation while a lock guard is live"}
Diagnostics impact
New codes:
| Code | Kind | Meaning |
|---|---|---|
| E4304 | sync.wait_while_locked | Waiting operation, spawn, join or call of a waiting/spawning function while a lock guard is live |
| E4305 | task.shield_order | Shield ended while a more inner shield is live |
Existing codes used:
E4001andE1001for element rules;E2001andE2002for values consumed bysend/select;E2102for guard and access borrows;E3002for leaked endpoints, guards and shields, and for differing shield stacks at a join;E3101fortask.wait;E0006forrwlock,channel_transfer,receiver_dupandguard_transfer.
No new trap codes. No new environment outcomes: deadlocks remain blocked.
Spec integration
On acceptance:
- spec 04: new §37 (waiting and cancellation), §38 (channels), §39 (select), §40 (mutex), §41 (critical-section rule); §14–§16 point to them; §11 marks RwLock as deferred;
- spec 02 §6 / spec 04 §35: Send/Share rows for the new types;
- spec 05: effect
task.wait; - spec 07 §8.11: types and the
selectsyntax; spec 07a: contract rows; - spec 08: verifier stages (shield stack, guard state, E4304);
- spec 11 §8: choice points, record;
reference/air-features.md,effects.md,error-codes.md;docs/agent/bundle.txt;- Q-013 marked resolved.
Compatibility and migration
Additive under spec 07 §8.7: three new features, new types, instructions, one effect and two diagnostic codes. tasks and every published feature keep their meaning:
- the plain
task.joinis not a cancellation point; task.cancelledignores shields (it reads the raw flag);task.joinrequirestask.waitonly in modules declaringcancellation, which no existing module does.
The dependency lists of the reserved channels and sync change under the general rule of §1 (D1). No module can use a reserved feature, so no accepted or rejected module changes status.
Agent complexity impact
- New concepts:
- endpoint pair;
- bounded and rendezvous capacity;
- the drain-then-close protocol;
- the three wait outcomes;
- cancellation points and shields;
- mutex, guard and the critical-section rule;
selectarms with per-edge ownership.
- New verifier state:
- per function, a stack of live shields;
- the set of live guards;
- per-edge consumption for
channel.sendandselect, which reuses the existing per-edge linear machinery (as forfs.close).
- New syntax:
- 3 features, 5 types, 1 effect;
- 17 instructions:
task.check_cancel,task.join.cancel,task.shield.begin/end,channel.make/sender.dup/send/recv/close_sender/close_receiver,select,mutex.make/take/lock/borrow/unlock(countingselectonce).
- Interactions: loans (sharing a
ref<mutex>), effects (task.wait, the E4304 call rule), linearity (endpoints, guards, shields), heap budgets (channel buffers), the scheduler (choices). - Repairability:
- each outcome is an edge the agent must route, so a forgotten case is a CFG error, not a runtime surprise;
- E4304 names the guard and the offending instruction; the repair is "unlock before waiting";
- deadlocks between mutexes are impossible, so the repair space of
blockedruns shrinks to channel and join cycles.
- Could existing primitives express it? No. Tasks can exchange data only at spawn and join.
- Uniformity chosen over brevity: one waiting-operation rule for all waits; one close-on-both-edges pattern (as
fs.close); endpoint operations always takemut. - Agent Reference Bundle growth: estimated +12–16 % tokens (about five new spec sections plus registry rows). RFC 0011's estimate was 3 points low, so this is a deliberately cautious range. It will be measured on integration.
Alternatives considered
- One
channel<T>value: closing would need two meanings on one value; separate endpoints make "last sender closed" and "receiver closed" explicit and allowdupfor several producers. - Unbounded channels: implicit, unbounded allocation; rejected (spec 04 §12). Unbounded queues remain library constructs.
- Dropping buffered values on
close_receiver: a hidden destructor for linear elements; rejected for the drain protocol (§3.4). - Allowing waits while locked (Rust, Go): reintroduces lock-order deadlocks and guard-across-await bugs, which are hard for agents to see. Rejected for format 0.
selectpicks the first ready arm in text: reproducible, but schedule exploration would never see the other branch. Rejected for a seeded draw.selectover arbitrary expressions: rejected; arms are operations with fixed transfer functions.- Cancellation as a trap or a universal
TaskError: rejected; outcomes are edges. - Automatic downward cancellation propagation: would change the published
task.cancel. Insteadtask.join.cancellets a parent forward cancellation explicitly. - A cancellable form of
task.join(same opcode with edges): a new instruction is clearer and keeps the published opcode's contract untouched. - Restoring a sent value implicitly on
closed/cancelled(the same SSA value stays live): ownership would not be visible in the CFG; rejected for block parameters. task.waitrequired bytask.joinunconditionally: would make publishedtasksmodules fail withE3101; rejected for the gated rule (§2.4).- Shield as a lexical block or a separate task: AIR has no lexical blocks; a linear token with innermost-first ending gives proper nesting with existing machinery.
RwLocknow: read and write guards, fairness, starvation and several concurrent guards add little expressive power over a mutex, ownership partitioning and channels. Deferred (reservedrwlock).- Channel capacity in the type, buffer in frame storage: avoids the heap but makes endpoints borrows, which cannot be moved into tasks or returned. Rejected for linear endpoints with an explicit
mem.alloccharge.
Unresolved questions
None. Owner decisions: D1 general rule for reserved dependencies; D2 task.join.cancel as a new instruction returning the handle on cancelled; D3 channel.sender.dup from ref<sender<T>>, no receiver duplication (receiver_dup reserved). Deferred: RwLock, several receivers, atomics.