Phase 6A: .aji layer 6 (intrinsics, resources, narrowing, unsafe operations)

- intrinsics from the registry as plain calls: fallible ones are outcome
  matches or `or trap` (E7006 otherwise), infallible ones plain calls
- resource operands by name, borrowed mut for the one operation and ended
  on every edge; a mut binding/parameter passes as is; `mut f` is E7006
- closes consume with `move` (E7003); no inserted closes (E3002/E3001)
- data operands explicit (ref/mut/byte string, E7005 otherwise)
- file<…>, stream, listener types; cap.narrow.prefix with cap_error edges
- ref/mut unchecked s[i] (also as a binding) and assume(c) under
  effects [unsafe]; boundary left to the verifier (E6001)
- trusted is reserved and rejected (E7006)
- parameter names preserved; generated names avoid them (normative)
- parser: >> closes two type arguments
- conformance: `equivalent:` compares the run record with a reference
  AIR program (hello, file_copy, tcp_echo, narrow ok/not_subset/invalid,
  random)
- spec 15, grammar, quick reference (io_error match fixed), plan, examples
This commit is contained in:
dev committed 2026-10-05 12:16:54 +03:00
1 parent bdcf871e5d
commit c18fb7acc1
39 files changed
+1309 -69

No files matched your search

+3 -2
View File
@@ -111,18 +111,19 @@ let n = net.recv(conn, mut buf) or trap; // any non-ok outcome traps
- Arms are named after the outcomes and the `match` must cover all of them (`E7004`).
- `or trap` is the only shorthand: it takes the `ok` value and traps on anything else.
- Matching an `err(e)` of type `io_error`: `match e { not_found => …, _ => … }`.
- `err(e)` binds a real `io_error`. Match it like any enum, every variant and no `_`: `match e { io_error::not_found => …, io_error::permission_denied => …, … }`, or just `trap`.
- Closing consumes the resource on **both** outcomes.
## 6. Authority, allocation, I/O
Capabilities are only ever received (as `main` parameters, passed down as arguments) or narrowed. They are copyable.
Capabilities are only ever received (as `main` parameters, passed down as arguments) or narrowed. They are copyable. A capability is needed only to acquire: the file or stream you get back carries the authority, so `fs.read(f, mut buf)` takes no capability. Pass a resource **by name** (the call borrows it); pass data with explicit `ref`/`mut`. Paths are byte strings: `b"/in/data.txt"`.
| Kind (`cap<K>`) | Effect | Operations (all fallible unless noted) |
|---|---|---|
| `io.read` / `io.write` | same | `io.stdin_read(c, mut buf) → ok(n)`; `io.stdout_write(c, ref bytes)`, `io.stderr_write(c, ref bytes)` |
| `fs.read` / `fs.write` | same | `fs.open_read(c, path) → ok(f)`, `fs.create(c, path)`, `fs.open_append(c, path)`; `fs.read(f, mut buf) → ok(n)`; `fs.write_all(f, ref bytes)`; `fs.sync(f)`; `fs.close(move f)` |
| `net.listen` / `net.connect` | same; `net.recv` needs `net.read`, `net.send_all` needs `net.write` | `net.listen(c, b"127.0.0.1:7") → ok(l)`; `net.accept(l) → ok(s)`; `net.connect(c, addr) → ok(s)`; `net.recv(s, mut buf) → ok(n)` (0 = closed); `net.send_all(s, ref bytes)`; `net.close_stream(move s)`; `net.close_listener(move l)` |
| narrowing | — | `cap.narrow.prefix(c, b"/data/logs") → ok(c2) / err(e: cap_error)` (`fs.read`, `fs.write`) |
| `clock.read`, `random.read` | same | `clock.monotonic(c)` (infallible, `u64`); `random.fill(c, mut buf)` (infallible) |
| `mem.alloc` | `mem.alloc` | `own.new(v, heap) → ok(o) / err(e)`; `own.array(n, v, heap)`; `own.take(move o)`, `own.free(move o)`; `region.create(heap) → ok(r)`; `ref arena = r;` then `region.new(arena, v) → ok(p)`, `region.array(arena, n, v)`; `region.reset(r)`; `region.destroy(move r)`; `cap.narrow.budget(heap, n) → ok(small) / err(e)` |