authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-27 00:14:03+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-06-27 00:14:03+01:00
loga016ca61706b300534a3a3a3c656b9b0ec24591c
tree87e9ae619d448ae4252931ba20393198f47dddc0
parent3e9ab6aa7b2d90c25cb906d425a148abf9da3dcb
parent4cb5318088b2eb66891f0d83b76a2740644b4156
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #20424 from mlugg/the-great-decl-split

Dismantle Decl a little bit more

11 files changed, 161 insertions(+), 138 deletions(-)

lib/std/zig/AstGen.zig+7-7
...@@ -4368,7 +4368,7 @@ fn fnDecl(...@@ -4368,7 +4368,7 @@ fn fnDecl(
4368 decl_inst,4368 decl_inst,
4369 std.zig.hashSrc(tree.getNodeSource(decl_node)),4369 std.zig.hashSrc(tree.getNodeSource(decl_node)),
4370 .{ .named = fn_name_token },4370 .{ .named = fn_name_token },
4371 decl_gz.decl_line - gz.decl_line,4371 decl_gz.decl_line,
4372 is_pub,4372 is_pub,
4373 is_export,4373 is_export,
4374 doc_comment_index,4374 doc_comment_index,
...@@ -4529,7 +4529,7 @@ fn globalVarDecl(...@@ -4529,7 +4529,7 @@ fn globalVarDecl(
4529 decl_inst,4529 decl_inst,
4530 std.zig.hashSrc(tree.getNodeSource(node)),4530 std.zig.hashSrc(tree.getNodeSource(node)),
4531 .{ .named = name_token },4531 .{ .named = name_token },
4532 block_scope.decl_line - gz.decl_line,4532 block_scope.decl_line,
4533 is_pub,4533 is_pub,
4534 is_export,4534 is_export,
4535 doc_comment_index,4535 doc_comment_index,
...@@ -4579,7 +4579,7 @@ fn comptimeDecl(...@@ -4579,7 +4579,7 @@ fn comptimeDecl(
4579 decl_inst,4579 decl_inst,
4580 std.zig.hashSrc(tree.getNodeSource(node)),4580 std.zig.hashSrc(tree.getNodeSource(node)),
4581 .@"comptime",4581 .@"comptime",
4582 decl_block.decl_line - gz.decl_line,4582 decl_block.decl_line,
4583 false,4583 false,
4584 false,4584 false,
4585 .empty,4585 .empty,
...@@ -4629,7 +4629,7 @@ fn usingnamespaceDecl(...@@ -4629,7 +4629,7 @@ fn usingnamespaceDecl(
4629 decl_inst,4629 decl_inst,
4630 std.zig.hashSrc(tree.getNodeSource(node)),4630 std.zig.hashSrc(tree.getNodeSource(node)),
4631 .@"usingnamespace",4631 .@"usingnamespace",
4632 decl_block.decl_line - gz.decl_line,4632 decl_block.decl_line,
4633 is_pub,4633 is_pub,
4634 false,4634 false,
4635 .empty,4635 .empty,
...@@ -4818,7 +4818,7 @@ fn testDecl(...@@ -4818,7 +4818,7 @@ fn testDecl(
4818 decl_inst,4818 decl_inst,
4819 std.zig.hashSrc(tree.getNodeSource(node)),4819 std.zig.hashSrc(tree.getNodeSource(node)),
4820 test_name,4820 test_name,
4821 decl_block.decl_line - gz.decl_line,4821 decl_block.decl_line,
4822 false,4822 false,
4823 false,4823 false,
4824 .empty,4824 .empty,
...@@ -13861,7 +13861,7 @@ fn setDeclaration(...@@ -13861,7 +13861,7 @@ fn setDeclaration(
13861 decl_inst: Zir.Inst.Index,13861 decl_inst: Zir.Inst.Index,
13862 src_hash: std.zig.SrcHash,13862 src_hash: std.zig.SrcHash,
13863 name: DeclarationName,13863 name: DeclarationName,
13864 line_offset: u32,13864 src_line: u32,
13865 is_pub: bool,13865 is_pub: bool,
13866 is_export: bool,13866 is_export: bool,
13867 doc_comment: Zir.NullTerminatedString,13867 doc_comment: Zir.NullTerminatedString,
...@@ -13913,7 +13913,7 @@ fn setDeclaration(...@@ -13913,7 +13913,7 @@ fn setDeclaration(
13913 .@"comptime" => .@"comptime",13913 .@"comptime" => .@"comptime",
13914 .@"usingnamespace" => .@"usingnamespace",13914 .@"usingnamespace" => .@"usingnamespace",
13915 },13915 },
13916 .line_offset = line_offset,13916 .src_line = src_line,
13917 .flags = .{13917 .flags = .{
13918 .value_body_len = @intCast(value_len),13918 .value_body_len = @intCast(value_len),
13919 .is_pub = is_pub,13919 .is_pub = is_pub,
lib/std/zig/Zir.zig+1-3
...@@ -2598,9 +2598,7 @@ pub const Inst = struct {...@@ -2598,9 +2598,7 @@ pub const Inst = struct {
2598 src_hash_3: u32,2598 src_hash_3: u32,
2599 /// The name of this `Decl`. Also indicates whether it is a test, comptime block, etc.2599 /// The name of this `Decl`. Also indicates whether it is a test, comptime block, etc.
2600 name: Name,2600 name: Name,
2601 /// This Decl's line number relative to that of its parent.2601 src_line: u32,
2602 /// TODO: column must be encoded similarly to respect non-formatted code!
2603 line_offset: u32,
2604 flags: Flags,2602 flags: Flags,
26052603
2606 pub const Flags = packed struct(u32) {2604 pub const Flags = packed struct(u32) {
src/Compilation.zig+1-1
...@@ -3494,7 +3494,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo...@@ -3494,7 +3494,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
3494 .{@errorName(err)},3494 .{@errorName(err)},
3495 ));3495 ));
3496 decl.analysis = .codegen_failure;3496 decl.analysis = .codegen_failure;
3497 try module.retryable_failures.append(gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));3497 try module.retryable_failures.append(gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
3498 };3498 };
3499 },3499 },
3500 .analyze_mod => |pkg| {3500 .analyze_mod => |pkg| {
src/InternPool.zig+25-26
...@@ -81,7 +81,7 @@ namespace_name_deps: std.AutoArrayHashMapUnmanaged(NamespaceNameKey, DepEntry.In...@@ -81,7 +81,7 @@ namespace_name_deps: std.AutoArrayHashMapUnmanaged(NamespaceNameKey, DepEntry.In
81/// Given a `Depender`, points to an entry in `dep_entries` whose `depender`81/// Given a `Depender`, points to an entry in `dep_entries` whose `depender`
82/// matches. The `next_dependee` field can be used to iterate all such entries82/// matches. The `next_dependee` field can be used to iterate all such entries
83/// and remove them from the corresponding lists.83/// and remove them from the corresponding lists.
84first_dependency: std.AutoArrayHashMapUnmanaged(Depender, DepEntry.Index) = .{},84first_dependency: std.AutoArrayHashMapUnmanaged(AnalSubject, DepEntry.Index) = .{},
8585
86/// Stores dependency information. The hashmaps declared above are used to look86/// Stores dependency information. The hashmaps declared above are used to look
87/// up entries in this list as required. This is not stored in `extra` so that87/// up entries in this list as required. This is not stored in `extra` so that
...@@ -132,39 +132,39 @@ pub fn trackZir(ip: *InternPool, gpa: Allocator, file: *Module.File, inst: Zir.I...@@ -132,39 +132,39 @@ pub fn trackZir(ip: *InternPool, gpa: Allocator, file: *Module.File, inst: Zir.I
132 return @enumFromInt(gop.index);132 return @enumFromInt(gop.index);
133}133}
134134
135/// Reperesents the "source" of a dependency edge, i.e. either a Decl or a135/// Analysis Subject. Represents a single entity which undergoes semantic analysis.
136/// runtime function (represented as an InternPool index).136/// This is either a `Decl` (in future `Cau`) or a runtime function.
137/// MSB is 0 for a Decl, 1 for a function.137/// The LSB is used as a tag bit.
138pub const Depender = enum(u32) {138/// This is the "source" of an incremental dependency edge.
139 _,139pub const AnalSubject = packed struct(u32) {
140 kind: enum(u1) { decl, func },
141 index: u31,
140 pub const Unwrapped = union(enum) {142 pub const Unwrapped = union(enum) {
141 decl: DeclIndex,143 decl: DeclIndex,
142 func: InternPool.Index,144 func: InternPool.Index,
143 };145 };
144 pub fn unwrap(dep: Depender) Unwrapped {146 pub fn unwrap(as: AnalSubject) Unwrapped {
145 const tag: u1 = @truncate(@intFromEnum(dep) >> 31);147 return switch (as.kind) {
146 const val: u31 = @truncate(@intFromEnum(dep));148 .decl => .{ .decl = @enumFromInt(as.index) },
147 return switch (tag) {149 .func => .{ .func = @enumFromInt(as.index) },
148 0 => .{ .decl = @enumFromInt(val) },
149 1 => .{ .func = @enumFromInt(val) },
150 };150 };
151 }151 }
152 pub fn wrap(raw: Unwrapped) Depender {152 pub fn wrap(raw: Unwrapped) AnalSubject {
153 return @enumFromInt(switch (raw) {153 return switch (raw) {
154 .decl => |decl| @intFromEnum(decl),154 .decl => |decl| .{ .kind = .decl, .index = @intCast(@intFromEnum(decl)) },
155 .func => |func| (1 << 31) | @intFromEnum(func),155 .func => |func| .{ .kind = .func, .index = @intCast(@intFromEnum(func)) },
156 });156 };
157 }157 }
158 pub fn toOptional(dep: Depender) Optional {158 pub fn toOptional(as: AnalSubject) Optional {
159 return @enumFromInt(@intFromEnum(dep));159 return @enumFromInt(@as(u32, @bitCast(as)));
160 }160 }
161 pub const Optional = enum(u32) {161 pub const Optional = enum(u32) {
162 none = std.math.maxInt(u32),162 none = std.math.maxInt(u32),
163 _,163 _,
164 pub fn unwrap(opt: Optional) ?Depender {164 pub fn unwrap(opt: Optional) ?AnalSubject {
165 return switch (opt) {165 return switch (opt) {
166 .none => null,166 .none => null,
167 _ => @enumFromInt(@intFromEnum(opt)),167 _ => @bitCast(@intFromEnum(opt)),
168 };168 };
169 }169 }
170 };170 };
...@@ -178,7 +178,7 @@ pub const Dependee = union(enum) {...@@ -178,7 +178,7 @@ pub const Dependee = union(enum) {
178 namespace_name: NamespaceNameKey,178 namespace_name: NamespaceNameKey,
179};179};
180180
181pub fn removeDependenciesForDepender(ip: *InternPool, gpa: Allocator, depender: Depender) void {181pub fn removeDependenciesForDepender(ip: *InternPool, gpa: Allocator, depender: AnalSubject) void {
182 var opt_idx = (ip.first_dependency.fetchSwapRemove(depender) orelse return).value.toOptional();182 var opt_idx = (ip.first_dependency.fetchSwapRemove(depender) orelse return).value.toOptional();
183183
184 while (opt_idx.unwrap()) |idx| {184 while (opt_idx.unwrap()) |idx| {
...@@ -207,7 +207,7 @@ pub fn removeDependenciesForDepender(ip: *InternPool, gpa: Allocator, depender:...@@ -207,7 +207,7 @@ pub fn removeDependenciesForDepender(ip: *InternPool, gpa: Allocator, depender:
207pub const DependencyIterator = struct {207pub const DependencyIterator = struct {
208 ip: *const InternPool,208 ip: *const InternPool,
209 next_entry: DepEntry.Index.Optional,209 next_entry: DepEntry.Index.Optional,
210 pub fn next(it: *DependencyIterator) ?Depender {210 pub fn next(it: *DependencyIterator) ?AnalSubject {
211 const idx = it.next_entry.unwrap() orelse return null;211 const idx = it.next_entry.unwrap() orelse return null;
212 const entry = it.ip.dep_entries.items[@intFromEnum(idx)];212 const entry = it.ip.dep_entries.items[@intFromEnum(idx)];
213 it.next_entry = entry.next;213 it.next_entry = entry.next;
...@@ -236,7 +236,7 @@ pub fn dependencyIterator(ip: *const InternPool, dependee: Dependee) DependencyI...@@ -236,7 +236,7 @@ pub fn dependencyIterator(ip: *const InternPool, dependee: Dependee) DependencyI
236 };236 };
237}237}
238238
239pub fn addDependency(ip: *InternPool, gpa: Allocator, depender: Depender, dependee: Dependee) Allocator.Error!void {239pub fn addDependency(ip: *InternPool, gpa: Allocator, depender: AnalSubject, dependee: Dependee) Allocator.Error!void {
240 const first_depender_dep: DepEntry.Index.Optional = if (ip.first_dependency.get(depender)) |idx| dep: {240 const first_depender_dep: DepEntry.Index.Optional = if (ip.first_dependency.get(depender)) |idx| dep: {
241 // The entry already exists, so there is capacity to overwrite it later.241 // The entry already exists, so there is capacity to overwrite it later.
242 break :dep idx.toOptional();242 break :dep idx.toOptional();
...@@ -300,7 +300,7 @@ pub const DepEntry = extern struct {...@@ -300,7 +300,7 @@ pub const DepEntry = extern struct {
300 /// the first and only entry in one of `intern_pool.*_deps`, and does not300 /// the first and only entry in one of `intern_pool.*_deps`, and does not
301 /// appear in any list by `first_dependency`, but is not in301 /// appear in any list by `first_dependency`, but is not in
302 /// `free_dep_entries` since `*_deps` stores a reference to it.302 /// `free_dep_entries` since `*_deps` stores a reference to it.
303 depender: Depender.Optional,303 depender: AnalSubject.Optional,
304 /// Index into `dep_entries` forming a doubly linked list of all dependencies on this dependee.304 /// Index into `dep_entries` forming a doubly linked list of all dependencies on this dependee.
305 /// Used to iterate all dependers for a given dependee during an update.305 /// Used to iterate all dependers for a given dependee during an update.
306 /// null if this is the end of the list.306 /// null if this is the end of the list.
...@@ -6958,7 +6958,6 @@ fn finishFuncInstance(...@@ -6958,7 +6958,6 @@ fn finishFuncInstance(
6958 const decl_index = try ip.createDecl(gpa, .{6958 const decl_index = try ip.createDecl(gpa, .{
6959 .name = undefined,6959 .name = undefined,
6960 .src_namespace = fn_owner_decl.src_namespace,6960 .src_namespace = fn_owner_decl.src_namespace,
6961 .src_line = fn_owner_decl.src_line,
6962 .has_tv = true,6961 .has_tv = true,
6963 .owns_tv = true,6962 .owns_tv = true,
6964 .val = @import("Value.zig").fromInterned(func_index),6963 .val = @import("Value.zig").fromInterned(func_index),
src/Sema.zig+17-34
...@@ -2735,12 +2735,12 @@ fn maybeRemoveOutdatedType(sema: *Sema, ty: InternPool.Index) !bool {...@@ -2735,12 +2735,12 @@ fn maybeRemoveOutdatedType(sema: *Sema, ty: InternPool.Index) !bool {
2735 if (!zcu.comp.debug_incremental) return false;2735 if (!zcu.comp.debug_incremental) return false;
27362736
2737 const decl_index = Type.fromInterned(ty).getOwnerDecl(zcu);2737 const decl_index = Type.fromInterned(ty).getOwnerDecl(zcu);
2738 const decl_as_depender = InternPool.Depender.wrap(.{ .decl = decl_index });2738 const decl_as_depender = InternPool.AnalSubject.wrap(.{ .decl = decl_index });
2739 const was_outdated = zcu.outdated.swapRemove(decl_as_depender) or2739 const was_outdated = zcu.outdated.swapRemove(decl_as_depender) or
2740 zcu.potentially_outdated.swapRemove(decl_as_depender);2740 zcu.potentially_outdated.swapRemove(decl_as_depender);
2741 if (!was_outdated) return false;2741 if (!was_outdated) return false;
2742 _ = zcu.outdated_ready.swapRemove(decl_as_depender);2742 _ = zcu.outdated_ready.swapRemove(decl_as_depender);
2743 zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));2743 zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
2744 zcu.intern_pool.remove(ty);2744 zcu.intern_pool.remove(ty);
2745 zcu.declPtr(decl_index).analysis = .dependency_failure;2745 zcu.declPtr(decl_index).analysis = .dependency_failure;
2746 try zcu.markDependeeOutdated(.{ .decl_val = decl_index });2746 try zcu.markDependeeOutdated(.{ .decl_val = decl_index });
...@@ -2827,7 +2827,6 @@ fn zirStructDecl(...@@ -2827,7 +2827,6 @@ fn zirStructDecl(
2827 small.name_strategy,2827 small.name_strategy,
2828 "struct",2828 "struct",
2829 inst,2829 inst,
2830 extra.data.src_line,
2831 );2830 );
2832 mod.declPtr(new_decl_index).owns_tv = true;2831 mod.declPtr(new_decl_index).owns_tv = true;
2833 errdefer mod.abortAnonDecl(new_decl_index);2832 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -2835,7 +2834,7 @@ fn zirStructDecl(...@@ -2835,7 +2834,7 @@ fn zirStructDecl(
2835 if (sema.mod.comp.debug_incremental) {2834 if (sema.mod.comp.debug_incremental) {
2836 try ip.addDependency(2835 try ip.addDependency(
2837 sema.gpa,2836 sema.gpa,
2838 InternPool.Depender.wrap(.{ .decl = new_decl_index }),2837 InternPool.AnalSubject.wrap(.{ .decl = new_decl_index }),
2839 .{ .src_hash = try ip.trackZir(sema.gpa, block.getFileScope(mod), inst) },2838 .{ .src_hash = try ip.trackZir(sema.gpa, block.getFileScope(mod), inst) },
2840 );2839 );
2841 }2840 }
...@@ -2864,7 +2863,6 @@ fn createAnonymousDeclTypeNamed(...@@ -2864,7 +2863,6 @@ fn createAnonymousDeclTypeNamed(
2864 name_strategy: Zir.Inst.NameStrategy,2863 name_strategy: Zir.Inst.NameStrategy,
2865 anon_prefix: []const u8,2864 anon_prefix: []const u8,
2866 inst: ?Zir.Inst.Index,2865 inst: ?Zir.Inst.Index,
2867 src_line: u32,
2868) !InternPool.DeclIndex {2866) !InternPool.DeclIndex {
2869 const zcu = sema.mod;2867 const zcu = sema.mod;
2870 const ip = &zcu.intern_pool;2868 const ip = &zcu.intern_pool;
...@@ -2876,7 +2874,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2876,7 +2874,7 @@ fn createAnonymousDeclTypeNamed(
2876 switch (name_strategy) {2874 switch (name_strategy) {
2877 .anon => {}, // handled after switch2875 .anon => {}, // handled after switch
2878 .parent => {2876 .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);
2880 return new_decl_index;2878 return new_decl_index;
2881 },2879 },
2882 .func => func_strat: {2880 .func => func_strat: {
...@@ -2921,7 +2919,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2921,7 +2919,7 @@ fn createAnonymousDeclTypeNamed(
29212919
2922 try writer.writeByte(')');2920 try writer.writeByte(')');
2923 const name = try ip.getOrPutString(gpa, buf.items, .no_embedded_nulls);2921 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);
2925 return new_decl_index;2923 return new_decl_index;
2926 },2924 },
2927 .dbg_var => {2925 .dbg_var => {
...@@ -2935,7 +2933,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2935,7 +2933,7 @@ fn createAnonymousDeclTypeNamed(
2935 const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{2933 const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{
2936 block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code),2934 block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code),
2937 }, .no_embedded_nulls);2935 }, .no_embedded_nulls);
2938 try zcu.initNewAnonDecl(new_decl_index, src_line, val, name);2936 try zcu.initNewAnonDecl(new_decl_index, val, name);
2939 return new_decl_index;2937 return new_decl_index;
2940 },2938 },
2941 else => {},2939 else => {},
...@@ -2956,7 +2954,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2956,7 +2954,7 @@ fn createAnonymousDeclTypeNamed(
2956 const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{2954 const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
2957 block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),2955 block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),
2958 }, .no_embedded_nulls) catch unreachable;2956 }, .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);
2960 return new_decl_index;2958 return new_decl_index;
2961}2959}
29622960
...@@ -3062,7 +3060,6 @@ fn zirEnumDecl(...@@ -3062,7 +3060,6 @@ fn zirEnumDecl(
3062 small.name_strategy,3060 small.name_strategy,
3063 "enum",3061 "enum",
3064 inst,3062 inst,
3065 extra.data.src_line,
3066 );3063 );
3067 const new_decl = mod.declPtr(new_decl_index);3064 const new_decl = mod.declPtr(new_decl_index);
3068 new_decl.owns_tv = true;3065 new_decl.owns_tv = true;
...@@ -3071,7 +3068,7 @@ fn zirEnumDecl(...@@ -3071,7 +3068,7 @@ fn zirEnumDecl(
3071 if (sema.mod.comp.debug_incremental) {3068 if (sema.mod.comp.debug_incremental) {
3072 try mod.intern_pool.addDependency(3069 try mod.intern_pool.addDependency(
3073 sema.gpa,3070 sema.gpa,
3074 InternPool.Depender.wrap(.{ .decl = new_decl_index }),3071 InternPool.AnalSubject.wrap(.{ .decl = new_decl_index }),
3075 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },3072 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
3076 );3073 );
3077 }3074 }
...@@ -3330,7 +3327,6 @@ fn zirUnionDecl(...@@ -3330,7 +3327,6 @@ fn zirUnionDecl(
3330 small.name_strategy,3327 small.name_strategy,
3331 "union",3328 "union",
3332 inst,3329 inst,
3333 extra.data.src_line,
3334 );3330 );
3335 mod.declPtr(new_decl_index).owns_tv = true;3331 mod.declPtr(new_decl_index).owns_tv = true;
3336 errdefer mod.abortAnonDecl(new_decl_index);3332 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -3338,7 +3334,7 @@ fn zirUnionDecl(...@@ -3338,7 +3334,7 @@ fn zirUnionDecl(
3338 if (sema.mod.comp.debug_incremental) {3334 if (sema.mod.comp.debug_incremental) {
3339 try mod.intern_pool.addDependency(3335 try mod.intern_pool.addDependency(
3340 sema.gpa,3336 sema.gpa,
3341 InternPool.Depender.wrap(.{ .decl = new_decl_index }),3337 InternPool.AnalSubject.wrap(.{ .decl = new_decl_index }),
3342 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },3338 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
3343 );3339 );
3344 }3340 }
...@@ -3419,7 +3415,6 @@ fn zirOpaqueDecl(...@@ -3419,7 +3415,6 @@ fn zirOpaqueDecl(
3419 small.name_strategy,3415 small.name_strategy,
3420 "opaque",3416 "opaque",
3421 inst,3417 inst,
3422 extra.data.src_line,
3423 );3418 );
3424 mod.declPtr(new_decl_index).owns_tv = true;3419 mod.declPtr(new_decl_index).owns_tv = true;
3425 errdefer mod.abortAnonDecl(new_decl_index);3420 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -3427,7 +3422,7 @@ fn zirOpaqueDecl(...@@ -3427,7 +3422,7 @@ fn zirOpaqueDecl(
3427 if (sema.mod.comp.debug_incremental) {3422 if (sema.mod.comp.debug_incremental) {
3428 try ip.addDependency(3423 try ip.addDependency(
3429 gpa,3424 gpa,
3430 InternPool.Depender.wrap(.{ .decl = new_decl_index }),3425 InternPool.AnalSubject.wrap(.{ .decl = new_decl_index }),
3431 .{ .src_hash = try ip.trackZir(gpa, block.getFileScope(mod), inst) },3426 .{ .src_hash = try ip.trackZir(gpa, block.getFileScope(mod), inst) },
3432 );3427 );
3433 }3428 }
...@@ -21546,7 +21541,7 @@ fn zirReify(...@@ -21546,7 +21541,7 @@ fn zirReify(
21546 .needed_comptime_reason = "struct fields must be comptime-known",21541 .needed_comptime_reason = "struct fields must be comptime-known",
21547 });21542 });
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());
21550 },21545 },
21551 .Enum => {21546 .Enum => {
21552 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21547 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
...@@ -21575,7 +21570,7 @@ fn zirReify(...@@ -21575,7 +21570,7 @@ fn zirReify(
21575 .needed_comptime_reason = "enum fields must be comptime-known",21570 .needed_comptime_reason = "enum fields must be comptime-known",
21576 });21571 });
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);
21579 },21574 },
21580 .Opaque => {21575 .Opaque => {
21581 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21576 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
...@@ -21606,7 +21601,6 @@ fn zirReify(...@@ -21606,7 +21601,6 @@ fn zirReify(
21606 name_strategy,21601 name_strategy,
21607 "opaque",21602 "opaque",
21608 inst,21603 inst,
21609 extra.src_line,
21610 );21604 );
21611 mod.declPtr(new_decl_index).owns_tv = true;21605 mod.declPtr(new_decl_index).owns_tv = true;
21612 errdefer mod.abortAnonDecl(new_decl_index);21606 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -21643,7 +21637,7 @@ fn zirReify(...@@ -21643,7 +21637,7 @@ fn zirReify(
21643 .needed_comptime_reason = "union fields must be comptime-known",21637 .needed_comptime_reason = "union fields must be comptime-known",
21644 });21638 });
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);
21647 },21641 },
21648 .Fn => {21642 .Fn => {
21649 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21643 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
...@@ -21745,7 +21739,6 @@ fn reifyEnum(...@@ -21745,7 +21739,6 @@ fn reifyEnum(
21745 is_exhaustive: bool,21739 is_exhaustive: bool,
21746 fields_val: Value,21740 fields_val: Value,
21747 name_strategy: Zir.Inst.NameStrategy,21741 name_strategy: Zir.Inst.NameStrategy,
21748 src_line: u32,
21749) CompileError!Air.Inst.Ref {21742) CompileError!Air.Inst.Ref {
21750 const mod = sema.mod;21743 const mod = sema.mod;
21751 const gpa = sema.gpa;21744 const gpa = sema.gpa;
...@@ -21807,7 +21800,6 @@ fn reifyEnum(...@@ -21807,7 +21800,6 @@ fn reifyEnum(
21807 name_strategy,21800 name_strategy,
21808 "enum",21801 "enum",
21809 inst,21802 inst,
21810 src_line,
21811 );21803 );
21812 mod.declPtr(new_decl_index).owns_tv = true;21804 mod.declPtr(new_decl_index).owns_tv = true;
21813 errdefer mod.abortAnonDecl(new_decl_index);21805 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -21871,7 +21863,6 @@ fn reifyUnion(...@@ -21871,7 +21863,6 @@ fn reifyUnion(
21871 opt_tag_type_val: Value,21863 opt_tag_type_val: Value,
21872 fields_val: Value,21864 fields_val: Value,
21873 name_strategy: Zir.Inst.NameStrategy,21865 name_strategy: Zir.Inst.NameStrategy,
21874 src_line: u32,
21875) CompileError!Air.Inst.Ref {21866) CompileError!Air.Inst.Ref {
21876 const mod = sema.mod;21867 const mod = sema.mod;
21877 const gpa = sema.gpa;21868 const gpa = sema.gpa;
...@@ -21955,7 +21946,6 @@ fn reifyUnion(...@@ -21955,7 +21946,6 @@ fn reifyUnion(
21955 name_strategy,21946 name_strategy,
21956 "union",21947 "union",
21957 inst,21948 inst,
21958 src_line,
21959 );21949 );
21960 mod.declPtr(new_decl_index).owns_tv = true;21950 mod.declPtr(new_decl_index).owns_tv = true;
21961 errdefer mod.abortAnonDecl(new_decl_index);21951 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -22051,7 +22041,7 @@ fn reifyUnion(...@@ -22051,7 +22041,7 @@ fn reifyUnion(
22051 }22041 }
22052 }22042 }
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));
22055 break :tag_ty .{ enum_tag_ty, false };22045 break :tag_ty .{ enum_tag_ty, false };
22056 };22046 };
22057 errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error22047 errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error
...@@ -22112,7 +22102,6 @@ fn reifyStruct(...@@ -22112,7 +22102,6 @@ fn reifyStruct(
22112 fields_val: Value,22102 fields_val: Value,
22113 name_strategy: Zir.Inst.NameStrategy,22103 name_strategy: Zir.Inst.NameStrategy,
22114 is_tuple: bool,22104 is_tuple: bool,
22115 src_line: u32,
22116) CompileError!Air.Inst.Ref {22105) CompileError!Air.Inst.Ref {
22117 const mod = sema.mod;22106 const mod = sema.mod;
22118 const gpa = sema.gpa;22107 const gpa = sema.gpa;
...@@ -22213,7 +22202,6 @@ fn reifyStruct(...@@ -22213,7 +22202,6 @@ fn reifyStruct(
22213 name_strategy,22202 name_strategy,
22214 "struct",22203 "struct",
22215 inst,22204 inst,
22216 src_line,
22217 );22205 );
22218 mod.declPtr(new_decl_index).owns_tv = true;22206 mod.declPtr(new_decl_index).owns_tv = true;
22219 errdefer mod.abortAnonDecl(new_decl_index);22207 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -26347,7 +26335,6 @@ fn zirBuiltinExtern(...@@ -26347,7 +26335,6 @@ fn zirBuiltinExtern(
26347 const new_decl = mod.declPtr(new_decl_index);26335 const new_decl = mod.declPtr(new_decl_index);
26348 try mod.initNewAnonDecl(26336 try mod.initNewAnonDecl(
26349 new_decl_index,26337 new_decl_index,
26350 sema.owner_decl.src_line,
26351 Value.fromInterned(26338 Value.fromInterned(
26352 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn)26339 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn)
26353 try ip.getExternFunc(sema.gpa, .{26340 try ip.getExternFunc(sema.gpa, .{
...@@ -36745,10 +36732,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36745,10 +36732,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36745 return sema.failWithOwnedErrorMsg(&block_scope, msg);36732 return sema.failWithOwnedErrorMsg(&block_scope, msg);
36746 }36733 }
36747 } else if (enum_field_vals.count() > 0) {36734 } 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));
36749 union_type.tagTypePtr(ip).* = enum_ty;36736 union_type.tagTypePtr(ip).* = enum_ty;
36750 } else {36737 } 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));
36752 union_type.tagTypePtr(ip).* = enum_ty;36739 union_type.tagTypePtr(ip).* = enum_ty;
36753 }36740 }
36754}36741}
...@@ -36766,7 +36753,6 @@ fn generateUnionTagTypeNumbered(...@@ -36766,7 +36753,6 @@ fn generateUnionTagTypeNumbered(
36766 enum_field_names: []const InternPool.NullTerminatedString,36753 enum_field_names: []const InternPool.NullTerminatedString,
36767 enum_field_vals: []const InternPool.Index,36754 enum_field_vals: []const InternPool.Index,
36768 union_owner_decl: *Module.Decl,36755 union_owner_decl: *Module.Decl,
36769 src_line: u32,
36770) !InternPool.Index {36756) !InternPool.Index {
36771 const mod = sema.mod;36757 const mod = sema.mod;
36772 const gpa = sema.gpa;36758 const gpa = sema.gpa;
...@@ -36783,7 +36769,6 @@ fn generateUnionTagTypeNumbered(...@@ -36783,7 +36769,6 @@ fn generateUnionTagTypeNumbered(
36783 );36769 );
36784 try mod.initNewAnonDecl(36770 try mod.initNewAnonDecl(
36785 new_decl_index,36771 new_decl_index,
36786 src_line,
36787 Value.@"unreachable",36772 Value.@"unreachable",
36788 name,36773 name,
36789 );36774 );
...@@ -36816,7 +36801,6 @@ fn generateUnionTagTypeSimple(...@@ -36816,7 +36801,6 @@ fn generateUnionTagTypeSimple(
36816 block: *Block,36801 block: *Block,
36817 enum_field_names: []const InternPool.NullTerminatedString,36802 enum_field_names: []const InternPool.NullTerminatedString,
36818 union_owner_decl: *Module.Decl,36803 union_owner_decl: *Module.Decl,
36819 src_line: u32,
36820) !InternPool.Index {36804) !InternPool.Index {
36821 const mod = sema.mod;36805 const mod = sema.mod;
36822 const ip = &mod.intern_pool;36806 const ip = &mod.intern_pool;
...@@ -36834,7 +36818,6 @@ fn generateUnionTagTypeSimple(...@@ -36834,7 +36818,6 @@ fn generateUnionTagTypeSimple(
36834 );36818 );
36835 try mod.initNewAnonDecl(36819 try mod.initNewAnonDecl(
36836 new_decl_index,36820 new_decl_index,
36837 src_line,
36838 Value.@"unreachable",36821 Value.@"unreachable",
36839 name,36822 name,
36840 );36823 );
...@@ -38379,7 +38362,7 @@ pub fn declareDependency(sema: *Sema, dependee: InternPool.Dependee) !void {...@@ -38379,7 +38362,7 @@ pub fn declareDependency(sema: *Sema, dependee: InternPool.Dependee) !void {
38379 return;38362 return;
38380 }38363 }
3838138364
38382 const depender = InternPool.Depender.wrap(38365 const depender = InternPool.AnalSubject.wrap(
38383 if (sema.owner_func_index != .none)38366 if (sema.owner_func_index != .none)
38384 .{ .func = sema.owner_func_index }38367 .{ .func = sema.owner_func_index }
38385 else38368 else
src/Zcu.zig+62-47
...@@ -139,26 +139,26 @@ global_error_set: GlobalErrorSet = .{},...@@ -139,26 +139,26 @@ global_error_set: GlobalErrorSet = .{},
139/// Maximum amount of distinct error values, set by --error-limit139/// Maximum amount of distinct error values, set by --error-limit
140error_limit: ErrorInt,140error_limit: ErrorInt,
141141
142/// Value is the number of PO or outdated Decls which this Depender depends on.142/// Value is the number of PO or outdated Decls which this AnalSubject depends on.
143potentially_outdated: std.AutoArrayHashMapUnmanaged(InternPool.Depender, u32) = .{},143potentially_outdated: std.AutoArrayHashMapUnmanaged(InternPool.AnalSubject, u32) = .{},
144/// Value is the number of PO or outdated Decls which this Depender depends on.144/// Value is the number of PO or outdated Decls which this AnalSubject depends on.
145/// Once this value drops to 0, the Depender is a candidate for re-analysis.145/// Once this value drops to 0, the AnalSubject is a candidate for re-analysis.
146outdated: std.AutoArrayHashMapUnmanaged(InternPool.Depender, u32) = .{},146outdated: std.AutoArrayHashMapUnmanaged(InternPool.AnalSubject, u32) = .{},
147/// This contains all `Depender`s in `outdated` whose PO dependency count is 0.147/// This contains all `AnalSubject`s in `outdated` whose PO dependency count is 0.
148/// Such `Depender`s are ready for immediate re-analysis.148/// Such `AnalSubject`s are ready for immediate re-analysis.
149/// See `findOutdatedToAnalyze` for details.149/// See `findOutdatedToAnalyze` for details.
150outdated_ready: std.AutoArrayHashMapUnmanaged(InternPool.Depender, void) = .{},150outdated_ready: std.AutoArrayHashMapUnmanaged(InternPool.AnalSubject, void) = .{},
151/// This contains a set of Decls which may not be in `outdated`, but are the151/// This contains a set of Decls which may not be in `outdated`, but are the
152/// root Decls of files which have updated source and thus must be re-analyzed.152/// root Decls of files which have updated source and thus must be re-analyzed.
153/// If such a Decl is only in this set, the struct type index may be preserved153/// If such a Decl is only in this set, the struct type index may be preserved
154/// (only the namespace might change). If such a Decl is also `outdated`, the154/// (only the namespace might change). If such a Decl is also `outdated`, the
155/// struct type index must be recreated.155/// struct type index must be recreated.
156outdated_file_root: std.AutoArrayHashMapUnmanaged(Decl.Index, void) = .{},156outdated_file_root: std.AutoArrayHashMapUnmanaged(Decl.Index, void) = .{},
157/// This contains a list of Dependers whose analysis or codegen failed, but the157/// This contains a list of AnalSubject whose analysis or codegen failed, but the
158/// failure was something like running out of disk space, and trying again may158/// failure was something like running out of disk space, and trying again may
159/// succeed. On the next update, we will flush this list, marking all members of159/// succeed. On the next update, we will flush this list, marking all members of
160/// it as outdated.160/// it as outdated.
161retryable_failures: std.ArrayListUnmanaged(InternPool.Depender) = .{},161retryable_failures: std.ArrayListUnmanaged(InternPool.AnalSubject) = .{},
162162
163stage1_flags: packed struct {163stage1_flags: packed struct {
164 have_winmain: bool = false,164 have_winmain: bool = false,
...@@ -347,10 +347,6 @@ pub const Decl = struct {...@@ -347,10 +347,6 @@ pub const Decl = struct {
347 /// there is no parent.347 /// there is no parent.
348 src_namespace: Namespace.Index,348 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,
354 /// Index of the ZIR `declaration` instruction from which this `Decl` was created.350 /// Index of the ZIR `declaration` instruction from which this `Decl` was created.
355 /// For the root `Decl` of a `File` and legacy anonymous decls, this is `.none`.351 /// For the root `Decl` of a `File` and legacy anonymous decls, this is `.none`.
356 zir_decl_index: InternPool.TrackedInst.Index.Optional,352 zir_decl_index: InternPool.TrackedInst.Index.Optional,
...@@ -564,6 +560,33 @@ pub const Decl = struct {...@@ -564,6 +560,33 @@ pub const Decl = struct {
564 .offset = LazySrcLoc.Offset.nodeOffset(0),560 .offset = LazySrcLoc.Offset.nodeOffset(0),
565 };561 };
566 }562 }
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 }
567};590};
568591
569/// This state is attached to every Decl when Module emit_h is non-null.592/// This state is attached to every Decl when Module emit_h is non-null.
...@@ -3114,9 +3137,9 @@ fn markPoDependeeUpToDate(zcu: *Zcu, dependee: InternPool.Dependee) !void {...@@ -3114,9 +3137,9 @@ fn markPoDependeeUpToDate(zcu: *Zcu, dependee: InternPool.Dependee) !void {
3114 }3137 }
3115}3138}
31163139
3117/// Given a Depender which is newly outdated or PO, mark all Dependers which may3140/// Given a AnalSubject which is newly outdated or PO, mark all AnalSubjects which may
3118/// in turn be PO, due to a dependency on the original Depender's tyval or IES.3141/// in turn be PO, due to a dependency on the original AnalSubject's tyval or IES.
3119fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: InternPool.Depender) !void {3142fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: InternPool.AnalSubject) !void {
3120 var it = zcu.intern_pool.dependencyIterator(switch (maybe_outdated.unwrap()) {3143 var it = zcu.intern_pool.dependencyIterator(switch (maybe_outdated.unwrap()) {
3121 .decl => |decl_index| .{ .decl_val = decl_index }, // TODO: also `decl_ref` deps when introduced3144 .decl => |decl_index| .{ .decl_val = decl_index }, // TODO: also `decl_ref` deps when introduced
3122 .func => |func_index| .{ .func_ies = func_index },3145 .func => |func_index| .{ .func_ies = func_index },
...@@ -3138,12 +3161,12 @@ fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: InternP...@@ -3138,12 +3161,12 @@ fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: InternP
3138 continue;3161 continue;
3139 }3162 }
3140 try zcu.potentially_outdated.putNoClobber(zcu.gpa, po, 1);3163 try zcu.potentially_outdated.putNoClobber(zcu.gpa, po, 1);
3141 // This Depender was not already PO, so we must recursively mark its dependers as also PO.3164 // This AnalSubject was not already PO, so we must recursively mark its dependers as also PO.
3142 try zcu.markTransitiveDependersPotentiallyOutdated(po);3165 try zcu.markTransitiveDependersPotentiallyOutdated(po);
3143 }3166 }
3144}3167}
31453168
3146pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {3169pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.AnalSubject {
3147 if (!zcu.comp.debug_incremental) return null;3170 if (!zcu.comp.debug_incremental) return null;
31483171
3149 if (zcu.outdated.count() == 0 and zcu.potentially_outdated.count() == 0) {3172 if (zcu.outdated.count() == 0 and zcu.potentially_outdated.count() == 0) {
...@@ -3151,8 +3174,8 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {...@@ -3151,8 +3174,8 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {
3151 return null;3174 return null;
3152 }3175 }
31533176
3154 // Our goal is to find an outdated Depender which itself has no outdated or3177 // Our goal is to find an outdated AnalSubject which itself has no outdated or
3155 // PO dependencies. Most of the time, such a Depender will exist - we track3178 // PO dependencies. Most of the time, such an AnalSubject will exist - we track
3156 // them in the `outdated_ready` set for efficiency. However, this is not3179 // them in the `outdated_ready` set for efficiency. However, this is not
3157 // necessarily the case, since the Decl dependency graph may contain loops3180 // necessarily the case, since the Decl dependency graph may contain loops
3158 // via mutually recursive definitions:3181 // via mutually recursive definitions:
...@@ -3174,7 +3197,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {...@@ -3174,7 +3197,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {
3174 // `outdated`. This set will be small (number of files changed in this3197 // `outdated`. This set will be small (number of files changed in this
3175 // update), so it's alright for us to just iterate here.3198 // update), so it's alright for us to just iterate here.
3176 for (zcu.outdated_file_root.keys()) |file_decl| {3199 for (zcu.outdated_file_root.keys()) |file_decl| {
3177 const decl_depender = InternPool.Depender.wrap(.{ .decl = file_decl });3200 const decl_depender = InternPool.AnalSubject.wrap(.{ .decl = file_decl });
3178 if (zcu.outdated.contains(decl_depender)) {3201 if (zcu.outdated.contains(decl_depender)) {
3179 // Since we didn't hit this in the first loop, this Decl must have3202 // Since we didn't hit this in the first loop, this Decl must have
3180 // pending dependencies, so is ineligible.3203 // pending dependencies, so is ineligible.
...@@ -3190,7 +3213,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {...@@ -3190,7 +3213,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {
3190 return decl_depender;3213 return decl_depender;
3191 }3214 }
31923215
3193 // There is no single Depender which is ready for re-analysis. Instead, we3216 // There is no single AnalSubject which is ready for re-analysis. Instead, we
3194 // must assume that some Decl with PO dependencies is outdated - e.g. in the3217 // must assume that some Decl with PO dependencies is outdated - e.g. in the
3195 // above example we arbitrarily pick one of A or B. We should select a Decl,3218 // above example we arbitrarily pick one of A or B. We should select a Decl,
3196 // since a Decl is definitely responsible for the loop in the dependency3219 // since a Decl is definitely responsible for the loop in the dependency
...@@ -3198,7 +3221,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {...@@ -3198,7 +3221,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {
31983221
3199 // The choice of this Decl could have a big impact on how much total3222 // The choice of this Decl could have a big impact on how much total
3200 // analysis we perform, since if analysis concludes its tyval is unchanged,3223 // analysis we perform, since if analysis concludes its tyval is unchanged,
3201 // then other PO Dependers may be resolved as up-to-date. To hopefully avoid3224 // then other PO AnalSubject may be resolved as up-to-date. To hopefully avoid
3202 // doing too much work, let's find a Decl which the most things depend on -3225 // doing too much work, let's find a Decl which the most things depend on -
3203 // the idea is that this will resolve a lot of loops (but this is only a3226 // the idea is that this will resolve a lot of loops (but this is only a
3204 // heuristic).3227 // heuristic).
...@@ -3248,7 +3271,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {...@@ -3248,7 +3271,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {
3248 chosen_decl_dependers,3271 chosen_decl_dependers,
3249 });3272 });
32503273
3251 return InternPool.Depender.wrap(.{ .decl = chosen_decl_idx.? });3274 return InternPool.AnalSubject.wrap(.{ .decl = chosen_decl_idx.? });
3252}3275}
32533276
3254/// During an incremental update, before semantic analysis, call this to flush all values from3277/// During an incremental update, before semantic analysis, call this to flush all values from
...@@ -3258,12 +3281,12 @@ pub fn flushRetryableFailures(zcu: *Zcu) !void {...@@ -3258,12 +3281,12 @@ pub fn flushRetryableFailures(zcu: *Zcu) !void {
3258 for (zcu.retryable_failures.items) |depender| {3281 for (zcu.retryable_failures.items) |depender| {
3259 if (zcu.outdated.contains(depender)) continue;3282 if (zcu.outdated.contains(depender)) continue;
3260 if (zcu.potentially_outdated.fetchSwapRemove(depender)) |kv| {3283 if (zcu.potentially_outdated.fetchSwapRemove(depender)) |kv| {
3261 // This Depender was already PO, but we now consider it outdated.3284 // This AnalSubject was already PO, but we now consider it outdated.
3262 // Any transitive dependencies are already marked PO.3285 // Any transitive dependencies are already marked PO.
3263 try zcu.outdated.put(gpa, depender, kv.value);3286 try zcu.outdated.put(gpa, depender, kv.value);
3264 continue;3287 continue;
3265 }3288 }
3266 // This Depender was not marked PO, but is now outdated. Mark it as3289 // This AnalSubject was not marked PO, but is now outdated. Mark it as
3267 // such, then recursively mark transitive dependencies as PO.3290 // such, then recursively mark transitive dependencies as PO.
3268 try zcu.outdated.put(gpa, depender, 0);3291 try zcu.outdated.put(gpa, depender, 0);
3269 try zcu.markTransitiveDependersPotentiallyOutdated(depender);3292 try zcu.markTransitiveDependersPotentiallyOutdated(depender);
...@@ -3433,7 +3456,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {...@@ -3433,7 +3456,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
3433 // which tries to limit re-analysis to Decls whose previously listed3456 // which tries to limit re-analysis to Decls whose previously listed
3434 // dependencies are all up-to-date.3457 // dependencies are all up-to-date.
34353458
3436 const decl_as_depender = InternPool.Depender.wrap(.{ .decl = decl_index });3459 const decl_as_depender = InternPool.AnalSubject.wrap(.{ .decl = decl_index });
3437 const decl_was_outdated = mod.outdated.swapRemove(decl_as_depender) or3460 const decl_was_outdated = mod.outdated.swapRemove(decl_as_depender) or
3438 mod.potentially_outdated.swapRemove(decl_as_depender);3461 mod.potentially_outdated.swapRemove(decl_as_depender);
34393462
...@@ -3499,7 +3522,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {...@@ -3499,7 +3522,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
3499 else => |e| {3522 else => |e| {
3500 decl.analysis = .sema_failure;3523 decl.analysis = .sema_failure;
3501 try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1);3524 try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1);
3502 try mod.retryable_failures.append(mod.gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));3525 try mod.retryable_failures.append(mod.gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
3503 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(3526 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
3504 mod.gpa,3527 mod.gpa,
3505 decl.navSrcLoc(mod).upgrade(mod),3528 decl.navSrcLoc(mod).upgrade(mod),
...@@ -3558,7 +3581,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In...@@ -3558,7 +3581,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
3558 // that's the case, we should remove this function from the binary.3581 // that's the case, we should remove this function from the binary.
3559 if (decl.val.ip_index != func_index) {3582 if (decl.val.ip_index != func_index) {
3560 try zcu.markDependeeOutdated(.{ .func_ies = func_index });3583 try zcu.markDependeeOutdated(.{ .func_ies = func_index });
3561 ip.removeDependenciesForDepender(gpa, InternPool.Depender.wrap(.{ .func = func_index }));3584 ip.removeDependenciesForDepender(gpa, InternPool.AnalSubject.wrap(.{ .func = func_index }));
3562 ip.remove(func_index);3585 ip.remove(func_index);
3563 @panic("TODO: remove orphaned function from binary");3586 @panic("TODO: remove orphaned function from binary");
3564 }3587 }
...@@ -3584,7 +3607,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In...@@ -3584,7 +3607,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
3584 .complete => {},3607 .complete => {},
3585 }3608 }
35863609
3587 const func_as_depender = InternPool.Depender.wrap(.{ .func = func_index });3610 const func_as_depender = InternPool.AnalSubject.wrap(.{ .func = func_index });
3588 const was_outdated = zcu.outdated.swapRemove(func_as_depender) or3611 const was_outdated = zcu.outdated.swapRemove(func_as_depender) or
3589 zcu.potentially_outdated.swapRemove(func_as_depender);3612 zcu.potentially_outdated.swapRemove(func_as_depender);
35903613
...@@ -3705,7 +3728,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In...@@ -3705,7 +3728,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
3705 .{@errorName(err)},3728 .{@errorName(err)},
3706 ));3729 ));
3707 func.analysis(ip).state = .codegen_failure;3730 func.analysis(ip).state = .codegen_failure;
3708 try zcu.retryable_failures.append(zcu.gpa, InternPool.Depender.wrap(.{ .func = func_index }));3731 try zcu.retryable_failures.append(zcu.gpa, InternPool.AnalSubject.wrap(.{ .func = func_index }));
3709 },3732 },
3710 };3733 };
3711 } else if (zcu.llvm_object) |llvm_object| {3734 } else if (zcu.llvm_object) |llvm_object| {
...@@ -3750,7 +3773,7 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)...@@ -3750,7 +3773,7 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)
37503773
3751 assert(decl.has_tv);3774 assert(decl.has_tv);
37523775
3753 const func_as_depender = InternPool.Depender.wrap(.{ .func = func_index });3776 const func_as_depender = InternPool.AnalSubject.wrap(.{ .func = func_index });
3754 const is_outdated = mod.outdated.contains(func_as_depender) or3777 const is_outdated = mod.outdated.contains(func_as_depender) or
3755 mod.potentially_outdated.contains(func_as_depender);3778 mod.potentially_outdated.contains(func_as_depender);
37563779
...@@ -3834,7 +3857,7 @@ fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespa...@@ -3834,7 +3857,7 @@ fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespa
3834 if (zcu.comp.debug_incremental) {3857 if (zcu.comp.debug_incremental) {
3835 try ip.addDependency(3858 try ip.addDependency(
3836 gpa,3859 gpa,
3837 InternPool.Depender.wrap(.{ .decl = decl_index }),3860 InternPool.AnalSubject.wrap(.{ .decl = decl_index }),
3838 .{ .src_hash = tracked_inst },3861 .{ .src_hash = tracked_inst },
3839 );3862 );
3840 }3863 }
...@@ -3883,7 +3906,7 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool {...@@ -3883,7 +3906,7 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool {
38833906
3884 if (type_outdated) {3907 if (type_outdated) {
3885 // Invalidate the existing type, reusing the decl and namespace.3908 // Invalidate the existing type, reusing the decl and namespace.
3886 zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.Depender.wrap(.{ .decl = file.root_decl.unwrap().? }));3909 zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.AnalSubject.wrap(.{ .decl = file.root_decl.unwrap().? }));
3887 zcu.intern_pool.remove(decl.val.toIntern());3910 zcu.intern_pool.remove(decl.val.toIntern());
3888 decl.val = undefined;3911 decl.val = undefined;
3889 _ = try zcu.getFileRootStruct(file.root_decl.unwrap().?, decl.src_namespace, file);3912 _ = try zcu.getFileRootStruct(file.root_decl.unwrap().?, decl.src_namespace, file);
...@@ -3944,7 +3967,6 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {...@@ -3944,7 +3967,6 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {
39443967
3945 new_decl.name = try file.fullyQualifiedName(mod);3968 new_decl.name = try file.fullyQualifiedName(mod);
3946 new_decl.name_fully_qualified = true;3969 new_decl.name_fully_qualified = true;
3947 new_decl.src_line = 0;
3948 new_decl.is_pub = true;3970 new_decl.is_pub = true;
3949 new_decl.is_exported = false;3971 new_decl.is_exported = false;
3950 new_decl.alignment = .none;3972 new_decl.alignment = .none;
...@@ -4075,7 +4097,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -4075,7 +4097,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
4075 break :ip_index .none;4097 break :ip_index .none;
4076 };4098 };
40774099
4078 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));4100 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
40794101
4080 decl.analysis = .in_progress;4102 decl.analysis = .in_progress;
40814103
...@@ -4301,7 +4323,7 @@ fn semaAnonOwnerDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult {...@@ -4301,7 +4323,7 @@ fn semaAnonOwnerDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult {
4301 // with a new Decl.4323 // with a new Decl.
4302 //4324 //
4303 // Yes, this does mean that any type owner Decl has a constant value for its entire lifetime.4325 // Yes, this does mean that any type owner Decl has a constant value for its entire lifetime.
4304 zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));4326 zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
4305 zcu.intern_pool.remove(decl.val.toIntern());4327 zcu.intern_pool.remove(decl.val.toIntern());
4306 decl.analysis = .dependency_failure;4328 decl.analysis = .dependency_failure;
4307 return .{4329 return .{
...@@ -4762,8 +4784,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void...@@ -4762,8 +4784,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
4762 const extra = zir.extraData(Zir.Inst.Declaration, inst_data.payload_index);4784 const extra = zir.extraData(Zir.Inst.Declaration, inst_data.payload_index);
4763 const declaration = extra.data;4785 const declaration = extra.data;
47644786
4765 const line = iter.parent_decl.src_line + declaration.line_offset;
4766
4767 // Every Decl needs a name.4787 // Every Decl needs a name.
4768 const decl_name: InternPool.NullTerminatedString, const kind: Decl.Kind, const is_named_test: bool = switch (declaration.name) {4788 const decl_name: InternPool.NullTerminatedString, const kind: Decl.Kind, const is_named_test: bool = switch (declaration.name) {
4769 .@"comptime" => info: {4789 .@"comptime" => info: {
...@@ -4850,7 +4870,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void...@@ -4850,7 +4870,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
4850 const was_exported = decl.is_exported;4870 const was_exported = decl.is_exported;
4851 assert(decl.kind == kind); // ZIR tracking should preserve this4871 assert(decl.kind == kind); // ZIR tracking should preserve this
4852 decl.name = decl_name;4872 decl.name = decl_name;
4853 decl.src_line = line;
4854 decl.is_pub = declaration.flags.is_pub;4873 decl.is_pub = declaration.flags.is_pub;
4855 decl.is_exported = declaration.flags.is_export;4874 decl.is_exported = declaration.flags.is_export;
4856 break :decl_index .{ was_exported, decl_index };4875 break :decl_index .{ was_exported, decl_index };
...@@ -4860,7 +4879,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void...@@ -4860,7 +4879,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
4860 const new_decl = zcu.declPtr(new_decl_index);4879 const new_decl = zcu.declPtr(new_decl_index);
4861 new_decl.kind = kind;4880 new_decl.kind = kind;
4862 new_decl.name = decl_name;4881 new_decl.name = decl_name;
4863 new_decl.src_line = line;
4864 new_decl.is_pub = declaration.flags.is_pub;4882 new_decl.is_pub = declaration.flags.is_pub;
4865 new_decl.is_exported = declaration.flags.is_export;4883 new_decl.is_exported = declaration.flags.is_export;
4866 new_decl.zir_decl_index = tracked_inst.toOptional();4884 new_decl.zir_decl_index = tracked_inst.toOptional();
...@@ -5008,7 +5026,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -5008,7 +5026,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
5008 const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(mod)).toSlice(ip), 0);5026 const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(mod)).toSlice(ip), 0);
5009 defer decl_prog_node.end();5027 defer decl_prog_node.end();
50105028
5011 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.Depender.wrap(.{ .func = func_index }));5029 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.AnalSubject.wrap(.{ .func = func_index }));
50125030
5013 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);5031 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
5014 defer comptime_err_ret_trace.deinit();5032 defer comptime_err_ret_trace.deinit();
...@@ -5263,7 +5281,6 @@ pub fn allocateNewDecl(zcu: *Zcu, namespace: Namespace.Index) !Decl.Index {...@@ -5263,7 +5281,6 @@ pub fn allocateNewDecl(zcu: *Zcu, namespace: Namespace.Index) !Decl.Index {
5263 const decl_index = try zcu.intern_pool.createDecl(gpa, .{5281 const decl_index = try zcu.intern_pool.createDecl(gpa, .{
5264 .name = undefined,5282 .name = undefined,
5265 .src_namespace = namespace,5283 .src_namespace = namespace,
5266 .src_line = undefined,
5267 .has_tv = false,5284 .has_tv = false,
5268 .owns_tv = false,5285 .owns_tv = false,
5269 .val = undefined,5286 .val = undefined,
...@@ -5311,14 +5328,12 @@ pub fn errorSetBits(mod: *Module) u16 {...@@ -5311,14 +5328,12 @@ pub fn errorSetBits(mod: *Module) u16 {
5311pub fn initNewAnonDecl(5328pub fn initNewAnonDecl(
5312 mod: *Module,5329 mod: *Module,
5313 new_decl_index: Decl.Index,5330 new_decl_index: Decl.Index,
5314 src_line: u32,
5315 val: Value,5331 val: Value,
5316 name: InternPool.NullTerminatedString,5332 name: InternPool.NullTerminatedString,
5317) Allocator.Error!void {5333) Allocator.Error!void {
5318 const new_decl = mod.declPtr(new_decl_index);5334 const new_decl = mod.declPtr(new_decl_index);
53195335
5320 new_decl.name = name;5336 new_decl.name = name;
5321 new_decl.src_line = src_line;
5322 new_decl.val = val;5337 new_decl.val = val;
5323 new_decl.alignment = .none;5338 new_decl.alignment = .none;
5324 new_decl.@"linksection" = .none;5339 new_decl.@"linksection" = .none;
...@@ -5612,7 +5627,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {...@@ -5612,7 +5627,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {
5612 .{@errorName(err)},5627 .{@errorName(err)},
5613 ));5628 ));
5614 decl.analysis = .codegen_failure;5629 decl.analysis = .codegen_failure;
5615 try zcu.retryable_failures.append(zcu.gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));5630 try zcu.retryable_failures.append(zcu.gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
5616 },5631 },
5617 };5632 };
5618 } else if (zcu.llvm_object) |llvm_object| {5633 } else if (zcu.llvm_object) |llvm_object| {
src/codegen/llvm.zig+9-9
...@@ -1697,7 +1697,7 @@ pub const Object = struct {...@@ -1697,7 +1697,7 @@ pub const Object = struct {
1697 const file, const subprogram = if (!wip.strip) debug_info: {1697 const file, const subprogram = if (!wip.strip) debug_info: {
1698 const file = try o.getDebugFile(namespace.file_scope);1698 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;
1701 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and1701 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and
1702 !zcu.decl_exports.contains(decl_index);1702 !zcu.decl_exports.contains(decl_index);
1703 const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu));1703 const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu));
...@@ -1741,7 +1741,7 @@ pub const Object = struct {...@@ -1741,7 +1741,7 @@ pub const Object = struct {
1741 .sync_scope = if (owner_mod.single_threaded) .singlethread else .system,1741 .sync_scope = if (owner_mod.single_threaded) .singlethread else .system,
1742 .file = file,1742 .file = file,
1743 .scope = subprogram,1743 .scope = subprogram,
1744 .base_line = dg.decl.src_line,1744 .base_line = dg.decl.navSrcLine(zcu),
1745 .prev_dbg_line = 0,1745 .prev_dbg_line = 0,
1746 .prev_dbg_column = 0,1746 .prev_dbg_column = 0,
1747 .err_ret_trace = err_ret_trace,1747 .err_ret_trace = err_ret_trace,
...@@ -2067,7 +2067,7 @@ pub const Object = struct {...@@ -2067,7 +2067,7 @@ pub const Object = struct {
2067 try o.builder.metadataString(name),2067 try o.builder.metadataString(name),
2068 file,2068 file,
2069 scope,2069 scope,
2070 owner_decl.src_line + 1, // Line2070 owner_decl.typeSrcLine(mod) + 1, // Line
2071 try o.lowerDebugType(int_ty),2071 try o.lowerDebugType(int_ty),
2072 ty.abiSize(mod) * 8,2072 ty.abiSize(mod) * 8,
2073 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,2073 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
...@@ -2237,7 +2237,7 @@ pub const Object = struct {...@@ -2237,7 +2237,7 @@ pub const Object = struct {
2237 try o.builder.metadataString(name),2237 try o.builder.metadataString(name),
2238 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),2238 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),
2239 try o.namespaceToDebugScope(owner_decl.src_namespace),2239 try o.namespaceToDebugScope(owner_decl.src_namespace),
2240 owner_decl.src_line + 1, // Line2240 owner_decl.typeSrcLine(mod) + 1, // Line
2241 .none, // Underlying type2241 .none, // Underlying type
2242 0, // Size2242 0, // Size
2243 0, // Align2243 0, // Align
...@@ -2867,7 +2867,7 @@ pub const Object = struct {...@@ -2867,7 +2867,7 @@ pub const Object = struct {
2867 try o.builder.metadataString(decl.name.toSlice(&mod.intern_pool)), // TODO use fully qualified name2867 try o.builder.metadataString(decl.name.toSlice(&mod.intern_pool)), // TODO use fully qualified name
2868 try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope),2868 try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope),
2869 try o.namespaceToDebugScope(decl.src_namespace),2869 try o.namespaceToDebugScope(decl.src_namespace),
2870 decl.src_line + 1,2870 decl.typeSrcLine(mod) + 1,
2871 .none,2871 .none,
2872 0,2872 0,
2873 0,2873 0,
...@@ -4762,7 +4762,7 @@ pub const DeclGen = struct {...@@ -4762,7 +4762,7 @@ pub const DeclGen = struct {
4762 else => try o.lowerValue(init_val),4762 else => try o.lowerValue(init_val),
4763 }, &o.builder);4763 }, &o.builder);
47644764
4765 const line_number = decl.src_line + 1;4765 const line_number = decl.navSrcLine(zcu) + 1;
4766 const is_internal_linkage = !o.module.decl_exports.contains(decl_index);4766 const is_internal_linkage = !o.module.decl_exports.contains(decl_index);
47674767
4768 const namespace = zcu.namespacePtr(decl.src_namespace);4768 const namespace = zcu.namespacePtr(decl.src_namespace);
...@@ -5188,7 +5188,7 @@ pub const FuncGen = struct {...@@ -5188,7 +5188,7 @@ pub const FuncGen = struct {
51885188
5189 self.file = try o.getDebugFile(namespace.file_scope);5189 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;
5192 self.inlined = self.wip.debug_location;5192 self.inlined = self.wip.debug_location;
51935193
5194 const fqn = try decl.fullyQualifiedName(zcu);5194 const fqn = try decl.fullyQualifiedName(zcu);
...@@ -5217,7 +5217,7 @@ pub const FuncGen = struct {...@@ -5217,7 +5217,7 @@ pub const FuncGen = struct {
5217 o.debug_compile_unit,5217 o.debug_compile_unit,
5218 );5218 );
52195219
5220 self.base_line = decl.src_line;5220 self.base_line = decl.navSrcLine(zcu);
5221 const inlined_at_location = try self.wip.debug_location.toMetadata(&o.builder);5221 const inlined_at_location = try self.wip.debug_location.toMetadata(&o.builder);
5222 self.wip.debug_location = .{5222 self.wip.debug_location = .{
5223 .location = .{5223 .location = .{
...@@ -8857,7 +8857,7 @@ pub const FuncGen = struct {...@@ -8857,7 +8857,7 @@ pub const FuncGen = struct {
8857 const src_index = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index;8857 const src_index = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index;
8858 const func_index = self.dg.decl.getOwnedFunctionIndex();8858 const func_index = self.dg.decl.getOwnedFunctionIndex();
8859 const func = mod.funcInfo(func_index);8859 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;
8861 const lbrace_col = func.lbrace_column + 1;8861 const lbrace_col = func.lbrace_column + 1;
88628862
8863 const debug_parameter = try o.builder.debugParameter(8863 const debug_parameter = try o.builder.debugParameter(
src/codegen/spirv.zig+2-2
...@@ -212,7 +212,7 @@ pub const Object = struct {...@@ -212,7 +212,7 @@ pub const Object = struct {
212 false => .{ .unstructured = .{} },212 false => .{ .unstructured = .{} },
213 },213 },
214 .current_block_label = undefined,214 .current_block_label = undefined,
215 .base_line = decl.src_line,215 .base_line = decl.navSrcLine(mod),
216 };216 };
217 defer decl_gen.deinit();217 defer decl_gen.deinit();
218218
...@@ -6345,7 +6345,7 @@ const DeclGen = struct {...@@ -6345,7 +6345,7 @@ const DeclGen = struct {
6345 const decl = mod.funcOwnerDeclPtr(extra.data.func);6345 const decl = mod.funcOwnerDeclPtr(extra.data.func);
6346 const old_base_line = self.base_line;6346 const old_base_line = self.base_line;
6347 defer self.base_line = old_base_line;6347 defer self.base_line = old_base_line;
6348 self.base_line = decl.src_line;6348 self.base_line = decl.navSrcLine(mod);
6349 return self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));6349 return self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
6350 }6350 }
63516351
src/link/Dwarf.zig+6-6
...@@ -948,8 +948,8 @@ pub const DeclState = struct {...@@ -948,8 +948,8 @@ pub const DeclState = struct {
948 leb128.writeUnsignedFixed(4, self.dbg_line.addManyAsArrayAssumeCapacity(4), new_file);948 leb128.writeUnsignedFixed(4, self.dbg_line.addManyAsArrayAssumeCapacity(4), new_file);
949 }949 }
950950
951 const old_src_line: i33 = self.mod.declPtr(old_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).src_line;952 const new_src_line: i33 = self.mod.declPtr(new_func_info.owner_decl).navSrcLine(self.mod);
953 if (new_src_line != old_src_line) {953 if (new_src_line != old_src_line) {
954 self.dbg_line.appendAssumeCapacity(DW.LNS.advance_line);954 self.dbg_line.appendAssumeCapacity(DW.LNS.advance_line);
955 leb128.writeSignedFixed(5, self.dbg_line.addManyAsArrayAssumeCapacity(5), new_src_line - old_src_line);955 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...@@ -1116,11 +1116,11 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde
1116 decl_state.dbg_line_func = decl.val.toIntern();1116 decl_state.dbg_line_func = decl.val.toIntern();
1117 const func = decl.val.getFunction(mod).?;1117 const func = decl.val.getFunction(mod).?;
1118 log.debug("decl.src_line={d}, func.lbrace_line={d}, func.rbrace_line={d}", .{1118 log.debug("decl.src_line={d}, func.lbrace_line={d}, func.rbrace_line={d}", .{
1119 decl.src_line,1119 decl.navSrcLine(mod),
1120 func.lbrace_line,1120 func.lbrace_line,
1121 func.rbrace_line,1121 func.rbrace_line,
1122 });1122 });
1123 const line: u28 = @intCast(decl.src_line + func.lbrace_line);1123 const line: u28 = @intCast(decl.navSrcLine(mod) + func.lbrace_line);
11241124
1125 dbg_line_buffer.appendSliceAssumeCapacity(&.{1125 dbg_line_buffer.appendSliceAssumeCapacity(&.{
1126 DW.LNS.extended_op,1126 DW.LNS.extended_op,
...@@ -1702,11 +1702,11 @@ pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: InternPool.D...@@ -1702,11 +1702,11 @@ pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: InternPool.D
1702 const decl = mod.declPtr(decl_index);1702 const decl = mod.declPtr(decl_index);
1703 const func = decl.val.getFunction(mod).?;1703 const func = decl.val.getFunction(mod).?;
1704 log.debug("decl.src_line={d}, func.lbrace_line={d}, func.rbrace_line={d}", .{1704 log.debug("decl.src_line={d}, func.lbrace_line={d}, func.rbrace_line={d}", .{
1705 decl.src_line,1705 decl.navSrcLine(mod),
1706 func.lbrace_line,1706 func.lbrace_line,
1707 func.rbrace_line,1707 func.rbrace_line,
1708 });1708 });
1709 const line: u28 = @intCast(decl.src_line + func.lbrace_line);1709 const line: u28 = @intCast(decl.navSrcLine(mod) + func.lbrace_line);
1710 var data: [4]u8 = undefined;1710 var data: [4]u8 = undefined;
1711 leb128.writeUnsignedFixed(4, &data, line);1711 leb128.writeUnsignedFixed(4, &data, line);
17121712
src/print_zir.zig+2-2
...@@ -583,7 +583,7 @@ const Writer = struct {...@@ -583,7 +583,7 @@ const Writer = struct {
583583
584 .reify => {584 .reify => {
585 const inst_data = self.code.extraData(Zir.Inst.Reify, extended.operand).data;585 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});
587 try self.writeInstRef(stream, inst_data.operand);587 try self.writeInstRef(stream, inst_data.operand);
588 try stream.writeAll(")) ");588 try stream.writeAll(")) ");
589 const prev_parent_decl_node = self.parent_decl_node;589 const prev_parent_decl_node = self.parent_decl_node;
...@@ -2749,7 +2749,7 @@ const Writer = struct {...@@ -2749,7 +2749,7 @@ const Writer = struct {
2749 extra.data.src_hash_3,2749 extra.data.src_hash_3,
2750 };2750 };
2751 const src_hash_bytes: [16]u8 = @bitCast(src_hash_arr);2751 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
2754 {2754 {
2755 const bodies = extra.data.getBodies(@intCast(extra.end), self.code);2755 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");...@@ -11,6 +11,7 @@ const target_util = @import("target.zig");
11const Sema = @import("Sema.zig");11const Sema = @import("Sema.zig");
12const InternPool = @import("InternPool.zig");12const InternPool = @import("InternPool.zig");
13const Alignment = InternPool.Alignment;13const Alignment = InternPool.Alignment;
14const Zir = std.zig.Zir;
1415
15/// Both types and values are canonically represented by a single 32-bit integer16/// Both types and values are canonically represented by a single 32-bit integer
16/// which is an index into an `InternPool` data structure.17/// which is an index into an `InternPool` data structure.
...@@ -3340,7 +3341,7 @@ pub const Type = struct {...@@ -3340,7 +3341,7 @@ pub const Type = struct {
3340 .struct_type, .union_type, .opaque_type, .enum_type => |info| switch (info) {3341 .struct_type, .union_type, .opaque_type, .enum_type => |info| switch (info) {
3341 .declared => |d| d.zir_index,3342 .declared => |d| d.zir_index,
3342 .reified => |r| r.zir_index,3343 .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 reifying3344 .generated_tag => |gt| ip.loadUnionType(gt.union_type).zir_index,
3344 .empty_struct => return null,3345 .empty_struct => return null,
3345 },3346 },
3346 else => return null,3347 else => return null,
...@@ -3440,6 +3441,33 @@ pub const Type = struct {...@@ -3440,6 +3441,33 @@ pub const Type = struct {
3440 };3441 };
3441 }3442 }
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
3443 /// Given a namespace type, returns its list of caotured values.3471 /// Given a namespace type, returns its list of caotured values.
3444 pub fn getCaptures(ty: Type, zcu: *const Zcu) InternPool.CaptureValue.Slice {3472 pub fn getCaptures(ty: Type, zcu: *const Zcu) InternPool.CaptureValue.Slice {
3445 const ip = &zcu.intern_pool;3473 const ip = &zcu.intern_pool;