authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-08 16:25:28+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-12 13:55:41+01:00
logac745edbbd6687c5898bb3a50bf9d31d86e57b9e
treecca2d95cd7cbb1576e604ef9f4ad46a1b029c990
parentdb5d85b8c89b755bd8865def3bd7114d5d9d4867
signaturelock-open Commit is signed but in an unrecognized format.

compiler: estimate totals for "Code Generation" and "Linking" progress nodes


2 files changed, 21 insertions(+), 14 deletions(-)

src/Compilation.zig+6
...@@ -4202,6 +4202,10 @@ fn performAllTheWork(...@@ -4202,6 +4202,10 @@ fn performAllTheWork(
4202 comp.link_task_wait_group.reset();4202 comp.link_task_wait_group.reset();
4203 defer comp.link_task_wait_group.wait();4203 defer comp.link_task_wait_group.wait();
42044204
4205 comp.link_prog_node.increaseEstimatedTotalItems(
4206 comp.link_task_queue.queued_prelink.items.len + // already queued prelink tasks
4207 comp.link_task_queue.pending_prelink_tasks, // prelink tasks which will be queued
4208 );
4205 comp.link_task_queue.start(comp);4209 comp.link_task_queue.start(comp);
42064210
4207 if (comp.emit_docs != null) {4211 if (comp.emit_docs != null) {
...@@ -4597,6 +4601,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {...@@ -4597,6 +4601,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
4597 .value = undefined,4601 .value = undefined,
4598 };4602 };
4599 assert(zcu.pending_codegen_jobs.rmw(.Add, 1, .monotonic) > 0); // the "Code Generation" node hasn't been ended4603 assert(zcu.pending_codegen_jobs.rmw(.Add, 1, .monotonic) > 0); // the "Code Generation" node hasn't been ended
4604 zcu.codegen_prog_node.increaseEstimatedTotalItems(1);
4600 if (comp.separateCodegenThreadOk()) {4605 if (comp.separateCodegenThreadOk()) {
4601 // `workerZcuCodegen` takes ownership of `air`.4606 // `workerZcuCodegen` takes ownership of `air`.
4602 comp.thread_pool.spawnWgId(&comp.link_task_wait_group, workerZcuCodegen, .{ comp, func.func, air, shared_mir });4607 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...@@ -7444,6 +7449,7 @@ pub fn queuePrelinkTasks(comp: *Compilation, tasks: []const link.PrelinkTask) vo
7444/// The reason for the double-queue here is that the first queue ensures any7449/// The reason for the double-queue here is that the first queue ensures any
7445/// resolve_type_fully tasks are complete before this dispatch function is called.7450/// resolve_type_fully tasks are complete before this dispatch function is called.
7446fn dispatchZcuLinkTask(comp: *Compilation, tid: usize, task: link.ZcuTask) void {7451fn dispatchZcuLinkTask(comp: *Compilation, tid: usize, task: link.ZcuTask) void {
7452 comp.link_prog_node.increaseEstimatedTotalItems(1);
7447 if (!comp.separateCodegenThreadOk()) {7453 if (!comp.separateCodegenThreadOk()) {
7448 assert(tid == 0);7454 assert(tid == 0);
7449 if (task == .link_func) {7455 if (task == .link_func) {
src/link.zig+15-14
...@@ -1290,7 +1290,10 @@ pub const ZcuTask = union(enum) {...@@ -1290,7 +1290,10 @@ pub const ZcuTask = union(enum) {
12901290
1291pub fn doPrelinkTask(comp: *Compilation, task: PrelinkTask) void {1291pub fn doPrelinkTask(comp: *Compilation, task: PrelinkTask) void {
1292 const diags = &comp.link_diags;1292 const diags = &comp.link_diags;
1293 const base = comp.bin_file orelse return;1293 const base = comp.bin_file orelse {
1294 comp.link_prog_node.completeOne();
1295 return;
1296 };
1294 switch (task) {1297 switch (task) {
1295 .load_explicitly_provided => {1298 .load_explicitly_provided => {
1296 const prog_node = comp.link_prog_node.start("Parse Inputs", comp.link_inputs.len);1299 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 {...@@ -1413,12 +1416,13 @@ pub fn doPrelinkTask(comp: *Compilation, task: PrelinkTask) void {
1413}1416}
1414pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void {1417pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void {
1415 const diags = &comp.link_diags;1418 const diags = &comp.link_diags;
1419 const zcu = comp.zcu.?;
1420 const ip = &zcu.intern_pool;
1421 const pt: Zcu.PerThread = .activate(zcu, @enumFromInt(tid));
1422 defer pt.deactivate();
1416 switch (task) {1423 switch (task) {
1417 .link_nav => |nav_index| {1424 .link_nav => |nav_index| {
1418 const zcu = comp.zcu.?;1425 const fqn_slice = ip.getNav(nav_index).fqn.toSlice(ip);
1419 const pt: Zcu.PerThread = .activate(zcu, @enumFromInt(tid));
1420 defer pt.deactivate();
1421 const fqn_slice = zcu.intern_pool.getNav(nav_index).fqn.toSlice(&zcu.intern_pool);
1422 const nav_prog_node = comp.link_prog_node.start(fqn_slice, 0);1426 const nav_prog_node = comp.link_prog_node.start(fqn_slice, 0);
1423 defer nav_prog_node.end();1427 defer nav_prog_node.end();
1424 if (zcu.llvm_object) |llvm_object| {1428 if (zcu.llvm_object) |llvm_object| {
...@@ -1440,11 +1444,8 @@ pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void {...@@ -1440,11 +1444,8 @@ pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void {
1440 }1444 }
1441 },1445 },
1442 .link_func => |func| {1446 .link_func => |func| {
1443 const zcu = comp.zcu.?;
1444 const nav = zcu.funcInfo(func.func).owner_nav;1447 const nav = zcu.funcInfo(func.func).owner_nav;
1445 const pt: Zcu.PerThread = .activate(zcu, @enumFromInt(tid));1448 const fqn_slice = ip.getNav(nav).fqn.toSlice(ip);
1446 defer pt.deactivate();
1447 const fqn_slice = zcu.intern_pool.getNav(nav).fqn.toSlice(&zcu.intern_pool);
1448 const nav_prog_node = comp.link_prog_node.start(fqn_slice, 0);1449 const nav_prog_node = comp.link_prog_node.start(fqn_slice, 0);
1449 defer nav_prog_node.end();1450 defer nav_prog_node.end();
1450 switch (func.mir.status.load(.monotonic)) {1451 switch (func.mir.status.load(.monotonic)) {
...@@ -1468,9 +1469,9 @@ pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void {...@@ -1468,9 +1469,9 @@ pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void {
1468 }1469 }
1469 },1470 },
1470 .link_type => |ty| {1471 .link_type => |ty| {
1471 const zcu = comp.zcu.?;1472 const name = Type.fromInterned(ty).containerTypeName(ip).toSlice(ip);
1472 const pt: Zcu.PerThread = .activate(zcu, @enumFromInt(tid));1473 const nav_prog_node = comp.link_prog_node.start(name, 0);
1473 defer pt.deactivate();1474 defer nav_prog_node.end();
1474 if (zcu.llvm_object == null) {1475 if (zcu.llvm_object == null) {
1475 if (comp.bin_file) |lf| {1476 if (comp.bin_file) |lf| {
1476 lf.updateContainerType(pt, ty) catch |err| switch (err) {1477 lf.updateContainerType(pt, ty) catch |err| switch (err) {
...@@ -1481,8 +1482,8 @@ pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void {...@@ -1481,8 +1482,8 @@ pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void {
1481 }1482 }
1482 },1483 },
1483 .update_line_number => |ti| {1484 .update_line_number => |ti| {
1484 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));1485 const nav_prog_node = comp.link_prog_node.start("Update line number", 0);
1485 defer pt.deactivate();1486 defer nav_prog_node.end();
1486 if (pt.zcu.llvm_object == null) {1487 if (pt.zcu.llvm_object == null) {
1487 if (comp.bin_file) |lf| {1488 if (comp.bin_file) |lf| {
1488 lf.updateLineNumber(pt, ti) catch |err| switch (err) {1489 lf.updateLineNumber(pt, ti) catch |err| switch (err) {