spec: Phase 0 spec gate (P0-1, P0-2, P0-3)
- text AIR format 0: grammar (reference/air-text.ebnf) and module, block, SSA, type and canonical-form rules (spec 07 §8) - instruction contracts for format 0 (new spec 07a) - traps: stable T0xxx codes and trap records (spec 01 §6) - integer edge cases and explicit casts (spec 02 §2.1) - fixed verifier resource limits (spec 08 §7) - target description with pointer_bits (spec 09 §9) - new codes E0001-E0006, E1003, T0001-T0007 - resolves Q-001, Q-003..Q-008, Q-018; Q-002 resolved for format 0
This commit is contained in:
1 parent
11ce6cb38c
commit
41b764ccfd
13 files changed
+425
-18
No files matched your search
@@ -182,3 +182,49 @@ Every binary must encode version and required feature bits.
|
||||
Native code must not be produced from unverified safe AIR.
|
||||
|
||||
Unsafe AIR modules are allowed only through explicit trusted/unsafe boundaries and must appear in the unsafe dependency report.
|
||||
|
||||
## 8. Text AIR, format version 0
|
||||
|
||||
The grammar is [`../reference/air-text.ebnf`](../reference/air-text.ebnf). Instruction semantics are in [`07a-air-instructions.md`](07a-air-instructions.md).
|
||||
|
||||
### 8.1 Module header
|
||||
|
||||
Every text module MUST begin with:
|
||||
|
||||
```text
|
||||
module <path>
|
||||
air 0
|
||||
lang 0.1
|
||||
features []
|
||||
```
|
||||
|
||||
An implementation MUST reject a module whose `air` format version or `lang` version it does not implement (`E0005`), and a module that lists a feature it does not implement (`E0006`). Format version 0 defines no features.
|
||||
|
||||
### 8.2 Functions and blocks
|
||||
|
||||
- A function body is a non-empty sequence of blocks. The first block is the entry block; it MUST NOT declare parameters. Function parameters are in scope in the entry block and every block it dominates.
|
||||
- Every block MUST contain at least one instruction, MUST end with exactly one terminator, and MUST NOT contain a terminator before its last instruction (`E5002`).
|
||||
- A branch target MUST name a block of the same function and pass exactly as many arguments as the block declares parameters (`E5002`). Argument binding is simultaneous: all arguments are read before any parameter is written.
|
||||
- Every `%name` MUST be defined exactly once per function, as a function parameter, a block parameter or an instruction result (`E5001`). Every use MUST be dominated by its definition (`E5001`); a use in the same block MUST come after the defining instruction. Uses in blocks unreachable from the entry block are only checked within their own block.
|
||||
- Function and type names MUST be unique within a module, and block labels within a function (`E0003`). Field names MUST be unique within a struct and variant names within an enum (`E0003`).
|
||||
|
||||
### 8.3 Types
|
||||
|
||||
- Integer types, `bool`, `void` and `never` are built in. `usize`/`isize` are distinct from all fixed-width types; their width comes from the target description (spec 09 §9).
|
||||
- `type @T = struct { … }` and `type @T = enum { … }` declare nominal aggregate types. An aggregate MUST NOT contain itself by value, directly or through other aggregates (`E1003`).
|
||||
- In format version 0 every value is copyable; ownership categories arrive with format version 1 (Phase 1).
|
||||
- `void` is only valid as a function return type. A `void` function returns with `ret` without operand; a call to it MUST NOT bind a result. A `never` function MUST NOT contain `ret`.
|
||||
|
||||
### 8.4 Reserved
|
||||
|
||||
`f32` and `f64` are reserved until floating-point determinism is specified (open question Q-016). A module that uses them MUST be rejected with `E0006`.
|
||||
|
||||
### 8.5 Canonical form
|
||||
|
||||
The canonical serialization of a module is: the four header lines; one blank line; type declarations in declaration order, one per line; for each function, a blank line, the signature line, the `effects` line, then each block label at column 0 followed by its instructions indented by four spaces. Separators are `", "` between list items and single spaces elsewhere. Comments are not preserved. Value, block, function and type names are preserved.
|
||||
|
||||
Serializing a parsed module and parsing the result MUST yield an equal module.
|
||||
|
||||
### 8.6 Diagnostic order
|
||||
|
||||
Verification stops after the first stage that reports an error, in this order: parsing and name resolution, resource limits, CFG structure, SSA, types. Within a stage, diagnostics are ordered by source position. The result is therefore deterministic for a given input.
|
||||
Reference in new issue
Block a user