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

+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