aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-05-15 13:18:08 +0100
committermlugg <mlugg@mlugg.co.uk>2025-05-16 13:28:15 +0100
commitd717c96877355090ea3a8e3662a2584eea02445c (patch)
tree3f76da87b8b222f9f103344aaacec8370a8ee3d4 /src/Compilation.zig
parent70040778fbde5d7fcbbfc26dbabc700024c538d5 (diff)
downloadzig-d717c96877355090ea3a8e3662a2584eea02445c.tar.gz
zig-d717c96877355090ea3a8e3662a2584eea02445c.zip
compiler: include inline calls in the reference trace
Inline calls which happened in the erroring `AnalUnit` still show as error notes, because they tend to make very important context (e.g. to see how comptime values propagate through them). However, "earlier" inline calls are still useful to see to understand how something is being referenced, so we should include them in the reference trace.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig66
1 files changed, 45 insertions, 21 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 57e36bfbf7..d3cf9e8f38 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -3681,32 +3681,27 @@ pub fn addModuleErrorMsg(
const ref = maybe_ref orelse break;
const gop = try seen.getOrPut(gpa, ref.referencer);
if (gop.found_existing) break;
- if (ref_traces.items.len < max_references) skip: {
- const src = ref.src.upgrade(zcu);
- const source = try src.file_scope.getSource(gpa);
- const span = try src.span(gpa);
- const loc = std.zig.findLineColumn(source.bytes, span.main);
- const rt_file_path = try src.file_scope.fullPath(gpa);
- defer gpa.free(rt_file_path);
- const name = switch (ref.referencer.unwrap()) {
+ if (ref_traces.items.len < max_references) {
+ var last_call_src = ref.src;
+ var opt_inline_frame = ref.inline_frame;
+ while (opt_inline_frame.unwrap()) |inline_frame| {
+ const f = inline_frame.ptr(zcu).*;
+ const func_nav = ip.indexToKey(f.callee).func.owner_nav;
+ const func_name = ip.getNav(func_nav).name.toSlice(ip);
+ try addReferenceTraceFrame(zcu, eb, &ref_traces, func_name, last_call_src, true);
+ last_call_src = f.call_src;
+ opt_inline_frame = f.parent;
+ }
+ const root_name: ?[]const u8 = switch (ref.referencer.unwrap()) {
.@"comptime" => "comptime",
.nav_val, .nav_ty => |nav| ip.getNav(nav).name.toSlice(ip),
.type => |ty| Type.fromInterned(ty).containerTypeName(ip).toSlice(ip),
.func => |f| ip.getNav(zcu.funcInfo(f).owner_nav).name.toSlice(ip),
- .memoized_state => break :skip,
+ .memoized_state => null,
};
- try ref_traces.append(gpa, .{
- .decl_name = try eb.addString(name),
- .src_loc = try eb.addSourceLocation(.{
- .src_path = try eb.addString(rt_file_path),
- .span_start = span.start,
- .span_main = span.main,
- .span_end = span.end,
- .line = @intCast(loc.line),
- .column = @intCast(loc.column),
- .source_line = 0,
- }),
- });
+ if (root_name) |n| {
+ try addReferenceTraceFrame(zcu, eb, &ref_traces, n, last_call_src, false);
+ }
}
referenced_by = ref.referencer;
}
@@ -3786,6 +3781,35 @@ pub fn addModuleErrorMsg(
}
}
+fn addReferenceTraceFrame(
+ zcu: *Zcu,
+ eb: *ErrorBundle.Wip,
+ ref_traces: *std.ArrayListUnmanaged(ErrorBundle.ReferenceTrace),
+ name: []const u8,
+ lazy_src: Zcu.LazySrcLoc,
+ inlined: bool,
+) !void {
+ const gpa = zcu.gpa;
+ const src = lazy_src.upgrade(zcu);
+ const source = try src.file_scope.getSource(gpa);
+ const span = try src.span(gpa);
+ const loc = std.zig.findLineColumn(source.bytes, span.main);
+ const rt_file_path = try src.file_scope.fullPath(gpa);
+ defer gpa.free(rt_file_path);
+ try ref_traces.append(gpa, .{
+ .decl_name = try eb.printString("{s}{s}", .{ name, if (inlined) " [inlined]" else "" }),
+ .src_loc = try eb.addSourceLocation(.{
+ .src_path = try eb.addString(rt_file_path),
+ .span_start = span.start,
+ .span_main = span.main,
+ .span_end = span.end,
+ .line = @intCast(loc.line),
+ .column = @intCast(loc.column),
+ .source_line = 0,
+ }),
+ });
+}
+
pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Zcu.File) !void {
const gpa = eb.gpa;
const src_path = try file.fullPath(gpa);