authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-02-04 15:05:40+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-02-04 16:20:30+00:00
logfb481d0bf81df7b0ce9afde5cd615133d9895726
treeb9b259669c258624f91f7c002245438677b804ce
parent3ca588bcc6d6640b7faa41a271580dd384963927
signaturelock-open Commit is signed but in an unrecognized format.

Zcu: fix bug clearing compile errors

And add an assertion in safe builds that our initial check is actually correct.

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

src/Zcu/PerThread.zig+20-9
......@@ -2795,21 +2795,32 @@ pub fn getErrorValueFromSlice(pt: Zcu.PerThread, name: []const u8) Allocator.Err
27952795/// Removes any entry from `Zcu.failed_files` associated with `file`. Acquires `Compilation.mutex` as needed.
27962796/// `file.zir` must be unchanged from the last update, as it is used to determine if there is such an entry.
27972797fn lockAndClearFileCompileError(pt: Zcu.PerThread, file: *Zcu.File) void {
2798 switch (file.getMode()) {
2799 .zig => {
2800 const zir = file.zir orelse return;
2801 if (!zir.hasCompileErrors()) return;
2802 },
2803 .zon => {
2804 const zoir = file.zoir orelse return;
2805 if (!zoir.hasCompileErrors()) return;
2798 const maybe_has_error = switch (file.status) {
2799 .never_loaded => false,
2800 .retryable_failure => true,
2801 .astgen_failure => true,
2802 .success => switch (file.getMode()) {
2803 .zig => has_error: {
2804 const zir = file.zir orelse break :has_error false;
2805 break :has_error zir.hasCompileErrors();
2806 },
2807 .zon => has_error: {
2808 const zoir = file.zoir orelse break :has_error false;
2809 break :has_error zoir.hasCompileErrors();
2810 },
28062811 },
2812 };
2813
2814 // If runtime safety is on, let's quickly lock the mutex and check anyway.
2815 if (!maybe_has_error and !std.debug.runtime_safety) {
2816 return;
28072817 }
28082818
28092819 pt.zcu.comp.mutex.lock();
28102820 defer pt.zcu.comp.mutex.unlock();
28112821 if (pt.zcu.failed_files.fetchSwapRemove(file)) |kv| {
2812 if (kv.value) |msg| msg.destroy(pt.zcu.gpa); // Delete previous error message.
2822 assert(maybe_has_error); // the runtime safety case above
2823 if (kv.value) |msg| msg.destroy(pt.zcu.gpa); // delete previous error message
28132824 }
28142825}
28152826