astgen: switchExprErrUnion, decl_val rvalue, identAsString ordering

Port switchExprErrUnion optimization for both catch and if patterns,
fix missing rvalue call in decl table lookup, fix identAsString
ordering for underscore error captures, and fill value_placeholder
with 0xaa to match upstream undefined pattern.

Enables corpus build.zig test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 09:54:28 +00:00
parent b2592f40be
commit 28ee5d40b7
2 changed files with 583 additions and 11 deletions

View File

@@ -243,7 +243,21 @@ fn expectEqualZir(gpa: Allocator, ref: Zir, got: c.Zir) !void {
const ref_datas = ref.instructions.items(.data);
// 1. Compare lengths.
try std.testing.expectEqual(ref_len, got.inst_len);
if (ref_len != got.inst_len) {
std.debug.print("inst_len mismatch: ref={d} got={d}\n", .{ ref_len, got.inst_len });
var ref_counts: [265]u32 = .{0} ** 265;
var got_counts: [265]u32 = .{0} ** 265;
for (0..ref_len) |i| ref_counts[@intFromEnum(ref_tags[i])] += 1;
for (0..got.inst_len) |i| got_counts[got.inst_tags[i]] += 1;
for (0..265) |t| {
if (ref_counts[t] != got_counts[t])
std.debug.print("tag {d}: ref={d} got={d} (diff={d})\n", .{
t, ref_counts[t], got_counts[t],
@as(i32, @intCast(got_counts[t])) - @as(i32, @intCast(ref_counts[t])),
});
}
return error.TestExpectedEqual;
}
// 2. Compare instruction tags.
for (0..ref_len) |i| {
@@ -793,10 +807,6 @@ test "astgen: corpus test_all.zig" {
}
test "astgen: corpus build.zig" {
// TODO: 6 extra instructions — missing switchExprErrUnion optimization
// (catch |err| switch(err) pattern emits SWITCH_BLOCK instead of
// SWITCH_BLOCK_ERR_UNION).
if (true) return error.SkipZigTest;
const gpa = std.testing.allocator;
try corpusCheck(gpa, @embedFile("../build.zig"));
}