- scope s { … }: task.scope.begin, task.scope.end at every normal exit
(scope ends generalized: borrow.end or task.scope.end, innermost first)
- task.spawn(s, f, args): call-like; named linear values moved (E7003);
lent borrows are bound first (inline borrow E7006); scope operand E7005
- task.join/cancel/cancelled; task<T>, sender<T>, receiver<T>, scope types
- channels: make<T>, dup, send, recv, close_sender, close_receiver; send,
recv and close_receiver are outcome matches; endpoints by name, borrowed
for the operation and ended on every edge (written `mut tx`: E7006)
- outcome rebinding: a value coming back under the name of a variable of
its type becomes the variable's value (pending(r))
- joins carry live variables only (pruned SSA): a linear value consumed
before a join does not travel to it; ordered after-walk over the
enclosing statement or tail, sibling arms not counted
- parser: a keyword after `.` is a member name (task.cancelled)
- conformance equivalence ignores schedule.choices (quantum counts AIR
instructions)
- tests: 10 run tests with AIR equivalence (Phase 3 programs), 12 rejects
(E4301, E4101 x2, E4002, E2001, E3101, E3002, E7006 x2, E7003, E0006,
E7005); Quick Reference tasks/channels programs now pass
- spec 15 §4/§6/§7, grammar, quick reference, bundle notes, plan
81 lines
2.3 KiB
Plaintext
81 lines
2.3 KiB
Plaintext
module demo.producerconsumer
|
|
air 0
|
|
lang 0.1
|
|
features [cancellation, capabilities, channels, effects, heap, ownership, resources, tasks]
|
|
|
|
fn @produce(%tx: sender<u64>, %n: u64) -> u8
|
|
effects [task.wait]
|
|
entry:
|
|
%c_1 = const.u64 0
|
|
br @while_2(%c_1)
|
|
while_2(%i_4: u64):
|
|
%cmp_5 = ne.u64 %i_4, %n
|
|
cbr %cmp_5, @body_6(), @after_3()
|
|
after_3:
|
|
channel.close_sender %tx
|
|
%c_17 = const.u8 0
|
|
ret %c_17
|
|
body_6:
|
|
%tx_7 = borrow.mut %tx
|
|
channel.send %tx_7, %i_4, ok -> @ok_8, closed -> @closed_9, cancelled -> @cancelled_11
|
|
ok_8:
|
|
borrow.end %tx_7
|
|
br @endmatch_13(%i_4)
|
|
closed_9(%closed_10: u64):
|
|
borrow.end %tx_7
|
|
br @after_3()
|
|
cancelled_11(%cancelled_12: u64):
|
|
borrow.end %tx_7
|
|
br @after_3()
|
|
endmatch_13(%i_14: u64):
|
|
%c_15 = const.u64 1
|
|
%t_16 = add.checked.u64 %i_14, %c_15
|
|
br @while_2(%t_16)
|
|
|
|
fn @main(%heap: cap<mem.alloc>) -> u64
|
|
effects [mem.alloc, task.spawn, task.wait]
|
|
entry:
|
|
%c_1 = const.usize 2
|
|
channel.make u64, %c_1, %heap, ok -> @ok_2, err -> @err_5
|
|
ok_2(%ok_3: sender<u64>, %ok_4: receiver<u64>):
|
|
%c_7 = const.u64 0
|
|
%sc_8 = task.scope.begin
|
|
%c_9 = const.u64 5
|
|
%t_10 = task.spawn %sc_8, @produce(%ok_3, %c_9)
|
|
br @loop_11(%c_7, %ok_4)
|
|
err_5(%err_6: alloc_error):
|
|
trap
|
|
loop_11(%acc_13: u64, %r_14: receiver<u64>):
|
|
%r_16 = borrow.mut %r_14
|
|
channel.recv %r_16, ok -> @ok_17, closed -> @closed_19, cancelled -> @cancelled_20
|
|
after_12(%acc_15: u64):
|
|
%r_37 = task.join %t_10
|
|
task.scope.end %sc_8
|
|
br @endmatch_38(%acc_15)
|
|
ok_17(%ok_18: u64):
|
|
borrow.end %r_16
|
|
%t_21 = add.checked.u64 %acc_13, %ok_18
|
|
br @endmatch_34(%t_21, %r_14)
|
|
closed_19:
|
|
borrow.end %r_16
|
|
channel.close_receiver %r_14, ok -> @ok_22, pending -> @pending_23
|
|
cancelled_20:
|
|
borrow.end %r_16
|
|
channel.close_receiver %r_14, ok -> @ok_28, pending -> @pending_29
|
|
ok_22:
|
|
br @after_12(%acc_13)
|
|
pending_23(%pending_24: receiver<u64>):
|
|
br @endmatch_25(%acc_13, %pending_24)
|
|
endmatch_25(%acc_26: u64, %r_27: receiver<u64>):
|
|
br @endmatch_34(%acc_26, %r_27)
|
|
ok_28:
|
|
br @after_12(%acc_13)
|
|
pending_29(%pending_30: receiver<u64>):
|
|
br @endmatch_31(%acc_13, %pending_30)
|
|
endmatch_31(%acc_32: u64, %r_33: receiver<u64>):
|
|
br @endmatch_34(%acc_32, %r_33)
|
|
endmatch_34(%acc_35: u64, %r_36: receiver<u64>):
|
|
br @loop_11(%acc_35, %r_36)
|
|
endmatch_38(%match_39: u64):
|
|
ret %match_39
|