verifier: traverse type validity and layouts iteratively
This commit is contained in:
1 parent
3906ce5a9b
commit
b0cd7d74ff
4 files changed
+228
-51
No files matched your search
@@ -48,3 +48,13 @@ The allocation-free fallback folds anonymous chains using a saturated affine map
|
||||
Unit cases cover 32,768 anonymous levels, 32,768 nominal declarations, zero/overflow behavior, null-result reuse, shared-content constructor identities and rebuilding a forged anonymous cache. Two AIR/source pairs additionally preserve acceptance of sixty-four huge arrays over an empty record and E5101 for the same chain over u64. All four new fixtures pass GC-before-each-step checking; the rejection adds a verified same-code twin. The existing full 1,765-case conformance snapshot and sixteen focused nested-size/heap-quota cases pass, and all 364 pre-existing AIR checks retain exact old/new outputs. The full snapshot plus four focused fixtures cover all 1,769 current conformance cases; test-extended also passes. These tests confirm the metric and cache behavior, not the whole Q-059 pipeline.
|
||||
|
||||
At depth 4,096 the complete check still accepts. At depth 16,384 it now reaches type validity and aborts with 8,711 wellFormed frames in verifier/types.zig, rather than sizeQuery/sizeValue. The size failure is removed; validity/property/equality/formatting and uncached nominal traversal remain open. No syntax-depth limit, semantic feature, public code or bundle text is added.
|
||||
|
||||
## Type-validity and finite-layout repair
|
||||
|
||||
Type-position validation and generic-argument array-length checking now walk anonymous chains iteratively. The order of per-node checks, the transition to each inner position, and the graph-owner stop remain unchanged: graph content is checked for IslandSafe and is not rechecked as an ordinary member. Property predicates called by those checks are a separate traversal obligation.
|
||||
|
||||
Finite-layout checking now uses suspended DFS frames for nominal declarations, retaining field order, enum variant/payload order, empty variants and the original grey/black cycle behavior. An active declaration continues its remaining siblings after a back edge marks it black. Anonymous layout edges are iterative too. Arrays always follow their element; the original ownership/borrow wrapper set follows its content only with linear_aggregates. Graph owners and atomic cells retain their original layout boundary. No new accepted/rejected type position or cycle rule is introduced.
|
||||
|
||||
Unit cases cover 32,768 anonymous levels, a 32,768-declaration acyclic nominal chain, a deep anonymous self-cycle, the wrapper feature gate, graph validation's single E2111 and diagnostic order through siblings after back edges. Unit/format checks and all 1,769 conformance cases pass. All 366 public conformance AIR checks retain exact old/new exit status, stdout and stderr. An additional 48 generated mixed struct/enum cyclic graphs retain exact old/new outputs, including cycle selection and order.
|
||||
|
||||
The complete 4,096-depth check still accepts. At 16,384 it passes wellFormed and then aborts in Module.isLinearType: the symbolized traceback contains 10,001 isLinearType frames, no JSON diagnostics and exit -6. The probe stops there; 32,768 is not claimed to pass the complete pipeline. This confirms the next property-query failure, while equality, formatting and uncached nominal traversals also remain open. Q-059 is not resolved. No syntax-depth limit, semantic feature, public diagnostic code or bundle text is added.
|
||||
@@ -462,3 +462,5 @@ Source inspection during Q-058 finds recursive `parseType` in `src/air/parse.zig
|
||||
Audit parser and subsequent type traversals before claiming bounded processing for arbitrary AIR type syntax. Iterative traversal could preserve accepted syntax; imposing a new acceptance limit instead needs normative spec 08 resource rules and fixed diagnostic facts. Q-058 does not add such a limit or claim to resolve this separate issue.
|
||||
|
||||
The [size-query increment](air-type-depth-audit.md#size-query-repair) removes recursive verifier sizing and inner-budget visiting, preserves nominal-depth/overflow/zero semantics, and adds immutable anonymous-node cache entries. Unit queries handle 32,768 anonymous and nominal levels; AIR/source zero/overflow fixtures and exact old/new output comparisons constrain compatibility. A repeated 16,384-depth CLI probe now aborts in verifier wellFormed, confirming the next native-recursion failure. Uncached nominal fallback, validity, properties, equality and formatting are still open; Q-059 is not resolved and no new input acceptance limit is introduced.
|
||||
|
||||
The [type-validity increment](air-type-depth-audit.md#type-validity-and-finite-layout-repair) iterates anonymous position/length checks and finite-layout DFS, preserving graph stops, wrapper gates and ordered cycle diagnostics. Deep unit cases cover 32,768 anonymous and nominal levels. Complete checking at 16,384 now passes wellFormed and aborts in Module.isLinearType; property, equality, formatting and uncached nominal queries remain open. No new depth limit or normative rule is introduced.
|
||||
@@ -343,6 +343,8 @@ The [Q-059 type-depth audit](../design/air-type-depth-audit.md) confirms a parse
|
||||
|
||||
The [Q-059 size-query increment](../design/air-type-depth-audit.md#size-query-repair) gives verifier sizing explicit continuations, iterates inner-budget visits and caches anonymous wrapper identities without changing size arithmetic or nominal cycle depth. Unit cases cover 32,768 anonymous/nominal levels, zero leaves, overflow/null caching, constructor identity and forged-cache rebuilding. The existing full 1,765-case snapshot, four new AIR/source zero/overflow fixtures and sixteen focused GC/quota cases pass; together the full/focused runs cover all 1,769 current conformance cases. Unit/format checks and test-extended pass, and 364 pre-existing AIR checks preserve exact old/new output. The new rejection twin brings P6-7 to 97/206, with zero pending, 45 source-error analogues, one source-early analogue and 63 AIR-only cases. A 16,384-depth probe now reaches the next failure in wellFormed; Q-059 and the phase stay open. No normative/bundle/feature or diagnostic code change, and no new syntax-depth limit; no fresh Claude review was available.
|
||||
|
||||
The [Q-059 type-validity increment](../design/air-type-depth-audit.md#type-validity-and-finite-layout-repair) iterates anonymous position/length checks and finite-layout DFS, preserving graph stops, wrapper gates, enum payload order and sibling traversal after cycle back edges. Unit tests cover 32,768 anonymous/nominal levels and ordered cycle diagnostics; all unit/format checks and 1,769/1,769 conformance cases pass. Exact old/new exit/stdout/stderr comparisons pass on 366 public AIR files and 48 generated mixed cyclic graphs. The 16,384-depth CLI probe now passes wellFormed and aborts in Module.isLinearType, confirming the next property traversal failure. Q-059 and Phase 6 remain open; no normative/bundle/feature/code change or new syntax-depth limit, and no fresh Claude review was available.
|
||||
|
||||
Spec 15's initial Phase 6A limits now point to its existing extensions. Its introductory diagnostic rule follows §10 and construct-specific codes; widening reports source E7005 while AIR retains E1002, including the corrected Quick Reference entry. Multi-result bindings include complete unpacking, byte escapes agree with the later exact list, and grammar comments locate graph access in §8. Old incremental limits link buffers/borrow returns to §17/§19. No grammar production, semantic rule or implementation changes. Six existing public fixtures confirm the reported code and deterministic successful AIR; Claude independently audited the corrections. The reference bundle rebuilds; source growth is +50/+47/+58 tokens across the three tokenizers, with unchanged Quick Reference token counts, AIR and std (docs/agent/README.md). P6-1/P6-5 remain open for their unimplemented surfaces.
|
||||
|
||||
## P6-6 contract spec gate (2026-10-09)
|
||||
|
||||
+214
-51
@@ -60,35 +60,82 @@ fn checkDeclarations(c: *Context) !void {
|
||||
|
||||
/// E1003 applies through arrays as well as direct nominal members.
|
||||
pub fn checkFiniteLayouts(c: *Context) !void {
|
||||
const m = c.module;
|
||||
const state = try c.arena.alloc(enum { white, grey, black }, m.types.len);
|
||||
const state = try c.arena.alloc(enum { white, grey, black }, c.module.types.len);
|
||||
@memset(state, .white);
|
||||
for (0..m.types.len) |i| try visitDecl(c, state, @intCast(i));
|
||||
var pending: std.ArrayList(LayoutFrame) = .empty;
|
||||
for (0..c.module.types.len) |i| {
|
||||
try pending.append(c.arena, .{ .decl = @intCast(i) });
|
||||
while (pending.items.len != 0) {
|
||||
const frame = &pending.items[pending.items.len - 1];
|
||||
const d = c.module.types[frame.decl];
|
||||
if (!frame.entered) {
|
||||
if (state[frame.decl] == .black) {
|
||||
_ = pending.pop();
|
||||
continue;
|
||||
}
|
||||
if (state[frame.decl] == .grey) {
|
||||
try c.report("E1003", d.span, "aggregate type contains itself by value", &.{.{ .name = "type", .value = .{ .str = d.name } }});
|
||||
state[frame.decl] = .black;
|
||||
_ = pending.pop();
|
||||
continue;
|
||||
}
|
||||
state[frame.decl] = .grey;
|
||||
frame.entered = true;
|
||||
}
|
||||
if (frame.nextType(d)) |t| {
|
||||
if (layoutTarget(c.module, t)) |child| try pending.append(c.arena, .{ .decl = child });
|
||||
} else {
|
||||
state[frame.decl] = .black;
|
||||
_ = pending.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visitDecl(c: *Context, state: anytype, i: u32) std.mem.Allocator.Error!void {
|
||||
if (state[i] == .black) return;
|
||||
if (state[i] == .grey) {
|
||||
const d = c.module.types[i];
|
||||
try c.report("E1003", d.span, "aggregate type contains itself by value", &.{.{ .name = "type", .value = .{ .str = d.name } }});
|
||||
state[i] = .black;
|
||||
return;
|
||||
}
|
||||
state[i] = .grey;
|
||||
switch (c.module.types[i].kind) {
|
||||
.@"struct" => |fs| for (fs) |f| try visitValue(c, state, f.ty),
|
||||
.@"enum" => |vs| for (vs) |v| for (v.payload) |t| try visitValue(c, state, t),
|
||||
}
|
||||
state[i] = .black;
|
||||
}
|
||||
/// Suspended DFS calls retain field/payload order, including after a back edge
|
||||
/// marks an active declaration black. That active call still visits its siblings.
|
||||
const LayoutFrame = struct {
|
||||
decl: u32,
|
||||
entered: bool = false,
|
||||
next: usize = 0,
|
||||
variant: usize = 0,
|
||||
|
||||
fn visitValue(c: *Context, state: anytype, t: Type) std.mem.Allocator.Error!void {
|
||||
switch (t) {
|
||||
.named => |i| try visitDecl(c, state, i),
|
||||
.array => |a| try visitValue(c, state, a.elem),
|
||||
.own, .own_array, .buffer, .sender, .receiver, .mutex, .ref, .mut, .slice, .slice_mut, .guard, .task, .local => |inner| if (c.module.declares("linear_aggregates")) try visitValue(c, state, inner.*),
|
||||
else => {},
|
||||
fn nextType(f: *LayoutFrame, d: air.TypeDecl) ?Type {
|
||||
switch (d.kind) {
|
||||
.@"struct" => |fs| {
|
||||
if (f.next == fs.len) return null;
|
||||
const t = fs[f.next].ty;
|
||||
f.next += 1;
|
||||
return t;
|
||||
},
|
||||
.@"enum" => |vs| {
|
||||
while (f.variant < vs.len) {
|
||||
const payload = vs[f.variant].payload;
|
||||
if (f.next < payload.len) {
|
||||
const t = payload[f.next];
|
||||
f.next += 1;
|
||||
return t;
|
||||
}
|
||||
f.variant += 1;
|
||||
f.next = 0;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fn layoutTarget(m: air.Module, initial: Type) ?u32 {
|
||||
var t = initial;
|
||||
while (true) switch (t) {
|
||||
.named => |i| return i,
|
||||
.array => |a| t = a.elem,
|
||||
.own, .own_array, .buffer, .sender, .receiver, .mutex, .ref, .mut, .slice, .slice_mut, .guard, .task, .local => |inner| {
|
||||
if (!m.declares("linear_aggregates")) return null;
|
||||
t = inner.*;
|
||||
},
|
||||
else => return null,
|
||||
};
|
||||
}
|
||||
|
||||
pub const Position = enum { member, param, ret, block_param, borrowed };
|
||||
@@ -118,33 +165,39 @@ pub fn innerPosition(tag: std.meta.Tag(Type)) Position {
|
||||
/// - borrows only as parameters, returns and (gated) block parameters,
|
||||
/// never as members (fields, payloads, elements, locals);
|
||||
/// - the inner type of every compound type is a value type.
|
||||
fn wellFormed(c: *Context, span: air.Span, t: Type, pos: Position, owner: []const u8) !void {
|
||||
const ok = allowedPosition(std.meta.activeTag(t), pos, c.module.declares("linear_aggregates"));
|
||||
if (t == .own_array and c.module.declares("linear_aggregates") and c.module.isLinearType(t.own_array.*)) try c.report("E1001", span, "dynamic heap arrays require Copy content", &.{});
|
||||
// An atomic cell holds an AtomicScalar (spec 04 §23).
|
||||
if (t == .atomic and !isAtomicScalar(t.atomic.*)) try c.report("E1001", span, "atomic<T> needs bool or an integer of at most 64 bits", &.{
|
||||
.{ .name = "in", .value = .{ .str = owner } },
|
||||
.{ .name = "found", .value = .{ .str = try c.typeName(t.atomic.*) } },
|
||||
});
|
||||
if (!ok) try c.report("E1001", span, "type not allowed in this position", &.{
|
||||
.{ .name = "in", .value = .{ .str = owner } },
|
||||
.{ .name = "position", .value = .{ .str = @tagName(pos) } },
|
||||
.{ .name = "found", .value = .{ .str = try c.typeName(t) } },
|
||||
});
|
||||
// A graph holds IslandSafe values only (spec 03 §22–§24): reported once,
|
||||
// as E2111, at the type.
|
||||
if (t.isGraphOwner()) {
|
||||
if (!isIslandSafe(c.module, t.inner().?)) try c.report("E2111", span, "a graph holds only plain data and iref handles", &.{
|
||||
fn wellFormed(c: *Context, span: air.Span, initial: Type, initial_pos: Position, owner: []const u8) !void {
|
||||
var t = initial;
|
||||
var pos = initial_pos;
|
||||
while (true) {
|
||||
const ok = allowedPosition(std.meta.activeTag(t), pos, c.module.declares("linear_aggregates"));
|
||||
if (t == .own_array and c.module.declares("linear_aggregates") and c.module.isLinearType(t.own_array.*)) try c.report("E1001", span, "dynamic heap arrays require Copy content", &.{});
|
||||
// An atomic cell holds an AtomicScalar (spec 04 §23).
|
||||
if (t == .atomic and !isAtomicScalar(t.atomic.*)) try c.report("E1001", span, "atomic<T> needs bool or an integer of at most 64 bits", &.{
|
||||
.{ .name = "in", .value = .{ .str = owner } },
|
||||
.{ .name = "found", .value = .{ .str = try c.typeName(t.inner().?) } },
|
||||
.{ .name = "found", .value = .{ .str = try c.typeName(t.atomic.*) } },
|
||||
});
|
||||
return;
|
||||
if (!ok) try c.report("E1001", span, "type not allowed in this position", &.{
|
||||
.{ .name = "in", .value = .{ .str = owner } },
|
||||
.{ .name = "position", .value = .{ .str = @tagName(pos) } },
|
||||
.{ .name = "found", .value = .{ .str = try c.typeName(t) } },
|
||||
});
|
||||
// A graph holds IslandSafe values only (spec 03 §22–§24): reported once,
|
||||
// as E2111, at the type.
|
||||
if (t.isGraphOwner()) {
|
||||
if (!isIslandSafe(c.module, t.inner().?)) try c.report("E2111", span, "a graph holds only plain data and iref handles", &.{
|
||||
.{ .name = "in", .value = .{ .str = owner } },
|
||||
.{ .name = "found", .value = .{ .str = try c.typeName(t.inner().?) } },
|
||||
});
|
||||
return;
|
||||
}
|
||||
// The pointee of ref/mut may be a linear value (`mut<file<read>>`), and
|
||||
// a task may return one; every other compound holds value types only.
|
||||
// Channel elements and mutex contents may be linear (spec 04 §38.1);
|
||||
// their remaining rules are the element rules of `checkElement`.
|
||||
const inner = t.inner() orelse return;
|
||||
pos = innerPosition(std.meta.activeTag(t));
|
||||
t = inner;
|
||||
}
|
||||
// The pointee of ref/mut may be a linear value (`mut<file<read>>`), and
|
||||
// a task may return one; every other compound holds value types only.
|
||||
// Channel elements and mutex contents may be linear (spec 04 §38.1);
|
||||
// their remaining rules are the element rules of `checkElement`.
|
||||
if (t.inner()) |inner| try wellFormed(c, span, inner, innerPosition(std.meta.activeTag(t)), owner);
|
||||
}
|
||||
|
||||
/// Validate a phantom or used source generic argument by ordinary type rules.
|
||||
@@ -152,9 +205,12 @@ pub fn checkTypeArgument(c: *Context, span: air.Span, t: Type) !void {
|
||||
try wellFormed(c, span, t, .param, "generic argument");
|
||||
try argumentLengths(c, span, t);
|
||||
}
|
||||
fn argumentLengths(c: *Context, span: air.Span, t: Type) !void {
|
||||
if (t == .array and (t.array.len == 0 or t.array.len > (1 << 32))) try c.report("E1001", span, "array length outside format-0 range", &.{});
|
||||
if (t.inner()) |inner| try argumentLengths(c, span, inner);
|
||||
fn argumentLengths(c: *Context, span: air.Span, initial: Type) !void {
|
||||
var t = initial;
|
||||
while (true) {
|
||||
if (t == .array and (t.array.len == 0 or t.array.len > (1 << 32))) try c.report("E1001", span, "array length outside format-0 range", &.{});
|
||||
t = t.inner() orelse return;
|
||||
}
|
||||
}
|
||||
|
||||
/// `local.alloc` results are checked separately: their own type is storage.
|
||||
@@ -1181,3 +1237,110 @@ test "aggregates and declarations" {
|
||||
try verifier.expectCodes(h ++ "type @A = struct { b: @B }\ntype @B = enum { X(@A) }\nfn @f() -> void\neffects []\nentry:\n ret\n", &.{"E1003"});
|
||||
try verifier.expectCodes(h ++ "fn @f(%v: void) -> void\neffects []\nentry:\n ret\n", &.{"E1001"});
|
||||
}
|
||||
|
||||
fn nestedArrays(a: std.mem.Allocator, depth: usize, leaf: Type) !Type {
|
||||
const rows = try a.alloc(Type.Array, depth);
|
||||
var t = leaf;
|
||||
for (rows) |*row| {
|
||||
row.* = .{ .elem = t, .len = 1 };
|
||||
t = .{ .array = row };
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
test "deep type positions and argument lengths avoid native recursion" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
var c: Context = .{ .arena = a, .file = "deep.air", .module = .{ .name = "deep", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{"arrays"}, .types = &.{}, .functions = &.{} } };
|
||||
const t = try nestedArrays(a, 32_768, .{ .int = .u8 });
|
||||
try checkTypeArgument(&c, .{ .line = 5, .col = 4 }, t);
|
||||
try std.testing.expectEqual(@as(usize, 0), c.diags.items.len);
|
||||
const bad = try nestedArrays(a, 32_768, .void);
|
||||
try wellFormed(&c, .{ .line = 7, .col = 3 }, bad, .param, "f");
|
||||
try std.testing.expectEqual(@as(usize, 1), c.diags.items.len);
|
||||
try std.testing.expectEqualStrings("E1001", c.diags.items[0].code.id);
|
||||
try std.testing.expectEqual(@as(u32, 7), c.diags.items[0].span.?.line);
|
||||
try std.testing.expectEqual(@as(u32, 3), c.diags.items[0].span.?.col);
|
||||
}
|
||||
|
||||
test "graph type validation retains its stop before ordinary inner positions" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
var c: Context = .{ .arena = a, .file = "graph.air", .module = .{ .name = "graph", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{"linear_aggregates"}, .types = &.{}, .functions = &.{} } };
|
||||
const scalar: Type = .{ .int = .u8 };
|
||||
const borrowed: Type = .{ .ref = &scalar };
|
||||
const graph: Type = .{ .island = &borrowed };
|
||||
try wellFormed(&c, .{ .line = 1, .col = 1 }, graph, .member, "R");
|
||||
try std.testing.expectEqual(@as(usize, 1), c.diags.items.len);
|
||||
try std.testing.expectEqualStrings("E2111", c.diags.items[0].code.id);
|
||||
}
|
||||
|
||||
test "deep nominal layouts and anonymous cycle edges use explicit traversal" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
const count = 32_768;
|
||||
const ds = try a.alloc(air.TypeDecl, count);
|
||||
for (ds, 0..) |*d, i| d.* = .{ .name = "N", .span = .{ .line = 1, .col = 1 }, .kind = .{ .@"struct" = try a.dupe(@import("../air/module.zig").Field, &.{.{ .name = "x", .ty = if (i + 1 == count) .{ .int = .u8 } else .{ .named = @intCast(i + 1) } }}) } };
|
||||
var c: Context = .{ .arena = a, .file = "layout.air", .module = .{ .name = "layout", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{}, .types = ds, .functions = &.{} } };
|
||||
try checkFiniteLayouts(&c);
|
||||
try std.testing.expectEqual(@as(usize, 0), c.diags.items.len);
|
||||
const loop = try nestedArrays(a, 32_768, .{ .named = 0 });
|
||||
ds[0] = .{ .name = "Loop", .span = .{ .line = 8, .col = 6 }, .kind = .{ .@"struct" = try a.dupe(@import("../air/module.zig").Field, &.{.{ .name = "x", .ty = loop }}) } };
|
||||
c.module.types = ds[0..1];
|
||||
try checkFiniteLayouts(&c);
|
||||
try std.testing.expectEqual(@as(usize, 1), c.diags.items.len);
|
||||
try std.testing.expectEqualStrings("E1003", c.diags.items[0].code.id);
|
||||
try std.testing.expectEqual(@as(u32, 8), c.diags.items[0].span.?.line);
|
||||
try std.testing.expectEqual(@as(u32, 6), c.diags.items[0].span.?.col);
|
||||
}
|
||||
|
||||
test "finite-layout wrapper edges retain their feature gate and graph boundary" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
const self: Type = .{ .named = 0 };
|
||||
inline for (.{ .array, .own, .ref, .island, .atomic }) |tag| {
|
||||
const row: Type.Array = .{ .elem = self, .len = 1 };
|
||||
const t: Type = if (tag == .array) .{ .array = &row } else @unionInit(Type, @tagName(tag), &self);
|
||||
for ([_]bool{ false, true }) |enabled| {
|
||||
const ds = [_]air.TypeDecl{.{ .name = "N", .span = .{ .line = 1, .col = 1 }, .kind = .{ .@"struct" = &.{.{ .name = "x", .ty = t }} } }};
|
||||
var c: Context = .{ .arena = a, .file = "edge.air", .module = .{ .name = "edge", .format_version = 0, .lang = .{ 0, 1 }, .features = if (enabled) &.{"linear_aggregates"} else &.{}, .types = &ds, .functions = &.{} } };
|
||||
try checkFiniteLayouts(&c);
|
||||
const cycle = tag == .array or ((tag == .own or tag == .ref) and enabled);
|
||||
try std.testing.expectEqual(@as(usize, if (cycle) 1 else 0), c.diags.items.len);
|
||||
if (cycle) try std.testing.expectEqualStrings("E1003", c.diags.items[0].code.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test "finite-layout diagnostics retain DFS siblings after back edges" {
|
||||
var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
const ds = [_]air.TypeDecl{
|
||||
.{ .name = "A", .span = .{ .line = 1, .col = 1 }, .kind = .{ .@"struct" = &.{
|
||||
.{ .name = "self", .ty = .{ .named = 0 } },
|
||||
.{ .name = "next", .ty = .{ .named = 1 } },
|
||||
} } },
|
||||
.{ .name = "B", .span = .{ .line = 2, .col = 1 }, .kind = .{ .@"enum" = &.{
|
||||
.{ .name = "Empty", .payload = &.{} },
|
||||
.{ .name = "Pair", .payload = &.{ .{ .named = 1 }, .{ .named = 2 } } },
|
||||
.{ .name = "EmptyAgain", .payload = &.{} },
|
||||
.{ .name = "Last", .payload = &.{.{ .named = 3 }} },
|
||||
} } },
|
||||
.{ .name = "C", .span = .{ .line = 3, .col = 1 }, .kind = .{ .@"struct" = &.{.{ .name = "self", .ty = .{ .named = 2 } }} } },
|
||||
.{ .name = "D", .span = .{ .line = 4, .col = 1 }, .kind = .{ .@"struct" = &.{.{ .name = "self", .ty = .{ .named = 3 } }} } },
|
||||
};
|
||||
var c: Context = .{ .arena = a, .file = "order.air", .module = .{ .name = "order", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{}, .types = &ds, .functions = &.{} } };
|
||||
try checkFiniteLayouts(&c);
|
||||
try std.testing.expectEqual(@as(usize, 4), c.diags.items.len);
|
||||
for (c.diags.items, ds) |d, decl| {
|
||||
try std.testing.expectEqualStrings("E1003", d.code.id);
|
||||
try std.testing.expectEqual(decl.span.line, d.span.?.line);
|
||||
try std.testing.expectEqual(decl.span.col, d.span.?.col);
|
||||
try std.testing.expectEqualStrings(decl.name, d.fields[0].value.str);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user