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:
dev committed 2026-10-05 22:14:05 +03:00
1 parent ca84ab4348
commit c699529fec
58 files changed
+2189 -98

No files matched your search

@@ -0,0 +1,13 @@
// An arc holds only ArcSafe values: a mutex is Share but not ArcSafe.
// expect: reject E2111
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.arc_mutex
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
{
let a = arc.new(mutex.make(0u64), heap) or trap;
arc.release(move a);
0
}
@@ -0,0 +1,19 @@
// A graph access is a borrow: it is bound with ref/mut, not used as a value.
// expect: reject E7006
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.at_as_value
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
{
let isl = island.create(1u64, heap) or trap;
var v: u64 = 0;
{
ref g = isl;
let r = island.root(g);
let x = island.at(g, r);
}
island.destroy(move isl);
v
}
@@ -0,0 +1,14 @@
// An island holds only IslandSafe values: an owner inside is E2111.
// expect: reject E2111
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.content_owner
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
{
let o = own.new(1u64, heap) or trap;
let isl = island.create(move o, heap) or trap;
island.destroy(move isl);
0
}
@@ -0,0 +1,14 @@
// Destroying an island while a borrow of it is live.
// expect: reject E2101
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.destroy_while_borrowed
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
{
let isl = island.create(1u64, heap) or trap;
ref g = isl;
island.destroy(move isl);
0
}
@@ -0,0 +1,19 @@
// A frozen graph gives ref access only.
// expect: reject E7005
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.frozen_mut
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
{
let f = island.freeze(island.create(1u64, heap) or trap);
{
ref g = f;
let r = frozen.root(g);
mut x = frozen.at(g, r);
*x = 2;
}
frozen.release(move f);
0
}
@@ -0,0 +1,20 @@
// The container borrow is bound first; written inline it would end before the access.
// expect: reject E7006
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.inline_container_borrow
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
{
let isl = island.create(1u64, heap) or trap;
var v: u64 = 0;
{
ref g = isl;
let r = island.root(g);
mut x = island.at(mut isl, r);
v = *x;
}
island.destroy(move isl);
v
}
@@ -0,0 +1,19 @@
// iref handles are compared with == and != only; they have no order.
// expect: reject E7005
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.iref_order
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
{
let isl = island.create(1u64, heap) or trap;
var v: u64 = 0;
{
ref g = isl;
let a = island.root(g);
if a < a { v = 1; }
}
island.destroy(move isl);
v
}
@@ -0,0 +1,12 @@
// A graph owner is consumed exactly once: an island never destroyed, frozen or moved leaks.
// expect: reject E3002
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.leak
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
{
let isl = island.create(1u64, heap) or trap;
0
}
@@ -0,0 +1,29 @@
// An island is not Share: its owner may mutate it. Freeze it to share it with tasks.
// expect: reject E4002
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.lend_island
fn read(g: ref<island<u64>>) -> u64
effects []
{
let r = island.root(g);
ref v = island.at(g, r);
*v
}
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc, task.spawn]
{
let isl = island.create(1u64, heap) or trap;
var v: u64 = 0;
{
ref g = isl;
scope sc {
let t = task.spawn(sc, read, g);
v = task.join(move t);
}
}
island.destroy(move isl);
v
}
@@ -0,0 +1,14 @@
// island.alloc takes the island's borrow binding, not the owner.
// expect: reject E7005
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.owner_not_borrow
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
{
let isl = island.create(1u64, heap) or trap;
let r = island.alloc(isl, 2u64) or trap;
island.destroy(move isl);
0
}
@@ -0,0 +1,20 @@
// One mutable access per island at a time, even through different irefs.
// expect: reject E2101
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.two_mut_access
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
{
let isl = island.create(1u64, heap) or trap;
{
mut g = isl;
let a = island.root(g);
let b = island.alloc(g, 2u64) or trap;
mut x = island.at(g, a);
mut y = island.at(g, b);
}
island.destroy(move isl);
0
}
@@ -0,0 +1,26 @@
// After an island is sent, the sender holds nothing that reaches it.
// expect: reject E2001
// phase: 6
// spec: docs/spec/03-memory-model.md
module demo.use_after_send
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc, task.wait]
{
match channel.make<island<u64>>(1, heap) {
ok(tx, rx) => {
let isl = island.create(1u64, heap) or trap;
channel.send(tx, move isl) or trap;
{
ref g = isl;
let r = island.root(g);
}
channel.close_sender(move tx);
let back = channel.recv(rx) or trap;
island.destroy(move back);
channel.close_receiver(move rx) or trap;
0
}
err(e) => { trap; }
}
}