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(...@@ -587,9 +587,12 @@ pub fn toErrorBundle(
587 defer cur_notes.deinit(gpa);587 defer cur_notes.deinit(gpa);
588 for (d.output.to_list.messages.items) |msg| {588 for (d.output.to_list.messages.items) |msg| {
589 switch (msg.kind) {589 switch (msg.kind) {
590 // Clear the current error so that notes don't bleed into unassociated errors
591 .off, .warning => {590 .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 }
593 continue;596 continue;
594 },597 },
595 .note => if (cur_err == null) continue,598 .note => if (cur_err == null) continue,
lib/compiler/translate-c/main.zig+1-1
...@@ -88,7 +88,7 @@ pub fn main() u8 {...@@ -88,7 +88,7 @@ pub fn main() u8 {
88}88}
8989
90fn serveErrorBundle(arena: std.mem.Allocator, diagnostics: *const aro.Diagnostics) !void {90fn 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");
92 var stdout_buffer: [1024]u8 = undefined;92 var stdout_buffer: [1024]u8 = undefined;
93 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);93 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
94 var server: std.zig.Server = .{94 var server: std.zig.Server = .{
src/main.zig+20-13
...@@ -4092,7 +4092,11 @@ fn serve(...@@ -4092,7 +4092,11 @@ fn serve(
4092 var output: Compilation.CImportResult = undefined;4092 var output: Compilation.CImportResult = undefined;
4093 try cmdTranslateC(comp, arena, &output, file_system_inputs, main_progress_node);4093 try cmdTranslateC(comp, arena, &output, file_system_inputs, main_progress_node);
4094 defer output.deinit(gpa);4094 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
4096 if (output.errors.errorMessageCount() != 0) {4100 if (output.errors.errorMessageCount() != 0) {
4097 try server.serveErrorBundle(output.errors);4101 try server.serveErrorBundle(output.errors);
4098 } else {4102 } else {
...@@ -4100,6 +4104,7 @@ fn serve(...@@ -4100,6 +4104,7 @@ fn serve(
4100 .flags = .{ .cache_hit = output.cache_hit },4104 .flags = .{ .cache_hit = output.cache_hit },
4101 });4105 });
4102 }4106 }
4107
4103 continue;4108 continue;
4104 }4109 }
41054110
...@@ -4567,6 +4572,19 @@ fn cmdTranslateC(...@@ -4567,6 +4572,19 @@ fn cmdTranslateC(
4567 var stdout: []u8 = undefined;4572 var stdout: []u8 = undefined;
4568 try translateC(comp.gpa, arena, argv.items, prog_node, &stdout);4573 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
4570 if (stdout.len > 0) {4588 if (stdout.len > 0) {
4571 var reader: std.Io.Reader = .fixed(stdout);4589 var reader: std.Io.Reader = .fixed(stdout);
4572 const MessageHeader = std.zig.Server.Message.Header;4590 const MessageHeader = std.zig.Server.Message.Header;
...@@ -4590,29 +4608,18 @@ fn cmdTranslateC(...@@ -4590,29 +4608,18 @@ fn cmdTranslateC(
4590 };4608 };
45914609
4592 if (fancy_output) |p| {4610 if (fancy_output) |p| {
4611 if (file_system_inputs) |buf| try man.populateFileSystemInputs(buf);
4593 p.errors = error_bundle;4612 p.errors = error_bundle;
4594 return;4613 return;
4595 } else {4614 } else {
4596 error_bundle.renderToStdErr(color.renderOptions());4615 error_bundle.renderToStdErr(color.renderOptions());
4597 process.exit(1);4616 process.exit(1);
4598 }4617 }
4599
4600 return error.AnalysisFail;
4601 },4618 },
4602 else => unreachable, // No other messagse are sent4619 else => unreachable, // No other messagse are sent
4603 }4620 }
4604 }4621 }
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
4616 const bin_digest = man.finalBin();4623 const bin_digest = man.finalBin();
4617 const hex_digest = Cache.binToHex(bin_digest);4624 const hex_digest = Cache.binToHex(bin_digest);
46184625