authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-22 22:35:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-22 22:35:18-07:00
log2d290d6f82b780fc5c1448bcc41fec602359dfec
tree2463539baceb3924f29906cf40c4084475527250
parenta830ebe7180e28cbedc312ee65d390962b673b37

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")`.

2 files changed, 11 insertions(+), 10 deletions(-)

src/Compilation.zig+9-10
......@@ -201,8 +201,6 @@ const Job = union(enum) {
201201 /// calls to, for example, memcpy and memset.
202202 zig_libc: void,
203203
204 /// Generate builtin.zig source code and write it into the correct place.
205 generate_builtin_zig: void,
206204 /// Use stage1 C++ code to compile zig code into an object file.
207205 stage1_module: void,
208206
......@@ -1307,10 +1305,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
13071305 try comp.astgen_wait_group.init();
13081306 errdefer comp.astgen_wait_group.deinit();
13091307
1310 if (comp.bin_file.options.module) |mod| {
1311 try comp.work_queue.writeItem(.{ .generate_builtin_zig = {} });
1312 }
1313
13141308 // Add a `CObject` for each `c_source_files`.
13151309 try comp.c_object_table.ensureCapacity(gpa, options.c_source_files.len);
13161310 for (options.c_source_files) |c_source_file| {
......@@ -1764,6 +1758,15 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
17641758 defer main_progress_node.end();
17651759 if (self.color == .off) progress.terminal = null;
17661760
1761 // If we need to write out builtin.zig, it needs to be done before starting
1762 // the AstGen tasks.
1763 if (self.bin_file.options.module) |mod| {
1764 if (mod.job_queued_update_builtin_zig) {
1765 mod.job_queued_update_builtin_zig = false;
1766 try self.updateBuiltinZigFile(mod);
1767 }
1768 }
1769
17671770 // Here we queue up all the AstGen tasks first, followed by C object compilation.
17681771 // We wait until the AstGen tasks are all completed before proceeding to the
17691772 // (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
20862089 ),
20872090 };
20882091 },
2089 .generate_builtin_zig => {
2090 // This Job is only queued up if there is a zig module.
2091 try self.updateBuiltinZigFile(self.bin_file.options.module.?);
2092 },
20932092 .stage1_module => {
20942093 if (!build_options.is_stage1)
20952094 unreachable;
src/Module.zig+2
......@@ -109,6 +109,8 @@ stage1_flags: packed struct {
109109
110110emit_h: ?Compilation.EmitLoc,
111111
112job_queued_update_builtin_zig: bool = true,
113
112114compile_log_text: ArrayListUnmanaged(u8) = .{},
113115
114116pub const ErrorInt = u32;