cli: write composed specialization identities iteratively
This commit is contained in:
1 parent
f5e2af15e8
commit
d98ddbc073
7 files changed
+284
-37
No files matched your search
@@ -194,3 +194,13 @@ The confirmed Lowerer.zeroValue failure is repaired by counting the array chain,
|
||||
Independent shallow comparison with the old derivation covers all leaves/wrappers and array lengths including zero/max-u64, reserved SSA-name collisions and exact error objects. A 1,024-level supported helper emits independently assembled exact instructions, preserving the original outer type pointer. A 65,536-level unsupported helper rejects without allocating even with a failing allocator; emitted prefixes and arena cleanup are checked across allocation failures on a supported chain. Units/format checks, independent-error integration (234 checks), reason integration (229 checks over 113 public E7006 fixtures), and all 1,791 conformance cases pass with exact corpus coverage. All 1,421 public source checks and 506 accepted lowerings preserve exact old/new exit/stdout/stderr. Twelve generated source programs preserve byte-identical lowering and 46 old/new run records across zero/final fuel boundaries; their nested u8/bool values are independently checked through depth 512.
|
||||
|
||||
Complete checking of the previously failing 16,384-level source, and a 65,536-level counterpart, now returns exactly one E7006/zero_not_zeroable at 3:32 without stderr. Only child core capture is disabled; no timeout ends a probe. The supported deep-helper result is not a claim of complete CLI acceptance of its varying-length type. Specialization/call-path inventory keeps Q-059 open; Q-056 policy, Q-060 closing validation and Phase 6 gates remain separate. No normative/bundle/feature/code, ownership/runtime/effect or accepted-depth limit changes; no fresh Claude review is claimed.
|
||||
|
||||
## Composed specialization identity
|
||||
|
||||
At f5e2af1, a recursive generic call adding 31 or 63 arrays around T aborts before the fixed active-expansion guard: the 272/432-byte sources produce no JSON and exit -6, with 1,851/2,340 identity frames and 61/39 instantiate frames. Adding one array instead reaches the existing depth-64 E7006; a single 64-array argument reaches the existing structural-traversal E7006. The guarded ty query can return an already composed environment argument, so it does not bound the subsequent recursive identity writer. These are executed failures, not a proposed wider source depth limit. Only child core capture is disabled; no timeout ends probes.
|
||||
|
||||
The identity writer now emits prefixes through a type cursor and stores suffix lengths/spans in explicit arena-owned frames. Its leaf checkpoint and each inner-to-outer closing checkpoint retain the original >16,384-byte test and exact offending span. Named defining-module identities, generated-type/function keys, capability/file spelling and punctuation are unchanged. It does not add a prefix checkpoint or alter expansion/structural/key/count limits, reuse, sorting or SHA-based AIR names. Host OOM propagates before a complete key/module is published; private prefix bytes retain their existing partial-output behavior, and caller-arena lifetime owns the metadata.
|
||||
|
||||
Independent shallow comparisons cover scalar/nominal/generated names, capabilities, file modes, static functions, all wrappers, array lengths and prefixes around the exact byte boundary, including complete error objects and intermediate bytes. Writer-only deep fixtures produce an independently assembled 4,095-array key (16,382 bytes), reject the next array at its outer closing span (16,386 bytes), and reject a 32,768-array prefix at the original leaf checkpoint. These helper fixtures are not full source acceptance claims. Failed allocations check propagated OOM, prefix bytes and arena cleanup. Units/format checks and generic/static-function CLI integration (42/25 checks) pass; both new conformance regressions pin code E7006, and hosted checks pin implementation_limit/name/call-site provenance and identical check/lower/report/run/explore diagnostics.
|
||||
|
||||
Both previously failing growth sources now reach one E7006/implementation_limit at 2:35 without stderr; the one-array and single-64-array results retain their prior behavior. All 1,421 pre-existing public source checks and 506 accepted lowerings retain exact old/new exit/stdout/stderr. The full 1,791-case snapshot plus the two added focused regressions cover all 1,793 current conformance files exactly, with every case passing. Closing call-path inventory keeps Q-059 open; Q-056, Q-060 validation and Phase 6 gates remain separate. No normative/bundle/feature/code, runtime/effect/ownership or accepted-depth limit changes; no fresh Claude review is claimed.
|
||||
@@ -495,6 +495,8 @@ The [remaining source linear-query increment](air-type-depth-audit.md#remaining-
|
||||
|
||||
The [source SSA zero increment](air-type-depth-audit.md#source-ssa-zero-emission) repairs that native failure with explicit parent storage, preserving constant/splat ordering and the implemented leaf classification. Both 16,384/65,536-level checks now return the existing E7006/zero_not_zeroable, with no new traversal allocation for unsupported leaves. Exact emission/error comparisons, supported helper sequencing, OOM cleanup and old/new fuel-boundary runs constrain compatibility. Specialization/call-path inventory keeps Q-059 open; Q-056's source zeroability decision is not resolved here.
|
||||
|
||||
The [composed identity increment](air-type-depth-audit.md#composed-specialization-identity) repairs independently reproduced native failures during expanding generic substitution. Iterative key emission retains postorder byte-limit checks, spans, canonical identities and all existing specialization limits. Two tiny source regressions now reach E7006/implementation_limit instead of aborting; all 1,793 current conformance files are covered by the full prior snapshot plus the two additions. Closing call-path inventory keeps Q-059 open; helper-only deep identity tests are not broader source acceptance claims.
|
||||
|
||||
## 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.
|
||||
|
||||
@@ -502,3 +502,9 @@ The [Q-059 query increment](../design/air-type-depth-audit.md#remaining-source-l
|
||||
## Source SSA zero emission (2026-10-10)
|
||||
|
||||
The [Q-059 zero increment](../design/air-type-depth-audit.md#source-ssa-zero-emission) makes array zero generation iterative, preserving the implemented leaf classification and constant/splat ordering. Deep checks at 16,384/65,536 levels now return one E7006/zero_not_zeroable without stderr. Units/format checks, independent shallow emission/error comparisons, exact 1,024-level helper output, allocation failures, reason/independent-error integration (229/234) and all 1,791 conformance cases with exact coverage pass. All 1,421 source checks and 506 accepted lowerings retain exact old/new exit/stdout/stderr. Twelve generated programs retain exact lowering and 46 old/new fuel-boundary records with independently checked values. Specialization/call-path inventory, Q-056 policy, Q-060 validation and Phase 6 gates remain open. No normative/bundle/feature/code or accepted-depth limit changes; no fresh Claude review is claimed.
|
||||
|
||||
## Composed specialization identity (2026-10-10)
|
||||
|
||||
The [Q-059 identity increment](../design/air-type-depth-audit.md#composed-specialization-identity) repairs native failures on tiny expanding-substitution sources. Key emission is iterative; canonical bytes, postorder size/error-span checks, reuse/names and all existing specialization limits remain unchanged. Two permanent conformance cases and hosted CLI checks retain one E7006/implementation_limit at the call site across all rejection entry points.
|
||||
|
||||
Units/format checks, shallow/deep key-boundary and OOM tests, generic/static-function integration (42/25), and old/new checks/lowerings over the pre-existing source corpus (1,421/506) pass. The full 1,791-case snapshot plus the two focused additions cover all 1,793 current conformance files exactly. Closing call-path inventory, Q-056 policy, Q-060 validation and Phase 6 gates remain open. No normative/bundle/feature/code or accepted-depth limit changes; no fresh Claude review is claimed.
|
||||
+235
-37
@@ -451,44 +451,60 @@ const Generator = struct {
|
||||
return null;
|
||||
}
|
||||
|
||||
fn identity(g: *Generator, t: ast.Type, out: *std.ArrayList(u8)) Error!void {
|
||||
switch (t.kind) {
|
||||
.name => |name| {
|
||||
if (g.typeDecl(name, t.span)) |d| {
|
||||
if (std.mem.indexOfScalar(u8, d.name, '.') == null) try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "{s}.", .{g.m.name}));
|
||||
try out.appendSlice(g.arena, d.name);
|
||||
} else if (g.instanceTypeKey(name)) |key| {
|
||||
try out.appendSlice(g.arena, key[5..]);
|
||||
} else try out.appendSlice(g.arena, name);
|
||||
},
|
||||
.array => |a| {
|
||||
try out.appendSlice(g.arena, "[");
|
||||
try g.identity(a.elem.*, out);
|
||||
try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, ";{d}]", .{a.len}));
|
||||
},
|
||||
.wrapped => |w| {
|
||||
try out.appendSlice(g.arena, w.wrapper);
|
||||
try out.append(g.arena, '<');
|
||||
try g.identity(w.inner.*, out);
|
||||
try out.append(g.arena, '>');
|
||||
},
|
||||
.cap => |k| try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "cap<{s}>", .{k})),
|
||||
.file => |mode| try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "file<{s}>", .{mode})),
|
||||
.applied => unreachable,
|
||||
.function_ref => |f| {
|
||||
try out.appendSlice(g.arena, "fn ");
|
||||
const instance_key = for (g.instances.items) |instance| {
|
||||
if (std.mem.eql(u8, instance.name, f.name)) break instance.key;
|
||||
} else null;
|
||||
if (instance_key) |key| {
|
||||
try out.appendSlice(g.arena, key[3..]);
|
||||
} else {
|
||||
if (std.mem.indexOfScalar(u8, f.name, '.') == null) try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "{s}.", .{g.m.name}));
|
||||
try out.appendSlice(g.arena, f.name);
|
||||
}
|
||||
},
|
||||
fn identity(g: *Generator, initial: ast.Type, out: *std.ArrayList(u8)) Error!void {
|
||||
var pending: std.ArrayList(struct { span: ast.Span, array_len: ?u64 }) = .empty;
|
||||
var t = initial;
|
||||
// Substitution can return a previously composed type whose nesting
|
||||
// exceeds a single guarded ty() traversal. Preserve preorder text and
|
||||
// postorder key checks without growing the native stack.
|
||||
while (true) {
|
||||
switch (t.kind) {
|
||||
.name => |name| {
|
||||
if (g.typeDecl(name, t.span)) |d| {
|
||||
if (std.mem.indexOfScalar(u8, d.name, '.') == null) try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "{s}.", .{g.m.name}));
|
||||
try out.appendSlice(g.arena, d.name);
|
||||
} else if (g.instanceTypeKey(name)) |key| {
|
||||
try out.appendSlice(g.arena, key[5..]);
|
||||
} else try out.appendSlice(g.arena, name);
|
||||
},
|
||||
.array => |a| {
|
||||
try out.appendSlice(g.arena, "[");
|
||||
try pending.append(g.arena, .{ .span = t.span, .array_len = a.len });
|
||||
t = a.elem.*;
|
||||
continue;
|
||||
},
|
||||
.wrapped => |w| {
|
||||
try out.appendSlice(g.arena, w.wrapper);
|
||||
try out.append(g.arena, '<');
|
||||
try pending.append(g.arena, .{ .span = t.span, .array_len = null });
|
||||
t = w.inner.*;
|
||||
continue;
|
||||
},
|
||||
.cap => |k| try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "cap<{s}>", .{k})),
|
||||
.file => |mode| try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "file<{s}>", .{mode})),
|
||||
.applied => unreachable,
|
||||
.function_ref => |f| {
|
||||
try out.appendSlice(g.arena, "fn ");
|
||||
const instance_key = for (g.instances.items) |instance| {
|
||||
if (std.mem.eql(u8, instance.name, f.name)) break instance.key;
|
||||
} else null;
|
||||
if (instance_key) |key| {
|
||||
try out.appendSlice(g.arena, key[3..]);
|
||||
} else {
|
||||
if (std.mem.indexOfScalar(u8, f.name, '.') == null) try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "{s}.", .{g.m.name}));
|
||||
try out.appendSlice(g.arena, f.name);
|
||||
}
|
||||
},
|
||||
}
|
||||
if (out.items.len > 16384) return g.invalid(.implementation_limit, t.span, "canonical specialization key exceeds 16384 bytes", "type");
|
||||
break;
|
||||
}
|
||||
while (pending.pop()) |frame| {
|
||||
if (frame.array_len) |length| {
|
||||
try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, ";{d}]", .{length}));
|
||||
} else try out.append(g.arena, '>');
|
||||
if (out.items.len > 16384) return g.invalid(.implementation_limit, frame.span, "canonical specialization key exceeds 16384 bytes", "type");
|
||||
}
|
||||
if (out.items.len > 16384) return g.invalid(.implementation_limit, t.span, "canonical specialization key exceeds 16384 bytes", "type");
|
||||
}
|
||||
|
||||
fn named(g: *Generator, name: []const u8, args: []const ast.Type, span: ast.Span, env: Env) Error!ast.Type {
|
||||
@@ -862,3 +878,185 @@ test "generic use work metadata errors propagate and temporary entries are relea
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Independent old key writer, used only on shallow test types.
|
||||
const ReferenceIdentity = struct {
|
||||
fn identity(g: *Generator, t: ast.Type, out: *std.ArrayList(u8)) Error!void {
|
||||
switch (t.kind) {
|
||||
.name => |name| {
|
||||
if (g.typeDecl(name, t.span)) |d| {
|
||||
if (std.mem.indexOfScalar(u8, d.name, '.') == null) try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "{s}.", .{g.m.name}));
|
||||
try out.appendSlice(g.arena, d.name);
|
||||
} else if (g.instanceTypeKey(name)) |key| {
|
||||
try out.appendSlice(g.arena, key[5..]);
|
||||
} else try out.appendSlice(g.arena, name);
|
||||
},
|
||||
.array => |a| {
|
||||
try out.appendSlice(g.arena, "[");
|
||||
try ReferenceIdentity.identity(g, a.elem.*, out);
|
||||
try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, ";{d}]", .{a.len}));
|
||||
},
|
||||
.wrapped => |w| {
|
||||
try out.appendSlice(g.arena, w.wrapper);
|
||||
try out.append(g.arena, '<');
|
||||
try ReferenceIdentity.identity(g, w.inner.*, out);
|
||||
try out.append(g.arena, '>');
|
||||
},
|
||||
.cap => |k| try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "cap<{s}>", .{k})),
|
||||
.file => |mode| try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "file<{s}>", .{mode})),
|
||||
.applied => unreachable,
|
||||
.function_ref => |f| {
|
||||
try out.appendSlice(g.arena, "fn ");
|
||||
const instance_key = for (g.instances.items) |instance| {
|
||||
if (std.mem.eql(u8, instance.name, f.name)) break instance.key;
|
||||
} else null;
|
||||
if (instance_key) |key| {
|
||||
try out.appendSlice(g.arena, key[3..]);
|
||||
} else {
|
||||
if (std.mem.indexOfScalar(u8, f.name, '.') == null) try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "{s}.", .{g.m.name}));
|
||||
try out.appendSlice(g.arena, f.name);
|
||||
}
|
||||
},
|
||||
}
|
||||
if (out.items.len > 16384) return g.invalid(.implementation_limit, t.span, "canonical specialization key exceeds 16384 bytes", "type");
|
||||
}
|
||||
};
|
||||
|
||||
fn identitySpan(line: u32) ast.Span {
|
||||
return .{ .start = .{ .line = line, .col = 7 }, .end = .{ .line = line, .col = 11 } };
|
||||
}
|
||||
|
||||
fn identityArray(a: A, elem: ast.Type, length: u64, line: u32) A.Error!ast.Type {
|
||||
const child = try a.create(ast.Type);
|
||||
child.* = elem;
|
||||
return .{ .span = identitySpan(line), .kind = .{ .array = .{ .elem = child, .len = length } } };
|
||||
}
|
||||
|
||||
fn identityWrapper(a: A, name: []const u8, elem: ast.Type, line: u32) A.Error!ast.Type {
|
||||
const child = try a.create(ast.Type);
|
||||
child.* = elem;
|
||||
return .{ .span = identitySpan(line), .kind = .{ .wrapped = .{ .wrapper = name, .inner = child } } };
|
||||
}
|
||||
|
||||
fn identityFixture(a: A) A.Error!Generator {
|
||||
const declarations = try a.alloc(ast.TypeDecl, 2);
|
||||
declarations[0] = .{ .name = "Plain", .span = identitySpan(1), .kind = .{ .@"struct" = &.{} } };
|
||||
declarations[1] = .{ .name = "lib.Item", .span = identitySpan(2), .kind = .{ .@"struct" = &.{} } };
|
||||
var g: Generator = .{ .arena = a, .m = .{ .name = "entry", .types = declarations, .functions = &.{} } };
|
||||
// Writer fixtures exercise resolved identity lookup, not complete source
|
||||
// validation or publication of these pending synthetic instances.
|
||||
try g.instances.appendSlice(a, &.{
|
||||
.{ .name = "__box", .air_name = "__box_air", .key = "type:lib.Box<u8>" },
|
||||
.{ .name = "__call", .air_name = "__call_air", .key = "fn:lib.call<u8>" },
|
||||
});
|
||||
return g;
|
||||
}
|
||||
|
||||
fn expectIdentityMatches(a: A, fixture: Generator, t: ast.Type, prefix_length: usize) !void {
|
||||
var original = fixture;
|
||||
var current = fixture;
|
||||
var old_out: std.ArrayList(u8) = .empty;
|
||||
var new_out: std.ArrayList(u8) = .empty;
|
||||
try old_out.appendNTimes(a, 'p', prefix_length);
|
||||
try new_out.appendNTimes(a, 'p', prefix_length);
|
||||
const before = ReferenceIdentity.identity(&original, t, &old_out);
|
||||
const after = current.identity(t, &new_out);
|
||||
if (before) |_| try after else |err| try std.testing.expectError(err, after);
|
||||
try std.testing.expectEqualStrings(old_out.items, new_out.items);
|
||||
try std.testing.expectEqualDeep(original.problem, current.problem);
|
||||
try std.testing.expectEqual(original.depth, current.depth);
|
||||
try std.testing.expectEqual(original.type_depth, current.type_depth);
|
||||
}
|
||||
|
||||
test "specialization identity preserves shallow keys and postorder error positions" {
|
||||
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const a = arena.allocator();
|
||||
const fixture = try identityFixture(a);
|
||||
var leaves: std.ArrayList(ast.Type) = .empty;
|
||||
for ([_][]const u8{ "u8", "u64", "usize", "void", "never", "bool", "region", "Plain", "lib.Item", "__box" }) |name| try leaves.append(a, .{ .span = identitySpan(10), .kind = .{ .name = name } });
|
||||
for (authority.kinds) |kind| try leaves.append(a, .{ .span = identitySpan(11), .kind = .{ .cap = kind.name } });
|
||||
for ([_][]const u8{ "read", "write", "append" }) |mode| try leaves.append(a, .{ .span = identitySpan(12), .kind = .{ .file = mode } });
|
||||
for ([_][]const u8{ "call", "lib.call", "__call" }) |name| try leaves.append(a, .{ .span = identitySpan(13), .kind = .{ .function_ref = .{ .name = name } } });
|
||||
for (leaves.items) |leaf| {
|
||||
try expectIdentityMatches(a, fixture, leaf, 0);
|
||||
for ([_]u64{ 0, 1, @as(u64, 1) << 32, std.math.maxInt(u64) }) |length| try expectIdentityMatches(a, fixture, try identityArray(a, leaf, length, 40), 0);
|
||||
for ([_][]const u8{ "ref", "mut", "slice", "slice_mut", "own", "own_array", "buffer", "task", "sender", "receiver", "mutex", "guard", "island", "frozen", "arc", "iref", "atomic" }) |wrapper| {
|
||||
const wrapped = try identityWrapper(a, wrapper, leaf, 50);
|
||||
try expectIdentityMatches(a, fixture, wrapped, 0);
|
||||
try expectIdentityMatches(a, fixture, try identityArray(a, wrapped, 123, 51), 0);
|
||||
try expectIdentityMatches(a, fixture, try identityWrapper(a, wrapper, try identityArray(a, leaf, 456, 52), 53), 0);
|
||||
}
|
||||
}
|
||||
const leaf: ast.Type = .{ .span = identitySpan(10), .kind = .{ .name = "u8" } };
|
||||
const array = try identityArray(a, leaf, 1, 40);
|
||||
const wrapper = try identityWrapper(a, "own", leaf, 50);
|
||||
for ([_]usize{ 16350, 16375, 16380, 16382, 16383, 16384, 16385 }) |prefix| for ([_]ast.Type{ leaf, array, wrapper, try identityWrapper(a, "ref", array, 60), try identityArray(a, wrapper, std.math.maxInt(u64), 70) }) |t| try expectIdentityMatches(a, fixture, t, prefix);
|
||||
}
|
||||
|
||||
test "specialization identity handles composed deep keys without changing the byte limit" {
|
||||
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const a = arena.allocator();
|
||||
const leaf: ast.Type = .{ .span = identitySpan(10), .kind = .{ .name = "u8" } };
|
||||
var t = leaf;
|
||||
for (0..4095) |i| t = try identityArray(a, t, 1, @intCast(i + 100));
|
||||
var g: Generator = .{ .arena = a, .m = .{ .name = "keys", .types = &.{}, .functions = &.{} } };
|
||||
var out: std.ArrayList(u8) = .empty;
|
||||
try g.identity(t, &out);
|
||||
var expected: std.ArrayList(u8) = .empty;
|
||||
try expected.appendNTimes(a, '[', 4095);
|
||||
try expected.appendSlice(a, "u8");
|
||||
for (0..4095) |_| try expected.appendSlice(a, ";1]");
|
||||
try std.testing.expectEqualStrings(expected.items, out.items);
|
||||
try std.testing.expectEqual(@as(usize, 16382), out.items.len);
|
||||
try std.testing.expect(g.problem == null);
|
||||
// The final array suffix is the first postorder checkpoint over the limit.
|
||||
t = try identityArray(a, t, 1, 5000);
|
||||
out.clearRetainingCapacity();
|
||||
try std.testing.expectError(error.InvalidGeneric, g.identity(t, &out));
|
||||
try std.testing.expectEqual(identitySpan(5000), g.problem.?.span);
|
||||
try std.testing.expectEqual(@as(usize, 16386), out.items.len);
|
||||
// Prefixes alone may exceed the limit before the old leaf checkpoint.
|
||||
for (4096..32768) |i| t = try identityArray(a, t, 1, @intCast(i + 100));
|
||||
g.problem = null;
|
||||
out.clearRetainingCapacity();
|
||||
try std.testing.expectError(error.InvalidGeneric, g.identity(t, &out));
|
||||
try std.testing.expectEqual(identitySpan(10), g.problem.?.span);
|
||||
try std.testing.expectEqual(@as(usize, 32770), out.items.len);
|
||||
try std.testing.expectEqualStrings("E7006", g.problem.?.code);
|
||||
try std.testing.expectEqual(lower.InvalidReason.implementation_limit, g.problem.?.reason.?);
|
||||
}
|
||||
|
||||
test "specialization identity OOM propagates with prefix bytes and arena cleanup" {
|
||||
var scratch: std.heap.ArenaAllocator = .init(std.testing.allocator);
|
||||
defer scratch.deinit();
|
||||
const a = scratch.allocator();
|
||||
const fixture = try identityFixture(a);
|
||||
var t: ast.Type = .{ .span = identitySpan(10), .kind = .{ .function_ref = .{ .name = "__call" } } };
|
||||
for (0..64) |i| t = if (i % 2 == 0) try identityArray(a, t, std.math.maxInt(u64), @intCast(i + 100)) else try identityWrapper(a, "own", t, @intCast(i + 100));
|
||||
var original = fixture;
|
||||
var expected: std.ArrayList(u8) = .empty;
|
||||
try ReferenceIdentity.identity(&original, t, &expected);
|
||||
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 g = fixture;
|
||||
g.arena = arena.allocator();
|
||||
var out: std.ArrayList(u8) = .empty;
|
||||
const result = g.identity(t, &out);
|
||||
if (failing.has_induced_failure) {
|
||||
try std.testing.expectError(error.OutOfMemory, result);
|
||||
try std.testing.expect(g.problem == null);
|
||||
} else {
|
||||
try result;
|
||||
try std.testing.expectEqualStrings(expected.items, out.items);
|
||||
}
|
||||
try std.testing.expect(std.mem.startsWith(u8, expected.items, out.items));
|
||||
arena.deinit();
|
||||
try std.testing.expectEqual(failing.allocated_bytes, failing.freed_bytes);
|
||||
if (!failing.has_induced_failure) break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §15.3
|
||||
// Substitution composes argument depth across active specializations.
|
||||
// The fixed expansion guard must reject before native stack exhaustion.
|
||||
module test.composed_growth
|
||||
fn grow<T>() -> void effects [] { grow::<[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[T; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]>(); }
|
||||
fn main() -> void effects [] { grow::<u8>(); }
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §15.3
|
||||
// Substitution composes argument depth across active specializations.
|
||||
// The fixed expansion guard must reject before native stack exhaustion.
|
||||
module test.composed_growth
|
||||
fn grow<T>() -> void effects [] { grow::<[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[T; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]; 1]>(); }
|
||||
fn main() -> void effects [] { grow::<u8>(); }
|
||||
@@ -100,4 +100,19 @@ fn main() -> u32 effects [] {
|
||||
entry.write_text("module app.entry\nimport app.lib;\nfn main() -> u64 effects [] { return app.lib.id::<u64>(); }\n")
|
||||
error = json.loads(cli("check", "--manifest", manifest, code=1))
|
||||
assert error["function"] == "app.lib.id<u64>"
|
||||
# Composed arguments can exceed one ty() traversal's depth while the active
|
||||
# specialization stack is still bounded. Every CLI entry rejects identically.
|
||||
for width in (31, 63):
|
||||
source = REPO / f"tests/conformance/source/generics/composed_identity_growth_{width}.aji"
|
||||
lines = source.read_text().splitlines()
|
||||
line = next(i for i, text in enumerate(lines, 1) if text.startswith("fn grow<"))
|
||||
col = lines[line - 1].index("grow::<") + 1
|
||||
expected = cli("check", source, code=1)
|
||||
diagnostics = [json.loads(text) for text in expected.splitlines()]
|
||||
assert len(diagnostics) == 1, diagnostics
|
||||
error = diagnostics[0]
|
||||
assert (error["code"], error["reason"], error["name"]) == ("E7006", "implementation_limit", "grow"), error
|
||||
assert (error["file"], error["line"], error["col"]) == (str(source), line, col), error
|
||||
for command in ("lower", "report", "run", "explore"):
|
||||
assert cli(command, source, code=1) == expected
|
||||
print(f"source generic CLI integration passed ({checks} checks)")
|
||||
Reference in new issue
Block a user