From bb80906868d26b9eec6ecd2ed2d7593ccbe88ae5 Mon Sep 17 00:00:00 2001 From: rpkak Date: Sun, 28 Dec 2025 21:48:43 +0100 Subject: [PATCH] Fix some counting errors related to std.Progress in the compiler --- src/Compilation.zig | 9 ++++++++- src/Zcu/PerThread.zig | 1 + src/link/Coff.zig | 4 +++- src/link/Elf2.zig | 6 ++++-- src/link/Wasm.zig | 1 + 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 3e3658021438b7aa518282c77c3d04bba3d269b9..8fb16e52c566de5e85771da874c3c723b3c1d411 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -2911,7 +2911,14 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE // The linker progress node is set up here instead of in `performAllTheWork`, because // we also want it around during `flush`. if (comp.bin_file) |lf| { - comp.link_prog_node = main_progress_node.start("Linking", 0); + // mirrors logic in `Compilation.flush`: + // For llvm: "LLVM Emit Object" and "Parse Object" with the zcu object + // Always: flush of the linker + const initial_estimated_total: usize = if (comp.zcu) |zcu| + if (zcu.llvm_object) |_| 3 else 1 + else + 1; + comp.link_prog_node = main_progress_node.start("Linking", initial_estimated_total); lf.startProgress(comp.link_prog_node); } defer if (comp.bin_file) |lf| { diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index 62f11a83f671cc7b2ea3b20c7b6e0e94f342d354..e708f35ff25102fa99655f4fb99d9396df198215 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -876,6 +876,7 @@ fn updateZirRefs(pt: Zcu.PerThread) (Io.Cancelable || Allocator.Error)!void { const old_line = old_zir.getDeclaration(old_inst).src_line; const new_line = new_zir.getDeclaration(new_inst).src_line; if (old_line != new_line) { + comp.link_prog_node.increaseEstimatedTotalItems(1); try comp.link_queue.enqueueZcu(comp, pt.tid, .{ .debug_update_line_number = tracked_inst_index }); } }, diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 756c4c8892b29f54be05456d12277aa49bc3a444..aff6d72fb3d956490ce1c0dc766fce9f1b192cb5 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -5886,7 +5886,9 @@ pub fn flush( prog_node: std.Progress.Node, ) link.Error!void { _ = arena; - _ = prog_node; + const sub_prog_node = prog_node.start("COFF Flush", 0); + defer sub_prog_node.end(); + const comp = coff.base.comp; // TODO: When https://github.com/ziglang/zig/issues/23617 is in, diff --git a/src/link/Elf2.zig b/src/link/Elf2.zig index 2c6aefe7bcbc8fc02fb9c46e3c12905e4d640826..62d152f057822e27cf1cce1eaa5cf0aa176a706d 100644 --- a/src/link/Elf2.zig +++ b/src/link/Elf2.zig @@ -5224,7 +5224,7 @@ fn loadObject( .first_symbol_reloc = .none, .first_got_reloc = .none, }; - elf.synth_prog_node.increaseEstimatedTotalItems(1); + elf.input_prog_node.increaseEstimatedTotalItems(1); } var symmap: std.ArrayList(Symbol.Id) = .empty; defer symmap.deinit(gpa); @@ -7105,9 +7105,11 @@ pub fn flush( ) link.Error!void { const comp = elf.base.comp; const diags = &comp.link_diags; - _ = prog_node; _ = arena; + const sub_prog_node = prog_node.start("ELF Flush", 0); + defer sub_prog_node.end(); + if (comp.config.output_mode == .Exe) { var any_undef = false; for (elf.globals.strong_undef.keys()) |name| { diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 40c3e412b4ac88c019cf6885e2d9e4bb1e2b329e..1894440ee1378807867cee8e4150c09161994f0e 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -3398,6 +3398,7 @@ pub fn prelink(wasm: *Wasm, prog_node: std.Progress.Node) link.Error!void { const tracy = trace(@src()); defer tracy.end(); + prog_node.increaseEstimatedTotalItems(1); const sub_prog_node = prog_node.start("Wasm Prelink", 0); defer sub_prog_node.end(); -- 2.54.0