From 40006855579bc42d9d2ed2b3db67be289e91750d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 10 Oct 2024 14:19:32 -0700 Subject: Compilation: don't write cache manifest on failure When errors occurred during flush(), incremental cache mode was still writing a successful cache manifest, making subsequent compilations fail because they would get a cache hit only to find invalid data. --- src/Compilation.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index 6ba09d5c6d..8d276980ea 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -2302,7 +2302,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { try pt.processExports(); } - if (try comp.totalErrorCount() != 0) { + if (anyErrors(comp)) { // Skip flushing and keep source files loaded for error reporting. comp.link_error_flags = .{}; return; @@ -2392,6 +2392,10 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { .sub_path = o_sub_path, }, .main, main_progress_node); + // Calling `flush` may have produced errors, in which case the + // cache manifest must not be written. + if (anyErrors(comp)) return; + // Failure here only means an unnecessary cache miss. man.writeManifest() catch |err| { log.warn("failed to write cache manifest: {s}", .{@errorName(err)}); @@ -3291,6 +3295,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { return bundle.toOwnedBundle(compile_log_text); } +fn anyErrors(comp: *Compilation) bool { + return (totalErrorCount(comp) catch return true) != 0; +} + fn totalErrorCount(comp: *Compilation) !u32 { var errors = try comp.getAllErrorsAlloc(); defer errors.deinit(comp.gpa); -- cgit v1.2.3