authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-08-08 09:13:38+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-08-08 23:14:26+01:00
log5f7a0bbabfde4eeb0ff4f40f0942ef710b6104a1
tree33d506f40e4f7eef8b423ba1740c77675a0c5428
parent2a8751e37f1e4d978400a95faca05119f17cf598

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.

2 files changed, 30 insertions(+), 6 deletions(-)

src/Sema.zig+30
...@@ -34199,6 +34199,9 @@ pub fn resolveStructAlignment(...@@ -34199,6 +34199,9 @@ pub fn resolveStructAlignment(
34199 if (struct_type.assumePointerAlignedIfWip(ip, ptr_align)) return;34199 if (struct_type.assumePointerAlignedIfWip(ip, ptr_align)) return;
34200 defer struct_type.clearAlignmentWip(ip);34200 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
34202 var alignment: Alignment = .@"1";34205 var alignment: Alignment = .@"1";
3420334206
34204 for (0..struct_type.field_types.len) |i| {34207 for (0..struct_type.field_types.len) |i| {
...@@ -34229,6 +34232,9 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -34229,6 +34232,9 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3422934232
34230 try sema.resolveStructFieldTypes(ty.toIntern(), struct_type);34233 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
34232 if (struct_type.layout == .@"packed") {34238 if (struct_type.layout == .@"packed") {
34233 sema.backingIntType(struct_type) catch |err| switch (err) {34239 sema.backingIntType(struct_type) catch |err| switch (err) {
34234 error.OutOfMemory, error.AnalysisFail => |e| return e,34240 error.OutOfMemory, error.AnalysisFail => |e| return e,
...@@ -34532,6 +34538,9 @@ pub fn resolveUnionAlignment(...@@ -34532,6 +34538,9 @@ pub fn resolveUnionAlignment(
3453234538
34533 try sema.resolveUnionFieldTypes(ty, union_type);34539 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
34535 var max_align: Alignment = .@"1";34544 var max_align: Alignment = .@"1";
34536 for (0..union_type.field_types.len) |field_index| {34545 for (0..union_type.field_types.len) |field_index| {
34537 const field_ty: Type = .fromInterned(union_type.field_types.get(ip)[field_index]);34546 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 {...@@ -34579,6 +34588,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3457934588
34580 union_type.setStatus(ip, .layout_wip);34589 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
34582 var max_size: u64 = 0;34594 var max_size: u64 = 0;
34583 var max_align: Alignment = .@"1";34595 var max_align: Alignment = .@"1";
34584 for (0..union_type.field_types.len) |field_index| {34596 for (0..union_type.field_types.len) |field_index| {
...@@ -34695,6 +34707,9 @@ pub fn resolveStructFully(sema: *Sema, ty: Type) SemaError!void {...@@ -34695,6 +34707,9 @@ pub fn resolveStructFully(sema: *Sema, ty: Type) SemaError!void {
34695 if (struct_type.setFullyResolved(ip)) return;34707 if (struct_type.setFullyResolved(ip)) return;
34696 errdefer struct_type.clearFullyResolved(ip);34708 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
34698 // After we have resolve struct layout we have to go over the fields again to34713 // After we have resolve struct layout we have to go over the fields again to
34699 // make sure pointer fields get their child types resolved as well.34714 // make sure pointer fields get their child types resolved as well.
34700 // See also similar code for unions.34715 // See also similar code for unions.
...@@ -34720,6 +34735,9 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {...@@ -34720,6 +34735,9 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
34720 .fully_resolved_wip, .fully_resolved => return,34735 .fully_resolved_wip, .fully_resolved => return,
34721 }34736 }
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
34723 {34741 {
34724 // After we have resolve union layout we have to go over the fields again to34742 // After we have resolve union layout we have to go over the fields again to
34725 // make sure pointer fields get their child types resolved as well.34743 // make sure pointer fields get their child types resolved as well.
...@@ -34762,6 +34780,10 @@ pub fn resolveStructFieldTypes(...@@ -34762,6 +34780,10 @@ pub fn resolveStructFieldTypes(
34762 }34780 }
34763 defer struct_type.clearFieldTypesWip(ip);34781 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
34765 sema.structFields(struct_type) catch |err| switch (err) {34787 sema.structFields(struct_type) catch |err| switch (err) {
34766 error.AnalysisFail, error.OutOfMemory => |e| return e,34788 error.AnalysisFail, error.OutOfMemory => |e| return e,
34767 error.ComptimeBreak, error.ComptimeReturn => unreachable,34789 error.ComptimeBreak, error.ComptimeReturn => unreachable,
...@@ -34791,6 +34813,10 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) SemaError!void {...@@ -34791,6 +34813,10 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) SemaError!void {
34791 }34813 }
34792 defer struct_type.clearInitsWip(ip);34814 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
34794 sema.structFieldInits(struct_type) catch |err| switch (err) {34820 sema.structFieldInits(struct_type) catch |err| switch (err) {
34795 error.AnalysisFail, error.OutOfMemory => |e| return e,34821 error.AnalysisFail, error.OutOfMemory => |e| return e,
34796 error.ComptimeBreak, error.ComptimeReturn => unreachable,34822 error.ComptimeBreak, error.ComptimeReturn => unreachable,
...@@ -34819,6 +34845,10 @@ pub fn resolveUnionFieldTypes(sema: *Sema, ty: Type, union_type: InternPool.Load...@@ -34819,6 +34845,10 @@ pub fn resolveUnionFieldTypes(sema: *Sema, ty: Type, union_type: InternPool.Load
34819 => return,34845 => return,
34820 }34846 }
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
34822 union_type.setStatus(ip, .field_types_wip);34852 union_type.setStatus(ip, .field_types_wip);
34823 errdefer union_type.setStatus(ip, .none);34853 errdefer union_type.setStatus(ip, .none);
34824 sema.unionFields(ty.toIntern(), union_type) catch |err| switch (err) {34854 sema.unionFields(ty.toIntern(), union_type) catch |err| switch (err) {
src/Type.zig-6
...@@ -3797,9 +3797,6 @@ fn resolveStructInner(...@@ -3797,9 +3797,6 @@ fn resolveStructInner(
3797 return error.AnalysisFail;3797 return error.AnalysisFail;
3798 }3798 }
37993799
3800 const tracked_unit = zcu.trackUnitSema(struct_obj.name.toSlice(&zcu.intern_pool), null);
3801 defer tracked_unit.end(zcu);
3802
3803 if (zcu.comp.debugIncremental()) {3800 if (zcu.comp.debugIncremental()) {
3804 const info = try zcu.incremental_debug_state.getUnitInfo(gpa, owner);3801 const info = try zcu.incremental_debug_state.getUnitInfo(gpa, owner);
3805 info.last_update_gen = zcu.generation;3802 info.last_update_gen = zcu.generation;
...@@ -3859,9 +3856,6 @@ fn resolveUnionInner(...@@ -3859,9 +3856,6 @@ fn resolveUnionInner(
3859 return error.AnalysisFail;3856 return error.AnalysisFail;
3860 }3857 }
38613858
3862 const tracked_unit = zcu.trackUnitSema(union_obj.name.toSlice(&zcu.intern_pool), null);
3863 defer tracked_unit.end(zcu);
3864
3865 if (zcu.comp.debugIncremental()) {3859 if (zcu.comp.debugIncremental()) {
3866 const info = try zcu.incremental_debug_state.getUnitInfo(gpa, owner);3860 const info = try zcu.incremental_debug_state.getUnitInfo(gpa, owner);
3867 info.last_update_gen = zcu.generation;3861 info.last_update_gen = zcu.generation;