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
@@ -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 |
|
||||
|
||||
Reference in new issue
Block a user