Skip to content

Commit 5f7a0bb

Browse files
committed
Sema: fix unreasonable progress node numbers
The "completed" count in the "Semantic Analysis" progress node had regressed since 0.14.0: the number got crazy big very fast, even on simple cases. For instance, an empty `pub fn main` got to ~59,000 where on 0.14 it only reached ~4,000. This was happening because I was unintentionally introducing a node every time type resolution was *requested*, even if (as is usually the case) it turned out to already be done. The fix is simply to start the progress node a little later, once we know we are actually doing semantic analysis. This brings the number for that empty test case down to ~5,000, which makes perfect sense. It won't exactly match 0.14, because the standard library has changed, and also because the compiler's progress output does have some *intentional* changes.
1 parent 2a8751e commit 5f7a0bb

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/Sema.zig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34199,6 +34199,9 @@ pub fn resolveStructAlignment(
3419934199
if (struct_type.assumePointerAlignedIfWip(ip, ptr_align)) return;
3420034200
defer struct_type.clearAlignmentWip(ip);
3420134201

34202+
// No `zcu.trackUnitSema` calls, since this phase isn't really doing any semantic analysis.
34203+
// It's just triggering *other* analysis, alongside a simple loop over already-resolved info.
34204+
3420234205
var alignment: Alignment = .@"1";
3420334206

3420434207
for (0..struct_type.field_types.len) |i| {
@@ -34229,6 +34232,9 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3422934232

3423034233
try sema.resolveStructFieldTypes(ty.toIntern(), struct_type);
3423134234

34235+
// No `zcu.trackUnitSema` calls, since this phase isn't really doing any semantic analysis.
34236+
// It's just triggering *other* analysis, alongside a simple loop over already-resolved info.
34237+
3423234238
if (struct_type.layout == .@"packed") {
3423334239
sema.backingIntType(struct_type) catch |err| switch (err) {
3423434240
error.OutOfMemory, error.AnalysisFail => |e| return e,
@@ -34532,6 +34538,9 @@ pub fn resolveUnionAlignment(
3453234538

3453334539
try sema.resolveUnionFieldTypes(ty, union_type);
3453434540

34541+
// No `zcu.trackUnitSema` calls, since this phase isn't really doing any semantic analysis.
34542+
// It's just triggering *other* analysis, alongside a simple loop over already-resolved info.
34543+
3453534544
var max_align: Alignment = .@"1";
3453634545
for (0..union_type.field_types.len) |field_index| {
3453734546
const field_ty: Type = .fromInterned(union_type.field_types.get(ip)[field_index]);
@@ -34579,6 +34588,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3457934588

3458034589
union_type.setStatus(ip, .layout_wip);
3458134590

34591+
// No `zcu.trackUnitSema` calls, since this phase isn't really doing any semantic analysis.
34592+
// It's just triggering *other* analysis, alongside a simple loop over already-resolved info.
34593+
3458234594
var max_size: u64 = 0;
3458334595
var max_align: Alignment = .@"1";
3458434596
for (0..union_type.field_types.len) |field_index| {
@@ -34695,6 +34707,9 @@ pub fn resolveStructFully(sema: *Sema, ty: Type) SemaError!void {
3469534707
if (struct_type.setFullyResolved(ip)) return;
3469634708
errdefer struct_type.clearFullyResolved(ip);
3469734709

34710+
// No `zcu.trackUnitSema` calls, since this phase isn't really doing any semantic analysis.
34711+
// It's just triggering *other* analysis, alongside a simple loop over already-resolved info.
34712+
3469834713
// After we have resolve struct layout we have to go over the fields again to
3469934714
// make sure pointer fields get their child types resolved as well.
3470034715
// See also similar code for unions.
@@ -34720,6 +34735,9 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3472034735
.fully_resolved_wip, .fully_resolved => return,
3472134736
}
3472234737

34738+
// No `zcu.trackUnitSema` calls, since this phase isn't really doing any semantic analysis.
34739+
// It's just triggering *other* analysis, alongside a simple loop over already-resolved info.
34740+
3472334741
{
3472434742
// After we have resolve union layout we have to go over the fields again to
3472534743
// make sure pointer fields get their child types resolved as well.
@@ -34762,6 +34780,10 @@ pub fn resolveStructFieldTypes(
3476234780
}
3476334781
defer struct_type.clearFieldTypesWip(ip);
3476434782

34783+
// can't happen earlier than this because we only want the progress node if not already resolved
34784+
const tracked_unit = zcu.trackUnitSema(struct_type.name.toSlice(ip), null);
34785+
defer tracked_unit.end(zcu);
34786+
3476534787
sema.structFields(struct_type) catch |err| switch (err) {
3476634788
error.AnalysisFail, error.OutOfMemory => |e| return e,
3476734789
error.ComptimeBreak, error.ComptimeReturn => unreachable,
@@ -34791,6 +34813,10 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) SemaError!void {
3479134813
}
3479234814
defer struct_type.clearInitsWip(ip);
3479334815

34816+
// can't happen earlier than this because we only want the progress node if not already resolved
34817+
const tracked_unit = zcu.trackUnitSema(struct_type.name.toSlice(ip), null);
34818+
defer tracked_unit.end(zcu);
34819+
3479434820
sema.structFieldInits(struct_type) catch |err| switch (err) {
3479534821
error.AnalysisFail, error.OutOfMemory => |e| return e,
3479634822
error.ComptimeBreak, error.ComptimeReturn => unreachable,
@@ -34819,6 +34845,10 @@ pub fn resolveUnionFieldTypes(sema: *Sema, ty: Type, union_type: InternPool.Load
3481934845
=> return,
3482034846
}
3482134847

34848+
// can't happen earlier than this because we only want the progress node if not already resolved
34849+
const tracked_unit = zcu.trackUnitSema(union_type.name.toSlice(ip), null);
34850+
defer tracked_unit.end(zcu);
34851+
3482234852
union_type.setStatus(ip, .field_types_wip);
3482334853
errdefer union_type.setStatus(ip, .none);
3482434854
sema.unionFields(ty.toIntern(), union_type) catch |err| switch (err) {

src/Type.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3797,9 +3797,6 @@ fn resolveStructInner(
37973797
return error.AnalysisFail;
37983798
}
37993799

3800-
const tracked_unit = zcu.trackUnitSema(struct_obj.name.toSlice(&zcu.intern_pool), null);
3801-
defer tracked_unit.end(zcu);
3802-
38033800
if (zcu.comp.debugIncremental()) {
38043801
const info = try zcu.incremental_debug_state.getUnitInfo(gpa, owner);
38053802
info.last_update_gen = zcu.generation;
@@ -3859,9 +3856,6 @@ fn resolveUnionInner(
38593856
return error.AnalysisFail;
38603857
}
38613858

3862-
const tracked_unit = zcu.trackUnitSema(union_obj.name.toSlice(&zcu.intern_pool), null);
3863-
defer tracked_unit.end(zcu);
3864-
38653859
if (zcu.comp.debugIncremental()) {
38663860
const info = try zcu.incremental_debug_state.getUnitInfo(gpa, owner);
38673861
info.last_update_gen = zcu.generation;

0 commit comments

Comments
 (0)