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,59 @@
|
||||
// Quick Reference: graphs (island → frozen → arc).
|
||||
// expect: run
|
||||
// grant: heap=mem.alloc:256
|
||||
// schedules: 10
|
||||
// result: 8
|
||||
// phase: 6
|
||||
// spec: docs/agent/quick-reference.md
|
||||
module demo.qrgraphs
|
||||
|
||||
struct Node {
|
||||
value: u64,
|
||||
next: Link,
|
||||
}
|
||||
|
||||
enum Link {
|
||||
End,
|
||||
To(iref<Node>),
|
||||
}
|
||||
|
||||
fn read(fr: ref<frozen<Node>>, a: iref<Node>) -> u64
|
||||
effects []
|
||||
{
|
||||
ref node = frozen.at(fr, a); // ref access only
|
||||
node.value
|
||||
}
|
||||
|
||||
fn main(heap: cap<mem.alloc>) -> u64
|
||||
effects [mem.alloc, task.spawn]
|
||||
{
|
||||
let isl = island.create(Node { value: 1, next: Link::End }, heap) or trap; // effect mem.alloc
|
||||
{
|
||||
mut g = isl; // borrow the island; it outlives the accesses
|
||||
let a = island.root(g);
|
||||
let b = island.alloc(g, Node { value: 2, next: Link::To(a) }) or trap;
|
||||
mut first = island.at(g, a); // mut<Node>; one mutable access at a time
|
||||
first.next = Link::To(b); // edges may form cycles
|
||||
}
|
||||
let f = island.freeze(move isl); // O(1), irreversible; irefs stay valid
|
||||
var sum: u64 = 0;
|
||||
{
|
||||
ref fr = f; // frozen graphs are Share: lend fr to tasks
|
||||
let a = frozen.root(fr);
|
||||
scope s {
|
||||
let t = task.spawn(s, read, fr, a);
|
||||
sum = task.join(move t);
|
||||
}
|
||||
}
|
||||
let shared = arc.from_frozen(move f); // O(1); the same graph
|
||||
let other = arc.clone(shared); // count + 1
|
||||
arc.release(move other); // the last release frees the graph
|
||||
{
|
||||
ref ar = shared;
|
||||
let a = arc.root(ar);
|
||||
ref node = arc.at(ar, a);
|
||||
sum = sum + node.value * 7;
|
||||
}
|
||||
arc.release(move shared);
|
||||
sum
|
||||
}
|
||||
Reference in new issue
Block a user