verifier: max_value_size and checked size accounting (Q-020, DD-015)

- spec 08 §7.1: platform-independent accounted size table shared by
  max_value_size and max_local_frame; enum tag is the smallest of
  1/2/4/8 bytes; borrows 8, slices 16; checked arithmetic, overflow is
  E5101 with found = "overflow"
- every materializable type in a module must be at most 1 MiB,
  checked before functions are verified; each oversized type reported
  once
- E5101 fields no longer truncate huge sizes
- conformance: frame_too_large, value_too_large, size_overflow
- Q-020 resolved; Phase 1 closed
This commit is contained in:
dev committed 2026-10-04 13:29:54 +03:00
1 parent e3dc0fb7bb
commit 2ddf424c14
8 files changed
+165 -34

No files matched your search

+6
View File
@@ -81,3 +81,9 @@ Reason: timeouts make test outcomes depend on machine speed; a trap code for exh
AIR format 0 uses the mandatory `features [...]` header as an explicit semantic compatibility contract. Every post-baseline AIR 0 extension belongs to a registered feature (`reference/air-features.md`). Modules MUST declare every feature they use and its dependency closure. Implementations MUST validate the feature set before validating the module body. Unknown, unsupported, undeclared, duplicated or dependency-incomplete features are reported as `E0006` with a structured `reason`. Feature semantics are immutable once published. `aji features` reports what a toolchain supports.
Reason: format 0 is frozen; features make it an extensible protocol without an older implementation half-parsing a module it cannot understand. One code with a reason keeps the §8.7 exception for `E0006` intact.
## DD-015 — Maximum AIR value size
AIR format 0 defines `max_value_size` = 1 048 576 bytes. Every materializable type in a module has an accounted size (spec 08 §7.1, a platform-independent metric, not a layout) of at most this value; violation, including overflow while computing a size, is `E5101`, checked during module validation. `max_local_frame` (1 MiB per function) is a separate guarantee. Neither depends on host memory.
Reason: a verified IR needs its own deterministic validity limits instead of inheriting host behavior; and large data should live in storage reached through borrows, not travel as SSA values. Total allocation is bounded separately in Phase 2, as fuel bounds execution.
+3 -1
View File
@@ -25,7 +25,7 @@ Status values: `open`, `resolved`.
| Q-017 | open | P5 | Replay file format |
| Q-018 | resolved | P2 | Runtime diagnostics (traps) vs verifier diagnostics |
| Q-019 | resolved | P3 | Non-terminating programs in test tooling |
| Q-020 | open | P2 | Size bound for SSA array values |
| Q-020 | resolved | P2 | Size bound for SSA array values |
## Q-001 — Text AIR grammar
@@ -134,3 +134,5 @@ A program may legitimately loop forever, so the language cannot bound execution.
## Q-020 — Size bound for SSA array values
Frame storage is bounded (`max_local_frame`, spec 08 §11.5), but an SSA value of type `array<T, N>` (for example from `array.splat`) is bounded only by `N ≤ 2^32`. A module can therefore ask the interpreter for gigabytes in one instruction, and the outcome then depends on host memory. Options: apply the same accounted-size limit to every type in the module (E5101), or a separate `max_value_bytes`. Needs an owner decision; changing it later would turn accepted modules into rejected ones, so it should be settled before format 0 is released.
**Resolved (owner decision, DD-015):** `max_value_size` = 1 048 576 bytes bounds the accounted size of every materializable type in a module (spec 08 §7.1); `max_local_frame` stays a separate limit. Both are normative, deterministic, independent of host memory and reported as `E5101`. Accounted sizes use checked arithmetic; overflow is `E5101`. Total allocation is a Phase 2 concern (allocation capabilities and runtime limits).
@@ -4,6 +4,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]`.
Later change: the accounted-size table moved to spec 08 §7.1 and gained `max_value_size` and the enum tag rule (DD-015, Q-020).
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: —
+28 -14
View File
@@ -98,8 +98,34 @@ Bounds are fixed by this specification, not configurable: a configurable bound w
| blocks per function | 16 384 |
| instructions per function | 262 144 |
| cases per `switch` | 4 096 |
| `max_value_size`: accounted size of any materializable type in the module (§7.1) | 1 048 576 bytes |
| `max_local_frame`: accounted frame storage per function (§11.5) | 1 048 576 bytes |
The `E5101` diagnostic carries the fields `limit` (name of the limit), `max` and `found`.
The `E5101` diagnostic carries the fields `limit` (name of the limit), `max` and `found`; when a size computation overflows, `found` is the string `"overflow"`.
### 7.1 Accounted size
The **accounted size** of a type is a normative, platform-independent metric of AIR. It is not an ABI layout and does not depend on host memory. All additions and multiplications are checked; an overflow while computing a size is `E5101`, never a program trap.
| Type | Accounted bytes |
|---|---|
| `u8`, `i8`, `bool` | 1 |
| `u16`, `i16` | 2 |
| `u32`, `i32`, `f32` (reserved) | 4 |
| `u64`, `i64`, `f64` (reserved) | 8 |
| `u128`, `i128` | 16 |
| `usize`, `isize` | 8 (accounting convention of AIR 0, independent of the target) |
| `array<T, N>` | `N ×` accounted size of `T` |
| struct | sum of the accounted sizes of its fields |
| enum | `tag + ` the largest sum over one variant's payload, where `tag` is the smallest of 1, 2, 4, 8 bytes that can hold the index of every variant |
| `ref<T>`, `mut<T>` | 8 |
| `slice<T>`, `slice_mut<T>` | 16 |
`void`, `never` and storage types (`local<T>`) are not materializable values and have no accounted size; the `T` inside a storage type does.
**Maximum value size.** Every materializable type that appears in a module — in declarations, signatures, block parameters, instruction type operands, and inside compound types — MUST have an accounted size of at most `max_value_size` (`E5101`, limit `value size bytes`). The check runs during module validation, before functions are verified or executed.
Large data does not travel as SSA values: buffers beyond `max_value_size` belong in storage reached through borrows (regions and heap allocations from Phase 2). `max_value_size` bounds single values only; the total memory a program allocates is bounded separately, by allocation capabilities and runtime limits (Phase 2), just as fuel bounds execution (spec 11 §7).
## 8. Contracts
@@ -177,19 +203,7 @@ Only the set of accepted programs is normative. Because states must match exactl
### 11.5 Frame size
Each function's frame storage is the sum of the accounted sizes of its `local.alloc` types. It MUST NOT exceed `max_local_frame` = 1 048 576 bytes (`E5101`, limit `local frame bytes`). Accounted size is a normative counting rule, not a memory layout:
| Type | Accounted bytes |
|---|---|
| `u8`/`i8`/`bool` | 1 |
| `u16`/`i16` | 2 |
| `u32`/`i32` | 4 |
| `u64`/`i64` | 8 |
| `u128`/`i128` | 16 |
| `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 |
| `array<T, N>` | `N ×` accounted size of `T` |
Each function's frame storage is the sum of the accounted sizes (§7.1) of its `local.alloc` types, computed with checked arithmetic. It MUST NOT exceed `max_local_frame` = 1 048 576 bytes (`E5101`, limit `local frame bytes`). `max_value_size` and `max_local_frame` are separate guarantees and both are checked: ten locals of 200 KiB each satisfy the first and violate the second.
### 11.6 Borrow-typed block parameters