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

+3 -2
View File
@@ -47,6 +47,7 @@ Growth never blocks a merge automatically; a complex feature can be justified, b
| RFC 0012 waits, channels, select, mutex | 19 | 38 | 133 781 | 20 748 | 35 119 (+15.8 %) | 35 219 (+15.7 %) | 36 238 (+15.7 %) |
| Phase 3 implementation | 19 | 38 | 134 576 | 20 884 | 35 324 (+0.6 %) | 35 424 (+0.6 %) | 36 453 (+0.6 %) |
| RFC 0014 islands, frozen graphs, arc (Phase 4) | 19 | 41 | 142 918 | 22 212 | 37 785 (+7.0 %) | — | — |
RFC 0011 crossed the 10 % warning line (its own estimate said "below 10 %"): four new sections in spec 04 (tasks, loans, `Send`/`Share` table, scheduler). Below the 20 % review threshold. RFC 0012 (+15.8 %, estimate 12–16 %): five sections in spec 04 (waits and cancellation, channels, select, mutex, critical-section rule). Implementation-time spec corrections (mutex linearity, `mutex.take` rules): +0.6 %. Phase 3 total since the Phase 2 baseline: +29.2 %. Next measurement: after the E-S smoke test, or with the next RFC.
@@ -56,11 +57,11 @@ The `.aji` condition does not get the AIR bundle as its documentation. It gets a
| Path | Contents | cl100k tokens |
|---|---|---:|
| `QUICK.md` | the Quick Reference, then a table of which file to open for what | ~4.4k |
| `QUICK.md` | the Quick Reference, then a table of which file to open for what | ~5.0k (Phase 4: +0.6k for §7 graphs) |
| `language/syntax.md` | grammar, spec 15 §1, §2, §4–§6 | ~5.4k |
| `language/types.md` | spec 15 §3, integer semantics, type properties, traps | ~1.0k |
| `language/ownership.md` | spec 15 §9, aliasing, borrow lifetime, stack storage, slices, initialization (spec 03) | ~1.0k |
| `language/memory.md` | `Own<T>`, regions, allocation authority (spec 03) | ~1.4k |
| `language/memory.md` | `Own<T>`, regions, islands, frozen graphs, arc, allocation authority (spec 03) | ~3.6k |
| `language/effects-capabilities.md` | spec 05 §2–§5, §9–§10, effect and capability registries | ~4.4k |
| `language/io-resources.md` | spec 15 §8, spec 06 §1–§3, §7, intrinsic registry | ~3.0k |
| `language/concurrency.md` | implementation status, spec 15 §7, `Send`/`Share`, scheduler | ~2.2k |
+3
View File
@@ -59,6 +59,9 @@ docs/spec/06-resources-and-errors.md :: ## 7. I/O errors
docs/spec/03-memory-model.md :: ## 18. Allocation authority in AIR
docs/spec/03-memory-model.md :: ## 19. Heap in AIR
docs/spec/03-memory-model.md :: ## 20. Regions in AIR
docs/spec/03-memory-model.md :: ## 22. Islands in AIR
docs/spec/03-memory-model.md :: ## 23. Frozen graphs in AIR
docs/spec/03-memory-model.md :: ## 24. Arc in AIR
# Unsafe boundaries
docs/spec/13-contracts-and-unsafe.md :: ## 6. Unsafe code in AIR
+16
View File
@@ -62,5 +62,21 @@
"o200k_base": 35424,
"qwen2.5": 36453
}
},
{
"label": "RFC 0014 islands, frozen graphs, arc (Phase 4)",
"language": "aji",
"air": 0,
"phase": 3,
"files": 19,
"sections": 41,
"bytes": 142918,
"lines": 2118,
"words": 22212,
"tokens": {
"cl100k_base": 37785,
"o200k_base": 37888,
"qwen2.5": 38988
}
}
]
+46 -3
View File
@@ -37,7 +37,8 @@ effects [io.read, io.write]
| `own<T>`, `own_array<T>`, `region` | heap and regions (§6) |
| `cap<K>` | authority; kinds below |
| `file<read>`, `file<write>`, `file<append>`, `listener`, `stream` | linear resources |
| `task<T>`, `sender<T>`, `receiver<T>`, `mutex<T>` | concurrency (§7) |
| `island<T>`, `frozen<T>`, `arc<T>`, `iref<T>` | object graphs (§7) |
| `task<T>`, `sender<T>`, `receiver<T>`, `mutex<T>` | concurrency (§8) |
| `io_error`, `alloc_error`, `cap_error` | built-in error enums |
**Linear** values (resources, `own`, `region`, `task`, endpoints, `mutex`) are consumed exactly once. Everything else that is a plain value is copyable.
@@ -152,7 +153,47 @@ region.reset(r);
- Resource operands (`f`, `s`, `l`, endpoints) are borrowed automatically for an operation; a region is not (bind `ref arena = r;`); data borrows (`mut buf`, `ref bytes`) are always written.
- Memory budgets count live bytes, so freeing returns them. In the deterministic profile `mem.alloc` needs a grant with a budget: `--grant heap=mem.alloc:4096`.
## 7. Concurrency
## 7. Graphs: island → frozen → arc
Choose by intent:
- change a graph → `island<T>`;
- read it in parallel → `frozen<T>`;
- give it several independent owners → `arc<T>`.
Objects are addressed by `iref<T>` handles: copyable, compared only with `==`/`!=`, cycles allowed. A graph holds only plain data and irefs (`E2111` otherwise).
```aji
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
…
ref fr = f; // frozen graphs are Share: lend fr to tasks
let a = frozen.root(fr);
…
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
```
- `island.at`, `frozen.at` and `arc.at` appear only as `ref x = …;`/`mut x = …;`, with a **named borrow of the owner** (`mut g = isl;`, `ref fr = f;`), as for regions. `frozen.at` and `arc.at` give `ref` only.
- An `iref` from another graph traps `T0010`.
- Ownership:
- an island is `Send`, not `Share`: move it through channels or spawn, or freeze it to share;
- `frozen` and `arc` are `Send` and `Share`.
- Every owner is consumed once:
- an island by `island.destroy(move i)` or `island.freeze`;
- a frozen graph by `frozen.release` or `arc.from_frozen`;
- each arc handle by `arc.release`.
- `create`, `alloc` and `arc.new` charge the `mem.alloc` budget. The bytes come back when the graph is freed.
## 8. Concurrency
Tasks, channels, `select`, `lock`/mutex, `shield` and the cancellation operations all work.
@@ -222,7 +263,7 @@ scope s { // every task spawned in s must
Inside a `lock` block no operation may wait or spawn, and no function may be called whose effects include `task.wait` or `task.spawn` (`E4304`). One lock at a time, so lock-order deadlocks cannot happen.
## 8. Common diagnostics → repair
## 9. Common diagnostics → repair
| Code | Meaning | Usual repair |
|---|---|---|
@@ -242,4 +283,6 @@ scope s { // every task spawned in s must
| E4101 | data race with a task | lend disjoint parts (`split_at`, fields) or join first |
| E4301 | task not joined at scope end | `task.join(move t)` before the `scope` block ends |
| E4304 | wait inside `lock` | move the wait out of the `lock` block |
| E2111 | graph content not plain data | store only integers, booleans, enums, structs/arrays of them and `iref`s in a graph |
| T0010 | `iref` of another graph | use a handle with the graph it came from |
| T0001–T0009 | runtime trap | see `kind` and `source_location` |
+7 -1
View File
@@ -9,7 +9,7 @@
> QUICK.md
docs/agent/quick-reference.md
docs/agent/source-notes.md :: ## 9. Where to read more
docs/agent/source-notes.md :: ## 10. Where to read more
> language/syntax.md
docs/reference/grammar.ebnf
@@ -37,6 +37,12 @@ docs/spec/03-memory-model.md :: ## 10. Initialization policy
docs/spec/03-memory-model.md :: ## 7. Own<T>
docs/spec/03-memory-model.md :: ## 8. Regions
docs/spec/03-memory-model.md :: ## 18. Allocation authority in AIR
docs/spec/03-memory-model.md :: ## 12. Island<T>
docs/spec/03-memory-model.md :: ## 13. Frozen<T>
docs/spec/03-memory-model.md :: ## 14. Arc<T>
docs/spec/03-memory-model.md :: ## 22. Islands in AIR
docs/spec/03-memory-model.md :: ## 23. Frozen graphs in AIR
docs/spec/03-memory-model.md :: ## 24. Arc in AIR
> language/effects-capabilities.md
docs/spec/05-effects-and-capabilities.md :: ## 2. Effects
+2 -2
View File
@@ -2,7 +2,7 @@
Text that exists only for the Source Reference Bundle (`source-bundle.txt`). Non-normative: it points at the normative files and states which source layers are implemented.
## 9. Where to read more
## 10. Where to read more
The other files in `/docs` hold the full rules. Open one only when this page is not enough.
@@ -11,7 +11,7 @@ The other files in `/docs` hold the full rules. Open one only when this page is
| exact syntax, every construct, `match` and outcomes | `/docs/language/syntax.md` |
| integer semantics, conversions, Copy/Send/Share, traps | `/docs/language/types.md` |
| borrows, scopes, frame storage, slices, initialization | `/docs/language/ownership.md` |
| `own`, regions, allocation budgets | `/docs/language/memory.md` |
| `own`, regions, islands, frozen graphs, arcs, allocation budgets | `/docs/language/memory.md` |
| effects, capabilities, grants, narrowing | `/docs/language/effects-capabilities.md` |
| files, streams, stdin/stdout, intrinsic operand tables, `io_error` | `/docs/language/io-resources.md` |
| tasks, channels, select, mutex, cancellation | `/docs/language/concurrency.md` |