verifier: resource limits, CFG, SSA dominance and types (P0-7..P0-10)
- verifier.zig: staged pipeline per spec 07 §8.6, deterministic order - budget.zig: fixed limits from spec 08 §7 (E5101) - cfg.zig: terminators, branch arity, switch/enum.switch shape (E5002) - ssa.zig: Cooper-Harvey-Kennedy dominators, use dominance (E5001) - types.zig: operand/result types, casts, calls, returns, recursive aggregates (E1001, E1002, E1003) - check.zig runs parse -> verify; seed conformance tests get module headers; tests for unimplemented phases report PENDING
This commit is contained in:
1 parent
ef6a2c5475
commit
50bf990355
14 files changed
+892
-11
No files matched your search
@@ -0,0 +1,67 @@
|
||||
//! Deterministic verifier resource limits (spec 08 §7, E5101).
|
||||
//!
|
||||
//! Limits are fixed by the spec so that no flag can change which programs
|
||||
//! are accepted.
|
||||
|
||||
const std = @import("std");
|
||||
const air = @import("../air.zig");
|
||||
const verifier = @import("../verifier.zig");
|
||||
|
||||
pub const Limits = struct {
|
||||
pub const functions = 65_536;
|
||||
pub const types = 65_536;
|
||||
pub const members = 256; // fields, variants, payload values
|
||||
pub const params = 64; // per function or block; arguments per call or branch
|
||||
pub const blocks = 16_384;
|
||||
pub const insts = 262_144;
|
||||
pub const cases = 4_096;
|
||||
};
|
||||
|
||||
pub fn check(c: *verifier.Context) !void {
|
||||
const m = c.module;
|
||||
const origin: air.Span = .{ .line = 1, .col = 1 };
|
||||
try limit(c, origin, "functions per module", Limits.functions, m.functions.len);
|
||||
try limit(c, origin, "type declarations per module", Limits.types, m.types.len);
|
||||
for (m.types) |d| switch (d.kind) {
|
||||
.@"struct" => |fs| try limit(c, d.span, "fields per struct", Limits.members, fs.len),
|
||||
.@"enum" => |vs| {
|
||||
try limit(c, d.span, "variants per enum", Limits.members, vs.len);
|
||||
for (vs) |v| try limit(c, d.span, "payload values per variant", Limits.members, v.payload.len);
|
||||
},
|
||||
};
|
||||
for (m.functions) |f| {
|
||||
try limit(c, f.span, "parameters per function", Limits.params, f.params.len);
|
||||
try limit(c, f.span, "blocks per function", Limits.blocks, f.blocks.len);
|
||||
var n: usize = 0;
|
||||
for (f.blocks) |b| {
|
||||
n += b.insts.len;
|
||||
try limit(c, b.span, "parameters per block", Limits.params, b.params.len);
|
||||
for (b.insts) |inst| switch (inst.op) {
|
||||
.call => |x| try limit(c, inst.span, "arguments per call", Limits.params, x.args.len),
|
||||
.struct_make => |x| try limit(c, inst.span, "arguments per call", Limits.params, x.args.len),
|
||||
.enum_make => |x| try limit(c, inst.span, "arguments per call", Limits.params, x.args.len),
|
||||
.@"switch" => |x| try limit(c, inst.span, "cases per switch", Limits.cases, x.cases.len),
|
||||
else => {},
|
||||
};
|
||||
}
|
||||
try limit(c, f.span, "instructions per function", Limits.insts, n);
|
||||
}
|
||||
}
|
||||
|
||||
fn limit(c: *verifier.Context, span: air.Span, name: []const u8, max: usize, found: usize) !void {
|
||||
if (found <= max) return;
|
||||
try c.report("E5101", span, "deterministic verifier resource limit exceeded", &.{
|
||||
.{ .name = "limit", .value = .{ .str = name } },
|
||||
.{ .name = "max", .value = .{ .int = @intCast(max) } },
|
||||
.{ .name = "found", .value = .{ .int = @intCast(found) } },
|
||||
});
|
||||
}
|
||||
|
||||
test "too many parameters" {
|
||||
var src: std.ArrayList(u8) = .empty;
|
||||
defer src.deinit(std.testing.allocator);
|
||||
try src.appendSlice(std.testing.allocator, verifier.test_header ++ "fn @f(");
|
||||
for (0..65) |i| try src.print(std.testing.allocator, "{s}%p{d}: u8", .{ if (i == 0) "" else ", ", i });
|
||||
try src.appendSlice(std.testing.allocator, ") -> void\neffects []\nentry:\n ret\n");
|
||||
try verifier.expectCodes(src.items, &.{"E5101"});
|
||||
}
|
||||
Reference in new issue
Block a user