diff --git a/docs/design/air-type-depth-audit.md b/docs/design/air-type-depth-audit.md index babeab8..93afb92 100644 --- a/docs/design/air-type-depth-audit.md +++ b/docs/design/air-type-depth-audit.md @@ -132,3 +132,11 @@ The original generic-use markers are unchanged: applied/static-function types, e Unit tests compare 387 shallow type/expression/pattern/block/module queries against the independent pre-repair derivation, including empty arguments and optional fields. Positive and negative queries traverse 32,768 type, expression and nested-block levels. Every work-allocation request is failed in turn for both outcomes, checking error propagation and cleanup. All units and format checks pass; generic and static-function CLI integration passes 32 and 25 checks. All 1,791 conformance cases pass with exact corpus coverage. All 1,421 public source checks and 506 accepted lowerings retain byte-identical old/new exit/stdout/stderr. The complete 4,096-array check still accepts before and after. The 16,384-array check now reaches a separate confirmed native-stack failure in lowering's resolveType (10,883 frames, exit -6), with no usesGenerics frames or diagnostic JSON. No timeout terminates these probes; only child core capture is disabled. This is progress through the pipeline, not full deep-source acceptance. Q-059's source lowering/remaining traversals and Phase 6 gates remain open. The earlier full per-step collection suite is still in progress. Claude's preceding property review does not cover this change. + +## Source annotation resolution + +The 16,384-array source again aborts before this increment at 24a3876: the fresh traceback contains 5,440 resolveType frames, exit -6 and no diagnostic JSON. Lowering now records array/wrapper continuations, resolves the leaf and constructs the source Ty chain from inside outward. Array-length and known-wrapper checks remain before child resolution; array value-content and AtomicScalar checks remain after it, with the original spans, messages and fields. Nominal names still stop at their declaration index. Pending storage is released on success, rejection or allocation error; metadata and resulting type allocation failures propagate as host OutOfMemory. No source/AIR constructor, semantic limit, diagnostic code, runtime/fuel/effect/ownership rule or bundle is changed. + +Tests compare 1,736 shallow leaf/array/wrapper combinations against the independent pre-repair derivation, including unknown names/constructors, array boundary lengths and competing error priority. A 32,768-level mixed annotation is constructed and inspected iteratively; unknown and nonvalue leaves retain their original diagnostics. Every allocator request is failed in turn, with arena cleanup checked. Type-position and Copy-content CLI integration pass 74 and 119 checks. All units and format checks pass. All 1,791 conformance cases pass with exact corpus coverage; all 1,421 public source checks and 506 accepted lowerings retain byte-identical old/new exit/stdout/stderr. + +Complete checking still accepts the 4,096-array input. At 16,384 it now passes resolveType and aborts in type_properties.firstInvalid (10,001 symbolized frames, exit -6 and no diagnostic JSON). Only child core capture is disabled; no timeout ends a probe. Recursive diagnostic type text and other source property/query paths remain audit candidates. This is not arbitrary-depth source acceptance: Q-059, Q-060's closing validation and Phase 6 gates remain open. Claude's previous nominal-property review covers neither this increment nor the generic-use repair. diff --git a/docs/design/open-questions.md b/docs/design/open-questions.md index 97c3c82..444197e 100644 --- a/docs/design/open-questions.md +++ b/docs/design/open-questions.md @@ -479,6 +479,8 @@ The [source parser increment](air-type-depth-audit.md#source-type-syntax-parser) The [source generic-use increment](air-type-depth-audit.md#source-generic-use-detection) replaces the confirmed recursive AST scan with explicit borrowed work entries. Generic-use markers, field order and the specialization path are unchanged; independent shallow comparisons, deep positive/negative ASTs and failed-allocation cleanup cover the query. The repeated 16,384-array check now passes this stage and confirms the next native-stack failure in lower.resolveType. Source lowering/remaining traversals and the closing audit keep Q-059 open; no generic guard is imposed on monomorphic parsing. +The [source annotation resolution increment](air-type-depth-audit.md#source-annotation-resolution) replaces recursive source-to-Ty construction with explicit continuations while preserving pre/post checks and error positions. Deep isolated resolution succeeds; complete checking exposes the next confirmed failure in type_properties.firstInvalid. Source property traversal, diagnostic text and closing call-path checks remain open; no universal source depth limit is added. + ## Q-060 — Native recursion while materializing runtime values The [executed runtime audit](runtime-value-depth-audit.md) confirms that a verified one-byte value with 32,768 length-one nested arrays aborts inside zeroValue under `aji run --fuel 8`, rather than producing a run record. The instruction has not exhausted fuel. Iterative runtime traversal must preserve initialization, value shape, allocator/root lifetimes, collection safety and instruction accounting; adding a depth trap/acceptance limit needs a normative decision. At that baseline, recursive copying, value sizing, collection and serialization were additional audit candidates with unverified failure paths; the increment below records subsequent executed failures. Compiler type repairs in Q-059 do not resolve Q-060. diff --git a/docs/plan/phase-6-source-language.md b/docs/plan/phase-6-source-language.md index 6a6ab71..1070f5b 100644 --- a/docs/plan/phase-6-source-language.md +++ b/docs/plan/phase-6-source-language.md @@ -460,3 +460,9 @@ Units/format checks and all 1,791 conformance cases pass with exact corpus cover The [Q-059 generic-use increment](../design/air-type-depth-audit.md#source-generic-use-detection) visits immutable AST fields/payloads through explicit work entries, retaining the original markers and field/element order. Metadata OOM propagates and pending entries are released; monomorphic syntax gains no new depth limit. Independent shallow comparisons (387), deep positive/negative types/expressions/blocks and work-allocation failure tests pass. The earlier failing source now passes usesGenerics and confirms the next failure in lower.resolveType at 16,384 array levels; complete checking at 4,096 still accepts. Units/format checks and generic/static-function CLI integration (32/25) pass. All 1,791 conformance cases pass with exact corpus coverage; all 1,421 public source checks and 506 accepted lowerings retain byte-identical old/new exit/stdout/stderr. No normative/bundle/feature/code change or semantic flag is introduced. Q-059's source lowering/closing audit, Q-060's closing validation and Phase 6/contract gates remain open. Claude's property review does not cover this increment. + +## Source annotation resolution (2026-10-10) + +The [Q-059 annotation-resolution increment](../design/air-type-depth-audit.md#source-annotation-resolution) lowers anonymous source types with explicit continuations. Constructor-before-child and content-after-child checks preserve the old error priority and spans; nominal identity and syntax are unchanged. Tests cover 1,736 independent shallow comparisons, 32,768 mixed annotation levels, leaf rejection and allocation-error cleanup. Type-position/Copy-content integration passes 74/119 checks; all units/format checks and 1,791 conformance cases pass with exact corpus coverage. All 1,421 public source checks and 506 accepted lowerings retain byte-identical old/new exit/stdout/stderr. + +The complete 4,096-array check still accepts; 16,384 now reaches the next confirmed native-stack failure in type_properties.firstInvalid. No normative/bundle/feature/code change or accepted-depth limit is introduced. Q-059's source property/closing audit, Q-060's closing validation and Phase 6 gates remain open. No fresh Claude review of this increment is claimed. diff --git a/src/frontend/lower.zig b/src/frontend/lower.zig index c743421..e39705a 100644 --- a/src/frontend/lower.zig +++ b/src/frontend/lower.zig @@ -746,60 +746,81 @@ const Lowerer = struct { }); } - fn resolveType(l: *Lowerer, t: ast.Type) Error!Ty { - switch (t.kind) { - .applied => return l.fail("E7002", t.span, "unknown generic type", &.{}), - .function_ref => return l.invalid(.invalid_static_function, t.span, "static functions are not runtime types", &.{}), - .name => |n| { - if (isIntName(n)) return .{ .int = n }; - if (std.mem.eql(u8, n, "bool")) return .bool; - if (std.mem.eql(u8, n, "void")) return .void; - if (std.mem.eql(u8, n, "never")) return .never; - if (l.enumOrStruct(n, t.span)) |ty| return ty; - if (std.mem.eql(u8, n, "region")) return .region; - if (std.meta.stringToEnum(authority.Builtin, n)) |b| return .{ .builtin = b }; - if (std.mem.eql(u8, n, "stream")) return .{ .resource = .stream }; - if (std.mem.eql(u8, n, "listener")) return .{ .resource = .listener }; - return l.fail("E7002", t.span, "unknown type", &.{.{ .name = "name", .value = n }}); - }, + const TypeWrapper = enum { ref, mut, slice, slice_mut, own, own_array, buffer, task, sender, receiver, mutex, island, frozen, arc, iref, atomic }; + const TypeResolutionFrame = union(enum) { + array: struct { len: u64, elem_span: Span }, + wrapped: struct { which: TypeWrapper, span: Span }, + }; + + fn resolveType(l: *Lowerer, annotation: ast.Type) Error!Ty { + var pending: std.ArrayList(TypeResolutionFrame) = .empty; + defer pending.deinit(l.arena); + var t = annotation; + // Validate each constructor before descending; content checks and + // construction happen while unwinding, in the original order. + var ty: Ty = leaf: while (true) { + switch (t.kind) { + .applied => return l.fail("E7002", t.span, "unknown generic type", &.{}), + .function_ref => return l.invalid(.invalid_static_function, t.span, "static functions are not runtime types", &.{}), + .name => |n| { + if (isIntName(n)) break :leaf .{ .int = n }; + if (std.mem.eql(u8, n, "bool")) break :leaf .bool; + if (std.mem.eql(u8, n, "void")) break :leaf .void; + if (std.mem.eql(u8, n, "never")) break :leaf .never; + if (l.enumOrStruct(n, t.span)) |named| break :leaf named; + if (std.mem.eql(u8, n, "region")) break :leaf .region; + if (std.meta.stringToEnum(authority.Builtin, n)) |b| break :leaf .{ .builtin = b }; + if (std.mem.eql(u8, n, "stream")) break :leaf .{ .resource = .stream }; + if (std.mem.eql(u8, n, "listener")) break :leaf .{ .resource = .listener }; + return l.fail("E7002", t.span, "unknown type", &.{.{ .name = "name", .value = n }}); + }, + .array => |a| { + if (a.len == 0 or a.len > (@as(u64, 1) << 32)) return l.fail("E7005", t.span, "array length must be between 1 and 2^32", &.{}); + try pending.append(l.arena, .{ .array = .{ .len = a.len, .elem_span = a.elem.span } }); + t = a.elem.*; + }, + .wrapped => |w| { + const which = std.meta.stringToEnum(TypeWrapper, w.wrapper) orelse return l.notYet(t.span, "this type (later layers)"); + try pending.append(l.arena, .{ .wrapped = .{ .which = which, .span = t.span } }); + t = w.inner.*; + }, + .cap => |k| { + if (authority.kindIndex(k) == null) return l.fail("E7002", t.span, "unknown capability kind", &.{.{ .name = "capability_kind", .value = k }}); + break :leaf .{ .cap = k }; + }, + .file => |m| { + const r: authority.Resource = if (std.mem.eql(u8, m, "read")) .file_read else if (std.mem.eql(u8, m, "write")) .file_write else if (std.mem.eql(u8, m, "append")) .file_append else return l.fail("E7002", t.span, "unknown file mode (read, write, append)", &.{.{ .name = "mode", .value = m }}); + break :leaf .{ .resource = r }; + }, + } + }; + while (pending.pop()) |frame| switch (frame) { .array => |a| { - if (a.len == 0 or a.len > (@as(u64, 1) << 32)) return l.fail("E7005", t.span, "array length must be between 1 and 2^32", &.{}); - const elem = try l.resolveType(a.elem.*); - if (elem == .void or elem == .never) return l.fail("E7005", a.elem.span, "an array element needs a value type", &.{}); - return l.arrayOf(elem, a.len); + if (ty == .void or ty == .never) return l.fail("E7005", a.elem_span, "an array element needs a value type", &.{}); + ty = try l.arrayOf(ty, a.len); }, .wrapped => |w| { - const Wr = enum { ref, mut, slice, slice_mut, own, own_array, buffer, task, sender, receiver, mutex, island, frozen, arc, iref, atomic }; - const which = std.meta.stringToEnum(Wr, w.wrapper) orelse return l.notYet(t.span, "this type (later layers)"); - const in = try l.resolveType(w.inner.*); - return switch (which) { - .ref => l.wrap(.ref, in), - .mut => l.wrap(.mut, in), - .slice => l.wrap(.slice, in), - .slice_mut => l.wrap(.slice_mut, in), - .own => l.wrap(.own, in), - .own_array => l.wrap(.own_array, in), - .buffer => l.wrap(.buffer, in), - .task => l.wrap(.task, in), - .sender => l.wrap(.sender, in), - .receiver => l.wrap(.receiver, in), - .mutex => l.wrap(.mutex, in), - .island => l.wrap(.island, in), - .frozen => l.wrap(.frozen, in), - .arc => l.wrap(.arc, in), - .iref => l.wrap(.iref, in), - .atomic => if (atomicScalar(in)) l.wrap(.atomic, in) else l.fail("E7005", t.span, "atomic needs bool or an integer of at most 64 bits", &.{.{ .name = "found", .value = l.diagnosticTyText(in) }}), + ty = try switch (w.which) { + .ref => l.wrap(.ref, ty), + .mut => l.wrap(.mut, ty), + .slice => l.wrap(.slice, ty), + .slice_mut => l.wrap(.slice_mut, ty), + .own => l.wrap(.own, ty), + .own_array => l.wrap(.own_array, ty), + .buffer => l.wrap(.buffer, ty), + .task => l.wrap(.task, ty), + .sender => l.wrap(.sender, ty), + .receiver => l.wrap(.receiver, ty), + .mutex => l.wrap(.mutex, ty), + .island => l.wrap(.island, ty), + .frozen => l.wrap(.frozen, ty), + .arc => l.wrap(.arc, ty), + .iref => l.wrap(.iref, ty), + .atomic => if (atomicScalar(ty)) l.wrap(.atomic, ty) else l.fail("E7005", w.span, "atomic needs bool or an integer of at most 64 bits", &.{.{ .name = "found", .value = l.diagnosticTyText(ty) }}), }; }, - .cap => |k| { - if (authority.kindIndex(k) == null) return l.fail("E7002", t.span, "unknown capability kind", &.{.{ .name = "capability_kind", .value = k }}); - return .{ .cap = k }; - }, - .file => |m| { - const r: authority.Resource = if (std.mem.eql(u8, m, "read")) .file_read else if (std.mem.eql(u8, m, "write")) .file_write else if (std.mem.eql(u8, m, "append")) .file_append else return l.fail("E7002", t.span, "unknown file mode (read, write, append)", &.{.{ .name = "mode", .value = m }}); - return .{ .resource = r }; - }, - } + }; + return ty; } // ------------------------------------------------------------ functions @@ -4240,3 +4261,191 @@ test "defensive nonmaterializable moves retain invalid_move even in generic tran try std.testing.expectEqual(@as(usize, 0), l.out.items.len); }; } + +// Independent pre-repair derivation, used only on shallow test trees. +const ReferenceTypeResolution = struct { + fn resolveType(l: *Lowerer, t: ast.Type) Error!Ty { + switch (t.kind) { + .applied => return l.fail("E7002", t.span, "unknown generic type", &.{}), + .function_ref => return l.invalid(.invalid_static_function, t.span, "static functions are not runtime types", &.{}), + .name => |n| { + if (isIntName(n)) return .{ .int = n }; + if (std.mem.eql(u8, n, "bool")) return .bool; + if (std.mem.eql(u8, n, "void")) return .void; + if (std.mem.eql(u8, n, "never")) return .never; + if (l.enumOrStruct(n, t.span)) |ty| return ty; + if (std.mem.eql(u8, n, "region")) return .region; + if (std.meta.stringToEnum(authority.Builtin, n)) |b| return .{ .builtin = b }; + if (std.mem.eql(u8, n, "stream")) return .{ .resource = .stream }; + if (std.mem.eql(u8, n, "listener")) return .{ .resource = .listener }; + return l.fail("E7002", t.span, "unknown type", &.{.{ .name = "name", .value = n }}); + }, + .array => |a| { + if (a.len == 0 or a.len > (@as(u64, 1) << 32)) return l.fail("E7005", t.span, "array length must be between 1 and 2^32", &.{}); + const elem = try ReferenceTypeResolution.resolveType(l, a.elem.*); + if (elem == .void or elem == .never) return l.fail("E7005", a.elem.span, "an array element needs a value type", &.{}); + return l.arrayOf(elem, a.len); + }, + .wrapped => |w| { + const Wr = enum { ref, mut, slice, slice_mut, own, own_array, buffer, task, sender, receiver, mutex, island, frozen, arc, iref, atomic }; + const which = std.meta.stringToEnum(Wr, w.wrapper) orelse return l.notYet(t.span, "this type (later layers)"); + const in = try ReferenceTypeResolution.resolveType(l, w.inner.*); + return switch (which) { + .ref => l.wrap(.ref, in), + .mut => l.wrap(.mut, in), + .slice => l.wrap(.slice, in), + .slice_mut => l.wrap(.slice_mut, in), + .own => l.wrap(.own, in), + .own_array => l.wrap(.own_array, in), + .buffer => l.wrap(.buffer, in), + .task => l.wrap(.task, in), + .sender => l.wrap(.sender, in), + .receiver => l.wrap(.receiver, in), + .mutex => l.wrap(.mutex, in), + .island => l.wrap(.island, in), + .frozen => l.wrap(.frozen, in), + .arc => l.wrap(.arc, in), + .iref => l.wrap(.iref, in), + .atomic => if (atomicScalar(in)) l.wrap(.atomic, in) else l.fail("E7005", t.span, "atomic needs bool or an integer of at most 64 bits", &.{.{ .name = "found", .value = l.diagnosticTyText(in) }}), + }; + }, + .cap => |k| { + if (authority.kindIndex(k) == null) return l.fail("E7002", t.span, "unknown capability kind", &.{.{ .name = "capability_kind", .value = k }}); + return .{ .cap = k }; + }, + .file => |m| { + const r: authority.Resource = if (std.mem.eql(u8, m, "read")) .file_read else if (std.mem.eql(u8, m, "write")) .file_write else if (std.mem.eql(u8, m, "append")) .file_append else return l.fail("E7002", t.span, "unknown file mode (read, write, append)", &.{.{ .name = "mode", .value = m }}); + return .{ .resource = r }; + }, + } + } +}; + +fn expectTypeResolutionMatches(arena: Allocator, m: ast.Module, t: ast.Type) !void { + const names = try arena.alloc([]const u8, m.types.len); + for (m.types, names) |declaration, *name| name.* = try std.fmt.allocPrint(arena, "@{s}", .{declaration.name}); + var original: Lowerer = .{ .arena = arena, .m = m, .typeNames = names }; + var current: Lowerer = .{ .arena = arena, .m = m, .typeNames = names }; + var original_error: ?Error = null; + var current_error: ?Error = null; + const before = ReferenceTypeResolution.resolveType(&original, t) catch |err| blk: { + original_error = err; + break :blk Ty.void; + }; + const after = current.resolveType(t) catch |err| blk: { + current_error = err; + break :blk Ty.void; + }; + try std.testing.expectEqual(original_error, current_error); + if (original_error == null) try std.testing.expect(before.eql(after)); + try std.testing.expectEqualDeep(original.problem, current.problem); + try std.testing.expectEqualDeep(original.unimpl, current.unimpl); +} + +test "source type resolution preserves shallow types and diagnostic priority" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + const m = (try parse_mod.parse(a, "module resolution\nstruct S { x: u8 }\nfn main() -> void effects [] {}\n")).ok; + const leaf_span: Span = .{ .start = .{ .line = 7, .col = 9 }, .end = .{ .line = 7, .col = 12 }, .file = "annotation.aji" }; + const outer_span: Span = .{ .start = .{ .line = 6, .col = 3 }, .end = .{ .line = 8, .col = 17 }, .file = "annotation.aji" }; + var leaves: std.ArrayList(ast.Type) = .empty; + for (int_types ++ [_][]const u8{ "bool", "void", "never", "region", "S", "alloc_error", "cap_error", "io_error", "stream", "listener", "missing" }) |name| { + try leaves.append(a, .{ .span = leaf_span, .kind = .{ .name = name } }); + } + for ([_][]const u8{ "mem.alloc", "unknown.kind" }) |kind| try leaves.append(a, .{ .span = leaf_span, .kind = .{ .cap = kind } }); + for ([_][]const u8{ "read", "write", "append", "unknown" }) |mode| try leaves.append(a, .{ .span = leaf_span, .kind = .{ .file = mode } }); + try leaves.append(a, .{ .span = leaf_span, .kind = .{ .applied = .{ .name = "Missing", .args = &.{} } } }); + try leaves.append(a, .{ .span = leaf_span, .kind = .{ .function_ref = .{ .name = "operation" } } }); + const wrappers = comptime std.meta.fieldNames(Lowerer.TypeWrapper) ++ [_][]const u8{"unknown_wrapper"}; + var comparisons: usize = 0; + for (leaves.items) |*leaf| { + try expectTypeResolutionMatches(a, m, leaf.*); + comparisons += 1; + for ([_]u64{ 0, 1, @as(u64, 1) << 32, (@as(u64, 1) << 32) + 1 }) |len| { + const array: ast.Type = .{ .span = outer_span, .kind = .{ .array = .{ .elem = leaf, .len = len } } }; + try expectTypeResolutionMatches(a, m, array); + comparisons += 1; + } + for (wrappers) |wrapper| { + const wrapped: ast.Type = .{ .span = outer_span, .kind = .{ .wrapped = .{ .wrapper = wrapper, .inner = leaf } } }; + try expectTypeResolutionMatches(a, m, wrapped); + comparisons += 1; + const outer_array: ast.Type = .{ .span = outer_span, .kind = .{ .array = .{ .elem = &wrapped, .len = 1 } } }; + try expectTypeResolutionMatches(a, m, outer_array); + comparisons += 1; + const bad_array: ast.Type = .{ .span = outer_span, .kind = .{ .array = .{ .elem = leaf, .len = 0 } } }; + const outer_wrapper: ast.Type = .{ .span = outer_span, .kind = .{ .wrapped = .{ .wrapper = wrapper, .inner = &bad_array } } }; + try expectTypeResolutionMatches(a, m, outer_wrapper); + comparisons += 1; + } + } + try std.testing.expectEqual(@as(usize, 1736), comparisons); +} + +test "source type resolution constructs deep types and preserves leaf errors iteratively" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + const span: Span = .{ .start = .{ .line = 2, .col = 3 }, .end = .{ .line = 2, .col = 9 } }; + var leaf: ast.Type = .{ .span = span, .kind = .{ .name = "u8" } }; + const nodes = try a.alloc(ast.Type, 32_768); + var child: *const ast.Type = &leaf; + for (nodes, 0..) |*node, i| { + node.* = .{ .span = span, .kind = if (i % 2 == 0) .{ .array = .{ .elem = child, .len = i + 1 } } else .{ .wrapped = .{ .wrapper = "ref", .inner = child } } }; + child = node; + } + var l: Lowerer = .{ .arena = a, .m = .{ .name = "resolution", .types = &.{}, .functions = &.{} } }; + var ty = try l.resolveType(child.*); + var remaining = nodes.len; + while (remaining != 0) { + remaining -= 1; + if (remaining % 2 == 0) { + try std.testing.expect(ty == .array); + try std.testing.expectEqual(@as(u64, remaining + 1), ty.array.len); + ty = ty.array.elem; + } else { + try std.testing.expect(ty == .ref); + ty = ty.ref.*; + } + } + try std.testing.expectEqualStrings("u8", ty.int); + leaf.kind = .{ .name = "missing" }; + try std.testing.expectError(error.Lower, l.resolveType(child.*)); + try std.testing.expectEqualStrings("E7002", l.problem.?.code); + try std.testing.expectEqualDeep(span, l.problem.?.span); + leaf.kind = .{ .name = "never" }; + try std.testing.expectError(error.Lower, l.resolveType(child.*)); + try std.testing.expectEqualStrings("an array element needs a value type", l.problem.?.message); + try std.testing.expectEqualDeep(span, l.problem.?.span); +} + +test "source type resolution allocation errors propagate and arena storage is released" { + var scratch: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer scratch.deinit(); + const span: Span = .{ .start = .{ .line = 2, .col = 1 }, .end = .{ .line = 2, .col = 2 } }; + const leaf: ast.Type = .{ .span = span, .kind = .{ .name = "u8" } }; + const nodes = try scratch.allocator().alloc(ast.Type, 256); + var child: *const ast.Type = &leaf; + for (nodes, 0..) |*node, i| { + node.* = .{ .span = span, .kind = if (i % 2 == 0) .{ .array = .{ .elem = child, .len = 1 } } else .{ .wrapped = .{ .wrapper = "ref", .inner = child } } }; + child = node; + } + var fail_index: usize = 0; + while (true) : (fail_index += 1) { + try std.testing.expect(fail_index < 100); + var failing: std.testing.FailingAllocator = .init(std.testing.allocator, .{ .fail_index = fail_index }); + var arena: std.heap.ArenaAllocator = .init(failing.allocator()); + var l: Lowerer = .{ .arena = arena.allocator(), .m = .{ .name = "resolution", .types = &.{}, .functions = &.{} } }; + const result = l.resolveType(child.*); + if (failing.has_induced_failure) { + try std.testing.expectError(error.OutOfMemory, result); + try std.testing.expect(l.problem == null); + } else { + _ = try result; + } + arena.deinit(); + try std.testing.expectEqual(failing.allocated_bytes, failing.freed_bytes); + if (!failing.has_induced_failure) break; + } +}