authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-19 16:30:09+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-19 17:01:44+02:00
log0c1d8659c51d9544fb8d5de7481e750149c262ae
tree0b751f4d3a5dfcd0bd8c3fead2d06ff579c55ed5
parentee334aea801c71cbcc567b1d19be9c04d911beda

Sema: print notes and reference traces when using `--debug-compile-errors`


2 files changed, 11 insertions(+), 12 deletions(-)

src/Compilation.zig+1-1
......@@ -572,7 +572,7 @@ pub const AllErrors = struct {
572572 self.arena.promote(gpa).deinit();
573573 }
574574
575 fn add(
575 pub fn add(
576576 module: *Module,
577577 arena: *std.heap.ArenaAllocator,
578578 errors: *std.ArrayList(Message),
src/Sema.zig+10-11
......@@ -113,6 +113,7 @@ const target_util = @import("target.zig");
113113const Package = @import("Package.zig");
114114const crash_report = @import("crash_report.zig");
115115const build_options = @import("build_options");
116const Compilation = @import("Compilation.zig");
116117
117118pub const default_branch_quota = 1000;
118119pub const default_reference_trace_len = 2;
......@@ -2191,18 +2192,16 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
21912192 @setCold(true);
21922193
21932194 if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) {
2194 const err_path = err_msg.src_loc.file_scope.fullPath(sema.mod.gpa) catch unreachable;
2195 const err_source = err_msg.src_loc.file_scope.getSource(sema.mod.gpa) catch unreachable;
21962195 if (err_msg.src_loc.lazy == .unneeded) return error.NeededSourceLocation;
2197 const err_span = err_msg.src_loc.span(sema.mod.gpa) catch unreachable;
2198 const err_loc = std.zig.findLineColumn(err_source.bytes, err_span.main);
2199 std.debug.print("compile error during Sema:\n{s}:{d}:{d}: error: {s}\n{s}\n\n", .{
2200 err_path,
2201 err_loc.line + 1,
2202 err_loc.column + 1,
2203 err_msg.msg,
2204 err_loc.source_line,
2205 });
2196 var arena = std.heap.ArenaAllocator.init(sema.gpa);
2197 errdefer arena.deinit();
2198 var errors = std.ArrayList(Compilation.AllErrors.Message).init(sema.gpa);
2199 defer errors.deinit();
2200
2201 Compilation.AllErrors.add(sema.mod, &arena, &errors, err_msg.*) catch unreachable;
2202
2203 std.debug.print("compile error during Sema:\n", .{});
2204 Compilation.AllErrors.Message.renderToStdErr(errors.items[0], .no_color);
22062205 crash_report.compilerPanic("unexpected compile error occurred", null, null);
22072206 }
22082207