@@ -348,12 +348,15 @@ const Job = union(enum) {
348
348
/// Corresponds to the task in `link.Task`.
349
349
/// Only needed for backends that haven't yet been updated to not race against Sema.
350
350
codegen_type : InternPool.Index ,
351
- /// The `Cau` must be semantically analyzed (and possibly export itself).
351
+ /// The `AnalUnit`, which is *not* a `func`, must be semantically analyzed.
352
+ /// This may be its first time being analyzed, or it may be outdated.
353
+ /// If the unit is a function, a `codegen_func` job will then be queued.
354
+ analyze_comptime_unit : InternPool.AnalUnit ,
355
+ /// This function must be semantically analyzed.
352
356
/// This may be its first time being analyzed, or it may be outdated.
353
- analyze_cau : InternPool.Cau.Index ,
354
- /// Analyze the body of a runtime function.
355
357
/// After analysis, a `codegen_func` job will be queued.
356
358
/// These must be separate jobs to ensure any needed type resolution occurs *before* codegen.
359
+ /// This job is separate from `analyze_comptime_unit` because it has a different priority.
357
360
analyze_func : InternPool.Index ,
358
361
/// The main source file for the module needs to be analyzed.
359
362
analyze_mod : * Package.Module ,
@@ -2903,6 +2906,7 @@ const Header = extern struct {
2903
2906
file_deps_len : u32 ,
2904
2907
src_hash_deps_len : u32 ,
2905
2908
nav_val_deps_len : u32 ,
2909
+ nav_ty_deps_len : u32 ,
2906
2910
namespace_deps_len : u32 ,
2907
2911
namespace_name_deps_len : u32 ,
2908
2912
first_dependency_len : u32 ,
@@ -2946,6 +2950,7 @@ pub fn saveState(comp: *Compilation) !void {
2946
2950
.file_deps_len = @intCast (ip .file_deps .count ()),
2947
2951
.src_hash_deps_len = @intCast (ip .src_hash_deps .count ()),
2948
2952
.nav_val_deps_len = @intCast (ip .nav_val_deps .count ()),
2953
+ .nav_ty_deps_len = @intCast (ip .nav_ty_deps .count ()),
2949
2954
.namespace_deps_len = @intCast (ip .namespace_deps .count ()),
2950
2955
.namespace_name_deps_len = @intCast (ip .namespace_name_deps .count ()),
2951
2956
.first_dependency_len = @intCast (ip .first_dependency .count ()),
@@ -2976,6 +2981,8 @@ pub fn saveState(comp: *Compilation) !void {
2976
2981
addBuf (& bufs , mem .sliceAsBytes (ip .src_hash_deps .values ()));
2977
2982
addBuf (& bufs , mem .sliceAsBytes (ip .nav_val_deps .keys ()));
2978
2983
addBuf (& bufs , mem .sliceAsBytes (ip .nav_val_deps .values ()));
2984
+ addBuf (& bufs , mem .sliceAsBytes (ip .nav_ty_deps .keys ()));
2985
+ addBuf (& bufs , mem .sliceAsBytes (ip .nav_ty_deps .values ()));
2979
2986
addBuf (& bufs , mem .sliceAsBytes (ip .namespace_deps .keys ()));
2980
2987
addBuf (& bufs , mem .sliceAsBytes (ip .namespace_deps .values ()));
2981
2988
addBuf (& bufs , mem .sliceAsBytes (ip .namespace_name_deps .keys ()));
@@ -3141,8 +3148,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3141
3148
}
3142
3149
3143
3150
const file_index = switch (anal_unit .unwrap ()) {
3144
- .cau = > | cau | zcu .namespacePtr (ip .getCau (cau ).namespace ).file_scope ,
3145
- .func = > | ip_index | (zcu .funcInfo (ip_index ).zir_body_inst .resolveFull (ip ) orelse continue ).file ,
3151
+ .@"comptime" = > | cu | ip .getComptimeUnit (cu ).zir_index .resolveFile (ip ),
3152
+ .nav_val , .nav_ty = > | nav | ip .getNav (nav ).analysis .? .zir_index .resolveFile (ip ),
3153
+ .type = > | ty | Type .fromInterned (ty ).typeDeclInst (zcu ).? .resolveFile (ip ),
3154
+ .func = > | ip_index | zcu .funcInfo (ip_index ).zir_body_inst .resolveFile (ip ),
3146
3155
};
3147
3156
3148
3157
// Skip errors for AnalUnits within files that had a parse failure.
@@ -3374,11 +3383,9 @@ pub fn addModuleErrorMsg(
3374
3383
const rt_file_path = try src .file_scope .fullPath (gpa );
3375
3384
defer gpa .free (rt_file_path );
3376
3385
const name = switch (ref .referencer .unwrap ()) {
3377
- .cau = > | cau | switch (ip .getCau (cau ).owner .unwrap ()) {
3378
- .nav = > | nav | ip .getNav (nav ).name .toSlice (ip ),
3379
- .type = > | ty | Type .fromInterned (ty ).containerTypeName (ip ).toSlice (ip ),
3380
- .none = > "comptime" ,
3381
- },
3386
+ .@"comptime" = > "comptime" ,
3387
+ .nav_val , .nav_ty = > | nav | ip .getNav (nav ).name .toSlice (ip ),
3388
+ .type = > | ty | Type .fromInterned (ty ).containerTypeName (ip ).toSlice (ip ),
3382
3389
.func = > | f | ip .getNav (zcu .funcInfo (f ).owner_nav ).name .toSlice (ip ),
3383
3390
};
3384
3391
try ref_traces .append (gpa , .{
@@ -3641,10 +3648,14 @@ fn performAllTheWorkInner(
3641
3648
// If there's no work queued, check if there's anything outdated
3642
3649
// which we need to work on, and queue it if so.
3643
3650
if (try zcu .findOutdatedToAnalyze ()) | outdated | {
3644
- switch (outdated .unwrap ()) {
3645
- .cau = > | cau | try comp .queueJob (.{ .analyze_cau = cau }),
3646
- .func = > | func | try comp .queueJob (.{ .analyze_func = func }),
3647
- }
3651
+ try comp .queueJob (switch (outdated .unwrap ()) {
3652
+ .func = > | f | .{ .analyze_func = f },
3653
+ .@"comptime" ,
3654
+ .nav_ty ,
3655
+ .nav_val ,
3656
+ .type ,
3657
+ = > .{ .analyze_comptime_unit = outdated },
3658
+ });
3648
3659
continue ;
3649
3660
}
3650
3661
}
@@ -3667,13 +3678,13 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
3667
3678
.codegen_nav = > | nav_index | {
3668
3679
const zcu = comp .zcu .? ;
3669
3680
const nav = zcu .intern_pool .getNav (nav_index );
3670
- if (nav .analysis_owner . unwrap ()) | cau | {
3671
- const unit = InternPool .AnalUnit .wrap (.{ .cau = cau });
3681
+ if (nav .analysis != null ) {
3682
+ const unit : InternPool.AnalUnit = .wrap (.{ .nav_val = nav_index });
3672
3683
if (zcu .failed_analysis .contains (unit ) or zcu .transitive_failed_analysis .contains (unit )) {
3673
3684
return ;
3674
3685
}
3675
3686
}
3676
- assert (nav .status == .resolved );
3687
+ assert (nav .status == .fully_resolved );
3677
3688
comp .dispatchCodegenTask (tid , .{ .codegen_nav = nav_index });
3678
3689
},
3679
3690
.codegen_func = > | func | {
@@ -3688,36 +3699,48 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
3688
3699
3689
3700
const pt : Zcu.PerThread = .activate (comp .zcu .? , @enumFromInt (tid ));
3690
3701
defer pt .deactivate ();
3691
- pt .ensureFuncBodyAnalyzed (func ) catch | err | switch (err ) {
3692
- error .OutOfMemory = > return error .OutOfMemory ,
3702
+
3703
+ pt .ensureFuncBodyUpToDate (func ) catch | err | switch (err ) {
3704
+ error .OutOfMemory = > | e | return e ,
3693
3705
error .AnalysisFail = > return ,
3694
3706
};
3695
3707
},
3696
- .analyze_cau = > | cau_index | {
3708
+ .analyze_comptime_unit = > | unit | {
3709
+ const named_frame = tracy .namedFrame ("analyze_comptime_unit" );
3710
+ defer named_frame .end ();
3711
+
3697
3712
const pt : Zcu.PerThread = .activate (comp .zcu .? , @enumFromInt (tid ));
3698
3713
defer pt .deactivate ();
3699
- pt .ensureCauAnalyzed (cau_index ) catch | err | switch (err ) {
3700
- error .OutOfMemory = > return error .OutOfMemory ,
3714
+
3715
+ const maybe_err : Zcu .SemaError ! void = switch (unit .unwrap ()) {
3716
+ .@"comptime" = > | cu | pt .ensureComptimeUnitUpToDate (cu ),
3717
+ .nav_ty = > | nav | pt .ensureNavTypeUpToDate (nav ),
3718
+ .nav_val = > | nav | pt .ensureNavValUpToDate (nav ),
3719
+ .type = > | ty | if (pt .ensureTypeUpToDate (ty )) | _ | {} else | err | err ,
3720
+ .func = > unreachable ,
3721
+ };
3722
+ maybe_err catch | err | switch (err ) {
3723
+ error .OutOfMemory = > | e | return e ,
3701
3724
error .AnalysisFail = > return ,
3702
3725
};
3726
+
3703
3727
queue_test_analysis : {
3704
3728
if (! comp .config .is_test ) break :queue_test_analysis ;
3729
+ const nav = switch (unit .unwrap ()) {
3730
+ .nav_val = > | nav | nav ,
3731
+ else = > break :queue_test_analysis ,
3732
+ };
3705
3733
3706
3734
// Check if this is a test function.
3707
3735
const ip = & pt .zcu .intern_pool ;
3708
- const cau = ip .getCau (cau_index );
3709
- const nav_index = switch (cau .owner .unwrap ()) {
3710
- .none , .type = > break :queue_test_analysis ,
3711
- .nav = > | nav | nav ,
3712
- };
3713
- if (! pt .zcu .test_functions .contains (nav_index )) {
3736
+ if (! pt .zcu .test_functions .contains (nav )) {
3714
3737
break :queue_test_analysis ;
3715
3738
}
3716
3739
3717
3740
// Tests are always emitted in test binaries. The decl_refs are created by
3718
3741
// Zcu.populateTestFunctions, but this will not queue body analysis, so do
3719
3742
// that now.
3720
- try pt .zcu .ensureFuncBodyAnalysisQueued (ip .getNav (nav_index ).status .resolved .val );
3743
+ try pt .zcu .ensureFuncBodyAnalysisQueued (ip .getNav (nav ).status .fully_resolved .val );
3721
3744
}
3722
3745
},
3723
3746
.resolve_type_fully = > | ty | {
0 commit comments