authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-31 19:07:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-01 00:17:02-07:00
log87179d91a76470eb5e09d4e070063a2021c7f176
tree681783fb3f0ce3123f0e4b7cc07592e3256d19d8
parentb45c6c757cb4a16f5021c8bf057d14183036f14c

stage2: hook up Sema to the progress bar


2 files changed, 49 insertions(+), 53 deletions(-)

src/Compilation.zig+44-53
......@@ -232,9 +232,6 @@ const Job = union(enum) {
232232 /// one of WASI libc static objects
233233 wasi_libc_crt_file: wasi_libc.CRTFile,
234234
235 /// Use stage1 C++ code to compile zig code into an object file.
236 stage1_module: void,
237
238235 /// The value is the index into `link.File.Options.system_libs`.
239236 windows_import_lib: usize,
240237};
......@@ -1831,10 +1828,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
18311828 }
18321829 }
18331830
1834 if (comp.bin_file.options.use_stage1 and comp.bin_file.options.module != null) {
1835 try comp.work_queue.writeItem(.{ .stage1_module = {} });
1836 }
1837
18381831 return comp;
18391832}
18401833
......@@ -2597,13 +2590,13 @@ pub fn getCompileLogOutput(self: *Compilation) []const u8 {
25972590 return module.compile_log_text.items;
25982591}
25992592
2600pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemory }!void {
2593pub fn performAllTheWork(comp: *Compilation) error{ TimerUnsupported, OutOfMemory }!void {
26012594 // If the terminal is dumb, we dont want to show the user all the
26022595 // output.
26032596 var progress: std.Progress = .{ .dont_print_on_dumb = true };
26042597 var main_progress_node = progress.start("", 0);
26052598 defer main_progress_node.end();
2606 if (self.color == .off) progress.terminal = null;
2599 if (comp.color == .off) progress.terminal = null;
26072600
26082601 // Here we queue up all the AstGen tasks first, followed by C object compilation.
26092602 // We wait until the AstGen tasks are all completed before proceeding to the
......@@ -2613,93 +2606,105 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
26132606 var zir_prog_node = main_progress_node.start("AST Lowering", 0);
26142607 defer zir_prog_node.end();
26152608
2616 var c_obj_prog_node = main_progress_node.start("Compile C Objects", self.c_source_files.len);
2609 var c_obj_prog_node = main_progress_node.start("Compile C Objects", comp.c_source_files.len);
26172610 defer c_obj_prog_node.end();
26182611
2619 var embed_file_prog_node = main_progress_node.start("Detect @embedFile updates", self.embed_file_work_queue.count);
2612 var embed_file_prog_node = main_progress_node.start("Detect @embedFile updates", comp.embed_file_work_queue.count);
26202613 defer embed_file_prog_node.end();
26212614
2622 self.work_queue_wait_group.reset();
2623 defer self.work_queue_wait_group.wait();
2615 comp.work_queue_wait_group.reset();
2616 defer comp.work_queue_wait_group.wait();
26242617
26252618 {
26262619 const astgen_frame = tracy.namedFrame("astgen");
26272620 defer astgen_frame.end();
26282621
2629 self.astgen_wait_group.reset();
2630 defer self.astgen_wait_group.wait();
2622 comp.astgen_wait_group.reset();
2623 defer comp.astgen_wait_group.wait();
26312624
26322625 // builtin.zig is handled specially for two reasons:
26332626 // 1. to avoid race condition of zig processes truncating each other's builtin.zig files
26342627 // 2. optimization; in the hot path it only incurs a stat() syscall, which happens
26352628 // in the `astgen_wait_group`.
2636 if (self.bin_file.options.module) |mod| {
2629 if (comp.bin_file.options.module) |mod| {
26372630 if (mod.job_queued_update_builtin_zig) {
26382631 mod.job_queued_update_builtin_zig = false;
26392632
2640 self.astgen_wait_group.start();
2641 try self.thread_pool.spawn(workerUpdateBuiltinZigFile, .{
2642 self, mod, &self.astgen_wait_group,
2633 comp.astgen_wait_group.start();
2634 try comp.thread_pool.spawn(workerUpdateBuiltinZigFile, .{
2635 comp, mod, &comp.astgen_wait_group,
26432636 });
26442637 }
26452638 }
26462639
2647 while (self.astgen_work_queue.readItem()) |file| {
2648 self.astgen_wait_group.start();
2649 try self.thread_pool.spawn(workerAstGenFile, .{
2650 self, file, &zir_prog_node, &self.astgen_wait_group, .root,
2640 while (comp.astgen_work_queue.readItem()) |file| {
2641 comp.astgen_wait_group.start();
2642 try comp.thread_pool.spawn(workerAstGenFile, .{
2643 comp, file, &zir_prog_node, &comp.astgen_wait_group, .root,
26512644 });
26522645 }
26532646
2654 while (self.embed_file_work_queue.readItem()) |embed_file| {
2655 self.astgen_wait_group.start();
2656 try self.thread_pool.spawn(workerCheckEmbedFile, .{
2657 self, embed_file, &embed_file_prog_node, &self.astgen_wait_group,
2647 while (comp.embed_file_work_queue.readItem()) |embed_file| {
2648 comp.astgen_wait_group.start();
2649 try comp.thread_pool.spawn(workerCheckEmbedFile, .{
2650 comp, embed_file, &embed_file_prog_node, &comp.astgen_wait_group,
26582651 });
26592652 }
26602653
2661 while (self.c_object_work_queue.readItem()) |c_object| {
2662 self.work_queue_wait_group.start();
2663 try self.thread_pool.spawn(workerUpdateCObject, .{
2664 self, c_object, &c_obj_prog_node, &self.work_queue_wait_group,
2654 while (comp.c_object_work_queue.readItem()) |c_object| {
2655 comp.work_queue_wait_group.start();
2656 try comp.thread_pool.spawn(workerUpdateCObject, .{
2657 comp, c_object, &c_obj_prog_node, &comp.work_queue_wait_group,
26652658 });
26662659 }
26672660 }
26682661
2669 const use_stage1 = build_options.is_stage1 and self.bin_file.options.use_stage1;
2662 const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;
26702663 if (!use_stage1) {
26712664 const outdated_and_deleted_decls_frame = tracy.namedFrame("outdated_and_deleted_decls");
26722665 defer outdated_and_deleted_decls_frame.end();
26732666
26742667 // Iterate over all the files and look for outdated and deleted declarations.
2675 if (self.bin_file.options.module) |mod| {
2668 if (comp.bin_file.options.module) |mod| {
26762669 try mod.processOutdatedAndDeletedDecls();
26772670 }
2678 } else if (self.bin_file.options.module) |mod| {
2671 } else if (comp.bin_file.options.module) |mod| {
26792672 // If there are any AstGen compile errors, report them now to avoid
26802673 // hitting stage1 bugs.
26812674 if (mod.failed_files.count() != 0) {
26822675 return;
26832676 }
2677 comp.updateStage1Module(main_progress_node) catch |err| {
2678 fatal("unable to build stage1 zig object: {s}", .{@errorName(err)});
2679 };
2680 }
2681
2682 if (comp.bin_file.options.module) |mod| {
2683 mod.sema_prog_node = main_progress_node.start("Semantic Analysis", 0);
2684 mod.sema_prog_node.activate();
26842685 }
2686 defer if (comp.bin_file.options.module) |mod| {
2687 mod.sema_prog_node.end();
2688 mod.sema_prog_node = undefined;
2689 };
26852690
26862691 // In this main loop we give priority to non-anonymous Decls in the work queue, so
26872692 // that they can establish references to anonymous Decls, setting alive=true in the
26882693 // backend, preventing anonymous Decls from being prematurely destroyed.
26892694 while (true) {
2690 if (self.work_queue.readItem()) |work_item| {
2691 try processOneJob(self, work_item, main_progress_node);
2695 if (comp.work_queue.readItem()) |work_item| {
2696 try processOneJob(comp, work_item);
26922697 continue;
26932698 }
2694 if (self.anon_work_queue.readItem()) |work_item| {
2695 try processOneJob(self, work_item, main_progress_node);
2699 if (comp.anon_work_queue.readItem()) |work_item| {
2700 try processOneJob(comp, work_item);
26962701 continue;
26972702 }
26982703 break;
26992704 }
27002705}
27012706
2702fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress.Node) !void {
2707fn processOneJob(comp: *Compilation, job: Job) !void {
27032708 switch (job) {
27042709 .codegen_decl => |decl| switch (decl.analysis) {
27052710 .unreferenced => unreachable,
......@@ -2807,9 +2812,6 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
28072812 if (build_options.omit_stage2)
28082813 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
28092814
2810 const named_frame = tracy.namedFrame("analyze_decl");
2811 defer named_frame.end();
2812
28132815 const module = comp.bin_file.options.module.?;
28142816 module.ensureDeclAnalyzed(decl) catch |err| switch (err) {
28152817 error.OutOfMemory => return error.OutOfMemory,
......@@ -3074,17 +3076,6 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
30743076 ),
30753077 };
30763078 },
3077 .stage1_module => {
3078 const named_frame = tracy.namedFrame("stage1_module");
3079 defer named_frame.end();
3080
3081 if (!build_options.is_stage1)
3082 unreachable;
3083
3084 comp.updateStage1Module(main_progress_node) catch |err| {
3085 fatal("unable to build stage1 zig object: {s}", .{@errorName(err)});
3086 };
3087 },
30883079 }
30893080}
30903081
src/Module.zig+5
......@@ -42,6 +42,7 @@ root_pkg: *Package,
4242/// Normally, `main_pkg` and `root_pkg` are the same. The exception is `zig test`, in which
4343/// `root_pkg` is the test runner, and `main_pkg` is the user's source file which has the tests.
4444main_pkg: *Package,
45sema_prog_node: std.Progress.Node = undefined,
4546
4647/// Used by AstGen worker to load and store ZIR cache.
4748global_zir_cache: Compilation.Directory,
......@@ -3517,6 +3518,10 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl: *Decl) SemaError!void {
35173518 .unreferenced => false,
35183519 };
35193520
3521 var decl_prog_node = mod.sema_prog_node.start(mem.sliceTo(decl.name, 0), 0);
3522 decl_prog_node.activate();
3523 defer decl_prog_node.end();
3524
35203525 const type_changed = mod.semaDecl(decl) catch |err| switch (err) {
35213526 error.AnalysisFail => {
35223527 if (decl.analysis == .in_progress) {