Files
aji/docs/plan/phase-4-islands.md
dev 7cc23338e2 Phase 4 exit review; AIR twins for the .aji-only island rejects
New AIR rejects: island_use_after_send (E2001), island_lend_task (E4002),
island_destroy_while_borrowed (E2101), arc_content_mutex (E2111),
frozen_borrow_mut (E1001). Every Phase 4 invariant now has an AIR and an
.aji test. Full suite 392/392, also under --stress 1000 and
--collect-every-step; test-extended, hosted smoke, source coverage 61/61.
2026-10-05 22:22:58 +03:00

82 lines
8.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Phase 4 — Islands
Non-normative. Part of the [implementation plan](README.md).
**Goal:** uniquely owned closed mutable graphs that move between tasks in O(1), and irreversible freezing into shareable immutable graphs.
**Exit criterion:** a cyclic graph moves between tasks with no deep copy and no shared mutation (`island-pipeline` reference program).
**Spec inputs:** spec 03 §12–15, 04 §13; [RFC 0014](../rfcs/0014-islands-frozen-arc.md) (Accepted, revision 2; integrated into spec 02 §6, 03 §12–§14 and §22–§24, 04 §13/§35/§38.1, 07a, 15 §8) makes RFC 0001's island sections concrete.
**Vertical rule (owner decision after P6A-9):** every feature goes through spec → AIR → verifier → interpreter → `.aji` lowering → Quick Reference → conformance (AIR and `.aji`) in this phase; nothing is left for a later frontend phase.
**Blocking questions:** none recorded; log new ones before starting.
## Invariants
- `iref<T>` points only inside its own island and is never dereferenced without access to the owning island;
- an island has no edges into foreign mutable memory;
- after transfer the sender holds nothing that reaches the island;
- a `Frozen<T>` never yields a mutable reference in safe code;
- reference counts change only through explicit `arc.clone` / `arc.release`.
## Tasks
| ID | Status | Task | Depends | Output | Done when |
|---|---|---|---|---|---|
| P4-0 | done | RFC 0014: decisions D1–D10, owner review | — | `docs/rfcs/0014-islands-frozen-arc.md` | Accepted (revision 2) |
| P4-1 | done | Spec integration: spec 03 §12–14, 04 §13/§35/§38.1, 07a contract tables, 15 (layer 9), error codes (`T0010`) | P4-0 | spec, reference | contract tables complete (spec 07 §4 fields) |
| P4-1a | done | Publish `islands` (depends on `heap`) and add `arc` (depends on `islands`) | P4-1 | `reference/air-features.md`, `src/air/features.zig` | feature_not_declared / missing_dependency tests |
| P4-2 | done | Interpreter: island tables, identities never reused, `T0010`, freeze, O(1) transfer; arc counts in the trace; collector support | P4-1 | `src/interp/` | transfer cost independent of graph size (unit test with an instruction-count bound); `--collect-every-step` passes |
| P4-3 | done | Verifier: types and classes, storability (`E2111`), container child borrows, arc rules (`E4002`/`E1001`), Send/Share rows | P4-1 | `src/verifier/` | accept/reject per rule |
| P4-4 | done | Transfer through channels and spawn; sender invalidation | P4-3 | verifier + interpreter | use after send rejected (`E2001`); schedule stress |
| P4-5 | done | Freeze and `frozen<T>`; lending to tasks | P4-3 | verifier + interpreter | concurrent reads accepted; mutable access rejected |
| P4-6 | done | `arc<T>`: `arc.from_frozen`, `arc.new` (`ArcSafe`), `clone`, `release`, `root`, `borrow` | P4-5 | verifier + interpreter | non-`ArcSafe` rejected (`E2111`); count changes visible in the trace |
| P4-7 | done | `.aji` layer 9: types, operations, `island.at`/`frozen.at`/`arc.at` places, explicit container borrows; Quick Reference section; source coverage rows | P4-3 | `src/frontend/`, `docs/agent/` | `.aji` run/reject tests; Quick Reference examples checked; `tools/source_coverage.py` passes |
| P4-8 | done | Reference program `island-pipeline` in AIR and `.aji` with equivalence | P4-4, P4-5, P4-6, P4-7 | `tests/conformance/` | passes under all P3 stress modes |
| P4-9 | done | Complexity budget: AIR bundle, Quick Reference, Source Reference Bundle measured against the RFC estimate | P4-7 | `docs/agent/README.md` | growth recorded and justified |
| P4-11 | done | `reference/air-text.ebnf` covers the syntax of Phases 2–4: `cap<K>`, endpoint, task, graph and built-in types; `own.*`, `task.*`, `channel.*` (with the type operand of `channel.make`), `island.*`/`frozen.*`/`arc.*`/`iref.eq`; the multi-edge terminator forms (found by the independent author of `program_island_pipeline.air`) | — | `docs/reference/air-text.ebnf` | every instruction of spec 07a and spec 03 §22–§24 has a production |
| P4-10 | done | Phase exit review | all | plan status | exit criterion passes |
## Conformance tests to add
Negative corpus entry owned by this phase: island internal reference escape. Plus E2111, freeze-then-mutate, `Arc` of non-`Share`.
All four are present in AIR and `.aji`: `island_destroy_while_borrowed.air` / `destroy_while_borrowed.aji` (internal reference escape, `E2101`), `island_content_owner.air` / `content_owner.aji` (`E2111`), `island_use_after_freeze.air` and `frozen_borrow_mut.air` / `frozen_mut.aji` (freeze-then-mutate), `arc_content_mutex.air` / `arc_mutex.aji` (`arc` of a non-`ArcSafe` value, `E2111`).
## Exit review
- Exit criterion met: `program_island_pipeline.air`, written by an independent author from the spec, moves a cyclic graph between tasks through channels and freezes it for concurrent readers. It runs with `schedules: 30`, under `--stress 1000` (the whole suite, 392 tests, without a failure) and with `--collect-every-step`. `source/programs/island_pipeline.aji` is `equivalent:` to it. Transfer moves the owner handle only: the unit test "moving an island costs the same for any graph size" checks this with an instruction count, not a timer.
- Invariants, each with an AIR and a `.aji` test:
| Invariant | Rejected example | Code |
|---|---|---|
| an `iref<T>` is used only with its own graph's owner | `island_foreign_iref.air`, `foreign_iref.aji` (run, trap) | `T0010` |
| no edges into foreign mutable memory | `island_content_owner.air`, `content_owner.aji` | `E2111` |
| after transfer the sender holds nothing | `island_use_after_send.air`, `use_after_send.aji` | `E2001` |
| a frozen graph yields no mutable reference | `frozen_borrow_mut.air`, `frozen_mut.aji` | `E1001` / `E7005` |
| counts change only through `arc.clone` / `arc.release` | `arc_release_twice.air`; trace test "arc count trace" | `E2002` |
| an island is not `Share` | `island_lend_task.air`, `lend_island.aji` | `E4002` |
- Decision record: RFC 0014 Accepted (revision 2, owner decisions D1–D10 plus `iref` equality) and integrated into spec 02 §6, 03 §12–§14 and §22–§24, 04 §13/§35/§38.1, 07a and 15 (layer 9). Features published: `islands` (depends on `heap`) and `arc` (depends on `islands`).
- Vertical rule: every construct went through spec → AIR → verifier → interpreter → `.aji` → Quick Reference (§7 Graphs, excerpts checked against `quickref/graphs.aji`) → conformance. Source coverage: 61/61 constructs.
- Conformance: 392 tests. Phase 4 adds 16 AIR tests (3 run, 13 reject) and 20 `.aji` tests (6 run, 12 reject, the Quick Reference excerpt and the reference program).
- Grammar: `reference/air-text.ebnf` now covers the syntax of Phases 2–4 (P4-11). Every opcode in the conformance corpus and in the spec contract tables has a production.
- Complexity budget (cl100k):
| Bundle | Before | After |
|---|---|---|
| AIR Agent Reference Bundle | 35 324 | 39 154 (+10.8 % over the phase: +7.0 % RFC 0014, +3.6 % the completed grammar) |
| `QUICK.md` | 4.37k | 5.01k |
| Source docs | 22.4k | 26.7k |
RFC 0014 estimates: AIR +3–4k (measured +2.5k for the semantics), Quick Reference +600–800 (measured +640), source docs +3–4k (measured +4.3k, slightly above). The extra +1.4k in the AIR bundle is the grammar the bundle had been missing since Phase 2, not new semantics.
- Known limitations:
- Graph contents are plain data and `iref` handles only: there are no owners, resources or endpoints inside a graph.
- `arc` is built from frozen graphs only: there is no `arc<mutex<T>>` and no weak handles.
- Island memory is reclaimed only by `island.destroy`, `frozen.release` or the last `arc.release`. There is no per-object free inside a live island.
- The execution-heap collector is an interpreter mechanism, not language semantics.
- Q-023 (array argument borrows in `.aji`) remains open and is unrelated to islands.
- Not run in this phase: the M/C regression corpus. It is a regression check only and needs a frozen matrix outside this repository.
- Next: per the owner's order, decide whether the language is stable enough to start Phase 5 (atomics and the memory model) or whether a specialized atomics/concurrency benchmark comes first.