AIR: types island<T>, frozen<T>, arc<T>, iref<T>; 16 instructions (island.create/alloc/root/borrow/freeze/destroy, frozen.root/borrow/ release, arc.from_frozen/new/clone/release/root/borrow, iref.eq); features islands (depends on heap) and arc (depends on islands) published. Verifier: IslandSafe/ArcSafe (E2111 at the owner type), container child borrows (one mut access per island), Send/Share rows (island not Share), linear owners, mem.alloc effect, element rules (recursion through iref). Interpreter: graphs with never-reused identities, T0010 for a foreign iref, O(1) freeze/conversion/transfer, arc counts in a trace hook (Options.arc_events), budgets per the quota table, collector support. .aji layer 9: types, operations, island.at/frozen.at/arc.at as borrow places with explicit container borrows, iref ==/!=. Frontend fix: joins carry only variables the construct assigns (and that are read again), so an unchanged linear value is never a block argument while borrowed. Tests: 10 AIR (phase4), 6 .aji run + 12 rejects (layer9), the reference program island-pipeline in .aji, equivalent to an independently hand-written AIR program (36 on 30 schedule seeds); unit tests for the arc count trace and O(1) transfer. Quick Reference §7 graphs (checked excerpt of quickref/graphs.aji); coverage 61/61. Bundle growth: AIR +7.0%, Quick Reference +0.6k, source docs +4.2k (recorded). Spec: quota rows match the header-reserved count; idioms and iref recursion in spec 03 §22; P4-11 (air-text.ebnf gaps) recorded.
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_16 = const.u8 0
|
|
ret %c_16
|
|
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()
|
|
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:
|
|
%c_14 = const.u64 1
|
|
%t_15 = add.checked.u64 %i_4, %c_14
|
|
br @while_2(%t_15)
|
|
|
|
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_35 = task.join %t_10
|
|
task.scope.end %sc_8
|
|
br @endmatch_36(%acc_15)
|
|
ok_17(%ok_18: u64):
|
|
borrow.end %r_16
|
|
%t_21 = add.checked.u64 %acc_13, %ok_18
|
|
br @endmatch_32(%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_27, pending -> @pending_28
|
|
ok_22:
|
|
br @after_12(%acc_13)
|
|
pending_23(%pending_24: receiver<u64>):
|
|
br @endmatch_25(%pending_24)
|
|
endmatch_25(%r_26: receiver<u64>):
|
|
br @endmatch_32(%acc_13, %r_26)
|
|
ok_27:
|
|
br @after_12(%acc_13)
|
|
pending_28(%pending_29: receiver<u64>):
|
|
br @endmatch_30(%pending_29)
|
|
endmatch_30(%r_31: receiver<u64>):
|
|
br @endmatch_32(%acc_13, %r_31)
|
|
endmatch_32(%acc_33: u64, %r_34: receiver<u64>):
|
|
br @loop_11(%acc_33, %r_34)
|
|
endmatch_36(%match_37: u64):
|
|
ret %match_37
|