Skip to content

Commit fdc9326

Browse files
mluggandrewrk
authored andcommitted
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
1 parent af4b393 commit fdc9326

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/Compilation.zig

+15-13
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
22612261

22622262
zcu.compile_log_text.shrinkAndFree(gpa, 0);
22632263

2264-
zcu.skip_analysis_errors = false;
2264+
zcu.skip_analysis_this_update = false;
22652265

22662266
// Make sure std.zig is inside the import_table. We unconditionally need
22672267
// it for start.zig.
@@ -2336,6 +2336,17 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
23362336
const pt: Zcu.PerThread = .activate(zcu, .main);
23372337
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+
23392350
if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {
23402351
std.debug.print("intern pool stats for '{s}':\n", .{
23412352
comp.root_name,
@@ -2350,15 +2361,6 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
23502361
});
23512362
zcu.intern_pool.dumpGenericInstances(gpa);
23522363
}
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();
23622364
}
23632365

23642366
if (anyErrors(comp)) {
@@ -3310,7 +3312,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
33103312
}
33113313
}
33123314
}
3313-
if (zcu.skip_analysis_errors) break :zcu_errors;
3315+
if (zcu.skip_analysis_this_update) break :zcu_errors;
33143316
var sorted_failed_analysis: std.AutoArrayHashMapUnmanaged(InternPool.AnalUnit, *Zcu.ErrorMsg).DataList.Slice = s: {
33153317
const SortOrder = struct {
33163318
zcu: *Zcu,
@@ -3446,7 +3448,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
34463448
try comp.link_diags.addMessagesToBundle(&bundle, comp.bin_file);
34473449

34483450
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) {
34503452
const values = zcu.compile_log_sources.values();
34513453
// First one will be the error; subsequent ones will be notes.
34523454
const src_loc = values[0].src();
@@ -3957,7 +3959,7 @@ fn performAllTheWorkInner(
39573959
// However, this means our analysis data is invalid, so we want to omit all analysis errors.
39583960

39593961
assert(zcu.failed_files.count() > 0); // we will get an error
3960-
zcu.skip_analysis_errors = true;
3962+
zcu.skip_analysis_this_update = true;
39613963
return;
39623964
}
39633965

src/Zcu.zig

+4-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ analysis_roots: std.BoundedArray(*Package.Module, 4) = .{},
181181
/// Allocated into `gpa`.
182182
resolved_references: ?std.AutoHashMapUnmanaged(AnalUnit, ?ResolvedReference) = null,
183183

184-
skip_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`.
187+
skip_analysis_this_update: bool = false,
185188

186189
stage1_flags: packed struct {
187190
have_winmain: bool = false,

0 commit comments

Comments
 (0)