Skip to content

Commit 7b9408b

Browse files
committed
- 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`
1 parent 0984eb0 commit 7b9408b

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

lib/compiler/aro/aro/Diagnostics.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn main() u8 {
8888
}
8989

9090
fn 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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4092,14 +4092,19 @@ 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 {
40994103
try server.serveEmitDigest(&output.digest, .{
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

0 commit comments

Comments
 (0)