- features cancellation, channels, sync supported - AIR model/parser/printer: shield, sender<T>, receiver<T>, mutex<T>, guard<T>; task.check_cancel, task.join.cancel, task.shield.*, channel.*, select (bracketed arms), mutex.* - verifier: arities (E5002), element rules (E4001/E1001, E0006 channel_transfer), guard_transfer gating, task.wait effect (gated for task.join by cancellation), per-edge consumption with values and handles returned as block parameters, loans moved to the handle on task.join.cancel's cancelled edge, shield order (E4305), guard children (E2102), critical-section rule (E4304) - interpreter: waiting-operation rule (ready, else cancelled if observable, else wait), shield depth, bounded and rendezvous channels with FIFO offers, drain-then-close receiver, budget release at the last close, select with seeded draw among ready arms, mutex wakeups; schedule record also after a select draw - report counts task.spawn, task.wait and channel allocations - spec erratum: mutex<T> is linear (format 0 has no droppable move-only class) - 30 new conformance tests (10 run with schedules, 4 accept, 16 reject); 6000-run schedule stress and 4350 mutants without failure
62 lines
1.7 KiB
LLVM
62 lines
1.7 KiB
LLVM
; Capacity 0: every send completes only when the receiver takes the value.
|
|
; expect: run
|
|
; grant: heap=mem.alloc:64
|
|
; schedules: 20
|
|
; quantum: 2
|
|
; result: 6
|
|
; phase: 3
|
|
; spec: docs/spec/04-concurrency-and-atomics.md
|
|
module test.channels_rendezvous
|
|
air 0
|
|
lang 0.1
|
|
features [cancellation, capabilities, channels, effects, heap, ownership, resources, tasks]
|
|
|
|
fn @main(%heap: cap<mem.alloc>) -> u64
|
|
effects [mem.alloc, task.spawn, task.wait]
|
|
entry:
|
|
%zero = const.usize 0
|
|
channel.make u64, %zero, %heap, ok -> @made, err -> @oom
|
|
made(%tx: sender<u64>, %rx: receiver<u64>):
|
|
%sc = task.scope.begin
|
|
%t = task.spawn %sc, @produce(%tx)
|
|
%z = const.u64 0
|
|
br @recv_loop(%rx, %z)
|
|
recv_loop(%r: receiver<u64>, %acc: u64):
|
|
%rb = borrow.mut %r
|
|
channel.recv %rb, ok -> @got, closed -> @drained, cancelled -> @drained
|
|
got(%v: u64):
|
|
borrow.end %rb
|
|
%acc2 = add.checked.u64 %acc, %v
|
|
br @recv_loop(%r, %acc2)
|
|
drained:
|
|
borrow.end %rb
|
|
channel.close_receiver %r, ok -> @closed, pending -> @pending
|
|
pending(%r2: receiver<u64>):
|
|
br @recv_loop(%r2, %acc)
|
|
closed:
|
|
%x = task.join %t
|
|
task.scope.end %sc
|
|
ret %acc
|
|
oom(%e: alloc_error):
|
|
trap
|
|
|
|
fn @produce(%tx: sender<u64>) -> u8
|
|
effects [task.wait]
|
|
entry:
|
|
%txb = borrow.mut %tx
|
|
%one = const.u64 1
|
|
channel.send %txb, %one, ok -> @s2, closed -> @gone, cancelled -> @gone
|
|
s2:
|
|
%two = const.u64 2
|
|
channel.send %txb, %two, ok -> @s3, closed -> @gone, cancelled -> @gone
|
|
s3:
|
|
%three = const.u64 3
|
|
channel.send %txb, %three, ok -> @finish, closed -> @gone, cancelled -> @gone
|
|
gone(%w: u64):
|
|
br @finish()
|
|
finish:
|
|
borrow.end %txb
|
|
channel.close_sender %tx
|
|
%r = const.u8 0
|
|
ret %r
|