From 2d290d6f82b780fc5c1448bcc41fec602359dfec Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 22 Apr 2021 22:35:18 -0700 Subject: stage2: write out builtin.zig before spawning AstGen tasks Otherwise it's possible for AstGen to get FileNotFound when trying to eager-load `import("builtin")`. --- src/Compilation.zig | 19 +++++++++---------- src/Module.zig | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/Compilation.zig b/src/Compilation.zig index d4d4228608..635465a0f7 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -201,8 +201,6 @@ const Job = union(enum) { /// calls to, for example, memcpy and memset. zig_libc: void, - /// Generate builtin.zig source code and write it into the correct place. - generate_builtin_zig: void, /// Use stage1 C++ code to compile zig code into an object file. stage1_module: void, @@ -1307,10 +1305,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { try comp.astgen_wait_group.init(); errdefer comp.astgen_wait_group.deinit(); - if (comp.bin_file.options.module) |mod| { - try comp.work_queue.writeItem(.{ .generate_builtin_zig = {} }); - } - // Add a `CObject` for each `c_source_files`. try comp.c_object_table.ensureCapacity(gpa, options.c_source_files.len); for (options.c_source_files) |c_source_file| { @@ -1764,6 +1758,15 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor defer main_progress_node.end(); if (self.color == .off) progress.terminal = null; + // If we need to write out builtin.zig, it needs to be done before starting + // the AstGen tasks. + if (self.bin_file.options.module) |mod| { + if (mod.job_queued_update_builtin_zig) { + mod.job_queued_update_builtin_zig = false; + try self.updateBuiltinZigFile(mod); + } + } + // Here we queue up all the AstGen tasks first, followed by C object compilation. // We wait until the AstGen tasks are all completed before proceeding to the // (at least for now) single-threaded main work queue. However, C object compilation @@ -2086,10 +2089,6 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor ), }; }, - .generate_builtin_zig => { - // This Job is only queued up if there is a zig module. - try self.updateBuiltinZigFile(self.bin_file.options.module.?); - }, .stage1_module => { if (!build_options.is_stage1) unreachable; diff --git a/src/Module.zig b/src/Module.zig index d456968caf..f58a66a16f 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -109,6 +109,8 @@ stage1_flags: packed struct { emit_h: ?Compilation.EmitLoc, +job_queued_update_builtin_zig: bool = true, + compile_log_text: ArrayListUnmanaged(u8) = .{}, pub const ErrorInt = u32; -- cgit v1.2.3