spec: accept RFC 0007 and integrate I/O and linear resources
- spec 06 §6-§7: feature resources, consumption and verifier rules, io_error - spec 05 §11.1 fallible intrinsic form; spec 07 §8.7 frozen built-in enum variants, §8.9 resource types; spec 07a resources and run record fields; spec 11 §8 execution profiles, blocked outcome, result channel - reference/intrinsics.md: formal catalogue; capabilities.md: io_error and fs prefix narrowing - features: resources published, linear_aggregates reserved
This commit is contained in:
1 parent
c7bcea294e
commit
571cc6e362
9 files changed
+199
-83
No files matched your search
@@ -250,6 +250,19 @@ An effectful operation takes its capability as an explicit operand (§11). If th
|
||||
|
||||
This RFC registers no I/O intrinsic yet. RFC 0007 adds the catalogue (console, files, sockets, clock, random) together with the error representation.
|
||||
|
||||
### 11.1 Fallible intrinsics
|
||||
|
||||
Two forms extend RFC 0006 §3:
|
||||
|
||||
```text
|
||||
[%r =] intrinsic <name>(%a…) ; infallible
|
||||
intrinsic <name>(%a…), ok -> @ok, err -> @err ; fallible: a terminator
|
||||
```
|
||||
|
||||
A fallible intrinsic delivers its results as the parameters of `@ok` (count and types per registry; `E5002`/`E1001`) and a single `io_error` to `@err`. The registry says which form each intrinsic has; using the other form is `E1001`. Resource operands consumed by an intrinsic are consumed on both edges.
|
||||
|
||||
The catalogue of intrinsics is [`../reference/intrinsics.md`](../reference/intrinsics.md).
|
||||
|
||||
## 12. Runtime
|
||||
|
||||
- A capability is represented as an index into a host-owned table of (kind, scope) entries. The index is not observable by the program.
|
||||
|
||||
@@ -58,3 +58,82 @@ Propagation syntax may exist only if its lowering is explicit and does not intro
|
||||
Use `Result` for failures callers may reasonably handle.
|
||||
|
||||
Use trap for invariant violations, failed assertions and explicitly trapping primitives.
|
||||
|
||||
## 6. Resources in AIR (feature `resources`)
|
||||
|
||||
Decision record: RFC 0007.
|
||||
|
||||
Invariants:
|
||||
|
||||
1. **Linearity.** A resource value (`file`, `listener`, `stream`) is consumed exactly once on every normal path: by a closing intrinsic, by passing it to a by-value resource parameter or block parameter, or by returning it. It is never used after consumption and never silently dropped.
|
||||
2. **No implicit release.** No resource is closed by scope exit, by a trap path being taken, or by any hidden action. Paths ending in `trap` end the program; the runtime then releases host resources as part of terminating the execution instance, which is not observable by the program.
|
||||
3. **Explicit failure.** Every operation that can fail for external reasons delivers either its results or an `io_error` to block parameters. Failure is never a trap and never an exception.
|
||||
4. **Object capabilities.** An open resource carries the authority it was opened with; operations on it need its effect but no further capability operand. Opening a resource requires a capability.
|
||||
5. **Determinism.** In the `deterministic` profile every intrinsic has a fully specified result; the same module, grants, inputs and fuel produce the same run record. Profiles never invent results the program did not ask for: a run that can make no further progress ends with the environment outcome `blocked`, not with an I/O error.
|
||||
|
||||
Depends on `capabilities`, `effects`, `ownership`.
|
||||
|
||||
### 6.1 Types
|
||||
|
||||
| Type | Meaning | Accounted size |
|
||||
|---|---|---|
|
||||
| `file<read>` | file opened for reading | 8 |
|
||||
| `file<write>` | file opened for writing (created or truncated) | 8 |
|
||||
| `file<append>` | file opened for appending | 8 |
|
||||
| `listener` | listening TCP socket | 8 |
|
||||
| `stream` | connected TCP stream | 8 |
|
||||
|
||||
The mode of a file is part of its type, so using a file in the wrong mode is a verifier error, not a runtime failure: `fs.read` takes `mut<file<read>>`; `fs.write_all` and `fs.sync` take `mut<file<write>>` or `mut<file<append>>`.
|
||||
|
||||
Resource types are **linear** and **authority-bearing** (spec 05 §10.1): not copyable (`copy` is `E1001`), not zeroable, not comparable, not serializable.
|
||||
|
||||
In format 0, resource types MUST NOT appear as struct fields, enum payloads or array elements; that requires the reserved feature `linear_aggregates` (`E0006` reason `feature_not_declared` without it). They may appear as function parameters, return types, block parameters and as operands of borrow instructions.
|
||||
|
||||
### 6.2 Consumption
|
||||
|
||||
A resource value is **consumed** by exactly one of:
|
||||
|
||||
- a closing intrinsic (`fs.close`, `net.close_stream`, `net.close_listener`). A closing intrinsic consumes the resource **regardless of its result**: on both the `ok` and the `err` edge the resource is dead, and closing it again is `E2002`. After a failed close the state of the underlying host handle is unspecified, so no retry is possible;
|
||||
- being a `call` argument for a parameter of resource type (ownership moves to the callee);
|
||||
- being a branch argument (`br`, `cbr`, `switch`, default targets) for a block parameter of resource type;
|
||||
- `ret`.
|
||||
|
||||
Every other operand use of a resource is a **non-consuming use**, which is only permitted through borrows: `borrow.ref %f` / `borrow.mut %f` take a resource SSA value as their root, exactly as for a `local` (RFC 0005), and produce `ref<file>` / `mut<file>`.
|
||||
|
||||
### 6.3 Verifier rules
|
||||
|
||||
The resource state of each resource value — `owned`, `consumed by close`, `consumed by transfer` — is tracked on every reachable path with the same discipline as borrows (spec 08 §11.4):
|
||||
|
||||
| Rule | Code |
|
||||
|---|---|
|
||||
| owned resource live at `ret` (other than the returned one) | `E3002` (`resource.leak`) |
|
||||
| resource state differs between edges into a block | `E3002` |
|
||||
| resource consumed again after any consumption | `E2002` (`ownership.double_consume`) |
|
||||
| non-consuming use after consumption by a closing intrinsic | `E3001` (`resource.use_after_consume`) |
|
||||
| non-consuming use after consumption by transfer | `E2001` (`ownership.use_after_move`) |
|
||||
| resource consumed while a borrow of it is live | `E2101` |
|
||||
|
||||
Resource parameters of the current function are owned by it (they were moved in). Resource block parameters own their argument.
|
||||
|
||||
## 7. I/O errors
|
||||
|
||||
`io_error` is a built-in enum (spelled without `@`, used with `enum.switch io_error %e, …`):
|
||||
|
||||
| Variant | Meaning |
|
||||
|---|---|
|
||||
| `not_found` | path or address does not exist |
|
||||
| `permission_denied` | the host refused, or the path is outside the capability's scope |
|
||||
| `already_exists` | exclusive creation of an existing path |
|
||||
| `invalid_input` | malformed path or address (relative path, `.`/`..` component, unparsable address) |
|
||||
| `no_space` | storage exhausted |
|
||||
| `broken_pipe` | the peer closed while writing |
|
||||
| `connection_refused` | nobody listens at the address |
|
||||
| `connection_reset` | the peer reset the connection |
|
||||
| `address_in_use` | listen address taken |
|
||||
| `address_unavailable` | listen or connect address not available to this host |
|
||||
| `timed_out` | an explicit timeout expired (reserved for timers in Phase 3; no Phase 2 operation produces it) |
|
||||
| `other` | any host error not listed above |
|
||||
|
||||
The mapping from host errors to variants is part of each profile's specification; `other` keeps the set closed. Host error numbers are not part of AIR semantics: a runtime may attach them as diagnostic metadata outside the run record's values, never in a way the program can observe.
|
||||
|
||||
**Frozen variant sets.** The variants of a published built-in enum never change: adding one would make an existing exhaustive `enum.switch` without `default` non-exhaustive, turning an accepted module into a rejected one (spec 07 §8.7). This is why `timed_out` is reserved now although nothing produces it yet.
|
||||
+4
-2
@@ -250,13 +250,15 @@ A change is permitted under `air 0` only if all of the following hold:
|
||||
3. the change adds instructions, types, diagnostic codes or trap codes; every added construct belongs to a feature registered in [`../reference/air-features.md`](../reference/air-features.md), and the feature's semantics are specified (spec 07a and the relevant spec files) before the feature is published and implemented;
|
||||
4. the canonical form (§8.5) of existing constructs is unchanged.
|
||||
|
||||
A published feature's semantics are immutable. Extending a feature with new semantics is not permitted; register a new feature instead.
|
||||
A published feature's semantics are immutable. In particular the variant set of a published built-in enum never changes, since a new variant would make existing exhaustive `enum.switch` instructions non-exhaustive. Extending a feature with new semantics is not permitted; register a new feature instead.
|
||||
|
||||
Any other change to format 0 — a different meaning, typing rule, trap behavior, diagnostic code or canonical spelling for an existing construct — requires a new format version (`air 1`) introduced by an RFC. An implementation that supports several format versions selects the semantics by the module's `air` line; it never mixes them.
|
||||
|
||||
### 8.9 Types of the features `effects` and `capabilities`
|
||||
|
||||
`cap<K>` (feature `capabilities`) is an opaque, copyable, authority-bearing value type; `K` is a registered capability kind ([`../reference/capabilities.md`](../reference/capabilities.md)). Built-in enums such as `cap_error` are spelled without `@`, have registered variants and are used with `enum.switch <builtin> %v, …` like declared enums. Rules: spec 05 §9–§12.
|
||||
`cap<K>` (feature `capabilities`) is an opaque, copyable, authority-bearing value type; `K` is a registered capability kind ([`../reference/capabilities.md`](../reference/capabilities.md)). Built-in enums such as `cap_error` and `io_error` are spelled without `@`, have registered variants and are used with `enum.switch <builtin> %v, …` like declared enums. Rules: spec 05 §9–§12.
|
||||
|
||||
Feature `resources`: `file<read>`, `file<write>`, `file<append>`, `listener`, `stream` are linear, authority-bearing resource types (spec 06 §6).
|
||||
|
||||
### 8.8 Types and syntax of the features `ownership` and `arrays`
|
||||
|
||||
|
||||
@@ -222,7 +222,11 @@ Rules: spec 05 §9–§12. Decision record: RFC 0006.
|
||||
| `cap.narrow.<form> %c, %arg…, ok -> @ok, err -> @err` (terminator) | `cap<K>`, form arguments | form registered for `K` (`E3202`); `@ok` has one parameter `cap<K>`, `@err` one parameter `cap_error` (`E5002` count, `E1001` type) | continues at `@ok` with a narrower capability sharing nothing wider than `%c`, or at `@err` with the reason; never traps |
|
||||
| `[%r =] intrinsic <name>(%a…)` | per registry entry | operand types (`E1001`), capability kind (`E3201`), effect (`E3101`), borrows as for `call`; unknown name `E0004` | forwards to the host through the capability |
|
||||
|
||||
No intrinsic is registered yet (RFC 0007). Effect checking applies to `call` and `intrinsic` in modules that declare `effects` (spec 05 §9.3).
|
||||
Intrinsics have an infallible form (`[%r =] intrinsic …`) and a fallible terminator form (`intrinsic …, ok -> @ok, err -> @err`) (spec 05 §11.1). The catalogue is `reference/intrinsics.md`. Effect checking applies to `call` and `intrinsic` in modules that declare `effects` (spec 05 §9.3).
|
||||
|
||||
## Feature `resources`
|
||||
|
||||
Resource types and their consumption rules: spec 06 §6. Resources are used through `borrow.ref`/`borrow.mut` (which accept a resource value as root) and consumed by closing intrinsics, by-value resource parameters, resource block parameters and `ret`.
|
||||
|
||||
## Run result
|
||||
|
||||
@@ -238,4 +242,4 @@ No intrinsic is registered yet (RFC 0007). Effect checking applies to `call` and
|
||||
|
||||
On a trap it reports `{"status":"trapped", "code":…, "kind":…, "function":…, "block":…, "inst":…}` (spec 01 §6).
|
||||
|
||||
When instantiation fails (spec 05 §10.2) the program does not start and the runner reports `{"status":"not_instantiated","reason":…,…}`. When the runner stops execution because an execution limit is exhausted (spec 11 §7), it reports `{"status":"limit_exceeded","kind":"fuel","limit":N,"steps":N}`. This is an outcome of the execution environment, not of the program, and is not a trap.
|
||||
Programs that declare `capabilities` also get `"stdout"` and `"stderr"` (captured output) and `"files"` (files written in the virtual file system) in the record of the `deterministic` profile (spec 11 §8). When the deterministic runtime detects quiescence it reports `{"status":"blocked","kind":"no_future_event",…}` (spec 11 §8). When instantiation fails (spec 05 §10.2) the program does not start and the runner reports `{"status":"not_instantiated","reason":…,…}`. When the runner stops execution because an execution limit is exhausted (spec 11 §7), it reports `{"status":"limit_exceeded","kind":"fuel","limit":N,"steps":N}`. This is an outcome of the execution environment, not of the program, and is not a trap.
|
||||
@@ -87,6 +87,7 @@ not_instantiated the environment did not start the program (spec 05 §10.2)
|
||||
returned the program finished
|
||||
trapped the program failed (T0xxx)
|
||||
limit_exceeded the environment stopped the program
|
||||
blocked the program can make no further progress (§8)
|
||||
```
|
||||
|
||||
Running without a fuel limit is permitted (for example `aji run program.air`). Conformance, fuzz and stress runs MUST use a fuel limit.
|
||||
@@ -100,3 +101,33 @@ With several tasks, fuel is global: the sum of instructions executed by all task
|
||||
| fuel | how long the program may execute |
|
||||
| schedule budget | how many interleavings schedule exploration examines |
|
||||
| quantum | how many instructions a task executes before a forced scheduling point |
|
||||
|
||||
## 8. Execution profiles
|
||||
|
||||
Decision record: RFC 0007.
|
||||
|
||||
The run record gains fields for observable output. `aji run` uses the **deterministic** profile by default; `--profile hosted` uses the real host.
|
||||
|
||||
| Aspect | `deterministic` | `hosted` |
|
||||
|---|---|---|
|
||||
| stdout / stderr | captured; reported as `"stdout"` / `"stderr"` strings in the run record, which is printed on stdout | the process's real streams; the run record is written to a separate result channel (below) |
|
||||
| stdin | from `--stdin TEXT` (empty by default) | real stdin |
|
||||
| files | in-memory file system seeded by `--vfs PATH=TEXT`; files written during the run are reported as `"files"` in the run record | real file system, limited by capability scopes |
|
||||
| network | in-process loopback: `net.connect` to a listening address of the same run queues a connection that `net.accept` returns; sends are buffered; an operation that would wait for an event that can never occur ends the run with the environment outcome `blocked` (below) | real sockets |
|
||||
| clock | the number of instructions executed so far (1 ns per instruction) | real monotonic clock |
|
||||
| random | PRNG seeded by `--seed N` (default 0), algorithm fixed by the spec | host CSPRNG |
|
||||
|
||||
**Quiescence.** In the `deterministic` profile, when an operation would wait, no other execution unit can run, and no future deterministic event can complete the wait, the run ends with the environment outcome
|
||||
|
||||
```json
|
||||
{"status":"blocked","kind":"no_future_event","function":"…","block":"…","inst":0}
|
||||
```
|
||||
|
||||
and `aji run` exits with code 7. This is not an `io_error` and not a trap: the program did not ask for a timeout, so none is invented. In the `hosted` profile the same operation simply blocks. A program that needs a timeout states it explicitly (timers and `select`, Phase 3). The outcomes are now:
|
||||
|
||||
```text
|
||||
program outcome: returned, trapped
|
||||
environment outcome: not_instantiated, limit_exceeded, blocked
|
||||
```
|
||||
|
||||
**Result channel.** In the `hosted` profile the program owns stdout and stderr, so the run record cannot share them unambiguously. The machine-readable record goes to a separate channel: `aji run --profile hosted --result-file PATH` (a `--result-fd N` form may follow; `ajid` has its own control channel). Without `--result-file` the CLI may print a human-readable summary on stderr after the program ends; that summary is not a machine interface.
|
||||
Reference in new issue
Block a user