fix(KB-9): move Lowering/ProgramIndex maps off page_allocator defaults

16 Lowering map fields and 8 ProgramIndex map fields were declared with
`= ....init(std.heap.page_allocator)` field defaults that init() never
replaced — every instance really allocated page-at-a-time outside the
compilation allocator, invisible to leak checking and never reclaimed.

All 24 now init explicitly with the compilation allocator (module.alloc
/ the init alloc param), which is arena-backed in both the driver
(main's arena) and the test suites (per-test arenas), so backing is
reclaimed at teardown. ProgramIndex's struct doc no longer claims the
page_allocator defaults.

Six lower.test.zig tests that constructed Module with bare
std.testing.allocator leaked once the checker could finally see these
maps; they now use the same per-test ArenaAllocator idiom as the rest
of the file and the facade test suites.

Gate: zig build OK; zig build test 426/426 (6/6 steps, leak-clean);
run_examples 541/0; zero expected/ snapshot churn.
This commit is contained in:
agra
2026-06-10 16:19:52 +03:00
parent 82500931ce
commit 5b304a29c1
3 changed files with 69 additions and 33 deletions

View File

@@ -464,7 +464,9 @@ test "lower: objcDefinedStateStructType skips non-field members" {
}
test "lower: objcTypeEncodingFromSignature emits @ for Obj-C class pointers" {
const alloc = std.testing.allocator;
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
const alloc = arena.allocator();
var module = ir_mod.Module.init(alloc);
defer module.deinit();
var lowering = Lowering.init(&module);
@@ -496,7 +498,9 @@ test "lower: objcTypeEncodingFromSignature emits @ for Obj-C class pointers" {
}
test "lower: objcTypeEncodingFromSignature unwraps optional to wire type" {
const alloc = std.testing.allocator;
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
const alloc = arena.allocator();
var module = ir_mod.Module.init(alloc);
defer module.deinit();
var lowering = Lowering.init(&module);
@@ -663,7 +667,9 @@ test "lower: deriveObjcSelector — niladic / keyword / multi-keyword / override
}
test "lower: isObjcClassPointer recognises pointer-to-foreign-Obj-C-class" {
const alloc = std.testing.allocator;
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
const alloc = arena.allocator();
var module = ir_mod.Module.init(alloc);
defer module.deinit();
var lowering = Lowering.init(&module);
@@ -710,7 +716,9 @@ test "lower: isObjcClassPointer recognises pointer-to-foreign-Obj-C-class" {
}
test "lower: objcPropertyKind defaults + explicit ARC modifiers" {
const alloc = std.testing.allocator;
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
const alloc = arena.allocator();
var module = ir_mod.Module.init(alloc);
defer module.deinit();
var lowering = Lowering.init(&module);
@@ -783,7 +791,9 @@ fn protoMethod(name: []const u8) ast.ProtocolMethodDecl {
}
test "pack projection: type-arg vs method namespace lookups" {
const alloc = std.testing.allocator;
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
const alloc = arena.allocator();
var module = ir_mod.Module.init(alloc);
defer module.deinit();
var lowering = Lowering.init(&module);
@@ -808,7 +818,9 @@ test "pack projection: type-arg vs method namespace lookups" {
}
test "pack projection: position-driven resolution (Decision 4)" {
const alloc = std.testing.allocator;
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
const alloc = arena.allocator();
var module = ir_mod.Module.init(alloc);
defer module.deinit();
var lowering = Lowering.init(&module);