authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-18 00:41:44-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-12-18 00:41:44-05:00
log4ae101ca851bb8a5437153137cfa70c4bf0c8d15
treeeda15ab2484e040370d68a418e9fae5659c837ae
parent12d64c456b7590b1486717232f77c6d3700813a6
parent98f63990d55c27969ebae3c0fe392c6716548781
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #22260 from jacobly0/dwarf-cleanup

Dwarf: cleanup

4 files changed, 64 insertions(+), 145 deletions(-)

lib/std/zig/AstGen.zig+18
...@@ -4151,6 +4151,8 @@ fn fnDecl(...@@ -4151,6 +4151,8 @@ fn fnDecl(
4151 };4151 };
4152 defer fn_gz.unstack();4152 defer fn_gz.unstack();
41534153
4154 const decl_column = astgen.source_column;
4155
4154 // Set this now, since parameter types, return type, etc may be generic.4156 // Set this now, since parameter types, return type, etc may be generic.
4155 const prev_within_fn = astgen.within_fn;4157 const prev_within_fn = astgen.within_fn;
4156 defer astgen.within_fn = prev_within_fn;4158 defer astgen.within_fn = prev_within_fn;
...@@ -4523,6 +4525,7 @@ fn fnDecl(...@@ -4523,6 +4525,7 @@ fn fnDecl(
4523 hash,4525 hash,
4524 .{ .named = fn_name_token },4526 .{ .named = fn_name_token },
4525 decl_gz.decl_line,4527 decl_gz.decl_line,
4528 decl_column,
4526 is_pub,4529 is_pub,
4527 is_export,4530 is_export,
4528 &decl_gz,4531 &decl_gz,
...@@ -4568,6 +4571,8 @@ fn globalVarDecl(...@@ -4568,6 +4571,8 @@ fn globalVarDecl(
4568 };4571 };
4569 defer block_scope.unstack();4572 defer block_scope.unstack();
45704573
4574 const decl_column = astgen.source_column;
4575
4571 const is_pub = var_decl.visib_token != null;4576 const is_pub = var_decl.visib_token != null;
4572 const is_export = blk: {4577 const is_export = blk: {
4573 const maybe_export_token = var_decl.extern_export_token orelse break :blk false;4578 const maybe_export_token = var_decl.extern_export_token orelse break :blk false;
...@@ -4693,6 +4698,7 @@ fn globalVarDecl(...@@ -4693,6 +4698,7 @@ fn globalVarDecl(
4693 hash,4698 hash,
4694 .{ .named = name_token },4699 .{ .named = name_token },
4695 block_scope.decl_line,4700 block_scope.decl_line,
4701 decl_column,
4696 is_pub,4702 is_pub,
4697 is_export,4703 is_export,
4698 &block_scope,4704 &block_scope,
...@@ -4738,6 +4744,8 @@ fn comptimeDecl(...@@ -4738,6 +4744,8 @@ fn comptimeDecl(
4738 };4744 };
4739 defer decl_block.unstack();4745 defer decl_block.unstack();
47404746
4747 const decl_column = astgen.source_column;
4748
4741 const block_result = try fullBodyExpr(&decl_block, &decl_block.base, .{ .rl = .none }, body_node, .normal);4749 const block_result = try fullBodyExpr(&decl_block, &decl_block.base, .{ .rl = .none }, body_node, .normal);
4742 if (decl_block.isEmpty() or !decl_block.refIsNoReturn(block_result)) {4750 if (decl_block.isEmpty() or !decl_block.refIsNoReturn(block_result)) {
4743 _ = try decl_block.addBreak(.break_inline, decl_inst, .void_value);4751 _ = try decl_block.addBreak(.break_inline, decl_inst, .void_value);
...@@ -4750,6 +4758,7 @@ fn comptimeDecl(...@@ -4750,6 +4758,7 @@ fn comptimeDecl(
4750 hash,4758 hash,
4751 .@"comptime",4759 .@"comptime",
4752 decl_block.decl_line,4760 decl_block.decl_line,
4761 decl_column,
4753 false,4762 false,
4754 false,4763 false,
4755 &decl_block,4764 &decl_block,
...@@ -4797,6 +4806,8 @@ fn usingnamespaceDecl(...@@ -4797,6 +4806,8 @@ fn usingnamespaceDecl(
4797 };4806 };
4798 defer decl_block.unstack();4807 defer decl_block.unstack();
47994808
4809 const decl_column = astgen.source_column;
4810
4800 const namespace_inst = try typeExpr(&decl_block, &decl_block.base, type_expr);4811 const namespace_inst = try typeExpr(&decl_block, &decl_block.base, type_expr);
4801 _ = try decl_block.addBreak(.break_inline, decl_inst, namespace_inst);4812 _ = try decl_block.addBreak(.break_inline, decl_inst, namespace_inst);
48024813
...@@ -4807,6 +4818,7 @@ fn usingnamespaceDecl(...@@ -4807,6 +4818,7 @@ fn usingnamespaceDecl(
4807 hash,4818 hash,
4808 .@"usingnamespace",4819 .@"usingnamespace",
4809 decl_block.decl_line,4820 decl_block.decl_line,
4821 decl_column,
4810 is_pub,4822 is_pub,
4811 false,4823 false,
4812 &decl_block,4824 &decl_block,
...@@ -4849,6 +4861,8 @@ fn testDecl(...@@ -4849,6 +4861,8 @@ fn testDecl(
4849 };4861 };
4850 defer decl_block.unstack();4862 defer decl_block.unstack();
48514863
4864 const decl_column = astgen.source_column;
4865
4852 const main_tokens = tree.nodes.items(.main_token);4866 const main_tokens = tree.nodes.items(.main_token);
4853 const token_tags = tree.tokens.items(.tag);4867 const token_tags = tree.tokens.items(.tag);
4854 const test_token = main_tokens[node];4868 const test_token = main_tokens[node];
...@@ -5013,6 +5027,7 @@ fn testDecl(...@@ -5013,6 +5027,7 @@ fn testDecl(
5013 hash,5027 hash,
5014 test_name,5028 test_name,
5015 decl_block.decl_line,5029 decl_block.decl_line,
5030 decl_column,
5016 false,5031 false,
5017 false,5032 false,
5018 &decl_block,5033 &decl_block,
...@@ -14013,6 +14028,7 @@ fn addFailedDeclaration(...@@ -14013,6 +14028,7 @@ fn addFailedDeclaration(
14013 @splat(0), // use a fixed hash to represent an AstGen failure; we don't care about source changes if AstGen still failed!14028 @splat(0), // use a fixed hash to represent an AstGen failure; we don't care about source changes if AstGen still failed!
14014 name,14029 name,
14015 gz.astgen.source_line,14030 gz.astgen.source_line,
14031 gz.astgen.source_column,
14016 is_pub,14032 is_pub,
14017 false, // we don't care about exports since semantic analysis will fail14033 false, // we don't care about exports since semantic analysis will fail
14018 &decl_gz,14034 &decl_gz,
...@@ -14027,6 +14043,7 @@ fn setDeclaration(...@@ -14027,6 +14043,7 @@ fn setDeclaration(
14027 src_hash: std.zig.SrcHash,14043 src_hash: std.zig.SrcHash,
14028 name: DeclarationName,14044 name: DeclarationName,
14029 src_line: u32,14045 src_line: u32,
14046 src_column: u32,
14030 is_pub: bool,14047 is_pub: bool,
14031 is_export: bool,14048 is_export: bool,
14032 value_gz: *GenZir,14049 value_gz: *GenZir,
...@@ -14079,6 +14096,7 @@ fn setDeclaration(...@@ -14079,6 +14096,7 @@ fn setDeclaration(
14079 .@"usingnamespace" => .@"usingnamespace",14096 .@"usingnamespace" => .@"usingnamespace",
14080 },14097 },
14081 .src_line = src_line,14098 .src_line = src_line,
14099 .src_column = src_column,
14082 .flags = .{14100 .flags = .{
14083 .value_body_len = @intCast(value_len),14101 .value_body_len = @intCast(value_len),
14084 .is_pub = is_pub,14102 .is_pub = is_pub,
lib/std/zig/Zir.zig+1
...@@ -2636,6 +2636,7 @@ pub const Inst = struct {...@@ -2636,6 +2636,7 @@ pub const Inst = struct {
2636 /// The name of this `Decl`. Also indicates whether it is a test, comptime block, etc.2636 /// The name of this `Decl`. Also indicates whether it is a test, comptime block, etc.
2637 name: Name,2637 name: Name,
2638 src_line: u32,2638 src_line: u32,
2639 src_column: u32,
2639 flags: Flags,2640 flags: Flags,
26402641
2641 pub const Flags = packed struct(u32) {2642 pub const Flags = packed struct(u32) {
src/InternPool.zig+1-1
...@@ -5365,7 +5365,7 @@ pub const Tag = enum(u8) {...@@ -5365,7 +5365,7 @@ pub const Tag = enum(u8) {
5365 .@"trailing.field_is_comptime_bits.?" = .@"payload.flags.any_comptime_fields",5365 .@"trailing.field_is_comptime_bits.?" = .@"payload.flags.any_comptime_fields",
5366 .@"trailing.field_is_comptime_bits.?.len" = .@"(payload.fields_len + 31) / 32",5366 .@"trailing.field_is_comptime_bits.?.len" = .@"(payload.fields_len + 31) / 32",
5367 .@"trailing.field_index.?" = .@"!payload.flags.is_extern",5367 .@"trailing.field_index.?" = .@"!payload.flags.is_extern",
5368 .@"trailing.field_index.?.len" = .@"!payload.flags.is_extern",5368 .@"trailing.field_index.?.len" = .@"payload.fields_len",
5369 .@"trailing.field_offset.len" = .@"payload.fields_len",5369 .@"trailing.field_offset.len" = .@"payload.fields_len",
5370 },5370 },
5371 },5371 },
src/link/Dwarf.zig+44-144
...@@ -2259,30 +2259,23 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2259,30 +2259,23 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2259 switch (ip.indexToKey(nav_val.toIntern())) {2259 switch (ip.indexToKey(nav_val.toIntern())) {
2260 else => {2260 else => {
2261 assert(file.zir_loaded);2261 assert(file.zir_loaded);
2262 const decl_inst = file.zir.instructions.get(@intFromEnum(inst_info.inst));2262 const decl = file.zir.getDeclaration(inst_info.inst)[0];
2263 assert(decl_inst.tag == .declaration);
2264 const tree = try file.getTree(dwarf.gpa);
2265 const loc = tree.tokenLocation(0, tree.nodes.items(.main_token)[decl_inst.data.declaration.src_node]);
2266 assert(loc.line == zcu.navSrcLine(nav_index));
22672263
2268 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {2264 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {
2269 const decl_extra = file.zir.extraData(Zir.Inst.Declaration, decl_inst.data.declaration.payload_index).data;
2270 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);2265 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);
2271 break :parent .{2266 break :parent .{
2272 parent_namespace_ptr.owner_type,2267 parent_namespace_ptr.owner_type,
2273 switch (decl_extra.name) {2268 switch (decl.name) {
2274 .@"comptime",2269 .@"comptime",
2275 .@"usingnamespace",2270 .@"usingnamespace",
2276 .unnamed_test,2271 .unnamed_test,
2277 => DW.ACCESS.private,2272 => DW.ACCESS.private,
2278 _ => if (decl_extra.name.isNamedTest(file.zir))2273 _ => if (decl.name.isNamedTest(file.zir))
2279 DW.ACCESS.private2274 DW.ACCESS.private
2280 else if (parent_namespace_ptr.pub_decls.containsContext(nav_index, .{ .zcu = zcu }))2275 else if (decl.flags.is_pub)
2281 DW.ACCESS.public2276 DW.ACCESS.public
2282 else if (parent_namespace_ptr.priv_decls.containsContext(nav_index, .{ .zcu = zcu }))
2283 DW.ACCESS.private
2284 else2277 else
2285 unreachable,2278 DW.ACCESS.private,
2286 },2279 },
2287 };2280 };
2288 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };2281 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };
...@@ -2291,8 +2284,8 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2291,8 +2284,8 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2291 try wip_nav.abbrevCode(.decl_var);2284 try wip_nav.abbrevCode(.decl_var);
2292 try wip_nav.refType(.fromInterned(parent_type));2285 try wip_nav.refType(.fromInterned(parent_type));
2293 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2286 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2294 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2287 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
2295 try uleb128(diw, loc.column + 1);2288 try uleb128(diw, decl.src_column + 1);
2296 try diw.writeByte(accessibility);2289 try diw.writeByte(accessibility);
2297 try wip_nav.strp(nav.name.toSlice(ip));2290 try wip_nav.strp(nav.name.toSlice(ip));
2298 try wip_nav.strp(nav.fqn.toSlice(ip));2291 try wip_nav.strp(nav.fqn.toSlice(ip));
...@@ -2308,30 +2301,23 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2308,30 +2301,23 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2308 },2301 },
2309 .variable => |variable| {2302 .variable => |variable| {
2310 assert(file.zir_loaded);2303 assert(file.zir_loaded);
2311 const decl_inst = file.zir.instructions.get(@intFromEnum(inst_info.inst));2304 const decl = file.zir.getDeclaration(inst_info.inst)[0];
2312 assert(decl_inst.tag == .declaration);
2313 const tree = try file.getTree(dwarf.gpa);
2314 const loc = tree.tokenLocation(0, tree.nodes.items(.main_token)[decl_inst.data.declaration.src_node]);
2315 assert(loc.line == zcu.navSrcLine(nav_index));
23162305
2317 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {2306 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {
2318 const decl_extra = file.zir.extraData(Zir.Inst.Declaration, decl_inst.data.declaration.payload_index).data;
2319 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);2307 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);
2320 break :parent .{2308 break :parent .{
2321 parent_namespace_ptr.owner_type,2309 parent_namespace_ptr.owner_type,
2322 switch (decl_extra.name) {2310 switch (decl.name) {
2323 .@"comptime",2311 .@"comptime",
2324 .@"usingnamespace",2312 .@"usingnamespace",
2325 .unnamed_test,2313 .unnamed_test,
2326 => DW.ACCESS.private,2314 => DW.ACCESS.private,
2327 _ => if (decl_extra.name.isNamedTest(file.zir))2315 _ => if (decl.name.isNamedTest(file.zir))
2328 DW.ACCESS.private2316 DW.ACCESS.private
2329 else if (parent_namespace_ptr.pub_decls.containsContext(nav_index, .{ .zcu = zcu }))2317 else if (decl.flags.is_pub)
2330 DW.ACCESS.public2318 DW.ACCESS.public
2331 else if (parent_namespace_ptr.priv_decls.containsContext(nav_index, .{ .zcu = zcu }))
2332 DW.ACCESS.private
2333 else2319 else
2334 unreachable,2320 DW.ACCESS.private,
2335 },2321 },
2336 };2322 };
2337 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };2323 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };
...@@ -2340,8 +2326,8 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2340,8 +2326,8 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2340 try wip_nav.abbrevCode(.decl_var);2326 try wip_nav.abbrevCode(.decl_var);
2341 try wip_nav.refType(.fromInterned(parent_type));2327 try wip_nav.refType(.fromInterned(parent_type));
2342 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2328 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2343 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2329 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
2344 try uleb128(diw, loc.column + 1);2330 try uleb128(diw, decl.src_column + 1);
2345 try diw.writeByte(accessibility);2331 try diw.writeByte(accessibility);
2346 try wip_nav.strp(nav.name.toSlice(ip));2332 try wip_nav.strp(nav.name.toSlice(ip));
2347 try wip_nav.strp(nav.fqn.toSlice(ip));2333 try wip_nav.strp(nav.fqn.toSlice(ip));
...@@ -2355,30 +2341,23 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2355,30 +2341,23 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2355 },2341 },
2356 .func => |func| {2342 .func => |func| {
2357 assert(file.zir_loaded);2343 assert(file.zir_loaded);
2358 const decl_inst = file.zir.instructions.get(@intFromEnum(inst_info.inst));2344 const decl = file.zir.getDeclaration(inst_info.inst)[0];
2359 assert(decl_inst.tag == .declaration);
2360 const tree = try file.getTree(dwarf.gpa);
2361 const loc = tree.tokenLocation(0, tree.nodes.items(.main_token)[decl_inst.data.declaration.src_node]);
2362 assert(loc.line == zcu.navSrcLine(nav_index));
23632345
2364 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {2346 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {
2365 const decl_extra = file.zir.extraData(Zir.Inst.Declaration, decl_inst.data.declaration.payload_index).data;
2366 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);2347 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);
2367 break :parent .{2348 break :parent .{
2368 parent_namespace_ptr.owner_type,2349 parent_namespace_ptr.owner_type,
2369 switch (decl_extra.name) {2350 switch (decl.name) {
2370 .@"comptime",2351 .@"comptime",
2371 .@"usingnamespace",2352 .@"usingnamespace",
2372 .unnamed_test,2353 .unnamed_test,
2373 => DW.ACCESS.private,2354 => DW.ACCESS.private,
2374 _ => if (decl_extra.name.isNamedTest(file.zir))2355 _ => if (decl.name.isNamedTest(file.zir))
2375 DW.ACCESS.private2356 DW.ACCESS.private
2376 else if (parent_namespace_ptr.pub_decls.containsContext(nav_index, .{ .zcu = zcu }))2357 else if (decl.flags.is_pub)
2377 DW.ACCESS.public2358 DW.ACCESS.public
2378 else if (parent_namespace_ptr.priv_decls.containsContext(nav_index, .{ .zcu = zcu }))
2379 DW.ACCESS.private
2380 else2359 else
2381 unreachable,2360 DW.ACCESS.private,
2382 },2361 },
2383 };2362 };
2384 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };2363 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };
...@@ -2432,8 +2411,8 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2432,8 +2411,8 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2432 try wip_nav.abbrevCode(.decl_func);2411 try wip_nav.abbrevCode(.decl_func);
2433 try wip_nav.refType(.fromInterned(parent_type));2412 try wip_nav.refType(.fromInterned(parent_type));
2434 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2413 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2435 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2414 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
2436 try uleb128(diw, loc.column + 1);2415 try uleb128(diw, decl.src_column + 1);
2437 try diw.writeByte(accessibility);2416 try diw.writeByte(accessibility);
2438 try wip_nav.strp(nav.name.toSlice(ip));2417 try wip_nav.strp(nav.name.toSlice(ip));
2439 try wip_nav.strp(nav.fqn.toSlice(ip));2418 try wip_nav.strp(nav.fqn.toSlice(ip));
...@@ -2482,7 +2461,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2482,7 +2461,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2482 try dlw.writeByte(DW.LNS.set_column);2461 try dlw.writeByte(DW.LNS.set_column);
2483 try uleb128(dlw, func.lbrace_column + 1);2462 try uleb128(dlw, func.lbrace_column + 1);
24842463
2485 try wip_nav.advancePCAndLine(@intCast(loc.line + func.lbrace_line), 0);2464 try wip_nav.advancePCAndLine(@intCast(decl.src_line + func.lbrace_line), 0);
2486 }2465 }
2487 },2466 },
2488 }2467 }
...@@ -2606,14 +2585,12 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2606,14 +2585,12 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2606 const inst_info = nav.srcInst(ip).resolveFull(ip).?;2585 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
2607 const file = zcu.fileByIndex(inst_info.file);2586 const file = zcu.fileByIndex(inst_info.file);
2608 assert(file.zir_loaded);2587 assert(file.zir_loaded);
2609 const decl_inst = file.zir.instructions.get(@intFromEnum(inst_info.inst));2588 const decl = file.zir.getDeclaration(inst_info.inst)[0];
2610 assert(decl_inst.tag == .declaration);
2611 const decl_extra = file.zir.extraData(Zir.Inst.Declaration, decl_inst.data.declaration.payload_index);
26122589
2613 const is_test = switch (decl_extra.data.name) {2590 const is_test = switch (decl.name) {
2614 .unnamed_test => true,2591 .unnamed_test => true,
2615 .@"comptime", .@"usingnamespace" => false,2592 .@"comptime", .@"usingnamespace" => false,
2616 _ => decl_extra.data.name.isNamedTest(file.zir),2593 _ => decl.name.isNamedTest(file.zir),
2617 };2594 };
2618 if (is_test) {2595 if (is_test) {
2619 // This isn't actually a comptime Nav! It's a test, so it'll definitely never be referenced at comptime.2596 // This isn't actually a comptime Nav! It's a test, so it'll definitely never be referenced at comptime.
...@@ -2624,19 +2601,10 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2624,19 +2601,10 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2624 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);2601 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);
2625 break :parent .{2602 break :parent .{
2626 parent_namespace_ptr.owner_type,2603 parent_namespace_ptr.owner_type,
2627 if (parent_namespace_ptr.pub_decls.containsContext(nav_index, .{ .zcu = zcu }))2604 if (decl.flags.is_pub) DW.ACCESS.public else DW.ACCESS.private,
2628 DW.ACCESS.public
2629 else if (parent_namespace_ptr.priv_decls.containsContext(nav_index, .{ .zcu = zcu }))
2630 DW.ACCESS.private
2631 else
2632 unreachable,
2633 };2605 };
2634 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };2606 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };
26352607
2636 const tree = try file.getTree(dwarf.gpa);
2637 const loc = tree.tokenLocation(0, tree.nodes.items(.main_token)[decl_inst.data.declaration.src_node]);
2638 assert(loc.line == zcu.navSrcLine(nav_index));
2639
2640 var wip_nav: WipNav = .{2608 var wip_nav: WipNav = .{
2641 .dwarf = dwarf,2609 .dwarf = dwarf,
2642 .pt = pt,2610 .pt = pt,
...@@ -2679,23 +2647,6 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2679,23 +2647,6 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2679 const type_inst_info = loaded_struct.zir_index.resolveFull(ip).?;2647 const type_inst_info = loaded_struct.zir_index.resolveFull(ip).?;
2680 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;2648 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;
26812649
2682 const value_inst = value_inst: {
2683 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2684 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2685 if (break_inst.tag != .break_inline) break :value_inst null;
2686 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2687 var value_inst = break_inst.data.@"break".operand.toIndex();
2688 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2689 else => break,
2690 .as_node => value_inst = file.zir.extraData(
2691 Zir.Inst.As,
2692 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2693 ).data.operand.toIndex(),
2694 };
2695 break :value_inst value_inst;
2696 };
2697 if (type_inst_info.inst != value_inst) break :tag .decl_alias;
2698
2699 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());2650 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2700 if (type_gop.found_existing) {2651 if (type_gop.found_existing) {
2701 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;2652 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;
...@@ -2716,8 +2667,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2716,8 +2667,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2716 try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .decl_namespace_struct else .decl_struct);2667 try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .decl_namespace_struct else .decl_struct);
2717 try wip_nav.refType(.fromInterned(parent_type));2668 try wip_nav.refType(.fromInterned(parent_type));
2718 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2669 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2719 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2670 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
2720 try uleb128(diw, loc.column + 1);2671 try uleb128(diw, decl.src_column + 1);
2721 try diw.writeByte(accessibility);2672 try diw.writeByte(accessibility);
2722 try wip_nav.strp(nav.name.toSlice(ip));2673 try wip_nav.strp(nav.name.toSlice(ip));
2723 if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {2674 if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {
...@@ -2776,8 +2727,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2776,8 +2727,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2776 try wip_nav.abbrevCode(.decl_packed_struct);2727 try wip_nav.abbrevCode(.decl_packed_struct);
2777 try wip_nav.refType(.fromInterned(parent_type));2728 try wip_nav.refType(.fromInterned(parent_type));
2778 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2729 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2779 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2730 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
2780 try uleb128(diw, loc.column + 1);2731 try uleb128(diw, decl.src_column + 1);
2781 try diw.writeByte(accessibility);2732 try diw.writeByte(accessibility);
2782 try wip_nav.strp(nav.name.toSlice(ip));2733 try wip_nav.strp(nav.name.toSlice(ip));
2783 try wip_nav.refType(.fromInterned(loaded_struct.backingIntTypeUnordered(ip)));2734 try wip_nav.refType(.fromInterned(loaded_struct.backingIntTypeUnordered(ip)));
...@@ -2802,23 +2753,6 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2802,23 +2753,6 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2802 const type_inst_info = loaded_enum.zir_index.unwrap().?.resolveFull(ip).?;2753 const type_inst_info = loaded_enum.zir_index.unwrap().?.resolveFull(ip).?;
2803 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;2754 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;
28042755
2805 const value_inst = value_inst: {
2806 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2807 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2808 if (break_inst.tag != .break_inline) break :value_inst null;
2809 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2810 var value_inst = break_inst.data.@"break".operand.toIndex();
2811 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2812 else => break,
2813 .as_node => value_inst = file.zir.extraData(
2814 Zir.Inst.As,
2815 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2816 ).data.operand.toIndex(),
2817 };
2818 break :value_inst value_inst;
2819 };
2820 if (type_inst_info.inst != value_inst) break :tag .decl_alias;
2821
2822 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());2756 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2823 if (type_gop.found_existing) {2757 if (type_gop.found_existing) {
2824 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;2758 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;
...@@ -2835,8 +2769,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2835,8 +2769,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2835 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .decl_enum else .decl_empty_enum);2769 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .decl_enum else .decl_empty_enum);
2836 try wip_nav.refType(.fromInterned(parent_type));2770 try wip_nav.refType(.fromInterned(parent_type));
2837 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2771 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2838 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2772 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
2839 try uleb128(diw, loc.column + 1);2773 try uleb128(diw, decl.src_column + 1);
2840 try diw.writeByte(accessibility);2774 try diw.writeByte(accessibility);
2841 try wip_nav.strp(nav.name.toSlice(ip));2775 try wip_nav.strp(nav.name.toSlice(ip));
2842 try wip_nav.refType(.fromInterned(loaded_enum.tag_ty));2776 try wip_nav.refType(.fromInterned(loaded_enum.tag_ty));
...@@ -2857,23 +2791,6 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2857,23 +2791,6 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2857 const type_inst_info = loaded_union.zir_index.resolveFull(ip).?;2791 const type_inst_info = loaded_union.zir_index.resolveFull(ip).?;
2858 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;2792 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;
28592793
2860 const value_inst = value_inst: {
2861 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2862 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2863 if (break_inst.tag != .break_inline) break :value_inst null;
2864 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2865 var value_inst = break_inst.data.@"break".operand.toIndex();
2866 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2867 else => break,
2868 .as_node => value_inst = file.zir.extraData(
2869 Zir.Inst.As,
2870 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2871 ).data.operand.toIndex(),
2872 };
2873 break :value_inst value_inst;
2874 };
2875 if (type_inst_info.inst != value_inst) break :tag .decl_alias;
2876
2877 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());2794 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2878 if (type_gop.found_existing) {2795 if (type_gop.found_existing) {
2879 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;2796 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;
...@@ -2890,8 +2807,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2890,8 +2807,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2890 try wip_nav.abbrevCode(.decl_union);2807 try wip_nav.abbrevCode(.decl_union);
2891 try wip_nav.refType(.fromInterned(parent_type));2808 try wip_nav.refType(.fromInterned(parent_type));
2892 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2809 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2893 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2810 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
2894 try uleb128(diw, loc.column + 1);2811 try uleb128(diw, decl.src_column + 1);
2895 try diw.writeByte(accessibility);2812 try diw.writeByte(accessibility);
2896 try wip_nav.strp(nav.name.toSlice(ip));2813 try wip_nav.strp(nav.name.toSlice(ip));
2897 const union_layout = Type.getUnionLayout(loaded_union, zcu);2814 const union_layout = Type.getUnionLayout(loaded_union, zcu);
...@@ -2948,23 +2865,6 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2948,23 +2865,6 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2948 const type_inst_info = loaded_opaque.zir_index.resolveFull(ip).?;2865 const type_inst_info = loaded_opaque.zir_index.resolveFull(ip).?;
2949 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;2866 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;
29502867
2951 const value_inst = value_inst: {
2952 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2953 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2954 if (break_inst.tag != .break_inline) break :value_inst null;
2955 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2956 var value_inst = break_inst.data.@"break".operand.toIndex();
2957 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2958 else => break,
2959 .as_node => value_inst = file.zir.extraData(
2960 Zir.Inst.As,
2961 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2962 ).data.operand.toIndex(),
2963 };
2964 break :value_inst value_inst;
2965 };
2966 if (type_inst_info.inst != value_inst) break :tag .decl_alias;
2967
2968 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());2868 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2969 if (type_gop.found_existing) {2869 if (type_gop.found_existing) {
2970 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;2870 if (dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).len > 0) break :tag .decl_alias;
...@@ -2981,8 +2881,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2981,8 +2881,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2981 try wip_nav.abbrevCode(.decl_namespace_struct);2881 try wip_nav.abbrevCode(.decl_namespace_struct);
2982 try wip_nav.refType(.fromInterned(parent_type));2882 try wip_nav.refType(.fromInterned(parent_type));
2983 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2883 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2984 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2884 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
2985 try uleb128(diw, loc.column + 1);2885 try uleb128(diw, decl.src_column + 1);
2986 try diw.writeByte(accessibility);2886 try diw.writeByte(accessibility);
2987 try wip_nav.strp(nav.name.toSlice(ip));2887 try wip_nav.strp(nav.name.toSlice(ip));
2988 try diw.writeByte(@intFromBool(false));2888 try diw.writeByte(@intFromBool(false));
...@@ -3037,8 +2937,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -3037,8 +2937,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
3037 .decl_empty_func_generic);2937 .decl_empty_func_generic);
3038 try wip_nav.refType(.fromInterned(parent_type));2938 try wip_nav.refType(.fromInterned(parent_type));
3039 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2939 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
3040 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2940 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
3041 try uleb128(diw, loc.column + 1);2941 try uleb128(diw, decl.src_column + 1);
3042 try diw.writeByte(accessibility);2942 try diw.writeByte(accessibility);
3043 try wip_nav.strp(nav.name.toSlice(ip));2943 try wip_nav.strp(nav.name.toSlice(ip));
3044 try wip_nav.refType(.fromInterned(func_type.return_type));2944 try wip_nav.refType(.fromInterned(func_type.return_type));
...@@ -3069,8 +2969,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -3069,8 +2969,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
3069 try wip_nav.abbrevCode(.decl_alias);2969 try wip_nav.abbrevCode(.decl_alias);
3070 try wip_nav.refType(.fromInterned(parent_type));2970 try wip_nav.refType(.fromInterned(parent_type));
3071 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2971 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
3072 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2972 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
3073 try uleb128(diw, loc.column + 1);2973 try uleb128(diw, decl.src_column + 1);
3074 try diw.writeByte(accessibility);2974 try diw.writeByte(accessibility);
3075 try wip_nav.strp(nav.name.toSlice(ip));2975 try wip_nav.strp(nav.name.toSlice(ip));
3076 try wip_nav.refType(nav_val.toType());2976 try wip_nav.refType(nav_val.toType());
...@@ -3080,8 +2980,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -3080,8 +2980,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
3080 try wip_nav.abbrevCode(.decl_var);2980 try wip_nav.abbrevCode(.decl_var);
3081 try wip_nav.refType(.fromInterned(parent_type));2981 try wip_nav.refType(.fromInterned(parent_type));
3082 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));2982 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
3083 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);2983 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
3084 try uleb128(diw, loc.column + 1);2984 try uleb128(diw, decl.src_column + 1);
3085 try diw.writeByte(accessibility);2985 try diw.writeByte(accessibility);
3086 try wip_nav.strp(nav.name.toSlice(ip));2986 try wip_nav.strp(nav.name.toSlice(ip));
3087 try wip_nav.strp(nav.fqn.toSlice(ip));2987 try wip_nav.strp(nav.fqn.toSlice(ip));
...@@ -3107,8 +3007,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -3107,8 +3007,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
3107 .decl_const);3007 .decl_const);
3108 try wip_nav.refType(.fromInterned(parent_type));3008 try wip_nav.refType(.fromInterned(parent_type));
3109 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));3009 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
3110 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);3010 try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian);
3111 try uleb128(diw, loc.column + 1);3011 try uleb128(diw, decl.src_column + 1);
3112 try diw.writeByte(accessibility);3012 try diw.writeByte(accessibility);
3113 try wip_nav.strp(nav.name.toSlice(ip));3013 try wip_nav.strp(nav.name.toSlice(ip));
3114 try wip_nav.strp(nav.fqn.toSlice(ip));3014 try wip_nav.strp(nav.fqn.toSlice(ip));