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 {...@@ -2302,7 +2302,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
2302 try pt.processExports();2302 try pt.processExports();
2303 }2303 }
23042304
2305 if (try comp.totalErrorCount() != 0) {2305 if (anyErrors(comp)) {
2306 // Skip flushing and keep source files loaded for error reporting.2306 // Skip flushing and keep source files loaded for error reporting.
2307 comp.link_error_flags = .{};2307 comp.link_error_flags = .{};
2308 return;2308 return;
...@@ -2392,6 +2392,10 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {...@@ -2392,6 +2392,10 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
2392 .sub_path = o_sub_path,2392 .sub_path = o_sub_path,
2393 }, .main, main_progress_node);2393 }, .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
2395 // Failure here only means an unnecessary cache miss.2399 // Failure here only means an unnecessary cache miss.
2396 man.writeManifest() catch |err| {2400 man.writeManifest() catch |err| {
2397 log.warn("failed to write cache manifest: {s}", .{@errorName(err)});2401 log.warn("failed to write cache manifest: {s}", .{@errorName(err)});
...@@ -3291,6 +3295,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3291,6 +3295,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3291 return bundle.toOwnedBundle(compile_log_text);3295 return bundle.toOwnedBundle(compile_log_text);
3292}3296}
32933297
3298fn anyErrors(comp: *Compilation) bool {
3299 return (totalErrorCount(comp) catch return true) != 0;
3300}
3301
3294fn totalErrorCount(comp: *Compilation) !u32 {3302fn totalErrorCount(comp: *Compilation) !u32 {
3295 var errors = try comp.getAllErrorsAlloc();3303 var errors = try comp.getAllErrorsAlloc();
3296 defer errors.deinit(comp.gpa);3304 defer errors.deinit(comp.gpa);