authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-15 16:50:20+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-16 01:12:28+02:00
logfb09093d95f2dc9bf454ba0d1d489316311adffc
treed033652857b160b2862c935fbd498a9f5aa7dfec
parent2cfa7165e715321dffea21380d4fde0dd5079925

Module: call `ensureDeclAnalyzed` on `builtin.test_functions`

Previously the compiler would crash on branching on undefined values if you tried using `zig test` with a freestanding target since there was no start code referencing `builtin.test_functions`. Closes #12554

2 files changed, 16 insertions(+), 2 deletions(-)

src/Compilation.zig+1-1
...@@ -2361,7 +2361,7 @@ pub fn update(comp: *Compilation) !void {...@@ -2361,7 +2361,7 @@ pub fn update(comp: *Compilation) !void {
2361 // The `test_functions` decl has been intentionally postponed until now,2361 // The `test_functions` decl has been intentionally postponed until now,
2362 // at which point we must populate it with the list of test functions that2362 // at which point we must populate it with the list of test functions that
2363 // have been discovered and not filtered out.2363 // have been discovered and not filtered out.
2364 try module.populateTestFunctions();2364 try module.populateTestFunctions(main_progress_node);
2365 }2365 }
23662366
2367 // Process the deletion set. We use a while loop here because the2367 // Process the deletion set. We use a while loop here because the
src/Module.zig+15-1
...@@ -6431,13 +6431,27 @@ pub fn processExports(mod: *Module) !void {...@@ -6431,13 +6431,27 @@ pub fn processExports(mod: *Module) !void {
6431 }6431 }
6432}6432}
64336433
6434pub fn populateTestFunctions(mod: *Module) !void {6434pub fn populateTestFunctions(
6435 mod: *Module,
6436 main_progress_node: *std.Progress.Node,
6437) !void {
6435 const gpa = mod.gpa;6438 const gpa = mod.gpa;
6436 const builtin_pkg = mod.main_pkg.table.get("builtin").?;6439 const builtin_pkg = mod.main_pkg.table.get("builtin").?;
6437 const builtin_file = (mod.importPkg(builtin_pkg) catch unreachable).file;6440 const builtin_file = (mod.importPkg(builtin_pkg) catch unreachable).file;
6438 const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?);6441 const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?);
6439 const builtin_namespace = root_decl.src_namespace;6442 const builtin_namespace = root_decl.src_namespace;
6440 const decl_index = builtin_namespace.decls.getKeyAdapted(@as([]const u8, "test_functions"), DeclAdapter{ .mod = mod }).?;6443 const decl_index = builtin_namespace.decls.getKeyAdapted(@as([]const u8, "test_functions"), DeclAdapter{ .mod = mod }).?;
6444 {
6445 // We have to call `ensureDeclAnalyzed` here in case `builtin.test_functions`
6446 // was not referenced by start code.
6447 mod.sema_prog_node = main_progress_node.start("Semantic Analysis", 0);
6448 mod.sema_prog_node.activate();
6449 defer {
6450 mod.sema_prog_node.end();
6451 mod.sema_prog_node = undefined;
6452 }
6453 try mod.ensureDeclAnalyzed(decl_index);
6454 }
6441 const decl = mod.declPtr(decl_index);6455 const decl = mod.declPtr(decl_index);
6442 var buf: Type.SlicePtrFieldTypeBuffer = undefined;6456 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
6443 const tmp_test_fn_ty = decl.ty.slicePtrFieldType(&buf).elemType();6457 const tmp_test_fn_ty = decl.ty.slicePtrFieldType(&buf).elemType();