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:
1 parent
7d8f147d1d
commit
ca84ab4348
10 files changed
+346
-224
No files matched your search
@@ -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).
|
||||
Reference in new issue
Block a user