authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-03-11 16:47:28+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-03-12 12:25:50-07:00
logfdc9326868d8ab68bfa540167175287282636b08
treeed424da8975bc410535f11626db4aa809f3adc65
parentaf4b39395c8b6af2fcbac708d012e267924e0652

Zcu: rename `skip_analysis_errors` to `skip_analysis_this_update` and respect it

On updates with failed files, we should refrain from doing any semantic analysis, or even touching codegen/link. That way, incremental compilation state is untouched for when the user fixes the AstGen errors. Resolves: #23205

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

src/Compilation.zig+15-13
...@@ -2261,7 +2261,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {...@@ -2261,7 +2261,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
22612261
2262 zcu.compile_log_text.shrinkAndFree(gpa, 0);2262 zcu.compile_log_text.shrinkAndFree(gpa, 0);
22632263
2264 zcu.skip_analysis_errors = false;2264 zcu.skip_analysis_this_update = false;
22652265
2266 // Make sure std.zig is inside the import_table. We unconditionally need2266 // Make sure std.zig is inside the import_table. We unconditionally need
2267 // it for start.zig.2267 // it for start.zig.
...@@ -2336,6 +2336,17 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {...@@ -2336,6 +2336,17 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
2336 const pt: Zcu.PerThread = .activate(zcu, .main);2336 const pt: Zcu.PerThread = .activate(zcu, .main);
2337 defer pt.deactivate();2337 defer pt.deactivate();
23382338
2339 if (!zcu.skip_analysis_this_update) {
2340 if (comp.config.is_test) {
2341 // The `test_functions` decl has been intentionally postponed until now,
2342 // at which point we must populate it with the list of test functions that
2343 // have been discovered and not filtered out.
2344 try pt.populateTestFunctions(main_progress_node);
2345 }
2346
2347 try pt.processExports();
2348 }
2349
2339 if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {2350 if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {
2340 std.debug.print("intern pool stats for '{s}':\n", .{2351 std.debug.print("intern pool stats for '{s}':\n", .{
2341 comp.root_name,2352 comp.root_name,
...@@ -2350,15 +2361,6 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {...@@ -2350,15 +2361,6 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
2350 });2361 });
2351 zcu.intern_pool.dumpGenericInstances(gpa);2362 zcu.intern_pool.dumpGenericInstances(gpa);
2352 }2363 }
2353
2354 if (comp.config.is_test) {
2355 // The `test_functions` decl has been intentionally postponed until now,
2356 // at which point we must populate it with the list of test functions that
2357 // have been discovered and not filtered out.
2358 try pt.populateTestFunctions(main_progress_node);
2359 }
2360
2361 try pt.processExports();
2362 }2364 }
23632365
2364 if (anyErrors(comp)) {2366 if (anyErrors(comp)) {
...@@ -3310,7 +3312,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3310,7 +3312,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3310 }3312 }
3311 }3313 }
3312 }3314 }
3313 if (zcu.skip_analysis_errors) break :zcu_errors;3315 if (zcu.skip_analysis_this_update) break :zcu_errors;
3314 var sorted_failed_analysis: std.AutoArrayHashMapUnmanaged(InternPool.AnalUnit, *Zcu.ErrorMsg).DataList.Slice = s: {3316 var sorted_failed_analysis: std.AutoArrayHashMapUnmanaged(InternPool.AnalUnit, *Zcu.ErrorMsg).DataList.Slice = s: {
3315 const SortOrder = struct {3317 const SortOrder = struct {
3316 zcu: *Zcu,3318 zcu: *Zcu,
...@@ -3446,7 +3448,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3446,7 +3448,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3446 try comp.link_diags.addMessagesToBundle(&bundle, comp.bin_file);3448 try comp.link_diags.addMessagesToBundle(&bundle, comp.bin_file);
34473449
3448 if (comp.zcu) |zcu| {3450 if (comp.zcu) |zcu| {
3449 if (!zcu.skip_analysis_errors and bundle.root_list.items.len == 0 and zcu.compile_log_sources.count() != 0) {3451 if (!zcu.skip_analysis_this_update and bundle.root_list.items.len == 0 and zcu.compile_log_sources.count() != 0) {
3450 const values = zcu.compile_log_sources.values();3452 const values = zcu.compile_log_sources.values();
3451 // First one will be the error; subsequent ones will be notes.3453 // First one will be the error; subsequent ones will be notes.
3452 const src_loc = values[0].src();3454 const src_loc = values[0].src();
...@@ -3957,7 +3959,7 @@ fn performAllTheWorkInner(...@@ -3957,7 +3959,7 @@ fn performAllTheWorkInner(
3957 // However, this means our analysis data is invalid, so we want to omit all analysis errors.3959 // However, this means our analysis data is invalid, so we want to omit all analysis errors.
39583960
3959 assert(zcu.failed_files.count() > 0); // we will get an error3961 assert(zcu.failed_files.count() > 0); // we will get an error
3960 zcu.skip_analysis_errors = true;3962 zcu.skip_analysis_this_update = true;
3961 return;3963 return;
3962 }3964 }
39633965
src/Zcu.zig+4-1
...@@ -181,7 +181,10 @@ analysis_roots: std.BoundedArray(*Package.Module, 4) = .{},...@@ -181,7 +181,10 @@ analysis_roots: std.BoundedArray(*Package.Module, 4) = .{},
181/// Allocated into `gpa`.181/// Allocated into `gpa`.
182resolved_references: ?std.AutoHashMapUnmanaged(AnalUnit, ?ResolvedReference) = null,182resolved_references: ?std.AutoHashMapUnmanaged(AnalUnit, ?ResolvedReference) = null,
183183
184skip_analysis_errors: bool = false,184/// If `true`, then semantic analysis must not occur on this update due to AstGen errors.
185/// Essentially the entire pipeline after AstGen, including Sema, codegen, and link, is skipped.
186/// Reset to `false` at the start of each update in `Compilation.update`.
187skip_analysis_this_update: bool = false,
185188
186stage1_flags: packed struct {189stage1_flags: packed struct {
187 have_winmain: bool = false,190 have_winmain: bool = false,