spec: spell the AIR array type array<T, N>
';' starts a comment in text AIR, so [T; N] cannot be parsed. Recorded as an erratum in RFC 0005; source syntax may keep [T; N].
This commit is contained in:
7 files changed
+20
-19
No files matched your search
@@ -12,7 +12,7 @@ Non-normative. Part of the [implementation plan](README.md).
|
||||
|
||||
## Scope
|
||||
|
||||
In: `local<T>`, `ref<T>`, `mut<T>`, `[T; N]`, `slice<T>`, `slice_mut<T>`; `local.alloc/store/zero/load`, `borrow.ref/mut/field/end`, `load`, `store`, `array.splat`, `borrow.index[.proven]`, `slice.make/len/sub/split/copy`, `guard`; `from` returns; multi-result syntax; feature gating (`feature_not_declared`).
|
||||
In: `local<T>`, `ref<T>`, `mut<T>`, `array<T, N>`, `slice<T>`, `slice_mut<T>`; `local.alloc/store/zero/load`, `borrow.ref/mut/field/end`, `load`, `store`, `array.splat`, `borrow.index[.proven]`, `slice.make/len/sub/split/copy`, `guard`; `from` returns; multi-result syntax; feature gating (`feature_not_declared`).
|
||||
|
||||
Out: heap, regions, move-only values, borrow-typed block parameters (`borrow_joins`).
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ Declaring `features [capabilities, effects, ownership]` grants no authority. It
|
||||
|
||||
| Feature | Status | Phase | Depends on | Semantic block |
|
||||
|---|---|---|---|---|
|
||||
| `arrays` | published | 1 | `ownership` | `[T; N]`, `slice<T>`, `slice_mut<T>`, `array.splat`, `borrow.index[.proven]`, `slice.*`, `guard`, bounds facts (spec 07a, spec 08 §12) |
|
||||
| `arrays` | published | 1 | `ownership` | `array<T, N>`, `slice<T>`, `slice_mut<T>`, `array.splat`, `borrow.index[.proven]`, `slice.*`, `guard`, bounds facts (spec 07a, spec 08 §12) |
|
||||
| `atomics` | reserved | 5 | `ownership` | atomic types, the five orderings, fences, `atomic.*` instructions |
|
||||
| `capabilities` | reserved | 2 | `effects`, `ownership` | `cap<…>` values, narrowing, delegation, capability-gated intrinsics |
|
||||
| `borrow_joins` | reserved | — | `ownership` | borrow-typed block parameters (spec 08 §11.6); unscheduled |
|
||||
|
||||
@@ -103,7 +103,7 @@ target = global "(" [ local_list ] ")" ;
|
||||
|
||||
type = int_type | "bool" | "void" | "never" | global
|
||||
| ( "local" | "ref" | "mut" ) "<" type ">" (* feature ownership *)
|
||||
| "[" type ";" int_lit "]" (* feature arrays *)
|
||||
| "array" "<" type "," int_lit ">" (* feature arrays; ";" starts a comment, so source syntax [T; N] is spelled array<T, N> *)
|
||||
| ( "slice" | "slice_mut" ) "<" type ">" ; (* feature arrays *)
|
||||
int_type = "u8" | "u16" | "u32" | "u64" | "u128" | "usize"
|
||||
| "i8" | "i16" | "i32" | "i64" | "i128" | "isize" ;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
Status: Accepted (revision 2, after owner review items 1–5)
|
||||
Scope: AIR format 0, features `ownership` and `arrays`
|
||||
Language version: 0.1
|
||||
Erratum (during integration): the array type is spelled `array<T, N>` in text AIR, because `;` starts a comment; revision 2 wrote `[T; N]`. Source syntax may keep `[T; N]`.
|
||||
Integrated into: spec 03 §6, §4, §8.1; spec 07 §8.8; spec 07a; spec 08 §11–§14; `reference/air-text.ebnf`, `reference/air-features.md`, `reference/error-codes.md`
|
||||
Supersedes: —
|
||||
|
||||
@@ -32,7 +33,7 @@ For every program accepted with `ownership` and `arrays`:
|
||||
| Feature | Depends on | Contents |
|
||||
|---|---|---|
|
||||
| `ownership` | — | `local<T>`, `ref<T>`, `mut<T>`; `local.*`, `borrow.*`, `load`, `store`; `from` on returns |
|
||||
| `arrays` | `ownership` | `[T; N]`, `slice<T>`, `slice_mut<T>`; `array.splat`, `borrow.index`, `slice.*`, `guard` |
|
||||
| `arrays` | `ownership` | `array<T, N>`, `slice<T>`, `slice_mut<T>`; `array.splat`, `borrow.index`, `slice.*`, `guard` |
|
||||
|
||||
Registry changes: `arrays` gains the dependency `ownership`; `regions` moves to Phase 2 and depends on `capabilities`, `effects`, `ownership`; a new reserved feature `heap` (Phase 2: `Own<T>`, `own.alloc`, `own.free`) depends on `capabilities`, `effects`, `ownership`; `islands` lists the new closure. A reserved feature `borrow_joins` (see §5.4) is added without a phase.
|
||||
|
||||
@@ -43,7 +44,7 @@ Registry changes: `arrays` gains the dependency `ownership`; `regions` moves to
|
||||
| `local<T>` | storage | frame storage holding a `T`; only an operand of `local.*` and `borrow.*` |
|
||||
| `ref<T>` | borrow | shared borrow |
|
||||
| `mut<T>` | borrow | exclusive borrow |
|
||||
| `[T; N]` | value | array of `N` values, `1 ≤ N ≤ 2^32`; copyable when `T` is |
|
||||
| `array<T, N>` | value | array of `N` values, `1 ≤ N ≤ 2^32`; copyable when `T` is |
|
||||
| `slice<T>` | borrow | shared borrow of a contiguous range |
|
||||
| `slice_mut<T>` | borrow | exclusive borrow of a contiguous range |
|
||||
|
||||
@@ -58,7 +59,7 @@ All value types of format 0 and Phase 1 are copyable. Move-only values arrive wi
|
||||
```text
|
||||
function = "fn" global "(" [ param_list ] ")" "->" type [ "from" local ] NL …
|
||||
type = … | "local" "<" type ">" | "ref" "<" type ">" | "mut" "<" type ">"
|
||||
| "[" type ";" int_lit "]" | "slice" "<" type ">" | "slice_mut" "<" type ">"
|
||||
| "array" "<" type "," int_lit ">" | "slice" "<" type ">" | "slice_mut" "<" type ">"
|
||||
instruction = [ local { "," local } "=" ] operation ; multi-result, used only by slice.split
|
||||
```
|
||||
|
||||
@@ -87,10 +88,10 @@ Common contract unless stated: no effects, no capabilities, no synchronization.
|
||||
|
||||
| Instruction | Operands → result | Verifier | Runtime |
|
||||
|---|---|---|---|
|
||||
| `%a = array.splat [T; N] %v` | `T` → `[T; N]` | — | every element is `%v` |
|
||||
| `%e = borrow.index %b, %i` | `ref`/`mut` of `[T; N]`, or `slice`/`slice_mut` of `T`; `usize` → `ref<T>`/`mut<T>` | child of `%b` | traps `T0008` if `%i ≥ length` |
|
||||
| `%a = array.splat array<T, N> %v` | `T` → `array<T, N>` | — | every element is `%v` |
|
||||
| `%e = borrow.index %b, %i` | `ref`/`mut` of `array<T, N>`, or `slice`/`slice_mut` of `T`; `usize` → `ref<T>`/`mut<T>` | child of `%b` | traps `T0008` if `%i ≥ length` |
|
||||
| `%e = borrow.index.proven %b, %i` | as above | `%i < length` proven (§6), otherwise `E2103` | no check |
|
||||
| `%s = slice.make %b` | `ref<[T; N]>`/`mut<[T; N]>` → `slice<T>`/`slice_mut<T>` | child of `%b` | whole array |
|
||||
| `%s = slice.make %b` | `ref<array<T, N>>`/`mut<array<T, N>>` → `slice<T>`/`slice_mut<T>` | child of `%b` | whole array |
|
||||
| `%n = slice.len %s` | `slice<T>`/`slice_mut<T>` → `usize` | — | length |
|
||||
| `%t = slice.sub %s, %start, %len` | slice, `usize`, `usize` → same slice type | child of `%s` | traps `T0008` unless `start ≤ slice.len(s)` and `len ≤ slice.len(s) − start` (evaluated without overflow); result covers `[start, start + len)` |
|
||||
| `%l, %r = slice.split %s, %at` | slice, `usize` → two slices of the same type | two children of `%s`, disjoint | traps `T0008` unless `at ≤ slice.len(s)`; `l` covers `[0, at)`, `r` covers `[at, len)` |
|
||||
@@ -154,7 +155,7 @@ Each function's frame storage is the sum of the accounted sizes of its `local.al
|
||||
| `usize`/`isize` | 8 (the largest supported pointer width, so the result is target-independent) |
|
||||
| struct | sum of its fields |
|
||||
| enum | 4 + the largest sum over a variant's payload |
|
||||
| `[T; N]` | `N ×` accounted size of `T` |
|
||||
| `array<T, N>` | `N ×` accounted size of `T` |
|
||||
|
||||
### 5.6 Borrow-typed block parameters
|
||||
|
||||
@@ -183,7 +184,7 @@ Scope of a fact:
|
||||
| Case | Condition |
|
||||
|---|---|
|
||||
| fact on the same slice | a fact `%i < %n` holds where `%n = slice.len %b`, with `%i` and `%b` the same SSA values as the operands |
|
||||
| constant index | `%i = const.usize k` and `%b` has a static length `N` (a borrow of `[T; N]`) with `k < N` |
|
||||
| constant index | `%i = const.usize k` and `%b` has a static length `N` (a borrow of `array<T, N>`) with `k < N` |
|
||||
| fact against a constant | a fact `%i < %n` holds where `%n = const.usize k`, `%b` has a static length `N` and `k ≤ N` |
|
||||
|
||||
This is the complete normative analysis: an implementation MUST NOT accept more or fewer programs.
|
||||
@@ -229,7 +230,7 @@ entry:
|
||||
fn @main() -> u8
|
||||
effects []
|
||||
entry:
|
||||
%buf = local.alloc [u8; 8]
|
||||
%buf = local.alloc array<u8, 8>
|
||||
local.zero %buf
|
||||
%m = borrow.mut %buf
|
||||
%s = slice.make %m
|
||||
|
||||
+2
-2
@@ -256,14 +256,14 @@ Any other change to format 0 — a different meaning, typing rule, trap behavior
|
||||
|
||||
### 8.8 Types and syntax of the features `ownership` and `arrays`
|
||||
|
||||
Feature membership: `local<T>`, `ref<T>`, `mut<T>` and the `from` clause belong to `ownership`; `[T; N]`, `slice<T>`, `slice_mut<T>` and multi-result binding belong to `arrays`. Using them without declaring the feature is `E0006` reason `feature_not_declared`.
|
||||
Feature membership: `local<T>`, `ref<T>`, `mut<T>` and the `from` clause belong to `ownership`; `array<T, N>`, `slice<T>`, `slice_mut<T>` and multi-result binding belong to `arrays`. Using them without declaring the feature is `E0006` reason `feature_not_declared`.
|
||||
|
||||
| Type | Class | Notes |
|
||||
|---|---|---|
|
||||
| `local<T>` | storage | frame storage holding a `T`; only an operand of `local.*` and `borrow.*` |
|
||||
| `ref<T>` | borrow | shared borrow |
|
||||
| `mut<T>` | borrow | exclusive borrow |
|
||||
| `[T; N]` | value | array of `N` values, `1 ≤ N ≤ 2^32`; copyable when `T` is |
|
||||
| `array<T, N>` | value | array of `N` values, `1 ≤ N ≤ 2^32`; copyable when `T` is |
|
||||
| `slice<T>` | borrow | shared borrow of a contiguous range |
|
||||
| `slice_mut<T>` | borrow | exclusive borrow of a contiguous range |
|
||||
|
||||
|
||||
@@ -193,10 +193,10 @@ Common contract unless stated: no effects, no capabilities, no synchronization.
|
||||
|
||||
| Instruction | Operands → result | Verifier | Runtime |
|
||||
|---|---|---|---|
|
||||
| `%a = array.splat [T; N] %v` | `T` → `[T; N]` | — | every element is `%v` |
|
||||
| `%e = borrow.index %b, %i` | `ref`/`mut` of `[T; N]`, or `slice`/`slice_mut` of `T`; `usize` → `ref<T>`/`mut<T>` | child of `%b` | traps `T0008` if `%i ≥ length` |
|
||||
| `%a = array.splat array<T, N> %v` | `T` → `array<T, N>` | — | every element is `%v` |
|
||||
| `%e = borrow.index %b, %i` | `ref`/`mut` of `array<T, N>`, or `slice`/`slice_mut` of `T`; `usize` → `ref<T>`/`mut<T>` | child of `%b` | traps `T0008` if `%i ≥ length` |
|
||||
| `%e = borrow.index.proven %b, %i` | as above | `%i < length` proven (spec 08 §12), otherwise `E2103` | no check |
|
||||
| `%s = slice.make %b` | `ref<[T; N]>`/`mut<[T; N]>` → `slice<T>`/`slice_mut<T>` | child of `%b` | whole array |
|
||||
| `%s = slice.make %b` | `ref<array<T, N>>`/`mut<array<T, N>>` → `slice<T>`/`slice_mut<T>` | child of `%b` | whole array |
|
||||
| `%n = slice.len %s` | `slice<T>`/`slice_mut<T>` → `usize` | — | length |
|
||||
| `%t = slice.sub %s, %start, %len` | slice, `usize`, `usize` → same slice type | child of `%s` | traps `T0008` unless `start ≤ slice.len(s)` and `len ≤ slice.len(s) − start` (evaluated without overflow); result covers `[start, start + len)` |
|
||||
| `%l, %r = slice.split %s, %at` | slice, `usize` → two slices of the same type | two children of `%s`, disjoint | traps `T0008` unless `at ≤ slice.len(s)`; `l` covers `[0, at)`, `r` covers `[at, len)` |
|
||||
|
||||
@@ -187,7 +187,7 @@ Each function's frame storage is the sum of the accounted sizes of its `local.al
|
||||
| `usize`/`isize` | 8 (the largest supported pointer width, so the result is target-independent) |
|
||||
| struct | sum of its fields |
|
||||
| enum | 4 + the largest sum over a variant's payload |
|
||||
| `[T; N]` | `N ×` accounted size of `T` |
|
||||
| `array<T, N>` | `N ×` accounted size of `T` |
|
||||
|
||||
### 11.6 Borrow-typed block parameters
|
||||
|
||||
@@ -216,7 +216,7 @@ Scope of a fact:
|
||||
| Case | Condition |
|
||||
|---|---|
|
||||
| fact on the same slice | a fact `%i < %n` holds where `%n = slice.len %b`, with `%i` and `%b` the same SSA values as the operands |
|
||||
| constant index | `%i = const.usize k` and `%b` has a static length `N` (a borrow of `[T; N]`) with `k < N` |
|
||||
| constant index | `%i = const.usize k` and `%b` has a static length `N` (a borrow of `array<T, N>`) with `k < N` |
|
||||
| fact against a constant | a fact `%i < %n` holds where `%n = const.usize k`, `%b` has a static length `N` and `k ≤ N` |
|
||||
|
||||
This is the complete normative analysis: an implementation MUST NOT accept more or fewer programs.
|
||||
|
||||
Reference in new issue
Block a user