Phase 6A: .aji layer 5 (linear values, own, regions, outcome matches, or trap)
- explicit move for named linear values; E7003 with suggestion "move x"; move of a copyable value is E7006; moved state left to the verifier - own.new/own.array/region.create/region.new/region.array/cap.narrow.budget as outcome matches or with `or trap`; own.take/own.free/region.reset/ region.destroy as AIR names in AIR operand order - region.new/region.array take an explicit ref/mut region binding (E7005 otherwise); reset/destroy end nothing (verifier E2104) - match kind (enum/outcome/integer) decided by the parser; built-in error enums (alloc_error, cap_error, io_error) matched exhaustively - cap<K> types; linear owners borrowed in place - features header = registry closure of the features used - parameters keep their source names (grants by @main parameter name) - aji lower --stats: mechanical_air_eliminated = 1 - source/AIR bytes - spec 15, grammar, quick reference, plan updated
This commit is contained in:
1 parent
eca30f817a
commit
bdcf871e5d
28 files changed
+882
-78
No files matched your search
@@ -192,7 +192,10 @@ The value is evaluated first, then the place is borrowed for the store and the b
|
||||
|
||||
**Moves.**
|
||||
|
||||
- A named linear value is consumed only by `move x`. Using a named linear value as a consuming operand without `move` is `E7003`.
|
||||
- A named linear value (`own<T>`, `own_array<T>`, `region`, and the resources and endpoints of later layers) is consumed only by `move x`. Using a named linear value as a consuming operand without `move` is `E7003`; the diagnostic carries `suggestion: "move x"`. Consuming operands are: call arguments, `let`/`var` initializers, assignments, `return`, the value operand of an allocation, and `own.take`, `own.free`, `region.destroy`.
|
||||
- `move` of a copyable value is `E7006`.
|
||||
- The frontend does not track moved state. Use after move (`E2001`), double consumption (`E2002`), use after consume (`E3001`) and leaks (`E3002`) are found by the verifier on the lowered AIR and reported at the source location.
|
||||
- A linear value used as a borrow place (`ref x`, `mut x`, `ref r = x;`) is borrowed in place: `own<T>` as `ref<T>`/`mut<T>`, `own_array<T>` as `slice<T>`/`slice_mut<T>`, `region` as `ref<region>`. There is no implicit dereference of an owner.
|
||||
- A temporary, that is the result of a call or operation used directly as an operand, needs no `move`: it has no other owner in the source.
|
||||
- Copyable values are copied by plain use.
|
||||
|
||||
@@ -217,6 +220,8 @@ match io.stdin_read(input, mut buf) {
|
||||
}
|
||||
```
|
||||
|
||||
- **Match kinds.** The parser decides the kind of a `match` from its arms: `Enum::Variant` arms make an enum match, integer literals and `_` an integer match, and bare outcome names (`ok`, `err`, `closed`, `cancelled`, `pending`) an outcome match. Outcome names are not enum patterns. In an outcome match the scrutinee MUST be a fallible operation (`E7006` otherwise). Each outcome is matched exactly once: a repeated one is `E7006`, an unknown one `E7002`, a wrong number of bound names `E7005`. A fallible operation outside an outcome match or `or trap` is `E7006`.
|
||||
- **Outcome values.** `err(e)` binds the real error value (`alloc_error`, `cap_error`, `io_error`). These built-in enums are matched like declared ones: `alloc_error::out_of_memory`, exhaustive, no `_`. A borrow bound by an outcome (the `ok(item)` of `region.new`) ends at the end of its arm. A borrow bound by `let item = region.new(arena, v) or trap;` ends at the end of the enclosing block.
|
||||
- **Rebinding.** A value that comes back on an edge is rebound by the name in its arm: `closed(v)`, `pending(rx)`, `cancelled(t)`.
|
||||
- **`or trap`.** `op(args) or trap` is the expression of the `ok` value, or of `void`. Every other outcome traps (`T0001`). It is the only shorthand.
|
||||
- **Enums.** A `match` over a value of an enum type has exactly one arm per variant, each written `Enum::Variant(names…)` (`Enum::Variant` without payload). It must be exhaustive (`E7004` lists the missing variants), and `_` is not allowed (`E7006`), so a new variant cannot slip through silently. Payload names are bound only inside their arm (they are the arm block's parameters in AIR). It lowers to `enum.switch`.
|
||||
@@ -286,23 +291,42 @@ Step 4 happens at **every normal exit** from the block: fall-through, and every
|
||||
|
||||
**Resource and endpoint operands.** An operation whose AIR operand is a borrow of a resource or endpoint accepts the resource by name and borrows it for the duration of the operation:
|
||||
|
||||
- `file<…>`, `stream`, `listener`, `region`;
|
||||
- `file<…>`, `stream`, `listener`;
|
||||
- `sender<T>`, `receiver<T>`;
|
||||
- `task<T>` for `task.cancel`.
|
||||
|
||||
For example `net.accept(l)`, `fs.read(f, mut buf)`, `channel.send(tx, move v)`. Data borrows (`ref`/`mut` of values, arrays and slices) are always written. A mutex is borrowed explicitly: `lock ref m`.
|
||||
For example `net.accept(l)`, `fs.read(f, mut buf)`, `channel.send(tx, move v)`. Data borrows (`ref`/`mut` of values, arrays and slices) are always written. A mutex is borrowed explicitly: `lock ref m`. A region is borrowed explicitly too (§8).
|
||||
|
||||
## 8. Allocation, resources and intrinsics
|
||||
|
||||
Allocation and resource operations keep their AIR names and operand order:
|
||||
|
||||
- `own.new(mem, v)` and `own.array(mem, n, v)` (matches, §6);
|
||||
- `own.take(move o)`, `own.free(move o)`;
|
||||
- `region.create(mem)`, `region.new(r, v)`, `region.array(r, n, v)`;
|
||||
- `own.new(v, mem)` and `own.array(n, v, mem)` (outcome matches, §6): `ok(o)` binds `own<T>` / `own_array<T>`, `err(e)` an `alloc_error`;
|
||||
- `let v = own.take(move o);`, `own.free(move o);` (`own<T>` or `own_array<T>`; there is no take for arrays);
|
||||
- `region.create(mem)`: `ok(r)` binds a `region`;
|
||||
- `region.new(rb, v)`, `region.array(rb, n, v)`: `rb` MUST be a `ref`/`mut` borrow binding of the region; `ok(item)` binds `mut<T>` / `slice_mut<T>`;
|
||||
- `region.reset(r)`, `region.destroy(move r)`;
|
||||
- `cap.narrow.budget(c, n)`, `cap.narrow.prefix(c, path)`;
|
||||
- `cap.narrow.budget(c, n)`: `ok(c2)` binds a `cap<K>`, `err(e)` a `cap_error`; `cap.narrow.prefix(c, path)` (layer 6);
|
||||
- capabilities are values of type `cap<K>`, received as parameters and copied by plain use (no `move`);
|
||||
- intrinsics under their registered names (`reference/intrinsics.md`): `io.stdout_write(out, ref buf[0..n])`, `fs.open_read(c, b"data.txt")`, `fs.close(move f)`, `net.listen(c, b"127.0.0.1:7")`.
|
||||
|
||||
**Region borrows are explicit.** The borrow of a region that `region.new`/`region.array` take is written by the programmer and lexically outlives the allocation borrows derived from it:
|
||||
|
||||
```aji
|
||||
{
|
||||
ref arena = r;
|
||||
match region.new(arena, 1u64) {
|
||||
ok(item) => { *item = *item + 1; }
|
||||
err(e) => { trap; }
|
||||
}
|
||||
}
|
||||
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.
|
||||
|
||||
**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.
|
||||
|
||||
## 9. Frame storage, borrow scopes and features
|
||||
|
||||
Reference in new issue
Block a user