From ac745edbbd6687c5898bb3a50bf9d31d86e57b9e Mon Sep 17 00:00:00 2001 From: mlugg Date: Sun, 8 Jun 2025 16:25:28 +0100 Subject: [PATCH] compiler: estimate totals for "Code Generation" and "Linking" progress nodes --- src/Compilation.zig | 6 ++++++ src/link.zig | 29 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 74f841723e..04cd03c3d8 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -4202,6 +4202,10 @@ fn performAllTheWork( comp.link_task_wait_group.reset(); defer comp.link_task_wait_group.wait(); + comp.link_prog_node.increaseEstimatedTotalItems( + comp.link_task_queue.queued_prelink.items.len + // already queued prelink tasks + comp.link_task_queue.pending_prelink_tasks, // prelink tasks which will be queued + ); comp.link_task_queue.start(comp); if (comp.emit_docs != null) { @@ -4597,6 +4601,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void { .value = undefined, }; assert(zcu.pending_codegen_jobs.rmw(.Add, 1, .monotonic) > 0); // the "Code Generation" node hasn't been ended + zcu.codegen_prog_node.increaseEstimatedTotalItems(1); if (comp.separateCodegenThreadOk()) { // `workerZcuCodegen` takes ownership of `air`. comp.thread_pool.spawnWgId(&comp.link_task_wait_group, workerZcuCodegen, .{ comp, func.func, air, shared_mir }); @@ -7444,6 +7449,7 @@ pub fn queuePrelinkTasks(comp: *Compilation, tasks: []const link.PrelinkTask) vo /// The reason for the double-queue here is that the first queue ensures any /// resolve_type_fully tasks are complete before this dispatch function is called. fn dispatchZcuLinkTask(comp: *Compilation, tid: usize, task: link.ZcuTask) void { + comp.link_prog_node.increaseEstimatedTotalItems(1); if (!comp.separateCodegenThreadOk()) { assert(tid == 0); if (task == .link_func) { diff --git a/src/link.zig b/src/link.zig index 7d522b94d3..ce98ac8929 100644 --- a/src/link.zig +++ b/src/link.zig @@ -1290,7 +1290,10 @@ pub const ZcuTask = union(enum) { pub fn doPrelinkTask(comp: *Compilation, task: PrelinkTask) void { const diags = &comp.link_diags; - const base = comp.bin_file orelse return; + const base = comp.bin_file orelse { + comp.link_prog_node.completeOne(); + return; + }; switch (task) { .load_explicitly_provided => { const prog_node = comp.link_prog_node.start("Parse Inputs", comp.link_inputs.len); @@ -1413,12 +1416,13 @@ pub fn doPrelinkTask(comp: *Compilation, task: PrelinkTask) void { } pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void { const diags = &comp.link_diags; + const zcu = comp.zcu.?; + const ip = &zcu.intern_pool; + const pt: Zcu.PerThread = .activate(zcu, @enumFromInt(tid)); + defer pt.deactivate(); switch (task) { .link_nav => |nav_index| { - const zcu = comp.zcu.?; - const pt: Zcu.PerThread = .activate(zcu, @enumFromInt(tid)); - defer pt.deactivate(); - const fqn_slice = zcu.intern_pool.getNav(nav_index).fqn.toSlice(&zcu.intern_pool); + const fqn_slice = ip.getNav(nav_index).fqn.toSlice(ip); const nav_prog_node = comp.link_prog_node.start(fqn_slice, 0); defer nav_prog_node.end(); if (zcu.llvm_object) |llvm_object| { @@ -1440,11 +1444,8 @@ pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void { } }, .link_func => |func| { - const zcu = comp.zcu.?; const nav = zcu.funcInfo(func.func).owner_nav; - const pt: Zcu.PerThread = .activate(zcu, @enumFromInt(tid)); - defer pt.deactivate(); - const fqn_slice = zcu.intern_pool.getNav(nav).fqn.toSlice(&zcu.intern_pool); + const fqn_slice = ip.getNav(nav).fqn.toSlice(ip); const nav_prog_node = comp.link_prog_node.start(fqn_slice, 0); defer nav_prog_node.end(); switch (func.mir.status.load(.monotonic)) { @@ -1468,9 +1469,9 @@ pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void { } }, .link_type => |ty| { - const zcu = comp.zcu.?; - const pt: Zcu.PerThread = .activate(zcu, @enumFromInt(tid)); - defer pt.deactivate(); + const name = Type.fromInterned(ty).containerTypeName(ip).toSlice(ip); + const nav_prog_node = comp.link_prog_node.start(name, 0); + defer nav_prog_node.end(); if (zcu.llvm_object == null) { if (comp.bin_file) |lf| { lf.updateContainerType(pt, ty) catch |err| switch (err) { @@ -1481,8 +1482,8 @@ pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void { } }, .update_line_number => |ti| { - const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid)); - defer pt.deactivate(); + const nav_prog_node = comp.link_prog_node.start("Update line number", 0); + defer nav_prog_node.end(); if (pt.zcu.llvm_object == null) { if (comp.bin_file) |lf| { lf.updateLineNumber(pt, ti) catch |err| switch (err) {