authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-22 00:29:38+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-26 05:28:03+01:00
log5b523d04690d8a01cb5d97e4f5a35443cb0cbde8
treea7c8c3d8266f103e64b1876a0dca90a5a82b663f
parent3e9ab6aa7b2d90c25cb906d425a148abf9da3dcb
signaturelock-open Commit is signed but in an unrecognized format.

Zir: make `src_line` absolute for `declaration` instructions

We need special logic for updating line numbers anyway, so it's fine to just use absolute numbers here. This eliminates a field from `Decl`.

10 files changed, 93 insertions(+), 70 deletions(-)

lib/std/zig/AstGen.zig+7-7
......@@ -4368,7 +4368,7 @@ fn fnDecl(
43684368 decl_inst,
43694369 std.zig.hashSrc(tree.getNodeSource(decl_node)),
43704370 .{ .named = fn_name_token },
4371 decl_gz.decl_line - gz.decl_line,
4371 decl_gz.decl_line,
43724372 is_pub,
43734373 is_export,
43744374 doc_comment_index,
......@@ -4529,7 +4529,7 @@ fn globalVarDecl(
45294529 decl_inst,
45304530 std.zig.hashSrc(tree.getNodeSource(node)),
45314531 .{ .named = name_token },
4532 block_scope.decl_line - gz.decl_line,
4532 block_scope.decl_line,
45334533 is_pub,
45344534 is_export,
45354535 doc_comment_index,
......@@ -4579,7 +4579,7 @@ fn comptimeDecl(
45794579 decl_inst,
45804580 std.zig.hashSrc(tree.getNodeSource(node)),
45814581 .@"comptime",
4582 decl_block.decl_line - gz.decl_line,
4582 decl_block.decl_line,
45834583 false,
45844584 false,
45854585 .empty,
......@@ -4629,7 +4629,7 @@ fn usingnamespaceDecl(
46294629 decl_inst,
46304630 std.zig.hashSrc(tree.getNodeSource(node)),
46314631 .@"usingnamespace",
4632 decl_block.decl_line - gz.decl_line,
4632 decl_block.decl_line,
46334633 is_pub,
46344634 false,
46354635 .empty,
......@@ -4818,7 +4818,7 @@ fn testDecl(
48184818 decl_inst,
48194819 std.zig.hashSrc(tree.getNodeSource(node)),
48204820 test_name,
4821 decl_block.decl_line - gz.decl_line,
4821 decl_block.decl_line,
48224822 false,
48234823 false,
48244824 .empty,
......@@ -13861,7 +13861,7 @@ fn setDeclaration(
1386113861 decl_inst: Zir.Inst.Index,
1386213862 src_hash: std.zig.SrcHash,
1386313863 name: DeclarationName,
13864 line_offset: u32,
13864 src_line: u32,
1386513865 is_pub: bool,
1386613866 is_export: bool,
1386713867 doc_comment: Zir.NullTerminatedString,
......@@ -13913,7 +13913,7 @@ fn setDeclaration(
1391313913 .@"comptime" => .@"comptime",
1391413914 .@"usingnamespace" => .@"usingnamespace",
1391513915 },
13916 .line_offset = line_offset,
13916 .src_line = src_line,
1391713917 .flags = .{
1391813918 .value_body_len = @intCast(value_len),
1391913919 .is_pub = is_pub,
lib/std/zig/Zir.zig+1-3
......@@ -2598,9 +2598,7 @@ pub const Inst = struct {
25982598 src_hash_3: u32,
25992599 /// The name of this `Decl`. Also indicates whether it is a test, comptime block, etc.
26002600 name: Name,
2601 /// This Decl's line number relative to that of its parent.
2602 /// TODO: column must be encoded similarly to respect non-formatted code!
2603 line_offset: u32,
2601 src_line: u32,
26042602 flags: Flags,
26052603
26062604 pub const Flags = packed struct(u32) {
src/InternPool.zig-1
......@@ -6958,7 +6958,6 @@ fn finishFuncInstance(
69586958 const decl_index = try ip.createDecl(gpa, .{
69596959 .name = undefined,
69606960 .src_namespace = fn_owner_decl.src_namespace,
6961 .src_line = fn_owner_decl.src_line,
69626961 .has_tv = true,
69636962 .owns_tv = true,
69646963 .val = @import("Value.zig").fromInterned(func_index),
src/Sema.zig+10-27
......@@ -2827,7 +2827,6 @@ fn zirStructDecl(
28272827 small.name_strategy,
28282828 "struct",
28292829 inst,
2830 extra.data.src_line,
28312830 );
28322831 mod.declPtr(new_decl_index).owns_tv = true;
28332832 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -2864,7 +2863,6 @@ fn createAnonymousDeclTypeNamed(
28642863 name_strategy: Zir.Inst.NameStrategy,
28652864 anon_prefix: []const u8,
28662865 inst: ?Zir.Inst.Index,
2867 src_line: u32,
28682866) !InternPool.DeclIndex {
28692867 const zcu = sema.mod;
28702868 const ip = &zcu.intern_pool;
......@@ -2876,7 +2874,7 @@ fn createAnonymousDeclTypeNamed(
28762874 switch (name_strategy) {
28772875 .anon => {}, // handled after switch
28782876 .parent => {
2879 try zcu.initNewAnonDecl(new_decl_index, src_line, val, block.type_name_ctx);
2877 try zcu.initNewAnonDecl(new_decl_index, val, block.type_name_ctx);
28802878 return new_decl_index;
28812879 },
28822880 .func => func_strat: {
......@@ -2921,7 +2919,7 @@ fn createAnonymousDeclTypeNamed(
29212919
29222920 try writer.writeByte(')');
29232921 const name = try ip.getOrPutString(gpa, buf.items, .no_embedded_nulls);
2924 try zcu.initNewAnonDecl(new_decl_index, src_line, val, name);
2922 try zcu.initNewAnonDecl(new_decl_index, val, name);
29252923 return new_decl_index;
29262924 },
29272925 .dbg_var => {
......@@ -2935,7 +2933,7 @@ fn createAnonymousDeclTypeNamed(
29352933 const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{
29362934 block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code),
29372935 }, .no_embedded_nulls);
2938 try zcu.initNewAnonDecl(new_decl_index, src_line, val, name);
2936 try zcu.initNewAnonDecl(new_decl_index, val, name);
29392937 return new_decl_index;
29402938 },
29412939 else => {},
......@@ -2956,7 +2954,7 @@ fn createAnonymousDeclTypeNamed(
29562954 const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
29572955 block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),
29582956 }, .no_embedded_nulls) catch unreachable;
2959 try zcu.initNewAnonDecl(new_decl_index, src_line, val, name);
2957 try zcu.initNewAnonDecl(new_decl_index, val, name);
29602958 return new_decl_index;
29612959}
29622960
......@@ -3062,7 +3060,6 @@ fn zirEnumDecl(
30623060 small.name_strategy,
30633061 "enum",
30643062 inst,
3065 extra.data.src_line,
30663063 );
30673064 const new_decl = mod.declPtr(new_decl_index);
30683065 new_decl.owns_tv = true;
......@@ -3330,7 +3327,6 @@ fn zirUnionDecl(
33303327 small.name_strategy,
33313328 "union",
33323329 inst,
3333 extra.data.src_line,
33343330 );
33353331 mod.declPtr(new_decl_index).owns_tv = true;
33363332 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -3419,7 +3415,6 @@ fn zirOpaqueDecl(
34193415 small.name_strategy,
34203416 "opaque",
34213417 inst,
3422 extra.data.src_line,
34233418 );
34243419 mod.declPtr(new_decl_index).owns_tv = true;
34253420 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -21546,7 +21541,7 @@ fn zirReify(
2154621541 .needed_comptime_reason = "struct fields must be comptime-known",
2154721542 });
2154821543
21549 return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_arr, name_strategy, is_tuple_val.toBool(), extra.src_line);
21544 return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_arr, name_strategy, is_tuple_val.toBool());
2155021545 },
2155121546 .Enum => {
2155221547 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
......@@ -21575,7 +21570,7 @@ fn zirReify(
2157521570 .needed_comptime_reason = "enum fields must be comptime-known",
2157621571 });
2157721572
21578 return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy, extra.src_line);
21573 return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy);
2157921574 },
2158021575 .Opaque => {
2158121576 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
......@@ -21606,7 +21601,6 @@ fn zirReify(
2160621601 name_strategy,
2160721602 "opaque",
2160821603 inst,
21609 extra.src_line,
2161021604 );
2161121605 mod.declPtr(new_decl_index).owns_tv = true;
2161221606 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -21643,7 +21637,7 @@ fn zirReify(
2164321637 .needed_comptime_reason = "union fields must be comptime-known",
2164421638 });
2164521639
21646 return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy, extra.src_line);
21640 return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy);
2164721641 },
2164821642 .Fn => {
2164921643 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
......@@ -21745,7 +21739,6 @@ fn reifyEnum(
2174521739 is_exhaustive: bool,
2174621740 fields_val: Value,
2174721741 name_strategy: Zir.Inst.NameStrategy,
21748 src_line: u32,
2174921742) CompileError!Air.Inst.Ref {
2175021743 const mod = sema.mod;
2175121744 const gpa = sema.gpa;
......@@ -21807,7 +21800,6 @@ fn reifyEnum(
2180721800 name_strategy,
2180821801 "enum",
2180921802 inst,
21810 src_line,
2181121803 );
2181221804 mod.declPtr(new_decl_index).owns_tv = true;
2181321805 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -21871,7 +21863,6 @@ fn reifyUnion(
2187121863 opt_tag_type_val: Value,
2187221864 fields_val: Value,
2187321865 name_strategy: Zir.Inst.NameStrategy,
21874 src_line: u32,
2187521866) CompileError!Air.Inst.Ref {
2187621867 const mod = sema.mod;
2187721868 const gpa = sema.gpa;
......@@ -21955,7 +21946,6 @@ fn reifyUnion(
2195521946 name_strategy,
2195621947 "union",
2195721948 inst,
21958 src_line,
2195921949 );
2196021950 mod.declPtr(new_decl_index).owns_tv = true;
2196121951 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -22051,7 +22041,7 @@ fn reifyUnion(
2205122041 }
2205222042 }
2205322043
22054 const enum_tag_ty = try sema.generateUnionTagTypeSimple(block, field_names.keys(), mod.declPtr(new_decl_index), src_line);
22044 const enum_tag_ty = try sema.generateUnionTagTypeSimple(block, field_names.keys(), mod.declPtr(new_decl_index));
2205522045 break :tag_ty .{ enum_tag_ty, false };
2205622046 };
2205722047 errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error
......@@ -22112,7 +22102,6 @@ fn reifyStruct(
2211222102 fields_val: Value,
2211322103 name_strategy: Zir.Inst.NameStrategy,
2211422104 is_tuple: bool,
22115 src_line: u32,
2211622105) CompileError!Air.Inst.Ref {
2211722106 const mod = sema.mod;
2211822107 const gpa = sema.gpa;
......@@ -22213,7 +22202,6 @@ fn reifyStruct(
2221322202 name_strategy,
2221422203 "struct",
2221522204 inst,
22216 src_line,
2221722205 );
2221822206 mod.declPtr(new_decl_index).owns_tv = true;
2221922207 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -26347,7 +26335,6 @@ fn zirBuiltinExtern(
2634726335 const new_decl = mod.declPtr(new_decl_index);
2634826336 try mod.initNewAnonDecl(
2634926337 new_decl_index,
26350 sema.owner_decl.src_line,
2635126338 Value.fromInterned(
2635226339 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn)
2635326340 try ip.getExternFunc(sema.gpa, .{
......@@ -36745,10 +36732,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3674536732 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3674636733 }
3674736734 } else if (enum_field_vals.count() > 0) {
36748 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl), extra.data.src_line);
36735 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl));
3674936736 union_type.tagTypePtr(ip).* = enum_ty;
3675036737 } else {
36751 const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, mod.declPtr(union_type.decl), extra.data.src_line);
36738 const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, mod.declPtr(union_type.decl));
3675236739 union_type.tagTypePtr(ip).* = enum_ty;
3675336740 }
3675436741}
......@@ -36766,7 +36753,6 @@ fn generateUnionTagTypeNumbered(
3676636753 enum_field_names: []const InternPool.NullTerminatedString,
3676736754 enum_field_vals: []const InternPool.Index,
3676836755 union_owner_decl: *Module.Decl,
36769 src_line: u32,
3677036756) !InternPool.Index {
3677136757 const mod = sema.mod;
3677236758 const gpa = sema.gpa;
......@@ -36783,7 +36769,6 @@ fn generateUnionTagTypeNumbered(
3678336769 );
3678436770 try mod.initNewAnonDecl(
3678536771 new_decl_index,
36786 src_line,
3678736772 Value.@"unreachable",
3678836773 name,
3678936774 );
......@@ -36816,7 +36801,6 @@ fn generateUnionTagTypeSimple(
3681636801 block: *Block,
3681736802 enum_field_names: []const InternPool.NullTerminatedString,
3681836803 union_owner_decl: *Module.Decl,
36819 src_line: u32,
3682036804) !InternPool.Index {
3682136805 const mod = sema.mod;
3682236806 const ip = &mod.intern_pool;
......@@ -36834,7 +36818,6 @@ fn generateUnionTagTypeSimple(
3683436818 );
3683536819 try mod.initNewAnonDecl(
3683636820 new_decl_index,
36837 src_line,
3683836821 Value.@"unreachable",
3683936822 name,
3684036823 );
src/Zcu.zig+27-12
......@@ -347,10 +347,6 @@ pub const Decl = struct {
347347 /// there is no parent.
348348 src_namespace: Namespace.Index,
349349
350 /// Line number corresponding to `src_node`. Stored separately so that source files
351 /// do not need to be loaded into memory in order to compute debug line numbers.
352 /// This value is absolute.
353 src_line: u32,
354350 /// Index of the ZIR `declaration` instruction from which this `Decl` was created.
355351 /// For the root `Decl` of a `File` and legacy anonymous decls, this is `.none`.
356352 zir_decl_index: InternPool.TrackedInst.Index.Optional,
......@@ -564,6 +560,33 @@ pub const Decl = struct {
564560 .offset = LazySrcLoc.Offset.nodeOffset(0),
565561 };
566562 }
563
564 pub fn navSrcLine(decl: Decl, zcu: *Zcu) u32 {
565 const tracked = decl.zir_decl_index.unwrap() orelse inst: {
566 // generic instantiation
567 assert(decl.has_tv);
568 assert(decl.owns_tv);
569 const generic_owner_func = switch (zcu.intern_pool.indexToKey(decl.val.toIntern())) {
570 .func => |func| func.generic_owner,
571 else => return 0, // TODO: this is probably a `variable` or something; figure this out when we finish sorting out `Decl`.
572 };
573 const generic_owner_decl = zcu.declPtr(zcu.funcInfo(generic_owner_func).owner_decl);
574 break :inst generic_owner_decl.zir_decl_index.unwrap().?;
575 };
576 const info = tracked.resolveFull(&zcu.intern_pool);
577 const file = zcu.import_table.values()[zcu.path_digest_map.getIndex(info.path_digest).?];
578 assert(file.zir_loaded);
579 const zir = file.zir;
580 const inst = zir.instructions.get(@intFromEnum(info.inst));
581 assert(inst.tag == .declaration);
582 return zir.extraData(Zir.Inst.Declaration, inst.data.declaration.payload_index).data.src_line;
583 }
584
585 pub fn typeSrcLine(decl: Decl, zcu: *Zcu) u32 {
586 assert(decl.has_tv);
587 assert(decl.owns_tv);
588 return decl.val.toType().typeDeclSrcLine(zcu).?;
589 }
567590};
568591
569592/// This state is attached to every Decl when Module emit_h is non-null.
......@@ -3944,7 +3967,6 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {
39443967
39453968 new_decl.name = try file.fullyQualifiedName(mod);
39463969 new_decl.name_fully_qualified = true;
3947 new_decl.src_line = 0;
39483970 new_decl.is_pub = true;
39493971 new_decl.is_exported = false;
39503972 new_decl.alignment = .none;
......@@ -4762,8 +4784,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
47624784 const extra = zir.extraData(Zir.Inst.Declaration, inst_data.payload_index);
47634785 const declaration = extra.data;
47644786
4765 const line = iter.parent_decl.src_line + declaration.line_offset;
4766
47674787 // Every Decl needs a name.
47684788 const decl_name: InternPool.NullTerminatedString, const kind: Decl.Kind, const is_named_test: bool = switch (declaration.name) {
47694789 .@"comptime" => info: {
......@@ -4850,7 +4870,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
48504870 const was_exported = decl.is_exported;
48514871 assert(decl.kind == kind); // ZIR tracking should preserve this
48524872 decl.name = decl_name;
4853 decl.src_line = line;
48544873 decl.is_pub = declaration.flags.is_pub;
48554874 decl.is_exported = declaration.flags.is_export;
48564875 break :decl_index .{ was_exported, decl_index };
......@@ -4860,7 +4879,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
48604879 const new_decl = zcu.declPtr(new_decl_index);
48614880 new_decl.kind = kind;
48624881 new_decl.name = decl_name;
4863 new_decl.src_line = line;
48644882 new_decl.is_pub = declaration.flags.is_pub;
48654883 new_decl.is_exported = declaration.flags.is_export;
48664884 new_decl.zir_decl_index = tracked_inst.toOptional();
......@@ -5263,7 +5281,6 @@ pub fn allocateNewDecl(zcu: *Zcu, namespace: Namespace.Index) !Decl.Index {
52635281 const decl_index = try zcu.intern_pool.createDecl(gpa, .{
52645282 .name = undefined,
52655283 .src_namespace = namespace,
5266 .src_line = undefined,
52675284 .has_tv = false,
52685285 .owns_tv = false,
52695286 .val = undefined,
......@@ -5311,14 +5328,12 @@ pub fn errorSetBits(mod: *Module) u16 {
53115328pub fn initNewAnonDecl(
53125329 mod: *Module,
53135330 new_decl_index: Decl.Index,
5314 src_line: u32,
53155331 val: Value,
53165332 name: InternPool.NullTerminatedString,
53175333) Allocator.Error!void {
53185334 const new_decl = mod.declPtr(new_decl_index);
53195335
53205336 new_decl.name = name;
5321 new_decl.src_line = src_line;
53225337 new_decl.val = val;
53235338 new_decl.alignment = .none;
53245339 new_decl.@"linksection" = .none;
src/codegen/llvm.zig+9-9
......@@ -1697,7 +1697,7 @@ pub const Object = struct {
16971697 const file, const subprogram = if (!wip.strip) debug_info: {
16981698 const file = try o.getDebugFile(namespace.file_scope);
16991699
1700 const line_number = decl.src_line + 1;
1700 const line_number = decl.navSrcLine(zcu) + 1;
17011701 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and
17021702 !zcu.decl_exports.contains(decl_index);
17031703 const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu));
......@@ -1741,7 +1741,7 @@ pub const Object = struct {
17411741 .sync_scope = if (owner_mod.single_threaded) .singlethread else .system,
17421742 .file = file,
17431743 .scope = subprogram,
1744 .base_line = dg.decl.src_line,
1744 .base_line = dg.decl.navSrcLine(zcu),
17451745 .prev_dbg_line = 0,
17461746 .prev_dbg_column = 0,
17471747 .err_ret_trace = err_ret_trace,
......@@ -2067,7 +2067,7 @@ pub const Object = struct {
20672067 try o.builder.metadataString(name),
20682068 file,
20692069 scope,
2070 owner_decl.src_line + 1, // Line
2070 owner_decl.typeSrcLine(mod) + 1, // Line
20712071 try o.lowerDebugType(int_ty),
20722072 ty.abiSize(mod) * 8,
20732073 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
......@@ -2237,7 +2237,7 @@ pub const Object = struct {
22372237 try o.builder.metadataString(name),
22382238 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),
22392239 try o.namespaceToDebugScope(owner_decl.src_namespace),
2240 owner_decl.src_line + 1, // Line
2240 owner_decl.typeSrcLine(mod) + 1, // Line
22412241 .none, // Underlying type
22422242 0, // Size
22432243 0, // Align
......@@ -2867,7 +2867,7 @@ pub const Object = struct {
28672867 try o.builder.metadataString(decl.name.toSlice(&mod.intern_pool)), // TODO use fully qualified name
28682868 try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope),
28692869 try o.namespaceToDebugScope(decl.src_namespace),
2870 decl.src_line + 1,
2870 decl.typeSrcLine(mod) + 1,
28712871 .none,
28722872 0,
28732873 0,
......@@ -4762,7 +4762,7 @@ pub const DeclGen = struct {
47624762 else => try o.lowerValue(init_val),
47634763 }, &o.builder);
47644764
4765 const line_number = decl.src_line + 1;
4765 const line_number = decl.navSrcLine(zcu) + 1;
47664766 const is_internal_linkage = !o.module.decl_exports.contains(decl_index);
47674767
47684768 const namespace = zcu.namespacePtr(decl.src_namespace);
......@@ -5188,7 +5188,7 @@ pub const FuncGen = struct {
51885188
51895189 self.file = try o.getDebugFile(namespace.file_scope);
51905190
5191 const line_number = decl.src_line + 1;
5191 const line_number = decl.navSrcLine(zcu) + 1;
51925192 self.inlined = self.wip.debug_location;
51935193
51945194 const fqn = try decl.fullyQualifiedName(zcu);
......@@ -5217,7 +5217,7 @@ pub const FuncGen = struct {
52175217 o.debug_compile_unit,
52185218 );
52195219
5220 self.base_line = decl.src_line;
5220 self.base_line = decl.navSrcLine(zcu);
52215221 const inlined_at_location = try self.wip.debug_location.toMetadata(&o.builder);
52225222 self.wip.debug_location = .{
52235223 .location = .{
......@@ -8857,7 +8857,7 @@ pub const FuncGen = struct {
88578857 const src_index = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index;
88588858 const func_index = self.dg.decl.getOwnedFunctionIndex();
88598859 const func = mod.funcInfo(func_index);
8860 const lbrace_line = mod.declPtr(func.owner_decl).src_line + func.lbrace_line + 1;
8860 const lbrace_line = mod.declPtr(func.owner_decl).navSrcLine(mod) + func.lbrace_line + 1;
88618861 const lbrace_col = func.lbrace_column + 1;
88628862
88638863 const debug_parameter = try o.builder.debugParameter(
src/codegen/spirv.zig+2-2
......@@ -212,7 +212,7 @@ pub const Object = struct {
212212 false => .{ .unstructured = .{} },
213213 },
214214 .current_block_label = undefined,
215 .base_line = decl.src_line,
215 .base_line = decl.navSrcLine(mod),
216216 };
217217 defer decl_gen.deinit();
218218
......@@ -6345,7 +6345,7 @@ const DeclGen = struct {
63456345 const decl = mod.funcOwnerDeclPtr(extra.data.func);
63466346 const old_base_line = self.base_line;
63476347 defer self.base_line = old_base_line;
6348 self.base_line = decl.src_line;
6348 self.base_line = decl.navSrcLine(mod);
63496349 return self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
63506350 }
63516351
src/link/Dwarf.zig+6-6
......@@ -948,8 +948,8 @@ pub const DeclState = struct {
948948 leb128.writeUnsignedFixed(4, self.dbg_line.addManyAsArrayAssumeCapacity(4), new_file);
949949 }
950950
951 const old_src_line: i33 = self.mod.declPtr(old_func_info.owner_decl).src_line;
952 const new_src_line: i33 = self.mod.declPtr(new_func_info.owner_decl).src_line;
951 const old_src_line: i33 = self.mod.declPtr(old_func_info.owner_decl).navSrcLine(self.mod);
952 const new_src_line: i33 = self.mod.declPtr(new_func_info.owner_decl).navSrcLine(self.mod);
953953 if (new_src_line != old_src_line) {
954954 self.dbg_line.appendAssumeCapacity(DW.LNS.advance_line);
955955 leb128.writeSignedFixed(5, self.dbg_line.addManyAsArrayAssumeCapacity(5), new_src_line - old_src_line);
......@@ -1116,11 +1116,11 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde
11161116 decl_state.dbg_line_func = decl.val.toIntern();
11171117 const func = decl.val.getFunction(mod).?;
11181118 log.debug("decl.src_line={d}, func.lbrace_line={d}, func.rbrace_line={d}", .{
1119 decl.src_line,
1119 decl.navSrcLine(mod),
11201120 func.lbrace_line,
11211121 func.rbrace_line,
11221122 });
1123 const line: u28 = @intCast(decl.src_line + func.lbrace_line);
1123 const line: u28 = @intCast(decl.navSrcLine(mod) + func.lbrace_line);
11241124
11251125 dbg_line_buffer.appendSliceAssumeCapacity(&.{
11261126 DW.LNS.extended_op,
......@@ -1702,11 +1702,11 @@ pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: InternPool.D
17021702 const decl = mod.declPtr(decl_index);
17031703 const func = decl.val.getFunction(mod).?;
17041704 log.debug("decl.src_line={d}, func.lbrace_line={d}, func.rbrace_line={d}", .{
1705 decl.src_line,
1705 decl.navSrcLine(mod),
17061706 func.lbrace_line,
17071707 func.rbrace_line,
17081708 });
1709 const line: u28 = @intCast(decl.src_line + func.lbrace_line);
1709 const line: u28 = @intCast(decl.navSrcLine(mod) + func.lbrace_line);
17101710 var data: [4]u8 = undefined;
17111711 leb128.writeUnsignedFixed(4, &data, line);
17121712
src/print_zir.zig+2-2
......@@ -583,7 +583,7 @@ const Writer = struct {
583583
584584 .reify => {
585585 const inst_data = self.code.extraData(Zir.Inst.Reify, extended.operand).data;
586 try stream.print("{d}, ", .{inst_data.src_line});
586 try stream.print("line({d}), ", .{inst_data.src_line});
587587 try self.writeInstRef(stream, inst_data.operand);
588588 try stream.writeAll(")) ");
589589 const prev_parent_decl_node = self.parent_decl_node;
......@@ -2749,7 +2749,7 @@ const Writer = struct {
27492749 extra.data.src_hash_3,
27502750 };
27512751 const src_hash_bytes: [16]u8 = @bitCast(src_hash_arr);
2752 try stream.print(" line(+{d}) hash({})", .{ extra.data.line_offset, std.fmt.fmtSliceHexLower(&src_hash_bytes) });
2752 try stream.print(" line({d}) hash({})", .{ extra.data.src_line, std.fmt.fmtSliceHexLower(&src_hash_bytes) });
27532753
27542754 {
27552755 const bodies = extra.data.getBodies(@intCast(extra.end), self.code);
src/type.zig+29-1
......@@ -11,6 +11,7 @@ const target_util = @import("target.zig");
1111const Sema = @import("Sema.zig");
1212const InternPool = @import("InternPool.zig");
1313const Alignment = InternPool.Alignment;
14const Zir = std.zig.Zir;
1415
1516/// Both types and values are canonically represented by a single 32-bit integer
1617/// which is an index into an `InternPool` data structure.
......@@ -3340,7 +3341,7 @@ pub const Type = struct {
33403341 .struct_type, .union_type, .opaque_type, .enum_type => |info| switch (info) {
33413342 .declared => |d| d.zir_index,
33423343 .reified => |r| r.zir_index,
3343 .generated_tag => |gt| ip.loadUnionType(gt.union_type).zir_index, // must be declared since we can't generate tags when reifying
3344 .generated_tag => |gt| ip.loadUnionType(gt.union_type).zir_index,
33443345 .empty_struct => return null,
33453346 },
33463347 else => return null,
......@@ -3440,6 +3441,33 @@ pub const Type = struct {
34403441 };
34413442 }
34423443
3444 pub fn typeDeclSrcLine(ty: Type, zcu: *const Zcu) ?u32 {
3445 const ip = &zcu.intern_pool;
3446 const tracked = switch (ip.indexToKey(ty.toIntern())) {
3447 .struct_type, .union_type, .opaque_type, .enum_type => |info| switch (info) {
3448 .declared => |d| d.zir_index,
3449 .reified => |r| r.zir_index,
3450 .generated_tag => |gt| ip.loadUnionType(gt.union_type).zir_index,
3451 .empty_struct => return null,
3452 },
3453 else => return null,
3454 };
3455 const info = tracked.resolveFull(&zcu.intern_pool);
3456 const file = zcu.import_table.values()[zcu.path_digest_map.getIndex(info.path_digest).?];
3457 assert(file.zir_loaded);
3458 const zir = file.zir;
3459 const inst = zir.instructions.get(@intFromEnum(info.inst));
3460 assert(inst.tag == .extended);
3461 return switch (inst.data.extended.opcode) {
3462 .struct_decl => zir.extraData(Zir.Inst.StructDecl, inst.data.extended.operand).data.src_line,
3463 .union_decl => zir.extraData(Zir.Inst.UnionDecl, inst.data.extended.operand).data.src_line,
3464 .enum_decl => zir.extraData(Zir.Inst.EnumDecl, inst.data.extended.operand).data.src_line,
3465 .opaque_decl => zir.extraData(Zir.Inst.OpaqueDecl, inst.data.extended.operand).data.src_line,
3466 .reify => zir.extraData(Zir.Inst.Reify, inst.data.extended.operand).data.src_line,
3467 else => unreachable,
3468 };
3469 }
3470
34433471 /// Given a namespace type, returns its list of caotured values.
34443472 pub fn getCaptures(ty: Type, zcu: *const Zcu) InternPool.CaptureValue.Slice {
34453473 const ip = &zcu.intern_pool;