cli: emit source SSA zero iteratively

This commit is contained in:
dev committed 2026-10-10 15:14:49 +03:00
1 parent c1bf99af83
commit f5e2af15e8
4 files changed
+194 -11

No files matched your search

+9 -1
View File
@@ -185,4 +185,12 @@ Call-path inspection finds native recursion in Lowerer.isLinear's array descent
An independent shallow copy of both old queries covers all leaves/wrappers, array lengths, mixed shapes and initial depths around the guard. Deep helper tests traverse 65,536 arrays ending in Copy/linear nominal leaves and 65,536 ref edges under a complete property snapshot of 65,536 declarations. The feature scan retains true at initial depth 32 and false at 33, pinning its inclusive boundary. This constructed snapshot tests the helper stage, not complete CLI acceptance of that module. Units/format checks, source linear/nominal CLI integration (49/110) 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. An independent shallow copy of both old queries covers all leaves/wrappers, array lengths, mixed shapes and initial depths around the guard. Deep helper tests traverse 65,536 arrays ending in Copy/linear nominal leaves and 65,536 ref edges under a complete property snapshot of 65,536 declarations. The feature scan retains true at initial depth 32 and false at 33, pinning its inclusive boundary. This constructed snapshot tests the helper stage, not complete CLI acceptance of that module. Units/format checks, source linear/nominal CLI integration (49/110) 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.
The closing inventory separately confirms source SSA zero generation as a remaining failure: at 16,384 array levels above a Plain record, a var initialized with zero aborts with 10,001 Lowerer.zeroValue frames, exit -6 and no JSON (82,026 input bytes). Its current source rule should report E7006/zero_not_zeroable; AIR's broader zeroability and Q-056 are separate. Only child core capture is disabled; no timeout ends the probe. Source zero emission and the remaining specialization/call-path inventory keep Q-059 open; Q-060 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. The closing inventory separately confirms source SSA zero generation as a remaining failure: at 16,384 array levels above a Plain record, a var initialized with zero aborts with 10,001 Lowerer.zeroValue frames, exit -6 and no JSON (82,026 input bytes). The existing SSA lowering rejects record leaves with E7006/zero_not_zeroable; AIR's broader zeroability and the unresolved source policy Q-056 are separate. Only child core capture is disabled; no timeout ends the probe. Source zero emission and the remaining specialization/call-path inventory keep Q-059 open; Q-060 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.
## Source SSA zero emission
The confirmed Lowerer.zeroValue failure is repaired by counting the array chain, classifying its leaf, then emitting through a single arena-owned table of immutable parent pointers. Unsupported leaves retain the implemented E7006/zero_not_zeroable before any traversal allocation or instruction emission; this does not resolve Q-056 or adopt broader source zeroability. Allowed leaves remain integers and bool. The original constant precedes array.splat instructions from inner to outer, retaining lengths, source type storage, names, spans, feature state and constant-group markers. The table adds only compiler metadata; its OOM propagates the existing host error. Completed private instruction prefixes may survive a later emission OOM as before, but the public lower wrapper returns that error rather than publishing partial AIR. Runtime/verifier rules, allocation authority, copies and fuel events are unchanged.
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.
+2
View File
@@ -493,6 +493,8 @@ The [source equality increment](air-type-depth-audit.md#source-type-equality) re
The [remaining source linear-query increment](air-type-depth-audit.md#remaining-source-linear-queries) replaces array descent and signature feature scanning with allocation-free loops, preserving prepared nominal reads and the module-sized depth guard exactly. No preceding CLI failure in these queries is claimed. The closing inventory independently confirms Lowerer.zeroValue stack exhaustion on 16,384 arrays above a non-zeroable source record. Source zero emission and specialization/call-path inspection keep Q-059 open; this does not resolve Q-056 or change zeroability. The [remaining source linear-query increment](air-type-depth-audit.md#remaining-source-linear-queries) replaces array descent and signature feature scanning with allocation-free loops, preserving prepared nominal reads and the module-sized depth guard exactly. No preceding CLI failure in these queries is claimed. The closing inventory independently confirms Lowerer.zeroValue stack exhaustion on 16,384 arrays above a non-zeroable source record. Source zero emission and specialization/call-path inspection keep Q-059 open; this does not resolve Q-056 or change zeroability.
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.
## Q-060 — Native recursion while materializing runtime values ## 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. 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.
+5 -1
View File
@@ -497,4 +497,8 @@ The [Q-059 equality increment](../design/air-type-depth-audit.md#source-type-equ
## Remaining source linear queries (2026-10-10) ## Remaining source linear queries (2026-10-10)
The [Q-059 query increment](../design/air-type-depth-audit.md#remaining-source-linear-queries) makes array linearity and signature feature discovery iterative, retaining the existing module-sized guard and prepared cache contract. Independent shallow comparisons, deep helper snapshots, units/format checks, source linear/nominal CLI integration (49/110) 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. A separate 16,384-level source zero probe confirms remaining Lowerer.zeroValue stack exhaustion where the current source rule requires E7006/zero_not_zeroable. Zero emission, specialization/call-path inventory, Q-060 validation and Phase 6 gates remain open. No source zeroability, normative/bundle/feature/code or accepted-depth limit changes; no fresh Claude review is claimed. The [Q-059 query increment](../design/air-type-depth-audit.md#remaining-source-linear-queries) makes array linearity and signature feature discovery iterative, retaining the existing module-sized guard and prepared cache contract. Independent shallow comparisons, deep helper snapshots, units/format checks, source linear/nominal CLI integration (49/110) 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. A separate 16,384-level source zero probe confirms remaining Lowerer.zeroValue stack exhaustion before reaching its implemented E7006/zero_not_zeroable leaf rejection. Zero emission, specialization/call-path inventory, Q-060 validation and Phase 6 gates remain open. No source zeroability, normative/bundle/feature/code or accepted-depth limit changes; no fresh Claude review is claimed.
## 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.
+178 -9
View File
@@ -2361,16 +2361,35 @@ const Lowerer = struct {
return st; return st;
} }
fn zeroValue(l: *Lowerer, ty: Ty, base: []const u8, span: Span) Error!Value { fn zeroValue(l: *Lowerer, annotation: Ty, base: []const u8, span: Span) Error!Value {
return switch (ty) { var leaf = annotation;
.int => |n| l.def(base, ty, try l.fmt("const.{s} 0", .{n}), span), var count: usize = 0;
.bool => l.def(base, ty, "const.bool false", span), while (leaf == .array) {
.array => |a| blk: { count += 1;
const z = try l.zeroValue(a.elem, base, span); leaf = leaf.array.elem;
break :blk l.def(base, ty, try l.fmt("array.splat {s} %{s}", .{ try l.tyText(ty), z.name }), span); }
}, // An unsupported leaf rejects before allocating traversal metadata,
else => l.invalid(.zero_not_zeroable, span, "`zero` needs a zeroable type (integers, booleans, arrays of them)", &.{}), // just as the recursive descent did before emitting any instruction.
if (leaf != .int and leaf != .bool) return l.invalid(.zero_not_zeroable, span, "`zero` needs a zeroable type (integers, booleans, arrays of them)", &.{});
const parents = try l.arena.alloc(*const Ty.Arr, count);
var t = annotation;
for (parents) |*parent| {
parent.* = t.array;
t = t.array.elem;
}
var value = switch (leaf) {
.int => |n| try l.def(base, leaf, try l.fmt("const.{s} 0", .{n}), span),
.bool => try l.def(base, leaf, "const.bool false", span),
else => unreachable,
}; };
// Original leaf-first order: one constant followed by each splat,
// retaining the source type nodes, names and source spans.
while (count != 0) {
count -= 1;
const ty: Ty = .{ .array = parents[count] };
value = try l.def(base, ty, try l.fmt("array.splat {s} %{s}", .{ try l.tyText(ty), value.name }), span);
}
return value;
} }
/// A byte string in frame storage: `[u8; N]`, one store per byte (no heap). /// A byte string in frame storage: `[u8; N]`, one store per byte (no heap).
@@ -5048,3 +5067,153 @@ test "source linear queries walk deep arrays and module-sized feature guards" {
try std.testing.expect(!l.needsLinearType(borrowed, 33)); try std.testing.expect(!l.needsLinearType(borrowed, 33));
try std.testing.expect(!l.needsLinearType(.{ .named = 1 }, count + 33)); try std.testing.expect(!l.needsLinearType(.{ .named = 1 }, count + 33));
} }
// Independent original SSA zero lowering, used only on shallow test types.
const ReferenceSourceZero = struct {
fn zeroValue(l: *Lowerer, ty: Ty, base: []const u8, span: Span) Error!Value {
return switch (ty) {
.int => |n| l.def(base, ty, try l.fmt("const.{s} 0", .{n}), span),
.bool => l.def(base, ty, "const.bool false", span),
.array => |a| blk: {
const z = try zeroValue(l, a.elem, base, span);
break :blk l.def(base, ty, try l.fmt("array.splat {s} %{s}", .{ try l.tyText(ty), z.name }), span);
},
else => l.invalid(.zero_not_zeroable, span, "`zero` needs a zeroable type (integers, booleans, arrays of them)", &.{}),
};
}
};
fn expectSourceZeroMatches(a: Allocator, ty: Ty) !void {
const m: ast.Module = .{ .name = "zero", .types = &.{}, .functions = &.{} };
const span: Span = .{ .start = .{ .line = 7, .col = 9 }, .end = .{ .line = 7, .col = 26 } };
const boolean: ast.Type = .{ .span = span, .kind = .{ .name = "bool" } };
const params = [_]ast.Param{ .{ .name = "z_1", .ty = boolean, .span = span }, .{ .name = "z_3", .ty = boolean, .span = span } };
var old: Lowerer = .{ .arena = a, .m = m, .params = &params, .in_constant = 12 };
var current: Lowerer = .{ .arena = a, .m = m, .params = &params, .in_constant = 12 };
old.cur = try old.newBlock("entry", span);
current.cur = try current.newBlock("entry", span);
const before = ReferenceSourceZero.zeroValue(&old, ty, "z", span);
const after = current.zeroValue(ty, "z", span);
if (before) |value| {
const result = try after;
try std.testing.expectEqualStrings(value.name, result.name);
try std.testing.expect(value.ty.eql(result.ty));
if (ty == .array) try std.testing.expect(ty.array == result.ty.array);
} else |err| try std.testing.expectError(err, after);
try std.testing.expectEqualDeep(old.problem, current.problem);
try std.testing.expectEqualDeep(old.blocks.items[0].insts.items, current.blocks.items[0].insts.items);
try std.testing.expectEqual(old.counter, current.counter);
try std.testing.expectEqualDeep(old.uses, current.uses);
}
test "source SSA zero retains shallow instructions, names, types and errors" {
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
const a = arena.allocator();
var l: Lowerer = .{ .arena = a, .m = .{ .name = "zero", .types = &.{}, .functions = &.{} } };
var leaves: std.ArrayList(Ty) = .empty;
for (int_types) |name| try leaves.append(a, .{ .int = name });
try leaves.appendSlice(a, &.{ .bool, .void, .never, .region, .scope, .shield, .{ .named = 0 }, .{ .named = 123 } });
for (authority.kinds) |kind| try leaves.append(a, .{ .cap = kind.name });
inline for (@typeInfo(authority.Builtin).@"enum".field_names) |name| try leaves.append(a, .{ .builtin = @field(authority.Builtin, name) });
inline for (@typeInfo(authority.Resource).@"enum".field_names) |name| try leaves.append(a, .{ .resource = @field(authority.Resource, name) });
inline for (@typeInfo(Ty).@"union".field_names, @typeInfo(Ty).@"union".field_types) |name, FieldType| if (comptime FieldType == *const Ty) try leaves.append(a, try l.wrap(@field(std.meta.Tag(Ty), name), .bool));
for (leaves.items) |leaf| {
try expectSourceZeroMatches(a, leaf);
for ([_]u64{ 0, 1, @as(u64, 1) << 32, std.math.maxInt(u64) }) |length| {
try expectSourceZeroMatches(a, try l.arrayOf(leaf, length));
try expectSourceZeroMatches(a, try l.arrayOf(try l.arrayOf(leaf, length), 7));
}
}
}
test "source SSA zero rejects deep unsupported leaves without traversal allocation" {
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
const a = arena.allocator();
const m: ast.Module = .{ .name = "zero", .types = &.{}, .functions = &.{} };
var builder: Lowerer = .{ .arena = a, .m = m };
var ty: Ty = .{ .named = 0 };
for (0..65_536) |_| ty = try builder.arrayOf(ty, 1);
var failing: std.testing.FailingAllocator = .init(std.testing.allocator, .{ .fail_index = 0 });
var l: Lowerer = .{ .arena = failing.allocator(), .m = m };
const span: Span = .{ .start = .{ .line = 3, .col = 31 }, .end = .{ .line = 3, .col = 100 } };
try std.testing.expectError(error.Lower, l.zeroValue(ty, "z", span));
try std.testing.expectEqualStrings("E7006", l.problem.?.code);
try std.testing.expectEqual(InvalidReason.zero_not_zeroable, l.problem.?.reason.?);
try std.testing.expectEqual(span, l.problem.?.span);
try std.testing.expectEqual(@as(usize, 0), l.problem.?.fields.len);
try std.testing.expectEqual(@as(usize, 0), l.blocks.items.len);
try std.testing.expectEqual(@as(usize, 0), l.counter);
try std.testing.expect(!failing.has_induced_failure);
try std.testing.expectEqual(@as(usize, 0), failing.allocated_bytes);
}
test "source SSA zero emits every supported array in inner-to-outer order" {
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
const a = arena.allocator();
var l: Lowerer = .{ .arena = a, .m = .{ .name = "zero", .types = &.{}, .functions = &.{} } };
const span: Span = .{ .start = .{ .line = 2, .col = 3 }, .end = .{ .line = 2, .col = 9 } };
var ty: Ty = .{ .int = "u8" };
const count = 1024;
for (0..count) |i| ty = try l.arrayOf(ty, i + 1);
l.cur = try l.newBlock("entry", span);
const value = try l.zeroValue(ty, "z", span);
try std.testing.expect(value.ty.array == ty.array);
try std.testing.expectEqualStrings("z_1025", value.name);
const instructions = l.blocks.items[0].insts.items;
try std.testing.expectEqual(@as(usize, count + 1), instructions.len);
try std.testing.expectEqualStrings("%z_1 = const.u8 0", instructions[0].text);
var expected_type: []const u8 = "u8";
for (instructions[1..], 0..) |inst, i| {
expected_type = try std.fmt.allocPrint(a, "array<{s}, {d}>", .{ expected_type, i + 1 });
const expected = try std.fmt.allocPrint(a, "%z_{d} = array.splat {s} %z_{d}", .{ i + 2, expected_type, i + 1 });
try std.testing.expectEqualStrings(expected, inst.text);
}
for (instructions) |inst| {
try std.testing.expectEqual(@as(?Span, span), inst.span);
try std.testing.expectEqual(@as(u32, 0), inst.constant);
}
}
test "source SSA zero OOM propagates with complete instruction prefixes and arena cleanup" {
var scratch: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer scratch.deinit();
const a = scratch.allocator();
const m: ast.Module = .{ .name = "zero", .types = &.{}, .functions = &.{} };
const span: Span = .{ .start = .{ .line = 2, .col = 3 }, .end = .{ .line = 2, .col = 9 } };
var builder: Lowerer = .{ .arena = a, .m = m };
var ty: Ty = .bool;
for (0..64) |i| ty = try builder.arrayOf(ty, i + 1);
builder.cur = try builder.newBlock("entry", span);
_ = try ReferenceSourceZero.zeroValue(&builder, ty, "z", span);
const expected = builder.blocks.items[0].insts.items;
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 = m };
const result: Error!Value = blk: {
l.cur = l.newBlock("entry", span) catch |err| break :blk err;
break :blk l.zeroValue(ty, "z", span);
};
if (failing.has_induced_failure) {
try std.testing.expectError(error.OutOfMemory, result);
try std.testing.expect(l.problem == null);
} else {
try std.testing.expect((try result).ty.eql(ty));
try std.testing.expectEqual(@as(usize, 65), l.blocks.items[0].insts.items.len);
}
if (l.cur) |index| {
const actual = l.blocks.items[index].insts.items;
try std.testing.expect(actual.len <= expected.len);
try std.testing.expectEqualDeep(expected[0..actual.len], actual);
}
try std.testing.expectEqual(@as(usize, 0), l.out.items.len);
arena.deinit();
try std.testing.expectEqual(failing.allocated_bytes, failing.freed_bytes);
if (!failing.has_induced_failure) break;
}
}