authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-15 00:52:26+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-15 00:58:35+01:00
logb8d2323b88e68bb5af061dd7e488f51aa0ae8176
treeadd6ff3944cddc07279fcf44191eb41a33abf174
parent1eaeb4a0a838a783d2060f4e5b3b26b483b26009
signaturelock-open Commit is signed but in an unrecognized format.

Sema: eliminate Block.src_decl

🦀 src_decl is gone 🦀 This commit eliminates the `src_decl` field from `Sema.Block`. This change goes further to eliminating unnecessary responsibilities of `Decl` in preparation for its major upcoming refactor. The two main remaining reponsibilities had to do with namespace types: `src_decl` was used to determine their line number and their name. The former use case is solved by storing the line number alongside type declarations (and reifications) in ZIR; this is actually more correct, since previously the line number assigned to the type was really the line number of the source declaration it was syntactically contained within, which does not necessarily line up. Consequently, this change makes debug info for namespace types more correct, although I am not sure how debuggers actually utilize this line number, if at all. Naming types was solved by a new field on `Block`, called `type_name_ctx`. In a sense, it represents the "namespace" we are currently within, including comptime function calls etc. We might want to revisit this in future, since the type naming rules seem to be a bit hand-wavey right now. As far as I can tell, there isn't any more preliminary work needed for me to start work on the behemoth task of splitting `Zcu.Decl` into the new `Nav` (Named Addressable Value) and `Cau` (Comptime Analysis Unit) types. This will be a sweeping change, impacting essentially every part of the pipeline after `AstGen`.

7 files changed, 154 insertions(+), 102 deletions(-)

