Files
aji/tests/conformance/phase3/run/select_ready_draw.air
T
dev aaf32b6853 Phase 3: channels, mutex, select and cancellation points (RFC 0012)
- 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
2026-10-04 16:49:37 +03:00

69 lines
1.9 KiB
LLVM

; Both arms are ready: the schedule generator picks one (a recorded choice even
; in a single task); the other value is received afterwards.
; expect: run
; grant: heap=mem.alloc:64
; schedules: 20
; result: 3
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md
module test.select_ready_draw
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.wait]
entry:
%one = const.usize 1
channel.make u64, %one, %heap, ok -> @a_made, err -> @oom
a_made(%ta: sender<u64>, %ra: receiver<u64>):
channel.make u64, %one, %heap, ok -> @b_made, err -> @oom2
b_made(%tb: sender<u64>, %rb: receiver<u64>):
%tab = borrow.mut %ta
%v1 = const.u64 1
channel.send %tab, %v1, ok -> @s1, closed -> @lost, cancelled -> @lost
s1:
%tbb = borrow.mut %tb
%v2 = const.u64 2
channel.send %tbb, %v2, ok -> @s2, closed -> @lost2, cancelled -> @lost2
s2:
borrow.end %tab
borrow.end %tbb
channel.close_sender %ta
channel.close_sender %tb
%rab = borrow.mut %ra
%rbb = borrow.mut %rb
select [recv %rab, ok -> @from_a, closed -> @gone], [recv %rbb, ok -> @from_b, closed -> @gone], cancelled -> @gone
from_a(%x: u64):
channel.recv %rbb, ok -> @second, closed -> @gone, cancelled -> @gone
from_b(%y: u64):
channel.recv %rab, ok -> @second_b, closed -> @gone, cancelled -> @gone
second(%z: u64):
%s = add.checked.u64 %x, %z
br @finish(%s)
second_b(%w: u64):
%s2 = add.checked.u64 %y, %w
br @finish(%s2)
finish(%sum: u64):
borrow.end %rab
borrow.end %rbb
channel.close_receiver %ra, ok -> @ca, pending -> @stuck
ca:
channel.close_receiver %rb, ok -> @cb, pending -> @stuck2
cb:
ret %sum
gone:
trap
stuck(%p: receiver<u64>):
trap
stuck2(%p2: receiver<u64>):
trap
lost(%l: u64):
trap
lost2(%l2: u64):
trap
oom(%e: alloc_error):
trap
oom2(%e2: alloc_error):
trap