spec: accept RFC 0005 and integrate Phase 1 memory model (P1-1, P1-2)
- RFC 0005 Accepted (revision 2) - spec 07 §8.8 types and syntax; spec 07a contracts for features ownership and arrays; spec 08 §11-§14 borrows, facts, initialization, stage order; spec 03 frame storage, second-class borrows, static region generations - grammar: from-returns, multi-result, new types and opcodes - feature registry: ownership and arrays published; heap added and regions moved to Phase 2; borrow_joins reserved and unscheduled - codes E2105-E2108, T0008 - Q-009, Q-010 resolved; Phase 1 and Phase 2 plans updated; Own test moved to phase 2
This commit is contained in:
15 files changed
+269
-55
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
Normative. Each instruction lists the fields required by spec 07 §4. Syntax is in [`../reference/air-text.ebnf`](../reference/air-text.ebnf).
|
||||
|
||||
This file covers format version 0 (Phase 0). Later phases add instructions here before implementing them.
|
||||
This file covers the format-0 baseline (Phase 0) and the features `ownership` and `arrays` (Phase 1). Later phases add instructions here, grouped by feature, before implementing them. An instruction of a feature is only valid in a module that declares the feature (spec 07 §8.1).
|
||||
|
||||
## Common contract for format version 0
|
||||
|
||||
@@ -168,6 +168,51 @@ A terminator ends a block (spec 07 §8.2). Terminators bind no result.
|
||||
|
||||
- Traps: `T0001`, always.
|
||||
|
||||
## Feature `ownership` and feature `arrays`
|
||||
|
||||
Types, borrow rules and bounds facts used below: spec 07 §8.8 (types), spec 08 §11 (borrows), spec 08 §12 (facts), spec 08 §13 (initialization). Decision record: RFC 0005.
|
||||
|
||||
Common contract unless stated: no effects, no capabilities, no synchronization. "Owned borrow" means a borrow created in the current function (§5.1).
|
||||
|
||||
### `ownership`
|
||||
|
||||
| Instruction | Operands → result | Verifier | Runtime |
|
||||
|---|---|---|---|
|
||||
| `%s = local.alloc T` | → `local<T>` | only in the entry block (`E5002`); storage is uninitialized; counts toward the frame limit (spec 08 §11.5) | allocates frame storage once per call, freed at return |
|
||||
| `local.store %s, %v` | `local<T>`, `T` | no live borrow of `%s` (`E2101`); initializes `%s` | writes `%v` |
|
||||
| `local.zero %s` | `local<T>` | `T` zeroable: integers, `bool`, arrays and structs of zeroable types (`E1001`); no live borrow (`E2101`); initializes | writes all-zero value |
|
||||
| `%v = local.load %s` | `local<T>` → `T` | initialized (`E1010`); no live `mut` borrow of `%s` (`E2101`) | reads |
|
||||
| `%r = borrow.ref %x` | `local<T>`, `ref<T>`, `mut<T>` → `ref<T>`; `slice<T>`, `slice_mut<T>` → `slice<T>` | spec 08 §11.2; locals must be initialized (`E1010`); child of `%x` unless `%x` is a local | shared view of the same place |
|
||||
| `%m = borrow.mut %x` | `local<T>`, `mut<T>` → `mut<T>`; `slice_mut<T>` → `slice_mut<T>` | spec 08 §11.2; locals must be initialized (`E1010`); child of `%x` unless `%x` is a local | exclusive view of the same place |
|
||||
| `%f = borrow.field @S.f, %b` | `ref<@S>`/`mut<@S>` → `ref<F>`/`mut<F>` | child of `%b`; distinct fields are disjoint | reference to the field |
|
||||
| `borrow.end %b` | owned borrow | no live children (`E2102`); not a parameter (`E2107`); not already ended (`E2106`) | none |
|
||||
| `%v = load %b` | `ref<T>`/`mut<T>` → `T` | `%b` usable for reading (spec 08 §11.2) | reads |
|
||||
| `store %b, %v` | `mut<T>`, `T` | `%b` usable for writing (spec 08 §11.2) | writes |
|
||||
|
||||
### `arrays`
|
||||
|
||||
| Instruction | Operands → result | Verifier | Runtime |
|
||||
|---|---|---|---|
|
||||
| `%a = array.splat [T; N] %v` | `T` → `[T; N]` | — | every element is `%v` |
|
||||
| `%e = borrow.index %b, %i` | `ref`/`mut` of `[T; N]`, or `slice`/`slice_mut` of `T`; `usize` → `ref<T>`/`mut<T>` | child of `%b` | traps `T0008` if `%i ≥ length` |
|
||||
| `%e = borrow.index.proven %b, %i` | as above | `%i < length` proven (spec 08 §12), otherwise `E2103` | no check |
|
||||
| `%s = slice.make %b` | `ref<[T; N]>`/`mut<[T; N]>` → `slice<T>`/`slice_mut<T>` | child of `%b` | whole array |
|
||||
| `%n = slice.len %s` | `slice<T>`/`slice_mut<T>` → `usize` | — | length |
|
||||
| `%t = slice.sub %s, %start, %len` | slice, `usize`, `usize` → same slice type | child of `%s` | traps `T0008` unless `start ≤ slice.len(s)` and `len ≤ slice.len(s) − start` (evaluated without overflow); result covers `[start, start + len)` |
|
||||
| `%l, %r = slice.split %s, %at` | slice, `usize` → two slices of the same type | two children of `%s`, disjoint | traps `T0008` unless `at ≤ slice.len(s)`; `l` covers `[0, at)`, `r` covers `[at, len)` |
|
||||
| `slice.copy %dst, %src` | `slice_mut<T>`, `slice<T>`/`slice_mut<T>` | both usable (spec 08 §11.2); overlapping operands are rejected by the aliasing rules (spec 08 §11.2), so this is never a `memmove` | traps `T0008` unless `len(dst) ≥ len(src)`; copies exactly `len(src)` elements into the start of `dst` |
|
||||
| `guard %c` | `bool` | adds a fact (spec 08 §12) | traps `T0002` if false |
|
||||
|
||||
New trap code: `T0008 trap.out_of_bounds`.
|
||||
|
||||
`slice.make` creates a slice only from an existing borrow of an array, covering exactly that array and inheriting its provenance. No instruction creates a slice from an address and a length. An overlap-safe copy, if ever needed, will be a separate instruction (`slice.move`).
|
||||
|
||||
### Runtime
|
||||
|
||||
- Frame storage is allocated by `local.alloc` and released at return; no code runs at release.
|
||||
- The interpreter represents a borrow as (storage, path) and a slice as (storage, path, offset, length). It performs no alias or liveness checks at runtime: the verifier guarantees them. Bounds checks run exactly where §4 says.
|
||||
- Behavior is deterministic; storage addresses are never observable.
|
||||
|
||||
## Run result
|
||||
|
||||
`aji run` executes the function `@main`, which MUST take no parameters. On return it reports `{"status":"returned","value":V}` where `V` renders the returned value as JSON:
|
||||
|
||||
Reference in new issue
Block a user