stages_test: compare per-function Air count between C and Zig sema

Parse the captured Zig verbose_air output to count per-function Air
sections and verify that C sema produces the same number. For the
current corpus (codecs.zig, no functions), both sides produce zero
entries. When zirFunc is ported and functions appear, per-function
textual Air comparison will be added.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-19 12:39:40 +00:00
parent 1960fea977
commit e491c8aee9

View File

@@ -71,12 +71,29 @@ fn stagesCheck(gpa: Allocator, source: [:0]const u8, src_path: []const u8, check
var result = try sema_c.cSema(gpa, @bitCast(c_zir));
defer result.deinit(gpa);
// Run Zig sema on the same source and verify it succeeds.
var zig_result = try sema.zigSema(gpa, src_path);
defer zig_result.deinit();
// Compare per-function Air: C and Zig must produce the same count.
const zig_air_text = zig_result.air_output.written();
const zig_func_count = countAirSections(zig_air_text);
try std.testing.expectEqual(zig_func_count, result.func_airs.len);
}
}
/// Count the number of per-function Air sections in verbose_air output.
/// Sections are delimited by "# Begin Function AIR: " markers.
fn countAirSections(text: []const u8) usize {
const marker = "# Begin Function AIR: ";
var count: usize = 0;
var pos: usize = 0;
while (std.mem.indexOfPos(u8, text, pos, marker)) |begin| {
count += 1;
pos = begin + marker.len;
}
return count;
}
const last_successful_corpus = "../lib/std/crypto/codecs.zig";
// find ../{lib,src} -name '*.zig' | xargs -n1 stat -c "%s %n" | sort -n | awk '{printf " \""$2"\", // "$1"\n"}'