cli: add explicit built-in error values
Add the error_values feature and error.const through specification, AIR, verification, interpretation and source lowering. Error values are Copy data with no allocation, effects or authority. Keep enum.make semantics frozen. Cover all registered tags, feature negotiation, payload/type errors and authority rejection in AIR/source; verify canonical and hosted CLI behavior. Record reference-bundle costs and the map preflight-validation prerequisite.
This commit is contained in:
1 parent
89c63c306b
commit
1eaf968f4f
56 files changed
+823
-4
No files matched your search
@@ -289,3 +289,15 @@ atomic.new, atomic.take → no effect
|
||||
For compare-exchange, the operation is non-`seq_cst` if either ordering is. A missing atom is `E3101`.
|
||||
|
||||
If `atomic.weak` is not among the transitive effects of `@main`, every atomic access is `seq_cst`, and every execution of the safe program is explainable as an SC interleaving (spec 04 §22).
|
||||
|
||||
## 14. Explicit error values (feature `error_values`)
|
||||
|
||||
An error is Copy data, not authority or proof that an operation occurred. Safe code MAY create any registered payload-free variant of `alloc_error` (spec 03 §18), `cap_error` (§10) or `io_error` (spec 06 §7). Creating an error MUST NOT allocate, perform I/O, narrow a capability, change resource state or grant authority. Actual fallible operations retain their specified outcome rules.
|
||||
|
||||
In AIR, `%e = error.const B.variant` has two static operands: a built-in error family `B` and one of its registered variant names. It takes no SSA operands or payloads and produces exactly one Copy value of type `B`. The module MUST declare `error_values` and its full dependency closure (`capabilities`, `effects`, `heap`, `ownership`, `resources`). These dependencies make all three existing error families available; they grant no capabilities.
|
||||
|
||||
The verifier MUST validate the family and variant (`E0004` for an unknown name in text), result uses (`E1001` for a type mismatch) and feature declaration (`E0006`). Its transfer function introduces one available Copy value; it changes no ownership, borrow, memory, concurrency or authority state. Effects and capabilities required: none. Instruction-specific traps: none. The interpreter deterministically binds the selected family/tag as ordinary built-in error data; the instruction consumes normal fuel. The payload syntax is not permitted (`E0001`).
|
||||
|
||||
Source uses the existing variant expression `alloc_error::budget_exceeded`, `cap_error::not_subset` or `io_error::invalid_input`, lowering to `error.const`; the frontend MUST include the feature closure. Every registered variant is constructible; errors cannot be converted into capabilities. Source rejects unknown variants with `E7002`, payloads with `E7005`, and wrong result types with `E7005`.
|
||||
|
||||
Valid: a pure function returning `alloc_error::budget_exceeded` before overflowing an allocation size. Rejected: returning that value from a function returning `cap<mem.alloc>` (`E7005` / AIR `E1001`). Existing `enum.make` remains restricted to declared enums. This is an additive format-0 feature; no existing instruction, error tag, fallible outcome or authority rule changes.
|
||||
@@ -258,6 +258,8 @@ Any other change to format 0 — a different meaning, typing rule, trap behavior
|
||||
|
||||
`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 `error_values`: `%e = error.const alloc_error.budget_exceeded` creates ordinary Copy error data without authority or effects (spec 05 §14); `enum.make` remains a declared-enum instruction.
|
||||
|
||||
Feature `resources`: `file<read>`, `file<write>`, `file<append>`, `listener`, `stream` are linear, authority-bearing resource types (spec 06 §6).
|
||||
|
||||
Feature `heap`: `own<T>` and `own_array<T>` (linear owners, `T` a value type) and the built-in enum `alloc_error`. Feature `regions`: `region` (linear). Rules: spec 03 §18–§21. Linear values — resources, owners and regions — follow the consumption rules of spec 06 §6.2–§6.3.
|
||||
|
||||
@@ -22,6 +22,15 @@ Notation: `T` is the type suffix of the opcode; `I` ranges over integer types; `
|
||||
|
||||
## Values
|
||||
|
||||
### `error.const B.variant` (feature `error_values`)
|
||||
|
||||
- Static operands: built-in error family `B` and its registered payload-free variant; no SSA operands.
|
||||
- Result: one Copy value of type `B`.
|
||||
- Ownership/borrow/memory/concurrency transitions: none; effects and capabilities required: none; traps: none.
|
||||
- Verifier transfer: define one available Copy value. Unknown family/variant: `E0004`; undeclared feature: `E0006`; incompatible result use: `E1001`. Payload syntax: `E0001`.
|
||||
- Interpreter: bind the built-in family/tag deterministically, using normal fuel; no program allocation or authority acquisition.
|
||||
- Complete contract and source syntax: spec 05 §14. `enum.make` is unchanged.
|
||||
|
||||
### `const.T lit`
|
||||
|
||||
- Operands: an integer literal (`T` ∈ `I`) or `true`/`false` (`T` = `bool`).
|
||||
|
||||
@@ -47,6 +47,8 @@ resource state
|
||||
|
||||
## 4. Ownership state machine
|
||||
|
||||
For `error.const` (feature `error_values`, spec 05 §14), verification introduces one available Copy value of the selected built-in error type. It MUST NOT alter authority, resource, memory, borrow or concurrency state. The static family/tag and ordinary result-use typing MUST be checked.
|
||||
|
||||
Representative states:
|
||||
|
||||
```text
|
||||
|
||||
@@ -235,6 +235,7 @@ 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.
|
||||
- **Error construction.** Every registered built-in error variant is also a payload-free expression, e.g. `let e = alloc_error::budget_exceeded;`. It lowers to `error.const` with feature `error_values` and its dependency closure (spec 05 §14), requires no effects or capabilities and changes no resource state. Unknown variants are `E7002`, payload arguments `E7005`; errors are Copy data and cannot confer authority.
|
||||
- **Rebinding.** A value that comes back on an edge is rebound by the name in its arm: `closed(v)`, `pending(rx)`, `cancelled(t)`. If that name is a variable (`var`) of the value's type, the value becomes the variable's new value. A receiver kept in `var r` is closed with `match channel.close_receiver(move r) { ok => …, pending(r) => … }` and received from again.
|
||||
- **`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`.
|
||||
|
||||
Reference in new issue
Block a user