From 0c1d8659c51d9544fb8d5de7481e750149c262ae Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Mon, 19 Dec 2022 16:30:09 +0200 Subject: [PATCH] Sema: print notes and reference traces when using `--debug-compile-errors` --- src/Compilation.zig | 2 +- src/Sema.zig | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 1d0997d20c..b385fa5f72 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -572,7 +572,7 @@ pub const AllErrors = struct { self.arena.promote(gpa).deinit(); } - fn add( + pub fn add( module: *Module, arena: *std.heap.ArenaAllocator, errors: *std.ArrayList(Message), diff --git a/src/Sema.zig b/src/Sema.zig index 02f6b24e2d..f03211210c 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -113,6 +113,7 @@ const target_util = @import("target.zig"); const Package = @import("Package.zig"); const crash_report = @import("crash_report.zig"); const build_options = @import("build_options"); +const Compilation = @import("Compilation.zig"); pub const default_branch_quota = 1000; pub const default_reference_trace_len = 2; @@ -2191,18 +2192,16 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { @setCold(true); if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) { - const err_path = err_msg.src_loc.file_scope.fullPath(sema.mod.gpa) catch unreachable; - const err_source = err_msg.src_loc.file_scope.getSource(sema.mod.gpa) catch unreachable; if (err_msg.src_loc.lazy == .unneeded) return error.NeededSourceLocation; - const err_span = err_msg.src_loc.span(sema.mod.gpa) catch unreachable; - const err_loc = std.zig.findLineColumn(err_source.bytes, err_span.main); - std.debug.print("compile error during Sema:\n{s}:{d}:{d}: error: {s}\n{s}\n\n", .{ - err_path, - err_loc.line + 1, - err_loc.column + 1, - err_msg.msg, - err_loc.source_line, - }); + var arena = std.heap.ArenaAllocator.init(sema.gpa); + errdefer arena.deinit(); + var errors = std.ArrayList(Compilation.AllErrors.Message).init(sema.gpa); + defer errors.deinit(); + + Compilation.AllErrors.add(sema.mod, &arena, &errors, err_msg.*) catch unreachable; + + std.debug.print("compile error during Sema:\n", .{}); + Compilation.AllErrors.Message.renderToStdErr(errors.items[0], .no_color); crash_report.compilerPanic("unexpected compile error occurred", null, null); }