From 478cb9ce6af2e1875840de6618bbf23c624937c8 Mon Sep 17 00:00:00 2001 From: kcbanner Date: Tue, 7 Oct 2025 01:07:49 -0400 Subject: [PATCH] - aro: fixup `toErrorBundle` not emitting the last error if it was followed by .off or .warning - translate-c: emit `file_system_inputs` even in the case of failure, if available - translate-c: fixup emitting zero-length `file_system_inputs` --- lib/compiler/aro/aro/Diagnostics.zig | 7 ++++-- lib/compiler/translate-c/main.zig | 2 +- src/main.zig | 33 +++++++++++++++++----------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/lib/compiler/aro/aro/Diagnostics.zig b/lib/compiler/aro/aro/Diagnostics.zig index 2e8f40f20a..17d2e9e09b 100644 --- a/lib/compiler/aro/aro/Diagnostics.zig +++ b/lib/compiler/aro/aro/Diagnostics.zig @@ -587,9 +587,12 @@ pub fn toErrorBundle( defer cur_notes.deinit(gpa); for (d.output.to_list.messages.items) |msg| { switch (msg.kind) { - // Clear the current error so that notes don't bleed into unassociated errors .off, .warning => { - cur_err = null; + if (cur_err) |err| { + try bundle.addRootErrorMessageWithNotes(err, cur_notes.items); + // Clear the current error so that notes don't bleed into unassociated errors + cur_err = null; + } continue; }, .note => if (cur_err == null) continue, diff --git a/lib/compiler/translate-c/main.zig b/lib/compiler/translate-c/main.zig index 7ed5f14514..bdf776af56 100644 --- a/lib/compiler/translate-c/main.zig +++ b/lib/compiler/translate-c/main.zig @@ -88,7 +88,7 @@ pub fn main() u8 { } fn serveErrorBundle(arena: std.mem.Allocator, diagnostics: *const aro.Diagnostics) !void { - const error_bundle = try diagnostics.toErrorBundle(arena, "failed during translation"); + const error_bundle = try diagnostics.toErrorBundle(arena, "translation failure"); var stdout_buffer: [1024]u8 = undefined; var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); var server: std.zig.Server = .{ diff --git a/src/main.zig b/src/main.zig index e8179d92d5..1bbc86b605 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4092,7 +4092,11 @@ fn serve( var output: Compilation.CImportResult = undefined; try cmdTranslateC(comp, arena, &output, file_system_inputs, main_progress_node); defer output.deinit(gpa); - try server.serveStringMessage(.file_system_inputs, file_system_inputs.items); + + if (file_system_inputs.items.len != 0) { + try server.serveStringMessage(.file_system_inputs, file_system_inputs.items); + } + if (output.errors.errorMessageCount() != 0) { try server.serveErrorBundle(output.errors); } else { @@ -4100,6 +4104,7 @@ fn serve( .flags = .{ .cache_hit = output.cache_hit }, }); } + continue; } @@ -4567,6 +4572,19 @@ fn cmdTranslateC( var stdout: []u8 = undefined; try translateC(comp.gpa, arena, argv.items, prog_node, &stdout); + if (out_dep_path) |dep_file_path| add_deps: { + const dep_basename = fs.path.basename(dep_file_path); + // Add the files depended on to the cache system, if a dep file was emitted + man.addDepFilePost(cache_tmp_dir, dep_basename) catch |err| switch (err) { + error.FileNotFound => break :add_deps, + else => |e| return e, + }; + // Just to save disk space, we delete the file because it is never needed again. + cache_tmp_dir.deleteFile(dep_basename) catch |err| { + warn("failed to delete '{s}': {t}", .{ dep_file_path, err }); + }; + } + if (stdout.len > 0) { var reader: std.Io.Reader = .fixed(stdout); const MessageHeader = std.zig.Server.Message.Header; @@ -4590,29 +4608,18 @@ fn cmdTranslateC( }; if (fancy_output) |p| { + if (file_system_inputs) |buf| try man.populateFileSystemInputs(buf); p.errors = error_bundle; return; } else { error_bundle.renderToStdErr(color.renderOptions()); process.exit(1); } - - return error.AnalysisFail; }, else => unreachable, // No other messagse are sent } } - if (out_dep_path) |dep_file_path| { - const dep_basename = fs.path.basename(dep_file_path); - // Add the files depended on to the cache system. - try man.addDepFilePost(cache_tmp_dir, dep_basename); - // Just to save disk space, we delete the file because it is never needed again. - cache_tmp_dir.deleteFile(dep_basename) catch |err| { - warn("failed to delete '{s}': {t}", .{ dep_file_path, err }); - }; - } - const bin_digest = man.finalBin(); const hex_digest = Cache.binToHex(bin_digest);