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
This commit is contained in:
1 parent
b82bc35c5f
commit
aaf32b6853
45 files changed
+2077
-43
No files matched your search
@@ -0,0 +1,71 @@
|
||||
; Closing a receiver with buffered owned values hands it back on pending; a
|
||||
; send after that ends closed and returns the value; the receiver drains
|
||||
; everything before the close succeeds. No owned value is dropped.
|
||||
; expect: run
|
||||
; grant: heap=mem.alloc:64
|
||||
; result: 13
|
||||
; phase: 3
|
||||
; spec: docs/spec/04-concurrency-and-atomics.md
|
||||
module test.channels_drain_linear
|
||||
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:
|
||||
%four = const.usize 4
|
||||
channel.make own<u64>, %four, %heap, ok -> @made, err -> @oom0
|
||||
made(%tx: sender<own<u64>>, %rx: receiver<own<u64>>):
|
||||
%txb = borrow.mut %tx
|
||||
%one = const.u64 1
|
||||
own.new %one, %heap, ok -> @o1, err -> @oom
|
||||
o1(%a: own<u64>):
|
||||
channel.send %txb, %a, ok -> @s1, closed -> @lost, cancelled -> @lost
|
||||
s1:
|
||||
%two = const.u64 2
|
||||
own.new %two, %heap, ok -> @o2, err -> @oom
|
||||
o2(%b: own<u64>):
|
||||
channel.send %txb, %b, ok -> @s2, closed -> @lost, cancelled -> @lost
|
||||
s2:
|
||||
channel.close_receiver %rx, ok -> @unexpected, pending -> @closing
|
||||
closing(%r: receiver<own<u64>>):
|
||||
%ten = const.u64 10
|
||||
own.new %ten, %heap, ok -> @o3, err -> @oom2
|
||||
o3(%c: own<u64>):
|
||||
channel.send %txb, %c, ok -> @unexpected2, closed -> @back, cancelled -> @back
|
||||
back(%returned: own<u64>):
|
||||
%v0 = own.take %returned
|
||||
br @drain(%r, %v0)
|
||||
drain(%rr: receiver<own<u64>>, %acc: u64):
|
||||
%rb = borrow.mut %rr
|
||||
channel.recv %rb, ok -> @got, closed -> @empty, cancelled -> @retry
|
||||
got(%o: own<u64>):
|
||||
borrow.end %rb
|
||||
%v = own.take %o
|
||||
%acc2 = add.checked.u64 %acc, %v
|
||||
br @drain(%rr, %acc2)
|
||||
retry:
|
||||
borrow.end %rb
|
||||
br @drain(%rr, %acc)
|
||||
empty:
|
||||
borrow.end %rb
|
||||
channel.close_receiver %rr, ok -> @done, pending -> @again
|
||||
again(%r4: receiver<own<u64>>):
|
||||
br @drain(%r4, %acc)
|
||||
done:
|
||||
borrow.end %txb
|
||||
channel.close_sender %tx
|
||||
ret %acc
|
||||
lost(%x: own<u64>):
|
||||
trap
|
||||
unexpected:
|
||||
trap
|
||||
unexpected2:
|
||||
trap
|
||||
oom(%e: alloc_error):
|
||||
trap
|
||||
oom2(%e2: alloc_error):
|
||||
trap
|
||||
oom0(%e0: alloc_error):
|
||||
trap
|
||||
Reference in new issue
Block a user