authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2025-10-07 01:07:49-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2025-10-09 01:06:09-04:00
log478cb9ce6af2e1875840de6618bbf23c624937c8
tree3b36b29f63671b32e270fe3f42bf03c7e5ac559e
parent4aa4d80ec640b869939111f35d7bf2509a227793

- 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`

3 files changed, 26 insertions(+), 16 deletions(-)

lib/compiler/aro/aro/Diagnostics.zig+5-2
......@@ -587,9 +587,12 @@ pub fn toErrorBundle(
587587 defer cur_notes.deinit(gpa);
588588 for (d.output.to_list.messages.items) |msg| {
589589 switch (msg.kind) {
590 // Clear the current error so that notes don't bleed into unassociated errors
591590 .off, .warning => {
592 cur_err = null;
591 if (cur_err) |err| {
592 try bundle.addRootErrorMessageWithNotes(err, cur_notes.items);
593 // Clear the current error so that notes don't bleed into unassociated errors
594 cur_err = null;
595 }
593596 continue;
594597 },
595598 .note => if (cur_err == null) continue,
lib/compiler/translate-c/main.zig+1-1
......@@ -88,7 +88,7 @@ pub fn main() u8 {
8888}
8989
9090fn serveErrorBundle(arena: std.mem.Allocator, diagnostics: *const aro.Diagnostics) !void {
91 const error_bundle = try diagnostics.toErrorBundle(arena, "failed during translation");
91 const error_bundle = try diagnostics.toErrorBundle(arena, "translation failure");
9292 var stdout_buffer: [1024]u8 = undefined;
9393 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
9494 var server: std.zig.Server = .{
src/main.zig+20-13
......@@ -4092,7 +4092,11 @@ fn serve(
40924092 var output: Compilation.CImportResult = undefined;
40934093 try cmdTranslateC(comp, arena, &output, file_system_inputs, main_progress_node);
40944094 defer output.deinit(gpa);
4095 try server.serveStringMessage(.file_system_inputs, file_system_inputs.items);
4095
4096 if (file_system_inputs.items.len != 0) {
4097 try server.serveStringMessage(.file_system_inputs, file_system_inputs.items);
4098 }
4099
40964100 if (output.errors.errorMessageCount() != 0) {
40974101 try server.serveErrorBundle(output.errors);
40984102 } else {
......@@ -4100,6 +4104,7 @@ fn serve(
41004104 .flags = .{ .cache_hit = output.cache_hit },
41014105 });
41024106 }
4107
41034108 continue;
41044109 }
41054110
......@@ -4567,6 +4572,19 @@ fn cmdTranslateC(
45674572 var stdout: []u8 = undefined;
45684573 try translateC(comp.gpa, arena, argv.items, prog_node, &stdout);
45694574
4575 if (out_dep_path) |dep_file_path| add_deps: {
4576 const dep_basename = fs.path.basename(dep_file_path);
4577 // Add the files depended on to the cache system, if a dep file was emitted
4578 man.addDepFilePost(cache_tmp_dir, dep_basename) catch |err| switch (err) {
4579 error.FileNotFound => break :add_deps,
4580 else => |e| return e,
4581 };
4582 // Just to save disk space, we delete the file because it is never needed again.
4583 cache_tmp_dir.deleteFile(dep_basename) catch |err| {
4584 warn("failed to delete '{s}': {t}", .{ dep_file_path, err });
4585 };
4586 }
4587
45704588 if (stdout.len > 0) {
45714589 var reader: std.Io.Reader = .fixed(stdout);
45724590 const MessageHeader = std.zig.Server.Message.Header;
......@@ -4590,29 +4608,18 @@ fn cmdTranslateC(
45904608 };
45914609
45924610 if (fancy_output) |p| {
4611 if (file_system_inputs) |buf| try man.populateFileSystemInputs(buf);
45934612 p.errors = error_bundle;
45944613 return;
45954614 } else {
45964615 error_bundle.renderToStdErr(color.renderOptions());
45974616 process.exit(1);
45984617 }
4599
4600 return error.AnalysisFail;
46014618 },
46024619 else => unreachable, // No other messagse are sent
46034620 }
46044621 }
46054622
4606 if (out_dep_path) |dep_file_path| {
4607 const dep_basename = fs.path.basename(dep_file_path);
4608 // Add the files depended on to the cache system.
4609 try man.addDepFilePost(cache_tmp_dir, dep_basename);
4610 // Just to save disk space, we delete the file because it is never needed again.
4611 cache_tmp_dir.deleteFile(dep_basename) catch |err| {
4612 warn("failed to delete '{s}': {t}", .{ dep_file_path, err });
4613 };
4614 }
4615
46164623 const bin_digest = man.finalBin();
46174624 const hex_digest = Cache.binToHex(bin_digest);
46184625