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:
1 parent
bdcf871e5d
commit
c18fb7acc1
39 files changed
+1309
-69
No files matched your search
@@ -60,8 +60,13 @@ effects [io.read, io.write]
|
||||
- A file holds one module: `module <dotted.path>`, then type and function declarations in any order.
|
||||
- `//` starts a line comment.
|
||||
- Function `f` lowers to `@f`; type `T` to `@T`.
|
||||
- **Signature.** `fn name(params) -> type`, then optionally `from p` for a borrow return (spec 08 §11.3), then the line `effects [...]`, then optionally `trusted "<obligation>"` (spec 13 §6), then the body block.
|
||||
- **The entry point** is `main`. Its parameters are capabilities bound by name (spec 05 §10.2).
|
||||
- **Signature.** `fn name(params) -> type`, then optionally `from p` for a borrow return (spec 08 §11.3), then the line `effects [...]`, then the body block.
|
||||
- **Parameter names are preserved.** A parameter `p` lowers to `%p`. Names the compiler generates are chosen so that they never equal a parameter name of the function. The names of `@main`'s parameters are part of the instantiation contract.
|
||||
- **The entry point** is `main`. Its parameters are capabilities `cap<K>`, bound by name (spec 05 §10.2). Startup values of other types (command-line arguments, for example) are not part of `.aji` 0.1.
|
||||
- **Grants are not source semantics.** A program only declares `main`'s capability parameters. Granting them is instantiation after the module is lowered and verified (`aji run --grant …`, `aji.toml`, spec 12 §1). A missing grant is `not_instantiated` at run time, never a source or verifier diagnostic.
|
||||
- **One source for every profile.** The frontend does not know the execution profile. The same `.aji` runs in the deterministic and the hosted profile (spec 11).
|
||||
- **`trusted` is not available.** It is the boundary of runtime, std and toolchain modules (spec 13 §6.3), not something a program declares about its own code. The word is reserved and a `trusted` clause is `E7006`.
|
||||
- **Unsafe operations** are the format-0 ones and nothing else: `ref unchecked s[i]` / `mut unchecked s[i]` (also bound: `ref unchecked e = s[i];`) lower to `borrow.index.unchecked`, and `assume(c)` to `assume`. Their boundary is the AIR one: the function declares `effects [unsafe]`, which propagates to its callers. Outside it the verifier reports `E6001`. There is no `unsafe { … }` block, because AIR has no block-level unsafe boundary. There is no FFI, raw address or syscall surface in format 0, so none exists in source.
|
||||
|
||||
## 3. Types
|
||||
|
||||
@@ -289,7 +294,7 @@ Arms bind the send values not sent on their edge, in the order of first appearan
|
||||
|
||||
Step 4 happens at **every normal exit** from the block: fall-through, and every `return`, `break` and `continue` that leaves it. The `cancelled { … }` block is the lock's cancelled edge. On a trap nothing is unlocked: the execution terminates (spec 04 §33.2). The guard is never a source value. The critical-section rule (spec 04 §41) applies to the block's contents.
|
||||
|
||||
**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:
|
||||
**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 (§8):
|
||||
|
||||
- `file<…>`, `stream`, `listener`;
|
||||
- `sender<T>`, `receiver<T>`;
|
||||
@@ -306,9 +311,19 @@ Allocation and resource operations keep their AIR names and operand order:
|
||||
- `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)`: `ok(c2)` binds a `cap<K>`, `err(e)` a `cap_error`; `cap.narrow.prefix(c, path)` (layer 6);
|
||||
- `cap.narrow.budget(c, n)` and `cap.narrow.prefix(c, path)`: `ok(c2)` binds a `cap<K>`, `err(e)` a `cap_error` (`invalid_restriction`, `not_subset`, `unsupported_restriction`). Narrowing is always fallible and never yields an empty capability;
|
||||
- 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")`.
|
||||
- intrinsics under their registered names and operand order (`reference/intrinsics.md`), as plain calls: `io.stdout_write(out, ref buf[0..n])`, `fs.open_read(c, b"/in/data.txt")`, `fs.close(move f)`, `net.listen(c, b"127.0.0.1:7")`. There are no methods, no `File.open()` and no implicit I/O.
|
||||
|
||||
**Intrinsics.**
|
||||
|
||||
- **Failure.** A fallible intrinsic is an outcome match (`ok(results…)`, `err(e)` with `e: io_error`) or `op(…) or trap` (§6). Used as a plain value or statement it is `E7006`. An infallible one (`clock.monotonic`, `random.fill`) is a plain call; matching it is `E7006`.
|
||||
- **Authority.** A capability is needed only to acquire authority: `fs.open_read(c, path)` returns a `file<read>` that carries it, and `fs.read(f, mut buf)` takes no capability. The capability kind is checked by the verifier (`E3201`), and the effect too (`E3101`).
|
||||
- **Resource operands.** An operand the registry marks as borrowed is the resource **by name**. The frontend borrows it `mut` for that one operation and ends the borrow on every outcome edge. A `mut` borrow binding or parameter of the resource (`f: mut<file<write>>`) is passed as is. Writing `mut f` there is `E7006` (one spelling); a resource of the wrong type or mode is `E7005`.
|
||||
- **Consumed operands** (`fs.close`, `net.close_stream`, `net.close_listener`) take `move f` (`E7003` without it). The frontend never inserts a close: an unclosed resource is the verifier's `E3002`, use after close `E3001`.
|
||||
- **Data operands** are always written: `ref bytes` / `ref buf[a..b]` / a byte string for read bytes, `mut buf` / `mut buf[a..b]` for a buffer the operation fills (`E7005` otherwise).
|
||||
- **Paths and addresses** are byte strings or borrowed bytes, passed as they are. There is no `Path` type and the frontend does not normalize. Whether a path is absolute, free of `.`/`..` and inside the capability's scope is decided by the intrinsic at run time (`invalid_input`, `permission_denied`; for narrowing, `invalid_restriction`, `not_subset`).
|
||||
- **Source map.** The intrinsic's terminator maps to the call. The borrow ends on each edge map to the call, and each arm's code to its arm. A runtime trap under `or trap` points at the call (`source_location` in the run record). A verifier diagnostic on an operand points at that operand's construct.
|
||||
|
||||
**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:
|
||||
|
||||
|
||||
Reference in new issue
Block a user