// 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), } fn read(fr: ref>, a: iref) -> u64 effects [] { ref node = frozen.at(fr, a); // ref access only node.value } fn main(heap: cap) -> 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; 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 }