Phase 4: islands, frozen graphs and arc through every layer (RFC 0014)
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.
This commit is contained in:
1 parent
ca84ab4348
commit
c699529fec
58 files changed
+2189
-98
No files matched your search
@@ -0,0 +1,107 @@
|
||||
module demo.ring
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arc, capabilities, effects, heap, islands, ownership, resources]
|
||||
|
||||
type @Node = struct { value: u64, next: @Link }
|
||||
type @Link = enum { End, To(iref<@Node>) }
|
||||
|
||||
fn @ring(%heap: cap<mem.alloc>) -> island<@Node>
|
||||
effects [mem.alloc]
|
||||
entry:
|
||||
%c_1 = const.u64 1
|
||||
%e_2 = enum.make @Link.End()
|
||||
%s_3 = struct.make @Node(%c_1, %e_2)
|
||||
island.create %s_3, %heap, ok -> @ok_4, err -> @err_6
|
||||
ok_4(%ok_5: island<@Node>):
|
||||
%isl_8 = borrow.mut %ok_5
|
||||
%root_9 = island.root %isl_8
|
||||
%c_10 = const.u64 2
|
||||
%e_11 = enum.make @Link.To(%root_9)
|
||||
%s_12 = struct.make @Node(%c_10, %e_11)
|
||||
island.alloc %isl_8, %s_12, ok -> @ok_13, err -> @err_15
|
||||
err_6(%err_7: alloc_error):
|
||||
trap
|
||||
ok_13(%ok_14: iref<@Node>):
|
||||
%c_17 = const.u64 3
|
||||
%e_18 = enum.make @Link.To(%ok_14)
|
||||
%s_19 = struct.make @Node(%c_17, %e_18)
|
||||
island.alloc %isl_8, %s_19, ok -> @ok_20, err -> @err_22
|
||||
err_15(%err_16: alloc_error):
|
||||
trap
|
||||
ok_20(%ok_21: iref<@Node>):
|
||||
%first_24 = island.borrow %isl_8, %root_9
|
||||
%e_25 = enum.make @Link.To(%ok_21)
|
||||
%next_26 = borrow.field @Node.next, %first_24
|
||||
store %next_26, %e_25
|
||||
borrow.end %next_26
|
||||
borrow.end %first_24
|
||||
borrow.end %isl_8
|
||||
ret %ok_5
|
||||
err_22(%err_23: alloc_error):
|
||||
trap
|
||||
|
||||
fn @walk(%f: ref<frozen<@Node>>, %steps: u64) -> u64
|
||||
effects []
|
||||
entry:
|
||||
%c_1 = const.u64 0
|
||||
%root_2 = frozen.root %f
|
||||
%c_3 = const.u64 0
|
||||
br @while_4(%c_1, %root_2, %c_3)
|
||||
while_4(%sum_7: u64, %at_8: iref<@Node>, %i_9: u64):
|
||||
%cmp_14 = lt.u64 %i_9, %steps
|
||||
cbr %cmp_14, @body_15(), @after_5(%sum_7)
|
||||
after_5(%sum_10: u64):
|
||||
ret %sum_10
|
||||
step_6(%sum_11: u64, %at_12: iref<@Node>, %i_13: u64):
|
||||
%one_27 = const.u64 1
|
||||
%i_28 = add.checked.u64 %i_13, %one_27
|
||||
br @while_4(%sum_11, %at_12, %i_28)
|
||||
body_15:
|
||||
%node_16 = frozen.borrow %f, %at_8
|
||||
%value_17 = borrow.field @Node.value, %node_16
|
||||
%value_18 = load %value_17
|
||||
borrow.end %value_17
|
||||
%t_19 = add.checked.u64 %sum_7, %value_18
|
||||
%next_20 = borrow.field @Node.next, %node_16
|
||||
%next_21 = load %next_20
|
||||
borrow.end %next_20
|
||||
enum.switch @Link %next_21, End -> @case_End_22, To -> @case_To_23
|
||||
case_End_22:
|
||||
br @endmatch_25(%at_8)
|
||||
case_To_23(%n_24: iref<@Node>):
|
||||
br @endmatch_25(%n_24)
|
||||
endmatch_25(%match_26: iref<@Node>):
|
||||
borrow.end %node_16
|
||||
br @step_6(%t_19, %match_26, %i_9)
|
||||
|
||||
fn @main(%heap: cap<mem.alloc>) -> u64
|
||||
effects [mem.alloc]
|
||||
entry:
|
||||
%ring_1 = call @ring(%heap)
|
||||
%frozen_2 = island.freeze %ring_1
|
||||
%c_3 = const.u64 0
|
||||
%f_4 = borrow.ref %frozen_2
|
||||
%c_5 = const.u64 7
|
||||
%walk_6 = call @walk(%f_4, %c_5)
|
||||
borrow.end %f_4
|
||||
%arc_7 = arc.from_frozen %frozen_2
|
||||
%a_8 = borrow.ref %arc_7
|
||||
%arc_9 = arc.clone %a_8
|
||||
borrow.end %a_8
|
||||
%b_10 = borrow.ref %arc_9
|
||||
%root_11 = arc.root %b_10
|
||||
%root_12 = arc.root %b_10
|
||||
%cmp_13 = iref.eq %root_11, %root_12
|
||||
cbr %cmp_13, @then_14(), @else_15()
|
||||
then_14:
|
||||
%c_16 = const.u64 0
|
||||
%t_17 = add.checked.u64 %walk_6, %c_16
|
||||
br @endif_18(%t_17)
|
||||
else_15:
|
||||
br @endif_18(%walk_6)
|
||||
endif_18(%total_19: u64):
|
||||
borrow.end %b_10
|
||||
arc.release %arc_7
|
||||
arc.release %arc_9
|
||||
ret %total_19
|
||||
Reference in new issue
Block a user