rfc: 0014 accepted (revision 2) and integrated into the spec

Owner review: D1-D4, D7-D9 accepted; D5 frozen.release, no thaw; D6
arc.from_frozen (island -> frozen -> arc, one graph identity), ArcSafe
(not Share alone; no arc<mutex>, no nested arc); D7 island Send, not
Share; D10 islands -> heap, arc -> islands; added: never-reused graph
identity, IslandSafe, the quota lifecycle, iref equality.

Integrated: spec 02 §6 (IslandSafe, ArcSafe), 03 §12-§14 and new
§22-§24 (instruction contracts, quota), 04 §13/§35/§38.1, 07a (features
islands, arc), 15 §8 (layer 9 syntax, explicit container borrows),
error codes (T0010, registered in src/diag.zig), type-properties. Phase 4
plan: P4-0, P4-1 done.
This commit is contained in:
dev committed 2026-10-05 21:57:08 +03:00
1 parent 7d8f147d1d
commit ca84ab4348
10 files changed
+346 -224

No files matched your search

+5 -5
View File
@@ -6,7 +6,7 @@ Non-normative. Part of the [implementation plan](README.md).
**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) (Proposed) makes RFC 0001's island sections concrete. Implementation starts after the owner accepts it.
**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.
@@ -24,14 +24,14 @@ Non-normative. Part of the [implementation plan](README.md).
| ID | Status | Task | Depends | Output | Done when |
|---|---|---|---|---|---|
| P4-0 | doing | RFC 0014: decisions D1–D10, owner review | — | `docs/rfcs/0014-islands-frozen-arc.md` | Accepted |
| P4-1 | todo | 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 | todo | Publish `islands` (dependencies per D10) and add `arc` | P4-1 | `reference/air-features.md`, `src/air/features.zig` | feature_not_declared / missing_dependency tests |
| 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 | todo | 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 | todo | 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 | todo | 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 | todo | Transfer through channels and spawn; sender invalidation | P4-3 | verifier + interpreter | use after send rejected (`E2001`); schedule stress |
| P4-5 | todo | Freeze and `frozen<T>`; lending to tasks | P4-3 | verifier + interpreter | concurrent reads accepted; mutable access rejected |
| P4-6 | todo | `arc<T>` | P4-5 | verifier + interpreter | non-`Share` rejected (`E4002`); count changes visible in the trace |
| P4-6 | todo | `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 | todo | `.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 | todo | 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 | todo | Complexity budget: AIR bundle, Quick Reference, Source Reference Bundle measured against the RFC estimate | P4-7 | `docs/agent/README.md` | growth recorded and justified |
+1
View File
@@ -108,3 +108,4 @@ Reported in trap records (spec 01 §6), not by the verifier.
| T0007 | trap.call_depth | Call depth limit (1 024 frames) exceeded |
| T0008 | trap.out_of_bounds | Runtime bounds check failed |
| T0009 | trap.unsafe_precondition | Unsafe precondition violated (detected) |
| T0010 | trap.foreign_iref | An `iref` was used to access a graph it does not belong to |
+14
View File
@@ -35,3 +35,17 @@ External resources that remain operational/mutable may prevent `Freeze`.
A `Local` value is tied to its current execution context and prevents migration/transfer.
Examples may include thread-local handles, event-loop-local registrations or platform UI objects.
## IslandSafe
An `IslandSafe` value may be stored in an island graph (spec 03 §22). Derived structurally:
- **IslandSafe:** integers, `bool`, built-in enums, `iref<U>`, and arrays, structs and enums of `IslandSafe` values.
- **Not IslandSafe:** borrows, owners, regions, graph owners (`island`, `frozen`, `arc`), resources, endpoints, `task`, `scope`, `shield`, `guard`, `mutex`, `cap<K>`.
Because of it, a graph never holds outside authority or a mutable ownership edge, so freeze, conversion and transfer are O(1).
## ArcSafe
An `ArcSafe` value may be held by an `arc` (spec 03 §24): the last release destroys it by freeing memory only, with no user or resource action. In format 0 it is exactly `IslandSafe`. `Share` alone is not enough; for example, a `mutex<T>` is `Share` but not `ArcSafe`.
+220 -161
View File
@@ -1,112 +1,171 @@
# RFC 0014: Islands, Frozen Graphs and Arc (Phase 4)
Status: Proposed
Status: Accepted (revision 2, after owner review). D1–D4, D7–D9 accepted. D5, D6 and D10 revised: `frozen.release`, no thaw; `arc.from_frozen` instead of `arc<frozen<T>>`; `ArcSafe`; `islands → heap`, `arc → islands`. Added: stable identity, `IslandSafe`, the quota lifecycle and `iref` equality.
Target: AIR format 0 extension (publishes `islands`, adds `arc`); `.aji` 0.1 layer 9
Builds on: RFC 0001 (Proposed; its island sections are made concrete here), RFC 0011, RFC 0012, RFC 0013
Builds on: RFC 0001 (its island sections are made concrete here), RFC 0011, RFC 0012, RFC 0013
Integrated into:
- spec 02 §6;
- spec 03 §12–§14, §22–§24;
- spec 04 §13, §35, §38.1;
- spec 07a (features `islands`, `arc`);
- spec 15 §5, §8;
- `reference/error-codes.md` (`T0010`);
- `reference/type-properties.md`.
## Summary
Three verifier-visible ownership forms for object graphs, delivered through every layer at once (spec, AIR, verifier, interpreter, `.aji`, Quick Reference, conformance; owner decision after P6A-9):
One immutable-graph lifecycle in three ownership modes, plus a handle type. It is delivered through every layer at once: spec, AIR, verifier, interpreter, `.aji`, Quick Reference and conformance (owner decision after P6A-9).
| Form | What it is | Class |
```text
island<T> mutable, unique "I want to change it"
│ island.freeze O(1)
▼
frozen<T> immutable, unique owner, Share "I want to read it in parallel"
│ arc.from_frozen O(1)
▼
arc<T> immutable, shared ownership "several independent owners"
```
| Type | What it is | Class |
|---|---|---|
| `island<T>` | a uniquely owned, closed, mutable graph whose root has type `T` | linear; `Send`, `Share` |
| `iref<T>` | a handle to an object of type `T` inside some island | copyable plain data |
| `frozen<T>` | an island made deeply immutable by `island.freeze` | linear; `Send`, `Share` |
| `arc<T>` | explicitly counted shared ownership of a `Share` value | linear handle; `Send`, `Share` |
| `island<T>` | a uniquely owned, closed, mutable graph whose root has type `T` | linear; `Send`, not `Share` |
| `frozen<T>` | the same graph, immutable, with one owner | linear; `Send`, `Share` |
| `arc<T>` | the same graph, immutable, with counted shared owners; each handle is linear | linear handle; `Send`, `Share` |
| `iref<T>` | an opaque handle to an object of type `T` inside a graph | copyable; `Send`, `Share` |
A cyclic graph is built in an island with `iref` edges, moved to another task in O(1) through the existing channel and spawn rules, frozen without copying, and shared by `arc` with explicit `clone` and `release`. There is no garbage collection, no implicit reference count, no hidden destructor and no shared mutable memory outside synchronization.
A graph keeps its identity through every mode, so an `iref` stays valid from island to frozen to arc. There is:
- no garbage collection;
- no implicit reference count;
- no thaw;
- no hidden destructor (releasing a graph frees memory and nothing else);
- no shared mutable memory outside synchronization.
## Motivation
Per-object ownership (`own<T>`) makes cyclic and arena-shaped data awkward, and regions give bulk lifetime but cannot move between tasks or be shared. Phase 3 can move values and lend borrows within a scope, but there is no way to:
Per-object ownership (`own<T>`) makes cyclic and arena-shaped data awkward. Regions give bulk lifetime but cannot move between tasks or be shared. Phase 3 moves values and lends borrows within a scope, but cannot:
- build a graph with cycles and move it to another task without copying;
- turn a graph built by one task into immutable data many tasks read for longer than one scope;
- share one immutable value among tasks that are not in the same scope.
- build a cyclic graph and move it to another task without copying;
- turn a graph built by one task into immutable data that many tasks read for longer than one scope;
- give one immutable value several independent owners.
These are the island-pipeline workloads of the Phase 4 exit criterion: parsers, message graphs, request contexts and actor-like state.
## Invariants
1. **Closure.** An island holds only island-storable values: plain data and `iref` handles. It never points into ordinary mutable memory outside itself (RFC 0001 invariant).
2. **No outside mutable alias.** Every access to an island's objects goes through a borrow of the island. While a mutable access is live, no other access to the island exists.
3. **Transfer invalidates the sender.** After an island, a frozen graph or an arc is moved, the sender holds nothing that reaches it. This is the ordinary linear-move rule, so a use after the move is `E2001`.
4. **Freeze is irreversible.** No safe operation yields a mutable borrow of a frozen graph.
5. **Explicit counting.** An arc's count changes only at `arc.clone` and `arc.release`. Memory is freed only at an explicit `island.destroy`, `frozen.destroy` or the last `arc.release`.
6. **Handles cannot be forged into memory errors.** An `iref` is checked against the island it is used with. Using it with another island traps (`T0010`). Island identities are never reused within an execution, so a stale handle can never reach a later island's objects.
7. **Determinism.** Island identities, slots and arc counts are deterministic. Transfer and freeze cost O(1) in the graph size.
1. **Closure.** A graph holds only `IslandSafe` values. They have no edge into mutable memory outside the graph and carry no authority.
2. **No outside mutable alias.** Every access to a graph's objects goes through a borrow of the graph's owner. While a mutable access is live, no other access to the island exists.
3. **Transfer invalidates the sender.** After a graph's owner is moved, the sender holds nothing that reaches it. This is the linear-move rule, and a later use is `E2001`.
4. **Freeze is irreversible.** No operation yields a mutable borrow of a frozen or arc graph.
5. **Explicit counting.** An arc's count changes only at `arc.clone` and `arc.release`. A graph's memory is freed only at `island.destroy`, `frozen.release` or the last `arc.release`, and that frees memory only.
6. **Identity.** A graph's identity is unique within an execution and never reused. An `iref` from one graph used with another traps (`T0010`). A stale `iref` (its graph released) is harmless: without an owner of that graph it cannot be used.
7. **Determinism.** Identities, slots and counts are deterministic. Freeze, conversion and transfer cost O(1) in the graph size.
## Decisions for the owner
## Decisions (revision 2)
### D1. `iref` provenance: checked at run time
### D1. `iref` is opaque; identity is never reused (accepted)
**Recommended.** An `iref<T>` is plain data: the island identity and a slot. It is dereferenced only together with a borrow of an island. The interpreter checks that the handle belongs to that island, and a mismatch traps `T0010` (`trap.foreign_iref`).
An `iref<T>` is an opaque pair `{graph identity, slot}`. The identity is unique for the execution: it comes from a counter that is never reset or reused. A handle cannot be:
**Alternative.** Track island identity in the verifier. Static provenance does not survive function boundaries, aggregates or channels without island-indexed types (dependent on values), which grows the verifier state and the agent's reasoning a great deal. The runtime check costs one comparison, keeps every check intraprocedural, and is memory-safe: an island is never freed while a borrow of it is live, and identities are never reused.
- constructed from an integer;
- cast to an integer;
- inspected as bytes;
- modified.
### D2. What an island may contain
It is checked against the graph whenever it is used to access one (`T0010` on a mismatch).
**Recommended.** Island-storable values are:
**Equality.** `iref.eq %a, %b` (source `a == b`, `a != b`) compares identity and slot. It is always defined. Handles of different graphs are simply unequal, never a trap. Hashing is deferred.
- integers, `bool` and built-in enums;
### D2. `IslandSafe` (accepted, as a structural property)
`IslandSafe` is derived structurally (spec 02 §6).
**IslandSafe:**
- integers, `bool`, built-in enums (and floats, when the language has them);
- `iref<U>`;
- structs, enums and arrays of island-storable values.
- arrays, structs and enums whose elements, fields and payloads are `IslandSafe`.
Everything else is `E2111` (`island.foreign_mutable_edge`, field `found`):
**Not IslandSafe:**
- borrows;
- `ref`, `mut`, `slice`, `slice_mut`;
- `own`, `own_array`, `region`;
- `island`, `frozen`, `arc`;
- resources and endpoints;
- tasks, scopes, shields, guards and mutexes;
- `cap<K>`;
- islands, frozen graphs and arcs.
- `task`, `scope`, `shield`, `guard`, `mutex`;
- `cap<K>`.
This keeps the closure invariant a property of types, with no ownership analysis. Allowing capabilities or nested islands is left open (Q1).
A graph contains only `IslandSafe` values (`E2111` otherwise, field `found`). This is what makes freeze, conversion and transfer provably O(1): a graph never holds outside authority or a mutable ownership edge.
### D3. Island memory
### D3. Memory and quota (accepted, lifecycle stated)
**Recommended.** `island.create` takes a `cap<mem.alloc>`. The island charges that authority for every object, as `own` does: live bytes, and freeing returns the budget. `island.alloc` is fallible (`alloc_error`). Objects are not freed one by one; `island.destroy` frees them all, and freezing keeps them. This is bulk lifetime, as for regions.
A graph charges the `cap<mem.alloc>` it was created with: live bytes, as for `own`. The ownership mode does not change the budget.
### D4. Access through a borrow of the island
| Operation | Live bytes |
|---|---|
| `island.create`, `island.alloc` | + the object |
| `island.freeze` | unchanged |
| `arc.new` | + the value and the count |
| `arc.from_frozen` | + the count only |
| `arc.clone` | unchanged |
| `arc.release`, not the last | unchanged |
| `arc.release`, the last | − the graph and the count |
| `frozen.release` | − the graph |
| `island.destroy` | − the graph |
**Recommended.**
Objects are never freed one by one: bulk lifetime, as for regions. `island.alloc` is fallible (`alloc_error`).
- `island.borrow %ib, %r` gives `ref<U>` from `ref<island<T>>` and `mut<U>` from `mut<island<T>>`.
- The result is a child borrow of `%ib`, with the usual rules: it ends before `%ib` (`E2102`); a mutable child is exclusive (`E2101` for any other access through `%ib` while it is live).
- Two irefs may name the same object, so two simultaneous `mut` accesses into one island are never accepted. Read accesses may coexist.
### D4. One mutable access per island (accepted, conservative on purpose)
This reuses the borrow machinery of Phases 1–3 unchanged.
- A `ref<island<T>>` gives any number of shared children.
- A `mut<island<T>>` gives at most one live mutable child; any other access through it while that child lives is `E2101`.
### D5. Freeze
Two irefs that happen to name different objects are not treated as disjoint: the verifier does not try to prove it. A proved-disjointness mechanism may come later if benchmarks need it.
**Recommended.** `island.freeze %i` consumes the island and returns `frozen<T>` over the same storage, in O(1). `frozen.borrow %fb, %r` gives `ref<U>` from `ref<frozen<T>>` and nothing else. `frozen<T>` is linear, with one owner, and is shared by lending `ref<frozen<T>>` to tasks (it is `Share`) or by putting it in an `arc` (D6). `frozen.destroy` frees it.
### D5. Freeze and `frozen.release` (accepted with clarification)
### D6. `arc<T>` (new feature `arc`)
- `island.freeze %i` consumes the island (so no borrow of it is live) and returns `frozen<T>` over the same storage. It is O(1), with no traversal; the identity is kept, irefs stay valid, and the quota is unchanged.
- `frozen.release %f` frees the whole graph and returns its bytes.
- There is no thaw in AIR format 0.
**Recommended.**
### D6. `arc.from_frozen` and `ArcSafe` (revised)
- `arc.new %v, %mem` (fallible) requires `T: Share`, otherwise `E4002`.
- In format 0, `T` contains no linear value other than `frozen<U>`, otherwise `E1001`. Releasing the last arc then frees only memory, never anything with an observable effect; that is what keeps the release from being a hidden destructor.
- `arc.clone %ar` takes `ref<arc<T>>` and returns a new `arc<T>` (count + 1).
- `arc.release %a` consumes the arc (count − 1). At zero, `T`'s memory is freed, together with a contained frozen graph.
- `arc.borrow %ar` gives `ref<T>`, a child borrow.
`arc<T>` is a shared, immutable graph with root type `T`. It is never `arc<frozen<T>>`: one graph, one ownership wrapper.
The count is synchronized inside the runtime. It is not a user atomic, so it introduces no memory-ordering choice. `arc<mutex<T>>` (shared mutable state beyond one scope) is deferred (Q2).
| Operation | Meaning |
|---|---|
| `arc.from_frozen %f` | consumes `frozen<T>` and gives the first `arc<T>` handle of the same graph; O(1); the identity is kept |
| `arc.new %v, %mem` (fallible) | a one-object shared graph whose root is `%v` |
| `arc.clone %ar` | takes `ref<arc<T>>` and gives a new linear handle (count + 1) |
| `arc.release %a` | consumes one handle (count − 1); the last release frees the graph |
| `arc.root %ar`, `arc.borrow %ar, %r` | read access, as for frozen graphs |
### D7. Transfer
**`ArcSafe`** is what an `arc` may hold. The last `arc.release` must be able to destroy the value by freeing memory alone: no user action, no resource action. In format 0, `ArcSafe` is exactly `IslandSafe`. It is named separately so that the two can diverge later. `T: Share` alone is not enough: a mutex is `Share`, yet `arc<mutex<T>>` is deliberately excluded. So there is no:
**Recommended.**
- `arc<file<…>>` or `arc<stream>`;
- `arc<cap<…>>`;
- `arc<own<T>>`;
- `arc<mutex<T>>`;
- `arc<sender<T>>`;
- nested `arc<arc<T>>`.
- `island<T>`, `frozen<T>` and `arc<T>` move through `channel.send`, `task.spawn` arguments and returns under the existing rules.
- They are `Send`.
- They are allowed as channel elements and mutex contents: they contain no borrow, task or guard.
- Moving the value moves a handle (O(1)).
- `ref<island<T>>` and `ref<frozen<T>>` may be lent to tasks: both are `Share`, since only reads go through a shared borrow.
A value that is not `ArcSafe` is `E2111`, the same code as an island's content, since both are graph contents. The count is synchronized inside the runtime. It is not a user atomic and adds no memory-ordering choice.
### D8. `.aji` syntax: an explicit container borrow, as for regions
### D7. Transfer (accepted, with the corrected Share)
**Recommended.** Every operation that yields a borrow into a container takes an explicit borrow binding of that container, which outlives the borrows derived from it. This is the rule spec 15 §8 already applies to regions, stated generally:
| Type | Send | Share |
|---|---|---|
| `island<T>` | yes | **no** |
| `frozen<T>` | yes | yes |
| `arc<T>` | yes | yes |
| `iref<T>` | yes | yes |
An island's owner may mutate it, so a `ref<island<T>>` is not lent to tasks: freeze first. Owners move through `channel.send`, `task.spawn` arguments and returns under the existing rules, in O(1). They are allowed as channel elements and mutex contents (spec 04 §38.1). `ref<frozen<T>>` and `ref<arc<T>>` may be lent to tasks.
### D8. Explicit container borrows in `.aji` (accepted)
An operation that yields a borrow into a graph takes a named borrow binding of the graph's owner, which outlives the borrows derived from it. This is the region rule of spec 15 §8, stated generally. A container borrow written inline (`island.at(mut isl, r)`) is `E7006`. The owner itself (`island.at(isl, r)`) is `E7005`, with a hint.
```aji
let isl = island.create(Node { value: 1, next: Link::End }, heap) or trap;
@@ -124,91 +183,86 @@ let f = island.freeze(move isl);
| Source | AIR |
|---|---|
| `island<T>`, `iref<T>`, `frozen<T>`, `arc<T>` | the same types |
| `island<T>`, `frozen<T>`, `arc<T>`, `iref<T>` | the same types |
| `island.create(v, mem)` (outcome match / `or trap`) | `island.create` |
| `island.root(g)`, `frozen.root(fr)` | `island.root`, `frozen.root` |
| `island.alloc(g, v)` (outcome match / `or trap`) | `island.alloc` |
| `ref x = island.at(g, r);` / `mut x = island.at(g, r);` | `island.borrow` on the binding `g` |
| `ref x = frozen.at(fr, r);` | `frozen.borrow` |
| `island.freeze(move i)`, `island.destroy(move i)`, `frozen.destroy(move f)` | the same |
| `arc.new(v, mem)` (outcome match / `or trap`), `arc.clone(a)`, `arc.release(move a)` | the same; `clone` borrows `a` for the operation |
| `ref x = arc.at(ar);` | `arc.borrow` on the binding `ar` |
| `island.root(g)`, `frozen.root(g)`, `arc.root(g)` | `island.root`, `frozen.root`, `arc.root` |
| `ref x = island.at(g, r);` / `mut x = island.at(g, r);` | `island.borrow` |
| `ref x = frozen.at(g, r);`, `ref x = arc.at(g, r);` | `frozen.borrow`, `arc.borrow` |
| `island.freeze(move i)`, `island.destroy(move i)`, `frozen.release(move f)` | the same |
| `arc.from_frozen(move f)`, `arc.new(v, mem)` (outcome match / `or trap`) | the same |
| `arc.clone(a)` (`a` borrowed for the operation), `arc.release(move a)` | the same |
| `a == b`, `a != b` on `iref<T>` | `iref.eq`, then `not` |
**Container operands.**
- **Bare name** (borrowed for the one operation, as for resources): `island.root`, `frozen.root` and `arc.clone`. Their results are plain values (`iref`, `arc`), not borrows.
- **Explicit borrow binding of the container**: `island.at`, `frozen.at`, `arc.at` and `island.alloc`. Passing the container itself is `E7005` with a hint, as for regions.
- **Named borrow binding of the owner:** `.root`, `.at` and `island.alloc`.
- **Owner by name** (a fresh handle, no borrow result): `arc.clone`.
**Accesses produce borrows.** `island.at`, `frozen.at` and `arc.at` appear only as the place of a `ref`/`mut` binding. Elsewhere they are `E7006`.
**Where `.at` may appear.** `island.at`, `frozen.at` and `arc.at` appear only as the place of a `ref`/`mut` binding (`E7006` elsewhere). `frozen.at` and `arc.at` bind `ref` only (`E7005` for `mut`).
### D9. Diagnostics
### D9. Diagnostics (accepted)
| Code | Use |
|---|---|
| `E2111` (`island.foreign_mutable_edge`, registered) | island content that is not island-storable; field `found` names the type |
| `E2110` (`island.escape`, registered) | stays reserved: a borrow derived from an island can no longer escape any other way than `E2102`, and with D1 an `iref` is plain data. It is kept for a later static-provenance mode (Q3) |
| `T0010` `trap.foreign_iref` (new) | an `iref` used with an island it does not belong to |
| `E4002` | `arc` of a non-`Share` value |
| `E1001` | an `arc` holding a linear value other than `frozen<…>` |
| `T0010` `trap.foreign_iref` (new) | an `iref` used to access a graph it does not belong to |
| `E2111` (`island.foreign_mutable_edge`) | a graph content that is not `IslandSafe`/`ArcSafe`; field `found` |
| `E2110` (`island.escape`) | stays registered and unused; reserved for a static-provenance mode (Q3) |
| `E4002` | lending `ref<island<T>>` to a task (not `Share`) |
`E2001`/`E2002`/`E3001`/`E3002` apply to islands, frozen graphs and arcs as linear values. `E2101`/`E2102`/`E4101`/`E4302` apply to their borrows and loans.
`E2001`/`E2002`/`E3001`/`E3002` apply to graph owners as linear values. `E2101`/`E2102`/`E4101`/`E4302` apply to their borrows and loans.
### D10. Features
### D10. Features (accepted with dependencies)
| Feature | Status | Depends on | Contents |
|---|---|---|---|
| `islands` | published (reserved until now) | `capabilities`, `effects`, `heap`, `ownership`, `resources` | `island<T>`, `iref<T>`, `frozen<T>`, `island.*`, `frozen.*` |
| `arc` | new, published | `capabilities`, `effects`, `heap`, `ownership`, `resources` | `arc<T>`, `arc.*` |
| Feature | Depends on | Contents |
|---|---|---|
| `islands` (published; reserved until now) | `heap` (and its closure) | `island<T>`, `frozen<T>`, `iref<T>`, `island.*`, `frozen.*`, `iref.eq` |
| `arc` (new, published) | `islands` | `arc<T>`, `arc.*` |
`islands` drops its registered dependency on `regions`, which reserved features may change before publication (DD-014). Islands do not use region instructions; they share the bulk-lifetime idea only.
`regions` is not a dependency (DD-014 allows changing a reserved feature's dependencies before publication).
## Types and instructions (AIR)
## Instructions (AIR)
| Instruction | Operands → result | Ownership and memory | Effect | Verifier | Runtime / trap |
|---|---|---|---|---|---|
| `island.create %v, %mem, ok -> @ok, err -> @err` (terminator) | `T` (consumed), `cap<mem.alloc>`; `@ok(island<T>)`, `@err(alloc_error)` | `%v` becomes object 0; charges `size(T)` plus the island header | `mem.alloc` | `T` island-storable (`E2111`) | new island identity; budget failure → `@err` |
| `%r = island.root %ib` | `ref<island<T>>` or `mut<island<T>>` → `iref<T>` | none | — | — | object 0 |
| `island.alloc %ib, %v, ok -> @ok, err -> @err` (terminator) | `mut<island<T>>`, `U` (consumed); `@ok(iref<U>)`, `@err(alloc_error)` | new object; charges the island's authority | `mem.alloc` | `U` island-storable (`E2111`) | — |
| `%p = island.borrow %ib, %r` | `ref<island<T>>` → `ref<U>`, `mut<island<T>>` → `mut<U>`; `%r: iref<U>` | child borrow of `%ib` | — | ends before `%ib` (`E2102`); a `mut` child is exclusive (`E2101`) | `T0010` if `%r` is not of this island |
| `%f = island.freeze %i` | `island<T>` (consumed) → `frozen<T>` | same storage, now immutable | — | — | O(1) |
| `island.destroy %i` | `island<T>` (consumed) | frees every object; returns the bytes | — | no live borrow (`E2101`) | — |
| `%r = frozen.root %fb` | `ref<frozen<T>>` → `iref<T>` | none | — | — | — |
| `island.create %v, %mem, ok -> @ok, err -> @err` (terminator) | `T` (consumed), `cap<mem.alloc>`; `@ok(island<T>)`, `@err(alloc_error)` | `%v` is the root object; charges its size and the graph header | `mem.alloc` | `T: IslandSafe` (`E2111`) | a new identity; over budget → `@err` |
| `island.alloc %ib, %v, ok -> @ok, err -> @err` (terminator) | `mut<island<T>>`, `U` (consumed); `@ok(iref<U>)`, `@err(alloc_error)` | a new object; charges the graph's authority | `mem.alloc` | `U: IslandSafe` (`E2111`) | — |
| `%r = island.root %ib` | `ref`/`mut<island<T>>` → `iref<T>` | — | — | — | the root object |
| `%p = island.borrow %ib, %r` | `ref<island<T>>` → `ref<U>`; `mut<island<T>>` → `mut<U>`; `%r: iref<U>` | child borrow of `%ib` | — | ends before `%ib` (`E2102`); a `mut` child is exclusive (`E2101`) | `T0010` |
| `%f = island.freeze %i` | `island<T>` (consumed) → `frozen<T>` | same storage and identity; quota unchanged | — | — | O(1) |
| `island.destroy %i` | `island<T>` (consumed) | frees the graph | — | — | — |
| `%r = frozen.root %fb` | `ref<frozen<T>>` → `iref<T>` | — | — | — | — |
| `%p = frozen.borrow %fb, %r` | `ref<frozen<T>>`, `iref<U>` → `ref<U>` | child borrow | — | `E2102` | `T0010` |
| `frozen.destroy %f` | `frozen<T>` (consumed) | frees the graph | — | no live borrow | — |
| `arc.new %v, %mem, ok -> @ok, err -> @err` (terminator) | `T` (consumed), `cap<mem.alloc>`; `@ok(arc<T>)`, `@err(alloc_error)` | count 1 | `mem.alloc` | `T: Share` (`E4002`); no linear value but `frozen<…>` (`E1001`) | — |
| `frozen.release %f` | `frozen<T>` (consumed) | frees the graph | — | — | — |
| `%a = arc.from_frozen %f` | `frozen<T>` (consumed) → `arc<T>` | same storage and identity; count 1; + count bytes | — | — | O(1) |
| `arc.new %v, %mem, ok -> @ok, err -> @err` (terminator) | `T` (consumed), `cap<mem.alloc>`; `@ok(arc<T>)`, `@err(alloc_error)` | a one-object graph, count 1 | `mem.alloc` | `T: ArcSafe` (`E2111`) | — |
| `%a2 = arc.clone %ar` | `ref<arc<T>>` → `arc<T>` | count + 1 | — | — | synchronized |
| `arc.release %a` | `arc<T>` (consumed) | count − 1; at 0 frees `T` (and a contained frozen graph) | — | — | synchronized; never fails |
| `%p = arc.borrow %ar` | `ref<arc<T>>` → `ref<T>` | child borrow | — | `E2102` | — |
| `arc.release %a` | `arc<T>` (consumed) | count − 1; at 0 frees the graph and the count | — | — | synchronized; never fails |
| `%r = arc.root %ar` | `ref<arc<T>>` → `iref<T>` | — | — | — | — |
| `%p = arc.borrow %ar, %r` | `ref<arc<T>>`, `iref<U>` → `ref<U>` | child borrow | — | `E2102` | `T0010` |
| `%c = iref.eq %a, %b` | `iref<U>`, `iref<U>` → `bool` | — | — | — | identity and slot equal |
Size accounting (spec 08 §7.1) is unchanged. `iref<T>` is 16 bytes (identity and slot). `island<T>`, `frozen<T>` and `arc<T>` are handles of 8 bytes.
**Sizes** (spec 08 §7.1): an `iref<T>` is 16 bytes. `island<T>`, `frozen<T>` and `arc<T>` are 8-byte handles.
## Verifier rules
- **Classes.** `island<T>`, `frozen<T>` and `arc<T>` are linear values: consumed exactly once on every path, never copied. `iref<T>` is copyable.
- **Storability.** The island-storable predicate (D2) is checked at `island.create` and `island.alloc` (`E2111`). The arc content rule (D6) is checked at `arc.new` (`E4002` or `E1001`).
- **Borrows.** Accesses are child borrows of the container borrow (D4, D5, D6). No new verifier state is needed beyond the existing borrow tree.
- **`Send`/`Share`** (spec 04 §35, new rows):
| Type | Send | Share |
|---|---|---|
| `island<T>`, `frozen<T>`, `arc<T>` | yes | yes |
| `iref<T>` | yes | yes |
Island and frozen contents are plain data, and `arc<T>` already requires `T: Share`.
- **Element rules.** Channel elements and mutex contents (spec 04 §38.1) accept islands, frozen graphs and arcs.
- **Classes.** `island<T>`, `frozen<T>` and `arc<T>` are linear, function-unbound values: they are parameters, returns, block arguments, channel elements and mutex contents. They are not aggregate members (`linear_aggregates` stays reserved). `iref<T>` is copyable and `IslandSafe`.
- **Properties.** `IslandSafe` is checked at `island.create`/`island.alloc`, and `ArcSafe` at `arc.new` (`E2111`).
- **Borrows.** Accesses are child borrows of the container borrow (D4–D6). The borrow tree of Phases 1–3 is unchanged, and no new verifier state is needed.
- **`Send`/`Share`.** The rows of D7 are added to spec 04 §35.
## Runtime rules (interpreter)
- **Islands.** An island is a table of object cells with an identity drawn from a per-execution counter that is never reused. An `iref` is the identity and a slot. `island.borrow` checks the identity, then makes a place into the cell.
- **Transfer.** Moving an island, frozen graph or arc moves the handle: no copy, O(1). The execution heap's collector copies island tables like other live state, preserving identity. Collection is amortized and independent of transfers.
- **Freeze** marks the table immutable and returns a `frozen` handle to it.
- **`arc`.** The count lives with the shared value. `arc.clone` and `arc.release` change it in the deterministic order the scheduler runs them. The count after each change appears in the execution trace (spec 11 §2), so P4-6 can test it.
- **Budgets.** An island charges its authority at `create` and `alloc` and returns the bytes at `destroy`, or at the last `arc.release` that frees a frozen graph.
- **Traps.** `T0010` is deterministic: the identity check fails the same way on every run.
- **Graphs.** A graph is a table of object cells with an identity from a per-execution counter that is never reused. An `iref` is the identity and a slot. Accesses check the identity, then make a place into the cell. Frozen and arc graphs give only `ref` places.
- **Mode changes and transfer.** Moving an owner moves a handle. Freeze marks the table immutable. `arc.from_frozen` adds a count. All are O(1).
- **The execution heap.** Graph tables live in the execution heap. Its collector copies them like other live state, preserving identity. The cost is amortized and independent of transfers.
- **Counts.** An arc's count changes in the deterministic order the scheduler runs `clone` and `release`. Each change appears in the execution trace (spec 11 §2).
- **Budgets.** They follow D3.
- **`T0010`** is deterministic.
## Valid example (`.aji`)
A ring of three nodes is built in an island and sent to a worker, which walks it. The parent then gets the island back, freezes it, and shares it through an `arc` with two readers.
A ring of three nodes is built in an island and walked.
```aji
struct Node { value: u64, next: Link }
@@ -229,93 +283,98 @@ effects [mem.alloc]
move isl
}
fn walk(isl: island<Node>, steps: u64) -> island<Node>
fn walk(f: ref<frozen<Node>>, steps: u64) -> u64
effects []
{
var sum: u64 = 0;
{
ref g = isl;
var at = island.root(g);
for i in 0..steps {
ref node = island.at(g, at);
sum = sum + node.value;
at = match node.next { Link::End => at, Link::To(n) => n };
}
var at = frozen.root(f);
for i in 0..steps {
ref node = frozen.at(f, at);
sum = sum + node.value;
at = match node.next { Link::End => at, Link::To(n) => n };
}
move isl
sum
}
```
(The full program, with the transfer through a channel and the `arc` readers, is the Phase 4 reference program `island-pipeline`.)
The Phase 4 reference program `island-pipeline` covers the rest:
- a producer task builds the island and sends it through a channel;
- the consumer freezes it and lends it to two readers;
- it converts the frozen graph with `arc.from_frozen`, clones the arc for a late reader, and releases every handle.
## Rejected examples
| Program | Code |
|---|---|
| `island.create(own.new(1u64, heap) or trap, heap)` (an owner inside an island) | `E2111` |
| `island.alloc(isl, v)` with the island itself instead of a borrow binding | `E7005` |
| `island.create(own.new(1u64, heap) or trap, heap)` | `E2111` (not `IslandSafe`) |
| `arc.new(mutex.make(0u64), heap)` | `E2111` (not `ArcSafe`) |
| `island.alloc(isl, v)`, the island itself | `E7005` |
| `mut x = island.at(mut isl, r);`, an inline container borrow | `E7006` |
| `mut x = island.at(g, a); mut y = island.at(g, b);`, both live | `E2101` |
| `mut x = frozen.at(g, r);` | `E7005` (frozen graphs give `ref` only) |
| using `isl` after `channel.send(tx, move isl)` | `E2001` |
| `mut x = frozen.at(fr, r);` | `E7005` (frozen graphs give `ref` only) |
| `arc.new(mutex.make(0u64), heap)` | `E1001` |
| an `iref` from island A with island B, at run time | `T0010` |
| an island never destroyed, frozen, moved or returned | `E3002` |
| `task.spawn(s, read, g)` with `g: ref<island<T>>` | `E4002` |
| an `iref` of graph A used with graph B, at run time | `T0010` |
| a graph owner never destroyed, released, frozen, converted, moved or returned | `E3002` |
## Diagnostics impact
- New trap `T0010` `trap.foreign_iref`.
- `E2111` becomes reachable. `E2110` stays registered and unused (D9).
- No new `E7xxx`: the source checks reuse `E7005`, `E7006` and `E7003`.
- `E2111` becomes reachable and also covers `ArcSafe`. `E2110` stays registered and unused.
- No new `E7xxx`: the source checks use `E7005` and `E7006`.
## Deterministic interpreter behavior
Identities, slots and counts are deterministic. Transfer, freeze and release are not scheduling points; their order is the program's. No outcome depends on addresses. The execution-heap collector preserves identity (the `--collect-every-step` conformance mode covers islands).
Identities, slots and counts are deterministic. Freeze, conversion, transfer and release are not scheduling points; their order is the program's. No outcome depends on addresses. The collect-every-step conformance mode covers graphs.
## Compatibility
- Existing modules are unaffected: `islands` was reserved, so no published module uses it, and `arc` is new.
- AIR format 0 is extended only as spec 07 §8.7 allows: new types, instructions and a feature.
- Spec 03 §12–14 becomes concrete. Spec 04 §13 points to D7. The Rust-like `Island<T>`/`Frozen<T>`/`Arc<T>` spellings in prose become the lowercase source types.
- No published module changes: `islands` was reserved and `arc` is new.
- AIR format 0 is extended as spec 07 §8.7 allows: new types, instructions and features.
- Spec 03 §12–§14 become concrete.
## Agent complexity impact
- **New concepts:**
- a closed graph addressed by handles;
- the container borrow (already known from regions);
- irreversible freeze;
- explicit shared ownership.
- **New verifier state:** none beyond the borrow tree. Storability and `Share` are type predicates.
- a closed graph addressed by opaque handles;
- three ownership modes of one graph, chosen by intent (change, parallel read, several owners);
- the container borrow, already known from regions.
- **New verifier state:** none beyond the borrow tree. `IslandSafe`, `ArcSafe` and `Share` are type predicates.
- **New syntax and instructions:**
- 4 types and 13 instructions;
- in source, 13 operations and one new place form: an `island.at`/`frozen.at`/`arc.at` call as the place of a `ref`/`mut` binding.
- **Interactions:** channels and spawn (transfer), loans (sharing a frozen graph), budgets.
- **Repairability:** misuse surfaces as existing borrow and linearity codes, or as `T0010` with a source location.
- 4 types and 16 instructions;
- in source, 15 operations plus `==`/`!=` on `iref`;
- one new place form: `island.at`, `frozen.at` or `arc.at` as the place of a `ref`/`mut` binding.
- **Interactions:** channels and spawn (transfer), loans (lending a frozen graph or an arc), budgets.
- **Repairability:** misuse surfaces as existing borrow and linearity codes, `E2111` with `found`, or `T0010` with a source location.
- **Could existing primitives express it?** No:
- cyclic graphs need handles;
- a region cannot move between tasks;
- an `own` tree cannot share.
- **Bundle growth (estimates, measured at implementation):**
- an `own` tree cannot be shared.
- **Bundle growth (estimates, measured in P4-9):**
| Bundle | Estimate |
|---|---|
| Quick Reference | +500–700 tokens (one section, one example) |
| Source Reference Bundle | +2.5–3.5k (`memory.md`: spec 03 §12–14; `concurrency.md`: D7 rows) |
| Quick Reference | +600–800 tokens (one section, one example) |
| Source Reference Bundle | +3–4k |
| AIR bundle | +3–4k (≈ +10 %) |
- **New diagnostics an agent sees in source:** `E2111`, `T0010`.
## Alternatives considered
- **Static island provenance** (D1): rejected for format 0, see D1.
- **A per-island garbage collector:** rejected, since lifetime stays explicit and bulk.
- **Implicit reference counting for frozen data:** rejected (principle), hence `arc` with explicit `clone`/`release`.
- **Freezing into `arc` directly** (`island.freeze` returning an `arc`): rejected. It would join two decisions (immutability, sharing) that are separately useful: a `frozen<T>` lent by `ref` needs no count.
- **Allowing owners and resources inside islands:** deferred. Transfer would stay O(1), but freeing an island would then have to close or free them, which is a hidden destructor.
- **Static graph provenance** (D1): rejected for format 0, because it does not survive function boundaries, aggregates or channels without value-indexed types.
- **`arc<frozen<T>>`** (revision 1): replaced by `arc.from_frozen`, which gives one graph and one wrapper.
- **A per-graph garbage collector:** rejected, since lifetime stays explicit and bulk.
- **Implicit reference counting:** rejected (principle).
- **Owners or resources inside graphs:** deferred. Releasing a graph would then have to close or free them, which is a hidden destructor.
- **Proved disjointness of mutable accesses** (D4): deferred until benchmarks ask for it.
## Unresolved questions
- **Q1.** Capabilities or nested islands inside islands.
- **Q2.** `arc<mutex<T>>`, shared mutable state beyond one scope (needs the mutex content and destruction rules spelled out).
- **Q3.** A later static-provenance mode reporting `E2110` instead of the `T0010` trap.
- **Q1.** Capabilities or nested graphs inside graphs.
- **Q2.** `arc<mutex<T>>`, shared mutable state beyond one scope.
- **Q3.** A static-provenance mode reporting `E2110` instead of the `T0010` trap.
- **Q4.** O(1) detach of a sub-island (RFC 0001).
- **Q5.** Memory-mapped islands (RFC 0001).
- **Q5.** Memory-mapped graphs (RFC 0001).
- **Q6.** Hashing of `iref` (deferred by the owner).
+3 -1
View File
@@ -123,7 +123,9 @@ The compiler derives:
- `Send`: may be moved to another concurrent execution context;
- `Share`: may be observed concurrently through immutable access;
- `Freeze`: can be converted to deeply immutable state;
- `Local`: tied to its current execution context.
- `Local`: tied to its current execution context;
- `IslandSafe`: may be stored in an island graph (spec 03 §22). Derived structurally: integers, `bool`, built-in enums and `iref<U>` are `IslandSafe`, and so are arrays, structs and enums of `IslandSafe` values. Borrows, owners, regions, graph owners (`island`, `frozen`, `arc`), resources, endpoints, `task`, `scope`, `shield`, `guard`, `mutex` and `cap<K>` are not;
- `ArcSafe`: may be held by an `arc` (spec 03 §24). The last release destroys it by freeing memory only. In format 0 it is exactly `IslandSafe`.
These are semantic properties, not user-extensible traits in v0.1. Their derivation for the types of AIR format 0 is the table of spec 04 §35.
+77 -53
View File
@@ -193,69 +193,26 @@ For arrays/buffers the verifier may track initialized prefixes or ranges.
## 12. Island<T>
An `Island<T>` is a uniquely owned, closed, transferable graph of mutable memory.
An island consists of:
- a root object of type `T`;
- one or more private allocation regions;
- internal references between island objects.
Properties:
- move-only ownership;
- mutable by the current owner;
- no external mutable aliases;
- no references from the island into ordinary foreign mutable memory, except explicitly modeled transferable capabilities;
- transferable between tasks without deep copy.
### 12.1 Internal references
Island graphs use verifier-recognized `iref<T>` handles for graph edges.
`iref<T>`:
- may point only inside the same island;
- may represent cycles;
- cannot be dereferenced without access to the owning island;
- cannot escape as a standalone safe reference.
### 12.2 Transfer
Moving an island into a channel or task transfers graph ownership.
After successful transfer the sender cannot access the island.
The operation is intended to be O(1) with respect to graph size.
An `island<T>` is a uniquely owned, closed, mutable graph whose root has type `T`. Its objects are addressed by opaque `iref<U>` handles, which may form cycles. It holds only `IslandSafe` values (spec 02 §6), so it never points into mutable memory outside itself and carries no authority. It moves between tasks in O(1), and after the move the sender holds nothing that reaches it. In AIR: §22.
## 13. Frozen<T>
`Frozen<T>` is a deeply immutable graph.
An island may be irreversibly frozen:
```aji
let immutable = island.freeze(move mutable_graph);
```
After freeze, no mutable reference may ever be obtained through safe Aji.
`Frozen<T>` is `Share` and `Send` when contained external resources permit sharing.
`island.freeze` turns an island into a `frozen<T>`. It is irreversible and O(1), and keeps the graph's identity. A `frozen<T>` is deeply immutable, has one owner, and is `Send` and `Share`, so it is lent to tasks by `ref`. No safe operation yields a mutable borrow of it. In AIR: §23.
## 14. Arc<T>
`Arc<T>` provides explicit shared ownership for `Share` values.
`arc<T>` is explicitly counted shared ownership of an immutable graph. It is made from a frozen graph (`arc.from_frozen`) or from one `ArcSafe` value (`arc.new`). The count changes only at `arc.clone` and `arc.release`, and the last release frees memory and nothing else. No operation silently changes a count. Cycles belong inside a graph (`iref` edges), not between arcs. In AIR: §24.
Reference-count manipulation is explicit:
The three modes of one graph, chosen by intent:
```aji
let another = arc.clone(config);
```text
island<T> mutable, unique change it
│ island.freeze O(1)
frozen<T> immutable, unique owner, Share read it in parallel
│ arc.from_frozen O(1)
arc<T> immutable, shared ownership several independent owners
```
No operation silently increments a reference count.
Aji does not recommend `Arc` for arbitrary cyclic object graphs. Cycles should normally be represented inside an `Island<T>` or through stable handles/indices.
## 15. Stable addresses and pinning
Region and island allocations are address-stable until reset/destruction.
@@ -403,3 +360,70 @@ Allocations cannot contain borrows (borrows are second-class), so linked structu
- Authority objects for `mem.alloc` carry `limit`, `used` and `parent`. Narrowing appends a child. Charges walk the parent chain.
- `own<T>` is a cell holding a value; `own_array<T>` a cell holding an array of `n` values. A region keeps a generation counter and the bytes charged by its current generation.
- In the `deterministic` profile memory is bounded by the mandatory budgets, so the interpreter's own memory use is bounded by a function of the module and its grants.
## 22. Islands in AIR (feature `islands`)
Decision record: RFC 0014. Depends on `heap` and its closure.
**Types.**
- `island<T>`: a graph owner; linear; `Send`, not `Share`.
- `iref<T>`: an opaque `{graph identity, slot}`; copyable, `IslandSafe`, `Send`, `Share`.
Graph owners may be parameters, returns, block arguments, channel elements and mutex contents. They may not be aggregate members (`linear_aggregates` stays reserved).
**Identity.** A graph's identity comes from a per-execution counter and is never reused. A handle cannot be built from, cast to or inspected as an integer.
| Instruction | Operands → result | Ownership and memory | Effect | Verifier | Runtime / trap |
|---|---|---|---|---|---|
| `island.create %v, %mem, ok -> @ok, err -> @err` (terminator) | `T` (consumed), `cap<mem.alloc>`; `@ok(island<T>)`, `@err(alloc_error)` | `%v` is the root object; charges its size and the graph header | `mem.alloc` | `T: IslandSafe` (`E2111`, field `found`) | a new identity; over budget → `@err` |
| `island.alloc %ib, %v, ok -> @ok, err -> @err` (terminator) | `mut<island<T>>`, `U` (consumed); `@ok(iref<U>)`, `@err(alloc_error)` | a new object; charges the graph's authority | `mem.alloc` | `U: IslandSafe` (`E2111`) | — |
| `%r = island.root %ib` | `ref`/`mut<island<T>>` → `iref<T>` | — | — | — | the root object |
| `%p = island.borrow %ib, %r` | `ref<island<T>>` → `ref<U>`; `mut<island<T>>` → `mut<U>`; `%r: iref<U>` | child borrow of `%ib` | — | ends before `%ib` (`E2102`); a `mut` child is exclusive: any other access through `%ib` while it lives is `E2101` | `T0010` if `%r` belongs to another graph |
| `%f = island.freeze %i` | `island<T>` (consumed) → `frozen<T>` | same storage, identity and quota | — | — | O(1) |
| `island.destroy %i` | `island<T>` (consumed) | frees the graph; returns its bytes | — | — | — |
| `%c = iref.eq %a, %b` | `iref<U>`, `iref<U>` → `bool` | — | — | — | equal identity and slot; handles of different graphs are unequal, never a trap |
Objects are never freed one by one. Two irefs naming different objects are not treated as disjoint: a mutable access is exclusive for the whole island.
## 23. Frozen graphs in AIR (feature `islands`)
`frozen<T>`: a graph owner; linear; `Send`, `Share`. There is no thaw.
| Instruction | Operands → result | Ownership and memory | Verifier | Runtime / trap |
|---|---|---|---|---|
| `%r = frozen.root %fb` | `ref<frozen<T>>` → `iref<T>` | — | — | — |
| `%p = frozen.borrow %fb, %r` | `ref<frozen<T>>`, `iref<U>` → `ref<U>` | child borrow | `E2102` | `T0010` |
| `frozen.release %f` | `frozen<T>` (consumed) | frees the graph; returns its bytes | — | — |
## 24. Arc in AIR (feature `arc`)
Decision record: RFC 0014. Depends on `islands`.
`arc<T>`: a handle to a shared, immutable graph with root type `T`. Each handle is linear; the type is `Send` and `Share`.
| Instruction | Operands → result | Ownership and memory | Effect | Verifier | Runtime |
|---|---|---|---|---|---|
| `%a = arc.from_frozen %f` | `frozen<T>` (consumed) → `arc<T>` | same storage and identity; count 1; charges the count | — | — | O(1) |
| `arc.new %v, %mem, ok -> @ok, err -> @err` (terminator) | `T` (consumed), `cap<mem.alloc>`; `@ok(arc<T>)`, `@err(alloc_error)` | a one-object graph; count 1 | `mem.alloc` | `T: ArcSafe` (`E2111`) | — |
| `%a2 = arc.clone %ar` | `ref<arc<T>>` → `arc<T>` | count + 1 | — | — | synchronized by the runtime |
| `arc.release %a` | `arc<T>` (consumed) | count − 1; the last release frees the graph and the count | — | — | synchronized; never fails |
| `%r = arc.root %ar` | `ref<arc<T>>` → `iref<T>` | — | — | — | — |
| `%p = arc.borrow %ar, %r` | `ref<arc<T>>`, `iref<U>` → `ref<U>` | child borrow | — | `E2102` | `T0010` |
The count is not a user atomic: no memory ordering is chosen by the program. Each count change appears in the execution trace (spec 11 §2).
**Quota (all three modes).** A graph charges the authority it was created with. The ownership mode does not change the budget.
| Operation | Live bytes |
|---|---|
| `island.create`, `island.alloc` | + the object |
| `island.freeze` | unchanged |
| `arc.new` | + the value and the count |
| `arc.from_frozen` | + the count |
| `arc.clone` | unchanged |
| `arc.release`, not the last | unchanged |
| `arc.release`, the last | − the graph and the count |
| `frozen.release` | − the graph |
| `island.destroy` | − the graph |
+5 -4
View File
@@ -143,9 +143,7 @@ AIR realization: §38 (separate `sender<T>`/`receiver<T>` endpoints, MPSC).
## 13. Island messaging
`Island<T>` is the preferred representation for large mutable messages and object graphs.
Sending an island transfers ownership without exposing shared mutation.
`island<T>` is the preferred representation for large mutable messages and object graphs. Sending an island transfers ownership in O(1) without exposing shared mutation. An immutable graph is shared as `frozen<T>` (lent by `ref`) or `arc<T>` (several owners): spec 03 §12–§14, §22–§24.
## 14. select
@@ -432,6 +430,9 @@ Example: two workers square the two halves of one buffer in parallel; both loans
| `task<T>`, `scope`, `shield`, `guard<T>` | no (`Local`) | no |
| `sender<T>`, `receiver<T>` | yes | no |
| `mutex<T>` | if `T` is | if `T` is `Send` (the lock synchronizes access) |
| `island<T>` | yes | no — its owner may mutate it; freeze to share |
| `frozen<T>`, `arc<T>` | yes | yes |
| `iref<T>` | yes | yes |
| struct, enum, array | if every field/payload/element is | if every field/payload/element is |
So an aggregate holding capabilities is `Send` and `Share` exactly when its other members are (Q-014).
@@ -581,7 +582,7 @@ Endpoints may be block arguments, function parameters and return values, and may
- `T` contains no borrow, `scope`, `task<…>`, `shield` or `guard<…>` (`E1001`);
- `T` contains no `sender<…>` or `receiver<…>`: reserved feature `channel_transfer` (`E0006`).
Linear elements (`own<T>`, `file<…>`, `stream`, …) are allowed.
Linear elements (`own<T>`, `file<…>`, `stream`, `island<T>`, `frozen<T>`, `arc<T>`, …) are allowed.
### 38.2 Instructions
+6
View File
@@ -269,6 +269,12 @@ Types `scope` and `task<T>` (linear, function-bound), instructions `task.scope.b
Every terminator of these features follows spec 07 §8.2: each named target receives exactly the parameters its contract lists.
## Features `islands`, `arc`
`islands`: types `island<T>`, `frozen<T>`, `iref<T>`, instructions `island.create`, `island.alloc`, `island.root`, `island.borrow`, `island.freeze`, `island.destroy`, `frozen.root`, `frozen.borrow`, `frozen.release`, `iref.eq`; `IslandSafe`, identity and `T0010`: spec 03 §22–§23.
`arc`: type `arc<T>`, instructions `arc.from_frozen`, `arc.new`, `arc.clone`, `arc.release`, `arc.root`, `arc.borrow`; `ArcSafe` and the quota lifecycle: spec 03 §24.
## Run result
`aji run` executes the function `@main`, whose parameters MUST all be capabilities, bound by name at instantiation (spec 05 §10.2); without the `capabilities` feature it takes no parameters. On return it reports `{"status":"returned","value":V}` where `V` renders the returned value as JSON:
+14
View File
@@ -342,6 +342,20 @@ region.reset(r);
Passing the region itself is `E7005`; the frontend never creates a temporary region borrow. `region.reset` and `region.destroy` end no borrow: a live allocation borrow at a reset or destroy is the verifier's `E2104`. The programmer narrows the scope.
**Islands, frozen graphs and arcs** (spec 03 §22–§24; layer 9). Types `island<T>`, `frozen<T>`, `arc<T>`, `iref<T>`.
| Source | AIR |
|---|---|
| `island.create(v, mem)`, `island.alloc(g, v)`, `arc.new(v, mem)` | outcome matches or `or trap` (`ok(…)`, `err(e: alloc_error)`) |
| `island.root(g)`, `frozen.root(g)`, `arc.root(g)` | `island.root`, `frozen.root`, `arc.root` |
| `ref x = island.at(g, r);` / `mut x = island.at(g, r);` | `island.borrow` (`mut` needs `g: mut<island<T>>`) |
| `ref x = frozen.at(g, r);`, `ref x = arc.at(g, r);` | `frozen.borrow`, `arc.borrow` (`mut` is `E7005`) |
| `island.freeze(move i)`, `island.destroy(move i)`, `frozen.release(move f)`, `arc.from_frozen(move f)`, `arc.release(move a)` | the same |
| `arc.clone(a)` | `arc.clone` on a shared borrow of `a`, made for the operation |
| `a == b`, `a != b` for `iref<T>` | `iref.eq` (then `not`) |
**Container borrows are explicit, as for regions.** `.root`, `.at` and `island.alloc` take a named borrow binding of the graph's owner (`mut g = isl;`), which outlives the borrows derived from it. Passing the owner itself is `E7005`, with a hint. A container borrow written inline is `E7006`. `island.at`, `frozen.at` and `arc.at` appear only as the place of a `ref`/`mut` binding (`E7006` elsewhere).
**Linear aggregates.** A struct or enum with a linear field (`own<T>`, `region`, a resource) needs the reserved feature `linear_aggregates`. The frontend lowers it as written and the AIR is rejected (`E0006`) until that feature is published.
A byte string or array used where a `slice<u8>` is expected is materialized in frame storage and borrowed for the operation.
+1
View File
@@ -82,6 +82,7 @@ pub const registry = [_]Code{
.{ .id = "T0007", .kind = "trap.call_depth", .meaning = "Call depth limit (1 024 frames) exceeded" },
.{ .id = "T0008", .kind = "trap.out_of_bounds", .meaning = "Runtime bounds check failed" },
.{ .id = "T0009", .kind = "trap.unsafe_precondition", .meaning = "Unsafe precondition violated (detected)" },
.{ .id = "T0010", .kind = "trap.foreign_iref", .meaning = "An `iref` was used to access a graph it does not belong to" },
};
pub fn lookup(id: []const u8) ?*const Code {