Skip to content

Commit c118e4d

Browse files
committed
compiler: improve progress output
Update the estimated total items for the codegen and link progress nodes earlier. Rather than waiting for the main thread to dispatch the tasks, we can add the item to the estimated total as soon as we queue the main task. The only difference is we need to complete it even in error cases.
1 parent f71f1ea commit c118e4d

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

src/Compilation.zig

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,8 @@ const Job = union(enum) {
848848
/// This `Job` exists (instead of the `link.ZcuTask` being directly queued) to ensure that
849849
/// all types are resolved before the linker task is queued.
850850
/// If the backend does not support `Zcu.Feature.separate_thread`, codegen and linking happen immediately.
851+
/// Before queueing this `Job`, increase the estimated total item count for both
852+
/// `comp.zcu.?.codegen_prog_node` and `comp.link_prog_node`.
851853
codegen_func: struct {
852854
func: InternPool.Index,
853855
/// The AIR emitted from analyzing `func`; owned by this `Job` in `gpa`.
@@ -857,12 +859,15 @@ const Job = union(enum) {
857859
/// This `Job` exists (instead of the `link.ZcuTask` being directly queued) to ensure that
858860
/// all types are resolved before the linker task is queued.
859861
/// If the backend does not support `Zcu.Feature.separate_thread`, the task is run immediately.
862+
/// Before queueing this `Job`, increase the estimated total item count for `comp.link_prog_node`.
860863
link_nav: InternPool.Nav.Index,
861864
/// Queue a `link.ZcuTask` to emit debug information for this container type.
862865
/// This `Job` exists (instead of the `link.ZcuTask` being directly queued) to ensure that
863866
/// all types are resolved before the linker task is queued.
864867
/// If the backend does not support `Zcu.Feature.separate_thread`, the task is run immediately.
868+
/// Before queueing this `Job`, increase the estimated total item count for `comp.link_prog_node`.
865869
link_type: InternPool.Index,
870+
/// Before queueing this `Job`, increase the estimated total item count for `comp.link_prog_node`.
866871
update_line_number: InternPool.TrackedInst.Index,
867872
/// The `AnalUnit`, which is *not* a `func`, must be semantically analyzed.
868873
/// This may be its first time being analyzed, or it may be outdated.
@@ -4592,11 +4597,17 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
45924597
const zcu = comp.zcu.?;
45934598
const gpa = zcu.gpa;
45944599
var air = func.air;
4595-
errdefer air.deinit(gpa);
4600+
errdefer {
4601+
zcu.codegen_prog_node.completeOne();
4602+
comp.link_prog_node.completeOne();
4603+
air.deinit(gpa);
4604+
}
45964605
if (!air.typesFullyResolved(zcu)) {
45974606
// Type resolution failed in a way which affects this function. This is a transitive
45984607
// failure, but it doesn't need recording, because this function semantically depends
45994608
// on the failed type, so when it is changed the function is updated.
4609+
zcu.codegen_prog_node.completeOne();
4610+
comp.link_prog_node.completeOne();
46004611
air.deinit(gpa);
46014612
return;
46024613
}
@@ -4606,7 +4617,6 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
46064617
.value = undefined,
46074618
};
46084619
assert(zcu.pending_codegen_jobs.rmw(.Add, 1, .monotonic) > 0); // the "Code Generation" node hasn't been ended
4609-
zcu.codegen_prog_node.increaseEstimatedTotalItems(1);
46104620
// This value is used as a heuristic to avoid queueing too much AIR/MIR at once (hence
46114621
// using a lot of memory). If this would cause too many AIR bytes to be in-flight, we
46124622
// will block on the `dispatchZcuLinkTask` call below.
@@ -4640,6 +4650,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
46404650
if (nav.analysis != null) {
46414651
const unit: InternPool.AnalUnit = .wrap(.{ .nav_val = nav_index });
46424652
if (zcu.failed_analysis.contains(unit) or zcu.transitive_failed_analysis.contains(unit)) {
4653+
comp.link_prog_node.completeOne();
46434654
return;
46444655
}
46454656
}
@@ -4648,6 +4659,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
46484659
// Type resolution failed in a way which affects this `Nav`. This is a transitive
46494660
// failure, but it doesn't need recording, because this `Nav` semantically depends
46504661
// on the failed type, so when it is changed the `Nav` will be updated.
4662+
comp.link_prog_node.completeOne();
46514663
return;
46524664
}
46534665
comp.dispatchZcuLinkTask(tid, .{ .link_nav = nav_index });
@@ -4659,6 +4671,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
46594671
// Type resolution failed in a way which affects this type. This is a transitive
46604672
// failure, but it doesn't need recording, because this type semantically depends
46614673
// on the failed type, so when that is changed, this type will be updated.
4674+
comp.link_prog_node.completeOne();
46624675
return;
46634676
}
46644677
comp.dispatchZcuLinkTask(tid, .{ .link_type = ty });
@@ -7460,7 +7473,6 @@ pub fn queuePrelinkTasks(comp: *Compilation, tasks: []const link.PrelinkTask) vo
74607473
/// The reason for the double-queue here is that the first queue ensures any
74617474
/// resolve_type_fully tasks are complete before this dispatch function is called.
74627475
fn dispatchZcuLinkTask(comp: *Compilation, tid: usize, task: link.ZcuTask) void {
7463-
comp.link_prog_node.increaseEstimatedTotalItems(1);
74647476
if (!comp.separateCodegenThreadOk()) {
74657477
assert(tid == 0);
74667478
if (task == .link_func) {

src/Sema.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2992,6 +2992,7 @@ fn zirStructDecl(
29922992
if (zcu.comp.config.use_llvm) break :codegen_type;
29932993
if (block.ownerModule().strip) break :codegen_type;
29942994
// This job depends on any resolve_type_fully jobs queued up before it.
2995+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
29952996
try zcu.comp.queueJob(.{ .link_type = wip_ty.index });
29962997
}
29972998
try sema.declareDependency(.{ .interned = wip_ty.index });
@@ -3266,6 +3267,7 @@ fn zirEnumDecl(
32663267
if (zcu.comp.config.use_llvm) break :codegen_type;
32673268
if (block.ownerModule().strip) break :codegen_type;
32683269
// This job depends on any resolve_type_fully jobs queued up before it.
3270+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
32693271
try zcu.comp.queueJob(.{ .link_type = wip_ty.index });
32703272
}
32713273
return Air.internedToRef(wip_ty.index);
@@ -3385,6 +3387,7 @@ fn zirUnionDecl(
33853387
if (zcu.comp.config.use_llvm) break :codegen_type;
33863388
if (block.ownerModule().strip) break :codegen_type;
33873389
// This job depends on any resolve_type_fully jobs queued up before it.
3390+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
33883391
try zcu.comp.queueJob(.{ .link_type = wip_ty.index });
33893392
}
33903393
try sema.declareDependency(.{ .interned = wip_ty.index });
@@ -3473,6 +3476,7 @@ fn zirOpaqueDecl(
34733476
if (zcu.comp.config.use_llvm) break :codegen_type;
34743477
if (block.ownerModule().strip) break :codegen_type;
34753478
// This job depends on any resolve_type_fully jobs queued up before it.
3479+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
34763480
try zcu.comp.queueJob(.{ .link_type = wip_ty.index });
34773481
}
34783482
try sema.addTypeReferenceEntry(src, wip_ty.index);
@@ -20105,6 +20109,7 @@ fn structInitAnon(
2010520109
codegen_type: {
2010620110
if (zcu.comp.config.use_llvm) break :codegen_type;
2010720111
if (block.ownerModule().strip) break :codegen_type;
20112+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
2010820113
try zcu.comp.queueJob(.{ .link_type = wip.index });
2010920114
}
2011020115
if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newType(zcu, wip.index);
@@ -21417,6 +21422,7 @@ fn reifyEnum(
2141721422
if (zcu.comp.config.use_llvm) break :codegen_type;
2141821423
if (block.ownerModule().strip) break :codegen_type;
2141921424
// This job depends on any resolve_type_fully jobs queued up before it.
21425+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
2142021426
try zcu.comp.queueJob(.{ .link_type = wip_ty.index });
2142121427
}
2142221428
return Air.internedToRef(wip_ty.index);
@@ -21671,6 +21677,7 @@ fn reifyUnion(
2167121677
if (zcu.comp.config.use_llvm) break :codegen_type;
2167221678
if (block.ownerModule().strip) break :codegen_type;
2167321679
// This job depends on any resolve_type_fully jobs queued up before it.
21680+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
2167421681
try zcu.comp.queueJob(.{ .link_type = wip_ty.index });
2167521682
}
2167621683
try sema.declareDependency(.{ .interned = wip_ty.index });
@@ -22026,6 +22033,7 @@ fn reifyStruct(
2202622033
if (zcu.comp.config.use_llvm) break :codegen_type;
2202722034
if (block.ownerModule().strip) break :codegen_type;
2202822035
// This job depends on any resolve_type_fully jobs queued up before it.
22036+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
2202922037
try zcu.comp.queueJob(.{ .link_type = wip_ty.index });
2203022038
}
2203122039
try sema.declareDependency(.{ .interned = wip_ty.index });

src/Sema/LowerZon.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ fn lowerExprAnonResTy(self: *LowerZon, node: Zoir.Node.Index) CompileError!Inter
195195
codegen_type: {
196196
if (pt.zcu.comp.config.use_llvm) break :codegen_type;
197197
if (self.block.ownerModule().strip) break :codegen_type;
198+
pt.zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
198199
try pt.zcu.comp.queueJob(.{ .link_type = wip.index });
199200
}
200201
break :ty wip.finish(ip, new_namespace_index);

src/Zcu/PerThread.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,7 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr
13211321
}
13221322

13231323
// This job depends on any resolve_type_fully jobs queued up before it.
1324+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
13241325
try zcu.comp.queueJob(.{ .link_nav = nav_id });
13251326
}
13261327

@@ -1717,6 +1718,8 @@ fn analyzeFuncBody(
17171718
}
17181719

17191720
// This job depends on any resolve_type_fully jobs queued up before it.
1721+
zcu.codegen_prog_node.increaseEstimatedTotalItems(1);
1722+
comp.link_prog_node.increaseEstimatedTotalItems(1);
17201723
try comp.queueJob(.{ .codegen_func = .{
17211724
.func = func_index,
17221725
.air = air,
@@ -1799,6 +1802,7 @@ fn createFileRootStruct(
17991802
codegen_type: {
18001803
if (file.mod.?.strip) break :codegen_type;
18011804
// This job depends on any resolve_type_fully jobs queued up before it.
1805+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
18021806
try zcu.comp.queueJob(.{ .link_type = wip_ty.index });
18031807
}
18041808
zcu.setFileRootType(file_index, wip_ty.index);
@@ -3827,6 +3831,7 @@ pub fn getExtern(pt: Zcu.PerThread, key: InternPool.Key.Extern) Allocator.Error!
38273831
const result = try pt.zcu.intern_pool.getExtern(pt.zcu.gpa, pt.tid, key);
38283832
if (result.new_nav.unwrap()) |nav| {
38293833
// This job depends on any resolve_type_fully jobs queued up before it.
3834+
pt.zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
38303835
try pt.zcu.comp.queueJob(.{ .link_nav = nav });
38313836
if (pt.zcu.comp.debugIncremental()) try pt.zcu.incremental_debug_state.newNav(pt.zcu, nav);
38323837
}
@@ -3974,6 +3979,7 @@ fn recreateStructType(
39743979
codegen_type: {
39753980
if (file.mod.?.strip) break :codegen_type;
39763981
// This job depends on any resolve_type_fully jobs queued up before it.
3982+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
39773983
try zcu.comp.queueJob(.{ .link_type = wip_ty.index });
39783984
}
39793985

@@ -4066,6 +4072,7 @@ fn recreateUnionType(
40664072
codegen_type: {
40674073
if (file.mod.?.strip) break :codegen_type;
40684074
// This job depends on any resolve_type_fully jobs queued up before it.
4075+
zcu.comp.link_prog_node.increaseEstimatedTotalItems(1);
40694076
try zcu.comp.queueJob(.{ .link_type = wip_ty.index });
40704077
}
40714078

0 commit comments

Comments
 (0)