Phase 1: frame storage, second-class borrows, arrays (P1-3..P1-10)

- air: types local/ref/mut/array/slice/slice_mut, from-returns,
  multi-result binding, 18 new instructions; feature gating reports
  E0006 feature_not_declared; borrow-typed block parameters gated by
  borrow_joins; printer and round-trip tests for all new forms
- verifier: second-class and zeroable type rules (E1001); local.alloc
  only in entry (E5002); frame size accounting (E5101); stages init
  (E1010), borrow (E2101, E2102, E2105-E2108) and bounds facts (E2103);
  value types shared between stages
- interp: frame cells, places, slices, deep copies between storage and
  SSA values, T0008 bounds traps
- features arrays and ownership supported; implemented_phase = 1
- conformance: 5 accept, 18 reject, 11 run tests for Phase 1, including
  the file-copy core exit program; 6000 mutants without a crash
This commit is contained in:
dev committed 2026-10-04 13:24:09 +03:00
1 parent be9dd0e1ed
commit 1ae6b485d8
50 files changed
+2376 -37

No files matched your search

+49 -1
View File
@@ -15,8 +15,37 @@ pub const Limits = struct {
pub const blocks = 16_384;
pub const insts = 262_144;
pub const cases = 4_096;
pub const local_frame = 1_048_576; // bytes, spec 08 §11.5
};
/// Accounted size in bytes (spec 08 §11.5). A counting rule, not a layout.
/// Recursive aggregates are reported later (E1003); they count as 0 here.
pub fn accountedSize(m: air.Module, t: air.Type, depth: usize) u64 {
if (depth > m.types.len + 1) return 0;
return switch (t) {
.int => |it| it.bits() / 8,
.bool => 1,
.array => |a| std.math.mul(u64, a.len, accountedSize(m, a.elem, depth + 1)) catch std.math.maxInt(u64),
.named => |i| switch (m.types[i].kind) {
.@"struct" => |fs| blk: {
var sum: u64 = 0;
for (fs) |f| sum +|= accountedSize(m, f.ty, depth + 1);
break :blk sum;
},
.@"enum" => |vs| blk: {
var max: u64 = 0;
for (vs) |v| {
var sum: u64 = 0;
for (v.payload) |p| sum +|= accountedSize(m, p, depth + 1);
max = @max(max, sum);
}
break :blk 4 +| max;
},
},
else => 0,
};
}
pub fn check(c: *verifier.Context) !void {
const m = c.module;
const origin: air.Span = .{ .line = 1, .col = 1 };
@@ -45,10 +74,15 @@ pub fn check(c: *verifier.Context) !void {
};
}
try limit(c, f.span, "instructions per function", Limits.insts, n);
var frame: u64 = 0;
for (f.blocks) |b| for (b.insts) |inst| if (inst.op == .local_alloc) {
frame +|= accountedSize(m, inst.op.local_alloc, 0);
};
try limit(c, f.span, "local frame bytes", Limits.local_frame, frame);
}
}
fn limit(c: *verifier.Context, span: air.Span, name: []const u8, max: usize, found: usize) !void {
fn limit(c: *verifier.Context, span: air.Span, name: []const u8, max: u64, found: u64) !void {
if (found <= max) return;
try c.report("E5101", span, "deterministic verifier resource limit exceeded", &.{
.{ .name = "limit", .value = .{ .str = name } },
@@ -65,3 +99,17 @@ test "too many parameters" {
try src.appendSlice(std.testing.allocator, ") -> void\neffects []\nentry:\n ret\n");
try verifier.expectCodes(src.items, &.{"E5101"});
}
test "local frame limit" {
const h = "module t\nair 0\nlang 0.1\nfeatures [arrays, ownership]\n";
try verifier.expectCodes(h ++ "fn @f() -> void\neffects []\nentry:\n %a = local.alloc array<u8, 1048576>\n ret\n", &.{});
try verifier.expectCodes(h ++ "fn @f() -> void\neffects []\nentry:\n %a = local.alloc array<u8, 1048576>\n %b = local.alloc u8\n ret\n", &.{"E5101"});
try verifier.expectCodes(h ++ "fn @f() -> void\neffects []\nentry:\n %a = local.alloc array<usize, 131073>\n ret\n", &.{"E5101"});
}
test "accounted sizes" {
const m: air.Module = .{ .name = "t", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{}, .types = &.{}, .functions = &.{} };
try std.testing.expectEqual(@as(u64, 8), accountedSize(m, .{ .int = .isize }, 0));
try std.testing.expectEqual(@as(u64, 16), accountedSize(m, .{ .int = .u128 }, 0));
try std.testing.expectEqual(@as(u64, 1), accountedSize(m, .bool, 0));
}