lib/std/zig/AstGen.zig+7-1
......@@ -13132,6 +13132,7 @@ const GenZir = struct {
1313213132 .fields_hash_1 = fields_hash_arr[1],
1313313133 .fields_hash_2 = fields_hash_arr[2],
1313413134 .fields_hash_3 = fields_hash_arr[3],
13135 .src_line = astgen.source_line,
1313513136 .src_node = args.src_node,
1313613137 });
1313713138
......@@ -13192,6 +13193,7 @@ const GenZir = struct {
1319213193 .fields_hash_1 = fields_hash_arr[1],
1319313194 .fields_hash_2 = fields_hash_arr[2],
1319413195 .fields_hash_3 = fields_hash_arr[3],
13196 .src_line = astgen.source_line,
1319513197 .src_node = args.src_node,
1319613198 });
1319713199
......@@ -13253,6 +13255,7 @@ const GenZir = struct {
1325313255 .fields_hash_1 = fields_hash_arr[1],
1325413256 .fields_hash_2 = fields_hash_arr[2],
1325513257 .fields_hash_3 = fields_hash_arr[3],
13258 .src_line = astgen.source_line,
1325613259 .src_node = args.src_node,
1325713260 });
1325813261
......@@ -13300,7 +13303,10 @@ const GenZir = struct {
1330013303 assert(args.src_node != 0);
1330113304
1330213305 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.OpaqueDecl).Struct.fields.len + 2);
13303 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.OpaqueDecl{ .src_node = args.src_node });
13306 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.OpaqueDecl{
13307 .src_line = astgen.source_line,
13308 .src_node = args.src_node,
13309 });
1330413310
1330513311 if (args.captures_len != 0) {
1330613312 astgen.extra.appendAssumeCapacity(args.captures_len);
lib/std/zig/Zir.zig+11-1
......@@ -1981,7 +1981,7 @@ pub const Inst = struct {
19811981 /// `operand` is payload index to `UnNode`.
19821982 error_from_int,
19831983 /// Implement builtin `@Type`.
1984 /// `operand` is payload index to `UnNode`.
1984 /// `operand` is payload index to `Reify`.
19851985 /// `small` contains `NameStrategy`.
19861986 reify,
19871987 /// Implements the `@asyncCall` builtin.
......@@ -2834,6 +2834,12 @@ pub const Inst = struct {
28342834 index: u32,
28352835 };
28362836
2837 pub const Reify = struct {
2838 node: i32,
2839 operand: Ref,
2840 src_line: u32,
2841 };
2842
28372843 pub const SwitchBlockErrUnion = struct {
28382844 operand: Ref,
28392845 bits: Bits,
......@@ -2992,6 +2998,7 @@ pub const Inst = struct {
29922998 fields_hash_1: u32,
29932999 fields_hash_2: u32,
29943000 fields_hash_3: u32,
3001 src_line: u32,
29953002 /// This node provides a new absolute baseline node for all instructions within this struct.
29963003 src_node: Ast.Node.Index,
29973004
......@@ -3121,6 +3128,7 @@ pub const Inst = struct {
31213128 fields_hash_1: u32,
31223129 fields_hash_2: u32,
31233130 fields_hash_3: u32,
3131 src_line: u32,
31243132 /// This node provides a new absolute baseline node for all instructions within this struct.
31253133 src_node: Ast.Node.Index,
31263134
......@@ -3166,6 +3174,7 @@ pub const Inst = struct {
31663174 fields_hash_1: u32,
31673175 fields_hash_2: u32,
31683176 fields_hash_3: u32,
3177 src_line: u32,
31693178 /// This node provides a new absolute baseline node for all instructions within this struct.
31703179 src_node: Ast.Node.Index,
31713180
......@@ -3195,6 +3204,7 @@ pub const Inst = struct {
31953204 /// 2. capture: Capture, // for every captures_len
31963205 /// 3. decl: Index, // for every decls_len; points to a `declaration` instruction
31973206 pub const OpaqueDecl = struct {
3207 src_line: u32,
31983208 /// This node provides a new absolute baseline node for all instructions within this struct.
31993209 src_node: Ast.Node.Index,
32003210
src/Module.zig+50-30
......@@ -88,6 +88,9 @@ export_owners: std.AutoArrayHashMapUnmanaged(Decl.Index, ArrayListUnmanaged(*Exp
8888/// an update is requested, as well as to cache `@import` results.
8989/// Keys are fully resolved file paths. This table owns the keys and values.
9090import_table: std.StringArrayHashMapUnmanaged(*File) = .{},
91/// This acts as a map from `path_digest` to the corresponding `File`.
92/// The value is omitted, as keys are ordered identically to `import_table`.
93path_digest_map: std.AutoArrayHashMapUnmanaged(Cache.BinDigest, void) = .{},
9194/// The set of all the files which have been loaded with `@embedFile` in the Module.
9295/// We keep track of this in order to iterate over it and check which files have been
9396/// modified on the file system when an update is requested, as well as to cache
......@@ -735,8 +738,7 @@ pub const File = struct {
735738 /// List of references to this file, used for multi-package errors.
736739 references: std.ArrayListUnmanaged(Reference) = .{},
737740 /// The hash of the path to this file, used to store `InternPool.TrackedInst`.
738 /// undefined until `zir_loaded == true`.
739 path_digest: Cache.BinDigest = undefined,
741 path_digest: Cache.BinDigest,
740742
741743 /// The most recent successful ZIR for this file, with no errors.
742744 /// This is only populated when a previously successful ZIR
......@@ -2357,10 +2359,10 @@ pub const LazySrcLoc = struct {
23572359 const info = base_node_inst.resolveFull(&zcu.intern_pool);
23582360 break :inst .{ info.path_digest, info.inst };
23592361 };
2360 // TODO: avoid iterating all files for this!
2361 const file = for (zcu.import_table.values()) |file| {
2362 if (std.mem.eql(u8, &file.path_digest, &want_path_digest)) break file;
2363 } else unreachable;
2362 const file = file: {
2363 const index = zcu.path_digest_map.getIndex(want_path_digest).?;
2364 break :file zcu.import_table.values()[index];
2365 };
23642366 assert(file.zir_loaded);
23652367
23662368 const zir = file.zir;
......@@ -2432,6 +2434,7 @@ pub fn deinit(zcu: *Zcu) void {
24322434 value.destroy(zcu);
24332435 }
24342436 zcu.import_table.deinit(gpa);
2437 zcu.path_digest_map.deinit(gpa);
24352438
24362439 for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| {
24372440 gpa.free(path);
......@@ -2596,26 +2599,12 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
25962599 const stat = try source_file.stat();
25972600
25982601 const want_local_cache = file.mod == mod.main_mod;
2599 const bin_digest = hash: {
2600 var path_hash: Cache.HashHelper = .{};
2601 path_hash.addBytes(build_options.version);
2602 path_hash.add(builtin.zig_backend);
2603 if (!want_local_cache) {
2604 path_hash.addOptionalBytes(file.mod.root.root_dir.path);
2605 path_hash.addBytes(file.mod.root.sub_path);
2606 }
2607 path_hash.addBytes(file.sub_file_path);
2608 var bin: Cache.BinDigest = undefined;
2609 path_hash.hasher.final(&bin);
2610 break :hash bin;
2611 };
2612 file.path_digest = bin_digest;
26132602 const hex_digest = hex: {
26142603 var hex: Cache.HexDigest = undefined;
26152604 _ = std.fmt.bufPrint(
26162605 &hex,
26172606 "{s}",
2618 .{std.fmt.fmtSliceHexLower(&bin_digest)},
2607 .{std.fmt.fmtSliceHexLower(&file.path_digest)},
26192608 ) catch unreachable;
26202609 break :hex hex;
26212610 };
......@@ -4122,12 +4111,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
41224111 var block_scope: Sema.Block = .{
41234112 .parent = null,
41244113 .sema = &sema,
4125 .src_decl = decl_index,
41264114 .namespace = decl.src_namespace,
41274115 .instructions = .{},
41284116 .inlining = null,
41294117 .is_comptime = true,
41304118 .src_base_inst = decl.zir_decl_index.unwrap().?,
4119 .type_name_ctx = decl.name,
41314120 };
41324121 defer block_scope.instructions.deinit(gpa);
41334122
......@@ -4355,6 +4344,7 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
43554344 keep_resolved_path = true; // It's now owned by import_table.
43564345 gop.value_ptr.* = builtin_file;
43574346 try builtin_file.addReference(zcu.*, .{ .root = mod });
4347 try zcu.path_digest_map.put(gpa, builtin_file.path_digest, {});
43584348 return .{
43594349 .file = builtin_file,
43604350 .is_new = false,
......@@ -4382,8 +4372,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
43824372 .status = .never_loaded,
43834373 .mod = mod,
43844374 .root_decl = .none,
4375 .path_digest = digest: {
4376 const want_local_cache = mod == zcu.main_mod;
4377 var path_hash: Cache.HashHelper = .{};
4378 path_hash.addBytes(build_options.version);
4379 path_hash.add(builtin.zig_backend);
4380 if (!want_local_cache) {
4381 path_hash.addOptionalBytes(mod.root.root_dir.path);
4382 path_hash.addBytes(mod.root.sub_path);
4383 }
4384 path_hash.addBytes(sub_file_path);
4385 var bin: Cache.BinDigest = undefined;
4386 path_hash.hasher.final(&bin);
4387 break :digest bin;
4388 },
43854389 };
43864390 try new_file.addReference(zcu.*, .{ .root = mod });
4391 try zcu.path_digest_map.put(gpa, new_file.path_digest, {});
43874392 return ImportFileResult{
43884393 .file = new_file,
43894394 .is_new = true,
......@@ -4392,23 +4397,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
43924397}
43934398
43944399pub fn importFile(
4395 mod: *Module,
4400 zcu: *Zcu,
43964401 cur_file: *File,
43974402 import_string: []const u8,
43984403) !ImportFileResult {
43994404 if (std.mem.eql(u8, import_string, "std")) {
4400 return mod.importPkg(mod.std_mod);
4405 return zcu.importPkg(zcu.std_mod);
44014406 }
44024407 if (std.mem.eql(u8, import_string, "root")) {
4403 return mod.importPkg(mod.root_mod);
4408 return zcu.importPkg(zcu.root_mod);
44044409 }
44054410 if (cur_file.mod.deps.get(import_string)) |pkg| {
4406 return mod.importPkg(pkg);
4411 return zcu.importPkg(pkg);
44074412 }
44084413 if (!mem.endsWith(u8, import_string, ".zig")) {
44094414 return error.ModuleNotFound;
44104415 }
4411 const gpa = mod.gpa;
4416 const gpa = zcu.gpa;
44124417
44134418 // The resolved path is used as the key in the import table, to detect if
44144419 // an import refers to the same as another, despite different relative paths
......@@ -4424,8 +4429,8 @@ pub fn importFile(
44244429 var keep_resolved_path = false;
44254430 defer if (!keep_resolved_path) gpa.free(resolved_path);
44264431
4427 const gop = try mod.import_table.getOrPut(gpa, resolved_path);
4428 errdefer _ = mod.import_table.pop();
4432 const gop = try zcu.import_table.getOrPut(gpa, resolved_path);
4433 errdefer _ = zcu.import_table.pop();
44294434 if (gop.found_existing) return ImportFileResult{
44304435 .file = gop.value_ptr.*,
44314436 .is_new = false,
......@@ -4470,7 +4475,22 @@ pub fn importFile(
44704475 .status = .never_loaded,
44714476 .mod = cur_file.mod,
44724477 .root_decl = .none,
4478 .path_digest = digest: {
4479 const want_local_cache = cur_file.mod == zcu.main_mod;
4480 var path_hash: Cache.HashHelper = .{};
4481 path_hash.addBytes(build_options.version);
4482 path_hash.add(builtin.zig_backend);
4483 if (!want_local_cache) {
4484 path_hash.addOptionalBytes(cur_file.mod.root.root_dir.path);
4485 path_hash.addBytes(cur_file.mod.root.sub_path);
4486 }
4487 path_hash.addBytes(sub_file_path);
4488 var bin: Cache.BinDigest = undefined;
4489 path_hash.hasher.final(&bin);
4490 break :digest bin;
4491 },
44734492 };
4493 try zcu.path_digest_map.put(gpa, new_file.path_digest, {});
44744494 return ImportFileResult{
44754495 .file = new_file,
44764496 .is_new = true,
......@@ -5039,7 +5059,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
50395059 var inner_block: Sema.Block = .{
50405060 .parent = null,
50415061 .sema = &sema,
5042 .src_decl = decl_index,
50435062 .namespace = decl.src_namespace,
50445063 .instructions = .{},
50455064 .inlining = null,
......@@ -5052,6 +5071,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
50525071 const orig_decl = mod.declPtr(owner_info.owner_decl);
50535072 break :inst orig_decl.zir_decl_index.unwrap().?;
50545073 },
5074 .type_name_ctx = decl.name,
50555075 };
50565076 defer inner_block.instructions.deinit(gpa);
50575077
src/Sema.zig+73-60
......@@ -16,9 +16,7 @@ air_instructions: std.MultiArrayList(Air.Inst) = .{},
1616air_extra: std.ArrayListUnmanaged(u32) = .{},
1717/// Maps ZIR to AIR.
1818inst_map: InstMap = .{},
19/// When analyzing an inline function call, owner_decl is the Decl of the caller
20/// and `src_decl` of `Block` is the `Decl` of the callee.
21/// This `Decl` owns the arena memory of this `Sema`.
19/// When analyzing an inline function call, owner_decl is the Decl of the caller.
2220owner_decl: *Decl,
2321owner_decl_index: InternPool.DeclIndex,
2422/// For an inline or comptime function call, this will be the root parent function
......@@ -342,7 +340,6 @@ pub const Block = struct {
342340 /// Shared among all child blocks.
343341 sema: *Sema,
344342 /// The namespace to use for lookups from this source block
345 /// When analyzing fields, this is different from src_decl.src_namespace.
346343 namespace: InternPool.NamespaceIndex,
347344 /// The AIR instructions generated for this block.
348345 instructions: std.ArrayListUnmanaged(Air.Inst.Index),
......@@ -360,10 +357,6 @@ pub const Block = struct {
360357 /// If runtime_index is not 0 then one of these is guaranteed to be non null.
361358 runtime_cond: ?LazySrcLoc = null,
362359 runtime_loop: ?LazySrcLoc = null,
363 /// This Decl is the Decl according to the Zig source code corresponding to this Block.
364 /// This can vary during inline or comptime function calls. See `Sema.owner_decl`
365 /// for the one that will be the same for all Block instances.
366 src_decl: InternPool.DeclIndex,
367360 /// Non zero if a non-inline loop or a runtime conditional have been encountered.
368361 /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.
369362 runtime_index: Value.RuntimeIndex = .zero,
......@@ -396,6 +389,12 @@ pub const Block = struct {
396389 /// treated as relative to the AST node of this ZIR instruction.
397390 src_base_inst: InternPool.TrackedInst.Index,
398391
392 /// The name of the current "context" for naming namespace types.
393 /// The interpretation of this depends on the name strategy in ZIR, but the name
394 /// is always incorporated into the type name somehow.
395 /// See `Sema.createAnonymousDeclTypeNamed`.
396 type_name_ctx: InternPool.NullTerminatedString,
397
399398 /// Create a `LazySrcLoc` based on an `Offset` from the code being analyzed in this block.
400399 /// Specifically, the given `Offset` is treated as relative to `block.src_base_inst`.
401400 pub fn src(block: Block, offset: LazySrcLoc.Offset) LazySrcLoc {
......@@ -516,7 +515,6 @@ pub const Block = struct {
516515 return .{
517516 .parent = parent,
518517 .sema = parent.sema,
519 .src_decl = parent.src_decl,
520518 .namespace = parent.namespace,
521519 .instructions = .{},
522520 .label = null,
......@@ -533,6 +531,7 @@ pub const Block = struct {
533531 .error_return_trace_index = parent.error_return_trace_index,
534532 .need_debug_scope = parent.need_debug_scope,
535533 .src_base_inst = parent.src_base_inst,
534 .type_name_ctx = parent.type_name_ctx,
536535 };
537536 }
538537
......@@ -993,9 +992,11 @@ fn analyzeBodyInner(
993992 while (true) {
994993 crash_info.setBodyIndex(i);
995994 const inst = body[i];
996 std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{
997 mod.namespacePtr(mod.declPtr(block.src_decl).src_namespace).file_scope.sub_file_path, inst,
998 });
995 std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ sub_file_path: {
996 const path_digest = block.src_base_inst.resolveFull(&mod.intern_pool).path_digest;
997 const index = mod.path_digest_map.getIndex(path_digest).?;
998 break :sub_file_path mod.import_table.values()[index].sub_file_path;
999 }, inst });
9991000 const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) {
10001001 // zig fmt: off
10011002 .alloc => try sema.zirAlloc(block, inst),
......@@ -2821,6 +2822,7 @@ fn zirStructDecl(
28212822 small.name_strategy,
28222823 "struct",
28232824 inst,
2825 extra.data.src_line,
28242826 );
28252827 mod.declPtr(new_decl_index).owns_tv = true;
28262828 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -2857,20 +2859,19 @@ fn createAnonymousDeclTypeNamed(
28572859 name_strategy: Zir.Inst.NameStrategy,
28582860 anon_prefix: []const u8,
28592861 inst: ?Zir.Inst.Index,
2862 src_line: u32,
28602863) !InternPool.DeclIndex {
28612864 const zcu = sema.mod;
28622865 const ip = &zcu.intern_pool;
28632866 const gpa = sema.gpa;
28642867 const namespace = block.namespace;
2865 const src_decl = zcu.declPtr(block.src_decl);
28662868 const new_decl_index = try zcu.allocateNewDecl(namespace);
28672869 errdefer zcu.destroyDecl(new_decl_index);
28682870
28692871 switch (name_strategy) {
28702872 .anon => {}, // handled after switch
28712873 .parent => {
2872 const name = zcu.declPtr(block.src_decl).name;
2873 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2874 try zcu.initNewAnonDecl(new_decl_index, src_line, val, block.type_name_ctx);
28742875 return new_decl_index;
28752876 },
28762877 .func => func_strat: {
......@@ -2881,7 +2882,7 @@ fn createAnonymousDeclTypeNamed(
28812882 defer buf.deinit();
28822883
28832884 const writer = buf.writer();
2884 try writer.print("{}(", .{zcu.declPtr(block.src_decl).name.fmt(ip)});
2885 try writer.print("{}(", .{block.type_name_ctx.fmt(ip)});
28852886
28862887 var arg_i: usize = 0;
28872888 for (fn_info.param_body) |zir_inst| switch (zir_tags[@intFromEnum(zir_inst)]) {
......@@ -2915,7 +2916,7 @@ fn createAnonymousDeclTypeNamed(
29152916
29162917 try writer.writeByte(')');
29172918 const name = try ip.getOrPutString(gpa, buf.items, .no_embedded_nulls);
2918 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2919 try zcu.initNewAnonDecl(new_decl_index, src_line, val, name);
29192920 return new_decl_index;
29202921 },
29212922 .dbg_var => {
......@@ -2927,9 +2928,9 @@ fn createAnonymousDeclTypeNamed(
29272928 if (zir_data[i].str_op.operand != ref) continue;
29282929
29292930 const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{
2930 src_decl.name.fmt(ip), zir_data[i].str_op.getStr(sema.code),
2931 block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code),
29312932 }, .no_embedded_nulls);
2932 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2933 try zcu.initNewAnonDecl(new_decl_index, src_line, val, name);
29332934 return new_decl_index;
29342935 },
29352936 else => {},
......@@ -2948,9 +2949,9 @@ fn createAnonymousDeclTypeNamed(
29482949 // renamed.
29492950
29502951 const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
2951 src_decl.name.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),
2952 block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),
29522953 }, .no_embedded_nulls) catch unreachable;
2953 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2954 try zcu.initNewAnonDecl(new_decl_index, src_line, val, name);
29542955 return new_decl_index;
29552956}
29562957
......@@ -3056,6 +3057,7 @@ fn zirEnumDecl(
30563057 small.name_strategy,
30573058 "enum",
30583059 inst,
3060 extra.data.src_line,
30593061 );
30603062 const new_decl = mod.declPtr(new_decl_index);
30613063 new_decl.owns_tv = true;
......@@ -3112,12 +3114,12 @@ fn zirEnumDecl(
31123114 var enum_block: Block = .{
31133115 .parent = null,
31143116 .sema = sema,
3115 .src_decl = new_decl_index,
31163117 .namespace = new_namespace_index.unwrap() orelse block.namespace,
31173118 .instructions = .{},
31183119 .inlining = null,
31193120 .is_comptime = true,
31203121 .src_base_inst = tracked_inst,
3122 .type_name_ctx = new_decl.name,
31213123 };
31223124 defer enum_block.instructions.deinit(sema.gpa);
31233125
......@@ -3323,6 +3325,7 @@ fn zirUnionDecl(
33233325 small.name_strategy,
33243326 "union",
33253327 inst,
3328 extra.data.src_line,
33263329 );
33273330 mod.declPtr(new_decl_index).owns_tv = true;
33283331 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -3411,6 +3414,7 @@ fn zirOpaqueDecl(
34113414 small.name_strategy,
34123415 "opaque",
34133416 inst,
3417 extra.data.src_line,
34143418 );
34153419 mod.declPtr(new_decl_index).owns_tv = true;
34163420 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -5942,7 +5946,6 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
59425946 var child_block: Block = .{
59435947 .parent = parent_block,
59445948 .sema = sema,
5945 .src_decl = parent_block.src_decl,
59465949 .namespace = parent_block.namespace,
59475950 .instructions = .{},
59485951 .inlining = parent_block.inlining,
......@@ -5953,6 +5956,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
59535956 .runtime_loop = parent_block.runtime_loop,
59545957 .runtime_index = parent_block.runtime_index,
59555958 .src_base_inst = parent_block.src_base_inst,
5959 .type_name_ctx = parent_block.type_name_ctx,
59565960 };
59575961 defer child_block.instructions.deinit(gpa);
59585962
......@@ -6063,7 +6067,6 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
60636067 var child_block: Block = .{
60646068 .parent = parent_block,
60656069 .sema = sema,
6066 .src_decl = parent_block.src_decl,
60676070 .namespace = parent_block.namespace,
60686071 .instructions = .{},
60696072 .label = &label,
......@@ -6079,6 +6082,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
60796082 .runtime_index = parent_block.runtime_index,
60806083 .error_return_trace_index = parent_block.error_return_trace_index,
60816084 .src_base_inst = parent_block.src_base_inst,
6085 .type_name_ctx = parent_block.type_name_ctx,
60826086 };
60836087
60846088 defer child_block.instructions.deinit(gpa);
......@@ -6726,7 +6730,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
67266730 .no_embedded_nulls,
67276731 );
67286732 const decl_index = try sema.lookupIdentifier(block, src, decl_name);
6729 try sema.addReferencedBy(block, src, decl_index);
6733 try sema.addReferencedBy(src, decl_index);
67306734 return sema.analyzeDeclRef(decl_index);
67316735}
67326736
......@@ -7695,7 +7699,6 @@ fn analyzeCall(
76957699 var child_block: Block = .{
76967700 .parent = null,
76977701 .sema = sema,
7698 .src_decl = module_fn.owner_decl,
76997702 .namespace = fn_owner_decl.src_namespace,
77007703 .instructions = .{},
77017704 .label = null,
......@@ -7708,6 +7711,7 @@ fn analyzeCall(
77087711 .runtime_loop = block.runtime_loop,
77097712 .runtime_index = block.runtime_index,
77107713 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
7714 .type_name_ctx = fn_owner_decl.name,
77117715 };
77127716
77137717 const merges = &child_block.inlining.?.merges;
......@@ -8217,12 +8221,12 @@ fn instantiateGenericCall(
82178221 var child_block: Block = .{
82188222 .parent = null,
82198223 .sema = &child_sema,
8220 .src_decl = generic_owner_func.owner_decl,
82218224 .namespace = namespace_index,
82228225 .instructions = .{},
82238226 .inlining = null,
82248227 .is_comptime = true,
82258228 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
8229 .type_name_ctx = fn_owner_decl.name,
82268230 };
82278231 defer child_block.instructions.deinit(gpa);
82288232
......@@ -8366,7 +8370,7 @@ fn instantiateGenericCall(
83668370 const callee = mod.funcInfo(callee_index);
83678371 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);
83688372
8369 try sema.addReferencedBy(block, call_src, callee.owner_decl);
8373 try sema.addReferencedBy(call_src, callee.owner_decl);
83708374
83718375 // Make a runtime call to the new function, making sure to omit the comptime args.
83728376 const func_ty = Type.fromInterned(callee.ty);
......@@ -9346,7 +9350,7 @@ fn zirFunc(
93469350 // If this instruction has a body it means it's the type of the `owner_decl`
93479351 // otherwise it's a function type without a `callconv` attribute and should
93489352 // never be `.C`.
9349 const cc: std.builtin.CallingConvention = if (has_body and mod.declPtr(block.src_decl).is_exported)
9353 const cc: std.builtin.CallingConvention = if (has_body and mod.declPtr(sema.owner_decl_index).is_exported)
93509354 .C
93519355 else
93529356 .Unspecified;
......@@ -11595,7 +11599,6 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1159511599 var child_block: Block = .{
1159611600 .parent = block,
1159711601 .sema = sema,
11598 .src_decl = block.src_decl,
1159911602 .namespace = block.namespace,
1160011603 .instructions = .{},
1160111604 .label = &label,
......@@ -11610,6 +11613,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1161011613 .error_return_trace_index = block.error_return_trace_index,
1161111614 .want_safety = block.want_safety,
1161211615 .src_base_inst = block.src_base_inst,
11616 .type_name_ctx = block.type_name_ctx,
1161311617 };
1161411618 const merges = &child_block.label.?.merges;
1161511619 defer child_block.instructions.deinit(gpa);
......@@ -12327,7 +12331,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1232712331 var child_block: Block = .{
1232812332 .parent = block,
1232912333 .sema = sema,
12330 .src_decl = block.src_decl,
1233112334 .namespace = block.namespace,
1233212335 .instructions = .{},
1233312336 .label = &label,
......@@ -12342,6 +12345,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1234212345 .want_safety = block.want_safety,
1234312346 .error_return_trace_index = block.error_return_trace_index,
1234412347 .src_base_inst = block.src_base_inst,
12348 .type_name_ctx = block.type_name_ctx,
1234512349 };
1234612350 const merges = &child_block.label.?.merges;
1234712351 defer child_block.instructions.deinit(gpa);
......@@ -18843,7 +18847,6 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1884318847 var child_block: Block = .{
1884418848 .parent = block,
1884518849 .sema = sema,
18846 .src_decl = block.src_decl,
1884718850 .namespace = block.namespace,
1884818851 .instructions = .{},
1884918852 .inlining = block.inlining,
......@@ -18852,6 +18855,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1885218855 .want_safety = false,
1885318856 .error_return_trace_index = block.error_return_trace_index,
1885418857 .src_base_inst = block.src_base_inst,
18858 .type_name_ctx = block.type_name_ctx,
1885518859 };
1885618860 defer child_block.instructions.deinit(sema.gpa);
1885718861
......@@ -18922,7 +18926,6 @@ fn zirTypeofPeer(
1892218926 var child_block: Block = .{
1892318927 .parent = block,
1892418928 .sema = sema,
18925 .src_decl = block.src_decl,
1892618929 .namespace = block.namespace,
1892718930 .instructions = .{},
1892818931 .inlining = block.inlining,
......@@ -18932,6 +18935,7 @@ fn zirTypeofPeer(
1893218935 .runtime_loop = block.runtime_loop,
1893318936 .runtime_index = block.runtime_index,
1893418937 .src_base_inst = block.src_base_inst,
18938 .type_name_ctx = block.type_name_ctx,
1893518939 };
1893618940 defer child_block.instructions.deinit(sema.gpa);
1893718941 // Ignore the result, we only care about the instructions in `args`.
......@@ -19398,13 +19402,13 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label
1939819402 .block = .{
1939919403 .parent = block,
1940019404 .sema = sema,
19401 .src_decl = block.src_decl,
1940219405 .namespace = block.namespace,
1940319406 .instructions = .{},
1940419407 .label = &labeled_block.label,
1940519408 .inlining = block.inlining,
1940619409 .is_comptime = block.is_comptime,
1940719410 .src_base_inst = block.src_base_inst,
19411 .type_name_ctx = block.type_name_ctx,
1940819412 },
1940919413 };
1941019414 sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block);
......@@ -21201,7 +21205,7 @@ fn zirReify(
2120121205 const gpa = sema.gpa;
2120221206 const ip = &mod.intern_pool;
2120321207 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);
21204 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
21208 const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data;
2120521209 const src = block.nodeOffset(extra.node);
2120621210 const type_info_ty = try sema.getBuiltinType("Type");
2120721211 const uncasted_operand = try sema.resolveInst(extra.operand);
......@@ -21521,7 +21525,7 @@ fn zirReify(
2152121525 .needed_comptime_reason = "struct fields must be comptime-known",
2152221526 });
2152321527
21524 return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_arr, name_strategy, is_tuple_val.toBool());
21528 return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_arr, name_strategy, is_tuple_val.toBool(), extra.src_line);
2152521529 },
2152621530 .Enum => {
2152721531 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
......@@ -21550,7 +21554,7 @@ fn zirReify(
2155021554 .needed_comptime_reason = "enum fields must be comptime-known",
2155121555 });
2155221556
21553 return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy);
21557 return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy, extra.src_line);
2155421558 },
2155521559 .Opaque => {
2155621560 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
......@@ -21581,6 +21585,7 @@ fn zirReify(
2158121585 name_strategy,
2158221586 "opaque",
2158321587 inst,
21588 extra.src_line,
2158421589 );
2158521590 mod.declPtr(new_decl_index).owns_tv = true;
2158621591 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -21617,7 +21622,7 @@ fn zirReify(
2161721622 .needed_comptime_reason = "union fields must be comptime-known",
2161821623 });
2161921624
21620 return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy);
21625 return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy, extra.src_line);
2162121626 },
2162221627 .Fn => {
2162321628 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
......@@ -21719,6 +21724,7 @@ fn reifyEnum(
2171921724 is_exhaustive: bool,
2172021725 fields_val: Value,
2172121726 name_strategy: Zir.Inst.NameStrategy,
21727 src_line: u32,
2172221728) CompileError!Air.Inst.Ref {
2172321729 const mod = sema.mod;
2172421730 const gpa = sema.gpa;
......@@ -21780,6 +21786,7 @@ fn reifyEnum(
2178021786 name_strategy,
2178121787 "enum",
2178221788 inst,
21789 src_line,
2178321790 );
2178421791 mod.declPtr(new_decl_index).owns_tv = true;
2178521792 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -21843,6 +21850,7 @@ fn reifyUnion(
2184321850 opt_tag_type_val: Value,
2184421851 fields_val: Value,
2184521852 name_strategy: Zir.Inst.NameStrategy,
21853 src_line: u32,
2184621854) CompileError!Air.Inst.Ref {
2184721855 const mod = sema.mod;
2184821856 const gpa = sema.gpa;
......@@ -21926,6 +21934,7 @@ fn reifyUnion(
2192621934 name_strategy,
2192721935 "union",
2192821936 inst,
21937 src_line,
2192921938 );
2193021939 mod.declPtr(new_decl_index).owns_tv = true;
2193121940 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -22021,7 +22030,7 @@ fn reifyUnion(
2202122030 }
2202222031 }
2202322032
22024 const enum_tag_ty = try sema.generateUnionTagTypeSimple(block, field_names.keys(), mod.declPtr(new_decl_index));
22033 const enum_tag_ty = try sema.generateUnionTagTypeSimple(block, field_names.keys(), mod.declPtr(new_decl_index), src_line);
2202522034 break :tag_ty .{ enum_tag_ty, false };
2202622035 };
2202722036 errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error
......@@ -22082,6 +22091,7 @@ fn reifyStruct(
2208222091 fields_val: Value,
2208322092 name_strategy: Zir.Inst.NameStrategy,
2208422093 is_tuple: bool,
22094 src_line: u32,
2208522095) CompileError!Air.Inst.Ref {
2208622096 const mod = sema.mod;
2208722097 const gpa = sema.gpa;
......@@ -22182,6 +22192,7 @@ fn reifyStruct(
2218222192 name_strategy,
2218322193 "struct",
2218422194 inst,
22195 src_line,
2218522196 );
2218622197 mod.declPtr(new_decl_index).owns_tv = true;
2218722198 errdefer mod.abortAnonDecl(new_decl_index);
......@@ -26903,12 +26914,12 @@ fn addSafetyCheck(
2690326914 var fail_block: Block = .{
2690426915 .parent = parent_block,
2690526916 .sema = sema,
26906 .src_decl = parent_block.src_decl,
2690726917 .namespace = parent_block.namespace,
2690826918 .instructions = .{},
2690926919 .inlining = parent_block.inlining,
2691026920 .is_comptime = false,
2691126921 .src_base_inst = parent_block.src_base_inst,
26922 .type_name_ctx = parent_block.type_name_ctx,
2691226923 };
2691326924
2691426925 defer fail_block.instructions.deinit(gpa);
......@@ -27012,12 +27023,12 @@ fn panicUnwrapError(
2701227023 var fail_block: Block = .{
2701327024 .parent = parent_block,
2701427025 .sema = sema,
27015 .src_decl = parent_block.src_decl,
2701627026 .namespace = parent_block.namespace,
2701727027 .instructions = .{},
2701827028 .inlining = parent_block.inlining,
2701927029 .is_comptime = false,
2702027030 .src_base_inst = parent_block.src_base_inst,
27031 .type_name_ctx = parent_block.type_name_ctx,
2702127032 };
2702227033
2702327034 defer fail_block.instructions.deinit(gpa);
......@@ -27129,12 +27140,12 @@ fn safetyCheckFormatted(
2712927140 var fail_block: Block = .{
2713027141 .parent = parent_block,
2713127142 .sema = sema,
27132 .src_decl = parent_block.src_decl,
2713327143 .namespace = parent_block.namespace,
2713427144 .instructions = .{},
2713527145 .inlining = parent_block.inlining,
2713627146 .is_comptime = false,
2713727147 .src_base_inst = parent_block.src_base_inst,
27148 .type_name_ctx = parent_block.type_name_ctx,
2713827149 };
2713927150
2714027151 defer fail_block.instructions.deinit(gpa);
......@@ -27682,7 +27693,7 @@ fn fieldCallBind(
2768227693 const decl_idx = (try sema.namespaceLookup(block, src, namespace, field_name)) orelse
2768327694 break :found_decl null;
2768427695
27685 try sema.addReferencedBy(block, src, decl_idx);
27696 try sema.addReferencedBy(src, decl_idx);
2768627697 const decl_val = try sema.analyzeDeclVal(block, src, decl_idx);
2768727698 const decl_type = sema.typeOf(decl_val);
2768827699 if (mod.typeToFunc(decl_type)) |func_type| f: {
......@@ -27838,7 +27849,7 @@ fn namespaceLookupRef(
2783827849 decl_name: InternPool.NullTerminatedString,
2783927850) CompileError!?Air.Inst.Ref {
2784027851 const decl = (try sema.namespaceLookup(block, src, opt_namespace, decl_name)) orelse return null;
27841 try sema.addReferencedBy(block, src, decl);
27852 try sema.addReferencedBy(src, decl);
2784227853 return try sema.analyzeDeclRef(decl);
2784327854}
2784427855
......@@ -31757,7 +31768,7 @@ fn analyzeDeclVal(
3175731768 src: LazySrcLoc,
3175831769 decl_index: InternPool.DeclIndex,
3175931770) CompileError!Air.Inst.Ref {
31760 try sema.addReferencedBy(block, src, decl_index);
31771 try sema.addReferencedBy(src, decl_index);
3176131772 if (sema.decl_val_table.get(decl_index)) |result| {
3176231773 return result;
3176331774 }
......@@ -31773,13 +31784,14 @@ fn analyzeDeclVal(
3177331784
3177431785fn addReferencedBy(
3177531786 sema: *Sema,
31776 block: *Block,
3177731787 src: LazySrcLoc,
3177831788 decl_index: InternPool.DeclIndex,
3177931789) !void {
3178031790 if (sema.mod.comp.reference_trace == 0) return;
3178131791 try sema.mod.reference_table.put(sema.gpa, decl_index, .{
31782 .referencer = block.src_decl,
31792 // TODO: this can make the reference trace suboptimal. This will be fixed
31793 // once the reference table is reworked for incremental compilation.
31794 .referencer = sema.owner_decl_index,
3178331795 .src = src,
3178431796 });
3178531797}
......@@ -35181,12 +35193,12 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3518135193 var block: Block = .{
3518235194 .parent = null,
3518335195 .sema = &sema,
35184 .src_decl = decl_index,
3518535196 .namespace = struct_type.namespace.unwrap() orelse decl.src_namespace,
3518635197 .instructions = .{},
3518735198 .inlining = null,
3518835199 .is_comptime = true,
3518935200 .src_base_inst = struct_type.zir_index.unwrap().?,
35201 .type_name_ctx = decl.name,
3519035202 };
3519135203 defer assert(block.instructions.items.len == 0);
3519235204
......@@ -36036,12 +36048,12 @@ fn semaStructFields(
3603636048 var block_scope: Block = .{
3603736049 .parent = null,
3603836050 .sema = &sema,
36039 .src_decl = decl_index,
3604036051 .namespace = namespace_index,
3604136052 .instructions = .{},
3604236053 .inlining = null,
3604336054 .is_comptime = true,
3604436055 .src_base_inst = struct_type.zir_index.unwrap().?,
36056 .type_name_ctx = decl.name,
3604536057 };
3604636058 defer assert(block_scope.instructions.items.len == 0);
3604736059
......@@ -36247,12 +36259,12 @@ fn semaStructFieldInits(
3624736259 var block_scope: Block = .{
3624836260 .parent = null,
3624936261 .sema = &sema,
36250 .src_decl = decl_index,
3625136262 .namespace = namespace_index,
3625236263 .instructions = .{},
3625336264 .inlining = null,
3625436265 .is_comptime = true,
3625536266 .src_base_inst = struct_type.zir_index.unwrap().?,
36267 .type_name_ctx = decl.name,
3625636268 };
3625736269 defer assert(block_scope.instructions.items.len == 0);
3625836270
......@@ -36359,7 +36371,8 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3635936371 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;
3636036372 assert(extended.opcode == .union_decl);
3636136373 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);
36362 var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len;
36374 const extra = zir.extraData(Zir.Inst.UnionDecl, extended.operand);
36375 var extra_index: usize = extra.end;
3636336376
3636436377 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {
3636536378 const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);
......@@ -36421,12 +36434,12 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3642136434 var block_scope: Block = .{
3642236435 .parent = null,
3642336436 .sema = &sema,
36424 .src_decl = decl_index,
3642536437 .namespace = union_type.namespace.unwrap().?,
3642636438 .instructions = .{},
3642736439 .inlining = null,
3642836440 .is_comptime = true,
3642936441 .src_base_inst = union_type.zir_index,
36442 .type_name_ctx = decl.name,
3643036443 };
3643136444 defer assert(block_scope.instructions.items.len == 0);
3643236445
......@@ -36711,10 +36724,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3671136724 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3671236725 }
3671336726 } else if (enum_field_vals.count() > 0) {
36714 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl));
36727 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl), extra.data.src_line);
3671536728 union_type.tagTypePtr(ip).* = enum_ty;
3671636729 } else {
36717 const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, mod.declPtr(union_type.decl));
36730 const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, mod.declPtr(union_type.decl), extra.data.src_line);
3671836731 union_type.tagTypePtr(ip).* = enum_ty;
3671936732 }
3672036733}
......@@ -36732,12 +36745,12 @@ fn generateUnionTagTypeNumbered(
3673236745 enum_field_names: []const InternPool.NullTerminatedString,
3673336746 enum_field_vals: []const InternPool.Index,
3673436747 union_owner_decl: *Module.Decl,
36748 src_line: u32,
3673536749) !InternPool.Index {
3673636750 const mod = sema.mod;
3673736751 const gpa = sema.gpa;
3673836752 const ip = &mod.intern_pool;
3673936753
36740 const src_decl = mod.declPtr(block.src_decl);
3674136754 const new_decl_index = try mod.allocateNewDecl(block.namespace);
3674236755 errdefer mod.destroyDecl(new_decl_index);
3674336756 const fqn = try union_owner_decl.fullyQualifiedName(mod);
......@@ -36749,7 +36762,7 @@ fn generateUnionTagTypeNumbered(
3674936762 );
3675036763 try mod.initNewAnonDecl(
3675136764 new_decl_index,
36752 src_decl.src_line,
36765 src_line,
3675336766 Value.@"unreachable",
3675436767 name,
3675536768 );
......@@ -36782,6 +36795,7 @@ fn generateUnionTagTypeSimple(
3678236795 block: *Block,
3678336796 enum_field_names: []const InternPool.NullTerminatedString,
3678436797 union_owner_decl: *Module.Decl,
36798 src_line: u32,
3678536799) !InternPool.Index {
3678636800 const mod = sema.mod;
3678736801 const ip = &mod.intern_pool;
......@@ -36789,7 +36803,6 @@ fn generateUnionTagTypeSimple(
3678936803
3679036804 const new_decl_index = new_decl_index: {
3679136805 const fqn = try union_owner_decl.fullyQualifiedName(mod);
36792 const src_decl = mod.declPtr(block.src_decl);
3679336806 const new_decl_index = try mod.allocateNewDecl(block.namespace);
3679436807 errdefer mod.destroyDecl(new_decl_index);
3679536808 const name = try ip.getOrPutStringFmt(
......@@ -36800,7 +36813,7 @@ fn generateUnionTagTypeSimple(
3680036813 );
3680136814 try mod.initNewAnonDecl(
3680236815 new_decl_index,
36803 src_decl.src_line,
36816 src_line,
3680436817 Value.@"unreachable",
3680536818 name,
3680636819 );
......@@ -36835,7 +36848,6 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
3683536848 var block: Block = .{
3683636849 .parent = null,
3683736850 .sema = sema,
36838 .src_decl = sema.owner_decl_index,
3683936851 .namespace = sema.owner_decl.src_namespace,
3684036852 .instructions = .{},
3684136853 .inlining = null,
......@@ -36853,6 +36865,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
3685336865 else => unreachable,
3685436866 }
3685536867 },
36868 .type_name_ctx = sema.owner_decl.name,
3685636869 };
3685736870 defer block.instructions.deinit(sema.gpa);
3685836871
......@@ -36898,7 +36911,6 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
3689836911 var block: Block = .{
3689936912 .parent = null,
3690036913 .sema = sema,
36901 .src_decl = sema.owner_decl_index,
3690236914 .namespace = sema.owner_decl.src_namespace,
3690336915 .instructions = .{},
3690436916 .inlining = null,
......@@ -36916,6 +36928,7 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
3691636928 else => unreachable,
3691736929 }
3691836930 },
36931 .type_name_ctx = sema.owner_decl.name,
3691936932 };
3692036933 defer block.instructions.deinit(sema.gpa);
3692136934
src/crash_report.zig+2-9
......@@ -81,7 +81,7 @@ fn dumpStatusReport() !void {
8181 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod);
8282
8383 try stderr.writeAll("Analyzing ");
84 try writeFullyQualifiedDeclWithFile(mod, block.src_decl, stderr);
84 try writeFilePath(file, stderr);
8585 try stderr.writeAll("\n");
8686
8787 print_zir.renderInstructionContext(
......@@ -105,7 +105,7 @@ fn dumpStatusReport() !void {
105105 fba.reset();
106106 try stderr.writeAll(" in ");
107107 const cur_block_file, const cur_block_src_base_node = Module.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, mod);
108 try writeFullyQualifiedDeclWithFile(mod, curr.block.src_decl, stderr);
108 try writeFilePath(cur_block_file, stderr);
109109 try stderr.writeAll("\n > ");
110110 print_zir.renderSingleInstruction(
111111 allocator,
......@@ -140,13 +140,6 @@ fn writeFilePath(file: *Module.File, writer: anytype) !void {
140140 try writer.writeAll(file.sub_file_path);
141141}
142142
143fn writeFullyQualifiedDeclWithFile(mod: *Module, decl_index: InternPool.DeclIndex, writer: anytype) !void {
144 const decl = mod.declPtr(decl_index);
145 try writeFilePath(decl.getFileScope(mod), writer);
146 try writer.writeAll(": ");
147 try decl.renderFullyQualifiedDebugName(mod, writer);
148}
149
150143pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn {
151144 PanicSwitch.preDispatch();
152145 @setCold(true);
src/main.zig+3
......@@ -5965,6 +5965,7 @@ fn cmdAstCheck(
59655965 .zir = undefined,
59665966 .mod = undefined,
59675967 .root_decl = .none,
5968 .path_digest = undefined,
59685969 };
59695970 if (zig_source_file) |file_name| {
59705971 var f = fs.cwd().openFile(file_name, .{}) catch |err| {
......@@ -6283,6 +6284,7 @@ fn cmdDumpZir(
62836284 .zir = try Module.loadZirCache(gpa, f),
62846285 .mod = undefined,
62856286 .root_decl = .none,
6287 .path_digest = undefined,
62866288 };
62876289 defer file.zir.deinit(gpa);
62886290
......@@ -6353,6 +6355,7 @@ fn cmdChangelist(
63536355 .zir = undefined,
63546356 .mod = undefined,
63556357 .root_decl = .none,
6358 .path_digest = undefined,
63566359 };
63576360
63586361 file.mod = try Package.Module.createLimited(arena, .{
src/print_zir.zig+8-1
......@@ -569,7 +569,6 @@ const Writer = struct {
569569 .wasm_memory_size,
570570 .int_from_error,
571571 .error_from_int,
572 .reify,
573572 .c_va_copy,
574573 .c_va_end,
575574 .work_item_id,
......@@ -582,6 +581,14 @@ const Writer = struct {
582581 try self.writeSrcNode(stream, inst_data.node);
583582 },
584583
584 .reify => {
585 const inst_data = self.code.extraData(Zir.Inst.Reify, extended.operand).data;
586 try stream.print("{d}, ", .{inst_data.src_line});
587 try self.writeInstRef(stream, inst_data.operand);
588 try stream.writeAll(")) ");
589 try self.writeSrcNode(stream, inst_data.node);
590 },
591
585592 .builtin_extern,
586593 .c_define,
587594 .error_cast,