authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-06-27 08:09:40-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-07-27 14:35:12-04:00
log409c89ee2161c071ca713b5b69e8707b0e538aab
tree089cc4bb052a901d2d5381e45a745b1b0285c0ef
parent897c0b35a92dba851edd2ce49314468d3e1fcaff

Compilation: avoid illegal behavior during create


2 files changed, 8 insertions(+), 0 deletions(-)

src/Compilation.zig+3
...@@ -2134,6 +2134,9 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2134,6 +2134,9 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2134 comp.config.any_fuzz = any_fuzz;2134 comp.config.any_fuzz = any_fuzz;
21352135
2136 if (opt_zcu) |zcu| {2136 if (opt_zcu) |zcu| {
2137 // Finish initializing the `zcu` after the fields on `comp` have been initialized.
2138 zcu.initAfterCompilation();
2139
2137 // Populate `zcu.module_roots`.2140 // Populate `zcu.module_roots`.
2138 const active = zcu.acquire();2141 const active = zcu.acquire();
2139 defer active.release();2142 defer active.release();
src/Zcu.zig+5
...@@ -2825,6 +2825,11 @@ pub const CompileError = error{...@@ -2825,6 +2825,11 @@ pub const CompileError = error{
28252825
2826pub fn init(zcu: *Zcu, gpa: Allocator, io: Io, thread_count: usize) !void {2826pub fn init(zcu: *Zcu, gpa: Allocator, io: Io, thread_count: usize) !void {
2827 try zcu.intern_pool.init(gpa, io, thread_count);2827 try zcu.intern_pool.init(gpa, io, thread_count);
2828}
2829
2830/// It is valid to not call this function before `deinit` in error paths.
2831/// Requires the fields on `zcu.comp` to already be initialized.
2832pub fn initAfterCompilation(zcu: *Zcu) void {
2828 zcu.initTracyPlots();2833 zcu.initTracyPlots();
2829}2834}
28302835