authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-10 14:19:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-10 14:21:52-07:00
log40006855579bc42d9d2ed2b3db67be289e91750d
tree75074f72d9193767243f6b805fccd9edfd402dbc
parent01aab9f6b38d13c37719cba1fdd0b4109ac0f6d2

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.

1 files changed, 9 insertions(+), 1 deletions(-)

src/Compilation.zig+9-1
......@@ -2302,7 +2302,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
23022302 try pt.processExports();
23032303 }
23042304
2305 if (try comp.totalErrorCount() != 0) {
2305 if (anyErrors(comp)) {
23062306 // Skip flushing and keep source files loaded for error reporting.
23072307 comp.link_error_flags = .{};
23082308 return;
......@@ -2392,6 +2392,10 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
23922392 .sub_path = o_sub_path,
23932393 }, .main, main_progress_node);
23942394
2395 // Calling `flush` may have produced errors, in which case the
2396 // cache manifest must not be written.
2397 if (anyErrors(comp)) return;
2398
23952399 // Failure here only means an unnecessary cache miss.
23962400 man.writeManifest() catch |err| {
23972401 log.warn("failed to write cache manifest: {s}", .{@errorName(err)});
......@@ -3291,6 +3295,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
32913295 return bundle.toOwnedBundle(compile_log_text);
32923296}
32933297
3298fn anyErrors(comp: *Compilation) bool {
3299 return (totalErrorCount(comp) catch return true) != 0;
3300}
3301
32943302fn totalErrorCount(comp: *Compilation) !u32 {
32953303 var errors = try comp.getAllErrorsAlloc();
32963304 defer errors.deinit(comp.gpa);