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 {...@@ -13132,6 +13132,7 @@ const GenZir = struct {
13132 .fields_hash_1 = fields_hash_arr[1],13132 .fields_hash_1 = fields_hash_arr[1],
13133 .fields_hash_2 = fields_hash_arr[2],13133 .fields_hash_2 = fields_hash_arr[2],
13134 .fields_hash_3 = fields_hash_arr[3],13134 .fields_hash_3 = fields_hash_arr[3],
13135 .src_line = astgen.source_line,
13135 .src_node = args.src_node,13136 .src_node = args.src_node,
13136 });13137 });
1313713138
...@@ -13192,6 +13193,7 @@ const GenZir = struct {...@@ -13192,6 +13193,7 @@ const GenZir = struct {
13192 .fields_hash_1 = fields_hash_arr[1],13193 .fields_hash_1 = fields_hash_arr[1],
13193 .fields_hash_2 = fields_hash_arr[2],13194 .fields_hash_2 = fields_hash_arr[2],
13194 .fields_hash_3 = fields_hash_arr[3],13195 .fields_hash_3 = fields_hash_arr[3],
13196 .src_line = astgen.source_line,
13195 .src_node = args.src_node,13197 .src_node = args.src_node,
13196 });13198 });
1319713199
...@@ -13253,6 +13255,7 @@ const GenZir = struct {...@@ -13253,6 +13255,7 @@ const GenZir = struct {
13253 .fields_hash_1 = fields_hash_arr[1],13255 .fields_hash_1 = fields_hash_arr[1],
13254 .fields_hash_2 = fields_hash_arr[2],13256 .fields_hash_2 = fields_hash_arr[2],
13255 .fields_hash_3 = fields_hash_arr[3],13257 .fields_hash_3 = fields_hash_arr[3],
13258 .src_line = astgen.source_line,
13256 .src_node = args.src_node,13259 .src_node = args.src_node,
13257 });13260 });
1325813261
...@@ -13300,7 +13303,10 @@ const GenZir = struct {...@@ -13300,7 +13303,10 @@ const GenZir = struct {
13300 assert(args.src_node != 0);13303 assert(args.src_node != 0);
1330113304
13302 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.OpaqueDecl).Struct.fields.len + 2);13305 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
13305 if (args.captures_len != 0) {13311 if (args.captures_len != 0) {
13306 astgen.extra.appendAssumeCapacity(args.captures_len);13312 astgen.extra.appendAssumeCapacity(args.captures_len);
lib/std/zig/Zir.zig+11-1
...@@ -1981,7 +1981,7 @@ pub const Inst = struct {...@@ -1981,7 +1981,7 @@ pub const Inst = struct {
1981 /// `operand` is payload index to `UnNode`.1981 /// `operand` is payload index to `UnNode`.
1982 error_from_int,1982 error_from_int,
1983 /// Implement builtin `@Type`.1983 /// Implement builtin `@Type`.
1984 /// `operand` is payload index to `UnNode`.1984 /// `operand` is payload index to `Reify`.
1985 /// `small` contains `NameStrategy`.1985 /// `small` contains `NameStrategy`.
1986 reify,1986 reify,
1987 /// Implements the `@asyncCall` builtin.1987 /// Implements the `@asyncCall` builtin.
...@@ -2834,6 +2834,12 @@ pub const Inst = struct {...@@ -2834,6 +2834,12 @@ pub const Inst = struct {
2834 index: u32,2834 index: u32,
2835 };2835 };
28362836
2837 pub const Reify = struct {
2838 node: i32,
2839 operand: Ref,
2840 src_line: u32,
2841 };
2842
2837 pub const SwitchBlockErrUnion = struct {2843 pub const SwitchBlockErrUnion = struct {
2838 operand: Ref,2844 operand: Ref,
2839 bits: Bits,2845 bits: Bits,
...@@ -2992,6 +2998,7 @@ pub const Inst = struct {...@@ -2992,6 +2998,7 @@ pub const Inst = struct {
2992 fields_hash_1: u32,2998 fields_hash_1: u32,
2993 fields_hash_2: u32,2999 fields_hash_2: u32,
2994 fields_hash_3: u32,3000 fields_hash_3: u32,
3001 src_line: u32,
2995 /// This node provides a new absolute baseline node for all instructions within this struct.3002 /// This node provides a new absolute baseline node for all instructions within this struct.
2996 src_node: Ast.Node.Index,3003 src_node: Ast.Node.Index,
29973004
...@@ -3121,6 +3128,7 @@ pub const Inst = struct {...@@ -3121,6 +3128,7 @@ pub const Inst = struct {
3121 fields_hash_1: u32,3128 fields_hash_1: u32,
3122 fields_hash_2: u32,3129 fields_hash_2: u32,
3123 fields_hash_3: u32,3130 fields_hash_3: u32,
3131 src_line: u32,
3124 /// This node provides a new absolute baseline node for all instructions within this struct.3132 /// This node provides a new absolute baseline node for all instructions within this struct.
3125 src_node: Ast.Node.Index,3133 src_node: Ast.Node.Index,
31263134
...@@ -3166,6 +3174,7 @@ pub const Inst = struct {...@@ -3166,6 +3174,7 @@ pub const Inst = struct {
3166 fields_hash_1: u32,3174 fields_hash_1: u32,
3167 fields_hash_2: u32,3175 fields_hash_2: u32,
3168 fields_hash_3: u32,3176 fields_hash_3: u32,
3177 src_line: u32,
3169 /// This node provides a new absolute baseline node for all instructions within this struct.3178 /// This node provides a new absolute baseline node for all instructions within this struct.
3170 src_node: Ast.Node.Index,3179 src_node: Ast.Node.Index,
31713180
...@@ -3195,6 +3204,7 @@ pub const Inst = struct {...@@ -3195,6 +3204,7 @@ pub const Inst = struct {
3195 /// 2. capture: Capture, // for every captures_len3204 /// 2. capture: Capture, // for every captures_len
3196 /// 3. decl: Index, // for every decls_len; points to a `declaration` instruction3205 /// 3. decl: Index, // for every decls_len; points to a `declaration` instruction
3197 pub const OpaqueDecl = struct {3206 pub const OpaqueDecl = struct {
3207 src_line: u32,
3198 /// This node provides a new absolute baseline node for all instructions within this struct.3208 /// This node provides a new absolute baseline node for all instructions within this struct.
3199 src_node: Ast.Node.Index,3209 src_node: Ast.Node.Index,
32003210
src/Module.zig+50-30
...@@ -88,6 +88,9 @@ export_owners: std.AutoArrayHashMapUnmanaged(Decl.Index, ArrayListUnmanaged(*Exp...@@ -88,6 +88,9 @@ export_owners: std.AutoArrayHashMapUnmanaged(Decl.Index, ArrayListUnmanaged(*Exp
88/// an update is requested, as well as to cache `@import` results.88/// an update is requested, as well as to cache `@import` results.
89/// Keys are fully resolved file paths. This table owns the keys and values.89/// Keys are fully resolved file paths. This table owns the keys and values.
90import_table: std.StringArrayHashMapUnmanaged(*File) = .{},90import_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) = .{},
91/// The set of all the files which have been loaded with `@embedFile` in the Module.94/// The set of all the files which have been loaded with `@embedFile` in the Module.
92/// We keep track of this in order to iterate over it and check which files have been95/// We keep track of this in order to iterate over it and check which files have been
93/// modified on the file system when an update is requested, as well as to cache96/// modified on the file system when an update is requested, as well as to cache
...@@ -735,8 +738,7 @@ pub const File = struct {...@@ -735,8 +738,7 @@ pub const File = struct {
735 /// List of references to this file, used for multi-package errors.738 /// List of references to this file, used for multi-package errors.
736 references: std.ArrayListUnmanaged(Reference) = .{},739 references: std.ArrayListUnmanaged(Reference) = .{},
737 /// The hash of the path to this file, used to store `InternPool.TrackedInst`.740 /// The hash of the path to this file, used to store `InternPool.TrackedInst`.
738 /// undefined until `zir_loaded == true`.741 path_digest: Cache.BinDigest,
739 path_digest: Cache.BinDigest = undefined,
740742
741 /// The most recent successful ZIR for this file, with no errors.743 /// The most recent successful ZIR for this file, with no errors.
742 /// This is only populated when a previously successful ZIR744 /// This is only populated when a previously successful ZIR
...@@ -2357,10 +2359,10 @@ pub const LazySrcLoc = struct {...@@ -2357,10 +2359,10 @@ pub const LazySrcLoc = struct {
2357 const info = base_node_inst.resolveFull(&zcu.intern_pool);2359 const info = base_node_inst.resolveFull(&zcu.intern_pool);
2358 break :inst .{ info.path_digest, info.inst };2360 break :inst .{ info.path_digest, info.inst };
2359 };2361 };
2360 // TODO: avoid iterating all files for this!2362 const file = file: {
2361 const file = for (zcu.import_table.values()) |file| {2363 const index = zcu.path_digest_map.getIndex(want_path_digest).?;
2362 if (std.mem.eql(u8, &file.path_digest, &want_path_digest)) break file;2364 break :file zcu.import_table.values()[index];
2363 } else unreachable;2365 };
2364 assert(file.zir_loaded);2366 assert(file.zir_loaded);
23652367
2366 const zir = file.zir;2368 const zir = file.zir;
...@@ -2432,6 +2434,7 @@ pub fn deinit(zcu: *Zcu) void {...@@ -2432,6 +2434,7 @@ pub fn deinit(zcu: *Zcu) void {
2432 value.destroy(zcu);2434 value.destroy(zcu);
2433 }2435 }
2434 zcu.import_table.deinit(gpa);2436 zcu.import_table.deinit(gpa);
2437 zcu.path_digest_map.deinit(gpa);
24352438
2436 for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| {2439 for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| {
2437 gpa.free(path);2440 gpa.free(path);
...@@ -2596,26 +2599,12 @@ pub fn astGenFile(mod: *Module, file: *File) !void {...@@ -2596,26 +2599,12 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
2596 const stat = try source_file.stat();2599 const stat = try source_file.stat();
25972600
2598 const want_local_cache = file.mod == mod.main_mod;2601 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;
2613 const hex_digest = hex: {2602 const hex_digest = hex: {
2614 var hex: Cache.HexDigest = undefined;2603 var hex: Cache.HexDigest = undefined;
2615 _ = std.fmt.bufPrint(2604 _ = std.fmt.bufPrint(
2616 &hex,2605 &hex,
2617 "{s}",2606 "{s}",
2618 .{std.fmt.fmtSliceHexLower(&bin_digest)},2607 .{std.fmt.fmtSliceHexLower(&file.path_digest)},
2619 ) catch unreachable;2608 ) catch unreachable;
2620 break :hex hex;2609 break :hex hex;
2621 };2610 };
...@@ -4122,12 +4111,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -4122,12 +4111,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
4122 var block_scope: Sema.Block = .{4111 var block_scope: Sema.Block = .{
4123 .parent = null,4112 .parent = null,
4124 .sema = &sema,4113 .sema = &sema,
4125 .src_decl = decl_index,
4126 .namespace = decl.src_namespace,4114 .namespace = decl.src_namespace,
4127 .instructions = .{},4115 .instructions = .{},
4128 .inlining = null,4116 .inlining = null,
4129 .is_comptime = true,4117 .is_comptime = true,
4130 .src_base_inst = decl.zir_decl_index.unwrap().?,4118 .src_base_inst = decl.zir_decl_index.unwrap().?,
4119 .type_name_ctx = decl.name,
4131 };4120 };
4132 defer block_scope.instructions.deinit(gpa);4121 defer block_scope.instructions.deinit(gpa);
41334122
...@@ -4355,6 +4344,7 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {...@@ -4355,6 +4344,7 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
4355 keep_resolved_path = true; // It's now owned by import_table.4344 keep_resolved_path = true; // It's now owned by import_table.
4356 gop.value_ptr.* = builtin_file;4345 gop.value_ptr.* = builtin_file;
4357 try builtin_file.addReference(zcu.*, .{ .root = mod });4346 try builtin_file.addReference(zcu.*, .{ .root = mod });
4347 try zcu.path_digest_map.put(gpa, builtin_file.path_digest, {});
4358 return .{4348 return .{
4359 .file = builtin_file,4349 .file = builtin_file,
4360 .is_new = false,4350 .is_new = false,
...@@ -4382,8 +4372,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {...@@ -4382,8 +4372,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
4382 .status = .never_loaded,4372 .status = .never_loaded,
4383 .mod = mod,4373 .mod = mod,
4384 .root_decl = .none,4374 .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 },
4385 };4389 };
4386 try new_file.addReference(zcu.*, .{ .root = mod });4390 try new_file.addReference(zcu.*, .{ .root = mod });
4391 try zcu.path_digest_map.put(gpa, new_file.path_digest, {});
4387 return ImportFileResult{4392 return ImportFileResult{
4388 .file = new_file,4393 .file = new_file,
4389 .is_new = true,4394 .is_new = true,
...@@ -4392,23 +4397,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {...@@ -4392,23 +4397,23 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
4392}4397}
43934398
4394pub fn importFile(4399pub fn importFile(
4395 mod: *Module,4400 zcu: *Zcu,
4396 cur_file: *File,4401 cur_file: *File,
4397 import_string: []const u8,4402 import_string: []const u8,
4398) !ImportFileResult {4403) !ImportFileResult {
4399 if (std.mem.eql(u8, import_string, "std")) {4404 if (std.mem.eql(u8, import_string, "std")) {
4400 return mod.importPkg(mod.std_mod);4405 return zcu.importPkg(zcu.std_mod);
4401 }4406 }
4402 if (std.mem.eql(u8, import_string, "root")) {4407 if (std.mem.eql(u8, import_string, "root")) {
4403 return mod.importPkg(mod.root_mod);4408 return zcu.importPkg(zcu.root_mod);
4404 }4409 }
4405 if (cur_file.mod.deps.get(import_string)) |pkg| {4410 if (cur_file.mod.deps.get(import_string)) |pkg| {
4406 return mod.importPkg(pkg);4411 return zcu.importPkg(pkg);
4407 }4412 }
4408 if (!mem.endsWith(u8, import_string, ".zig")) {4413 if (!mem.endsWith(u8, import_string, ".zig")) {
4409 return error.ModuleNotFound;4414 return error.ModuleNotFound;
4410 }4415 }
4411 const gpa = mod.gpa;4416 const gpa = zcu.gpa;
44124417
4413 // The resolved path is used as the key in the import table, to detect if4418 // The resolved path is used as the key in the import table, to detect if
4414 // an import refers to the same as another, despite different relative paths4419 // an import refers to the same as another, despite different relative paths
...@@ -4424,8 +4429,8 @@ pub fn importFile(...@@ -4424,8 +4429,8 @@ pub fn importFile(
4424 var keep_resolved_path = false;4429 var keep_resolved_path = false;
4425 defer if (!keep_resolved_path) gpa.free(resolved_path);4430 defer if (!keep_resolved_path) gpa.free(resolved_path);
44264431
4427 const gop = try mod.import_table.getOrPut(gpa, resolved_path);4432 const gop = try zcu.import_table.getOrPut(gpa, resolved_path);
4428 errdefer _ = mod.import_table.pop();4433 errdefer _ = zcu.import_table.pop();
4429 if (gop.found_existing) return ImportFileResult{4434 if (gop.found_existing) return ImportFileResult{
4430 .file = gop.value_ptr.*,4435 .file = gop.value_ptr.*,
4431 .is_new = false,4436 .is_new = false,
...@@ -4470,7 +4475,22 @@ pub fn importFile(...@@ -4470,7 +4475,22 @@ pub fn importFile(
4470 .status = .never_loaded,4475 .status = .never_loaded,
4471 .mod = cur_file.mod,4476 .mod = cur_file.mod,
4472 .root_decl = .none,4477 .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 },
4473 };4492 };
4493 try zcu.path_digest_map.put(gpa, new_file.path_digest, {});
4474 return ImportFileResult{4494 return ImportFileResult{
4475 .file = new_file,4495 .file = new_file,
4476 .is_new = true,4496 .is_new = true,
...@@ -5039,7 +5059,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -5039,7 +5059,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
5039 var inner_block: Sema.Block = .{5059 var inner_block: Sema.Block = .{
5040 .parent = null,5060 .parent = null,
5041 .sema = &sema,5061 .sema = &sema,
5042 .src_decl = decl_index,
5043 .namespace = decl.src_namespace,5062 .namespace = decl.src_namespace,
5044 .instructions = .{},5063 .instructions = .{},
5045 .inlining = null,5064 .inlining = null,
...@@ -5052,6 +5071,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -5052,6 +5071,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
5052 const orig_decl = mod.declPtr(owner_info.owner_decl);5071 const orig_decl = mod.declPtr(owner_info.owner_decl);
5053 break :inst orig_decl.zir_decl_index.unwrap().?;5072 break :inst orig_decl.zir_decl_index.unwrap().?;
5054 },5073 },
5074 .type_name_ctx = decl.name,
5055 };5075 };
5056 defer inner_block.instructions.deinit(gpa);5076 defer inner_block.instructions.deinit(gpa);
50575077
src/Sema.zig+73-60
...@@ -16,9 +16,7 @@ air_instructions: std.MultiArrayList(Air.Inst) = .{},...@@ -16,9 +16,7 @@ air_instructions: std.MultiArrayList(Air.Inst) = .{},
16air_extra: std.ArrayListUnmanaged(u32) = .{},16air_extra: std.ArrayListUnmanaged(u32) = .{},
17/// Maps ZIR to AIR.17/// Maps ZIR to AIR.
18inst_map: InstMap = .{},18inst_map: InstMap = .{},
19/// When analyzing an inline function call, owner_decl is the Decl of the caller19/// 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`.
22owner_decl: *Decl,20owner_decl: *Decl,
23owner_decl_index: InternPool.DeclIndex,21owner_decl_index: InternPool.DeclIndex,
24/// For an inline or comptime function call, this will be the root parent function22/// For an inline or comptime function call, this will be the root parent function
...@@ -342,7 +340,6 @@ pub const Block = struct {...@@ -342,7 +340,6 @@ pub const Block = struct {
342 /// Shared among all child blocks.340 /// Shared among all child blocks.
343 sema: *Sema,341 sema: *Sema,
344 /// The namespace to use for lookups from this source block342 /// The namespace to use for lookups from this source block
345 /// When analyzing fields, this is different from src_decl.src_namespace.
346 namespace: InternPool.NamespaceIndex,343 namespace: InternPool.NamespaceIndex,
347 /// The AIR instructions generated for this block.344 /// The AIR instructions generated for this block.
348 instructions: std.ArrayListUnmanaged(Air.Inst.Index),345 instructions: std.ArrayListUnmanaged(Air.Inst.Index),
...@@ -360,10 +357,6 @@ pub const Block = struct {...@@ -360,10 +357,6 @@ pub const Block = struct {
360 /// If runtime_index is not 0 then one of these is guaranteed to be non null.357 /// If runtime_index is not 0 then one of these is guaranteed to be non null.
361 runtime_cond: ?LazySrcLoc = null,358 runtime_cond: ?LazySrcLoc = null,
362 runtime_loop: ?LazySrcLoc = null,359 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,
367 /// Non zero if a non-inline loop or a runtime conditional have been encountered.360 /// Non zero if a non-inline loop or a runtime conditional have been encountered.
368 /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.361 /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.
369 runtime_index: Value.RuntimeIndex = .zero,362 runtime_index: Value.RuntimeIndex = .zero,
...@@ -396,6 +389,12 @@ pub const Block = struct {...@@ -396,6 +389,12 @@ pub const Block = struct {
396 /// treated as relative to the AST node of this ZIR instruction.389 /// treated as relative to the AST node of this ZIR instruction.
397 src_base_inst: InternPool.TrackedInst.Index,390 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
399 /// Create a `LazySrcLoc` based on an `Offset` from the code being analyzed in this block.398 /// Create a `LazySrcLoc` based on an `Offset` from the code being analyzed in this block.
400 /// Specifically, the given `Offset` is treated as relative to `block.src_base_inst`.399 /// Specifically, the given `Offset` is treated as relative to `block.src_base_inst`.
401 pub fn src(block: Block, offset: LazySrcLoc.Offset) LazySrcLoc {400 pub fn src(block: Block, offset: LazySrcLoc.Offset) LazySrcLoc {
...@@ -516,7 +515,6 @@ pub const Block = struct {...@@ -516,7 +515,6 @@ pub const Block = struct {
516 return .{515 return .{
517 .parent = parent,516 .parent = parent,
518 .sema = parent.sema,517 .sema = parent.sema,
519 .src_decl = parent.src_decl,
520 .namespace = parent.namespace,518 .namespace = parent.namespace,
521 .instructions = .{},519 .instructions = .{},
522 .label = null,520 .label = null,
...@@ -533,6 +531,7 @@ pub const Block = struct {...@@ -533,6 +531,7 @@ pub const Block = struct {
533 .error_return_trace_index = parent.error_return_trace_index,531 .error_return_trace_index = parent.error_return_trace_index,
534 .need_debug_scope = parent.need_debug_scope,532 .need_debug_scope = parent.need_debug_scope,
535 .src_base_inst = parent.src_base_inst,533 .src_base_inst = parent.src_base_inst,
534 .type_name_ctx = parent.type_name_ctx,
536 };535 };
537 }536 }
538537
...@@ -993,9 +992,11 @@ fn analyzeBodyInner(...@@ -993,9 +992,11 @@ fn analyzeBodyInner(
993 while (true) {992 while (true) {
994 crash_info.setBodyIndex(i);993 crash_info.setBodyIndex(i);
995 const inst = body[i];994 const inst = body[i];
996 std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{995 std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ sub_file_path: {
997 mod.namespacePtr(mod.declPtr(block.src_decl).src_namespace).file_scope.sub_file_path, inst,996 const path_digest = block.src_base_inst.resolveFull(&mod.intern_pool).path_digest;
998 });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 });
999 const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) {1000 const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) {
1000 // zig fmt: off1001 // zig fmt: off
1001 .alloc => try sema.zirAlloc(block, inst),1002 .alloc => try sema.zirAlloc(block, inst),
...@@ -2821,6 +2822,7 @@ fn zirStructDecl(...@@ -2821,6 +2822,7 @@ fn zirStructDecl(
2821 small.name_strategy,2822 small.name_strategy,
2822 "struct",2823 "struct",
2823 inst,2824 inst,
2825 extra.data.src_line,
2824 );2826 );
2825 mod.declPtr(new_decl_index).owns_tv = true;2827 mod.declPtr(new_decl_index).owns_tv = true;
2826 errdefer mod.abortAnonDecl(new_decl_index);2828 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -2857,20 +2859,19 @@ fn createAnonymousDeclTypeNamed(...@@ -2857,20 +2859,19 @@ fn createAnonymousDeclTypeNamed(
2857 name_strategy: Zir.Inst.NameStrategy,2859 name_strategy: Zir.Inst.NameStrategy,
2858 anon_prefix: []const u8,2860 anon_prefix: []const u8,
2859 inst: ?Zir.Inst.Index,2861 inst: ?Zir.Inst.Index,
2862 src_line: u32,
2860) !InternPool.DeclIndex {2863) !InternPool.DeclIndex {
2861 const zcu = sema.mod;2864 const zcu = sema.mod;
2862 const ip = &zcu.intern_pool;2865 const ip = &zcu.intern_pool;
2863 const gpa = sema.gpa;2866 const gpa = sema.gpa;
2864 const namespace = block.namespace;2867 const namespace = block.namespace;
2865 const src_decl = zcu.declPtr(block.src_decl);
2866 const new_decl_index = try zcu.allocateNewDecl(namespace);2868 const new_decl_index = try zcu.allocateNewDecl(namespace);
2867 errdefer zcu.destroyDecl(new_decl_index);2869 errdefer zcu.destroyDecl(new_decl_index);
28682870
2869 switch (name_strategy) {2871 switch (name_strategy) {
2870 .anon => {}, // handled after switch2872 .anon => {}, // handled after switch
2871 .parent => {2873 .parent => {
2872 const name = zcu.declPtr(block.src_decl).name;2874 try zcu.initNewAnonDecl(new_decl_index, src_line, val, block.type_name_ctx);
2873 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2874 return new_decl_index;2875 return new_decl_index;
2875 },2876 },
2876 .func => func_strat: {2877 .func => func_strat: {
...@@ -2881,7 +2882,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2881,7 +2882,7 @@ fn createAnonymousDeclTypeNamed(
2881 defer buf.deinit();2882 defer buf.deinit();
28822883
2883 const writer = buf.writer();2884 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
2886 var arg_i: usize = 0;2887 var arg_i: usize = 0;
2887 for (fn_info.param_body) |zir_inst| switch (zir_tags[@intFromEnum(zir_inst)]) {2888 for (fn_info.param_body) |zir_inst| switch (zir_tags[@intFromEnum(zir_inst)]) {
...@@ -2915,7 +2916,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2915,7 +2916,7 @@ fn createAnonymousDeclTypeNamed(
29152916
2916 try writer.writeByte(')');2917 try writer.writeByte(')');
2917 const name = try ip.getOrPutString(gpa, buf.items, .no_embedded_nulls);2918 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);
2919 return new_decl_index;2920 return new_decl_index;
2920 },2921 },
2921 .dbg_var => {2922 .dbg_var => {
...@@ -2927,9 +2928,9 @@ fn createAnonymousDeclTypeNamed(...@@ -2927,9 +2928,9 @@ fn createAnonymousDeclTypeNamed(
2927 if (zir_data[i].str_op.operand != ref) continue;2928 if (zir_data[i].str_op.operand != ref) continue;
29282929
2929 const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{2930 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),
2931 }, .no_embedded_nulls);2932 }, .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);
2933 return new_decl_index;2934 return new_decl_index;
2934 },2935 },
2935 else => {},2936 else => {},
...@@ -2948,9 +2949,9 @@ fn createAnonymousDeclTypeNamed(...@@ -2948,9 +2949,9 @@ fn createAnonymousDeclTypeNamed(
2948 // renamed.2949 // renamed.
29492950
2950 const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{2951 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),
2952 }, .no_embedded_nulls) catch unreachable;2953 }, .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);
2954 return new_decl_index;2955 return new_decl_index;
2955}2956}
29562957
...@@ -3056,6 +3057,7 @@ fn zirEnumDecl(...@@ -3056,6 +3057,7 @@ fn zirEnumDecl(
3056 small.name_strategy,3057 small.name_strategy,
3057 "enum",3058 "enum",
3058 inst,3059 inst,
3060 extra.data.src_line,
3059 );3061 );
3060 const new_decl = mod.declPtr(new_decl_index);3062 const new_decl = mod.declPtr(new_decl_index);
3061 new_decl.owns_tv = true;3063 new_decl.owns_tv = true;
...@@ -3112,12 +3114,12 @@ fn zirEnumDecl(...@@ -3112,12 +3114,12 @@ fn zirEnumDecl(
3112 var enum_block: Block = .{3114 var enum_block: Block = .{
3113 .parent = null,3115 .parent = null,
3114 .sema = sema,3116 .sema = sema,
3115 .src_decl = new_decl_index,
3116 .namespace = new_namespace_index.unwrap() orelse block.namespace,3117 .namespace = new_namespace_index.unwrap() orelse block.namespace,
3117 .instructions = .{},3118 .instructions = .{},
3118 .inlining = null,3119 .inlining = null,
3119 .is_comptime = true,3120 .is_comptime = true,
3120 .src_base_inst = tracked_inst,3121 .src_base_inst = tracked_inst,
3122 .type_name_ctx = new_decl.name,
3121 };3123 };
3122 defer enum_block.instructions.deinit(sema.gpa);3124 defer enum_block.instructions.deinit(sema.gpa);
31233125
...@@ -3323,6 +3325,7 @@ fn zirUnionDecl(...@@ -3323,6 +3325,7 @@ fn zirUnionDecl(
3323 small.name_strategy,3325 small.name_strategy,
3324 "union",3326 "union",
3325 inst,3327 inst,
3328 extra.data.src_line,
3326 );3329 );
3327 mod.declPtr(new_decl_index).owns_tv = true;3330 mod.declPtr(new_decl_index).owns_tv = true;
3328 errdefer mod.abortAnonDecl(new_decl_index);3331 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -3411,6 +3414,7 @@ fn zirOpaqueDecl(...@@ -3411,6 +3414,7 @@ fn zirOpaqueDecl(
3411 small.name_strategy,3414 small.name_strategy,
3412 "opaque",3415 "opaque",
3413 inst,3416 inst,
3417 extra.data.src_line,
3414 );3418 );
3415 mod.declPtr(new_decl_index).owns_tv = true;3419 mod.declPtr(new_decl_index).owns_tv = true;
3416 errdefer mod.abortAnonDecl(new_decl_index);3420 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -5942,7 +5946,6 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -5942,7 +5946,6 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
5942 var child_block: Block = .{5946 var child_block: Block = .{
5943 .parent = parent_block,5947 .parent = parent_block,
5944 .sema = sema,5948 .sema = sema,
5945 .src_decl = parent_block.src_decl,
5946 .namespace = parent_block.namespace,5949 .namespace = parent_block.namespace,
5947 .instructions = .{},5950 .instructions = .{},
5948 .inlining = parent_block.inlining,5951 .inlining = parent_block.inlining,
...@@ -5953,6 +5956,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -5953,6 +5956,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
5953 .runtime_loop = parent_block.runtime_loop,5956 .runtime_loop = parent_block.runtime_loop,
5954 .runtime_index = parent_block.runtime_index,5957 .runtime_index = parent_block.runtime_index,
5955 .src_base_inst = parent_block.src_base_inst,5958 .src_base_inst = parent_block.src_base_inst,
5959 .type_name_ctx = parent_block.type_name_ctx,
5956 };5960 };
5957 defer child_block.instructions.deinit(gpa);5961 defer child_block.instructions.deinit(gpa);
59585962
...@@ -6063,7 +6067,6 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt...@@ -6063,7 +6067,6 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
6063 var child_block: Block = .{6067 var child_block: Block = .{
6064 .parent = parent_block,6068 .parent = parent_block,
6065 .sema = sema,6069 .sema = sema,
6066 .src_decl = parent_block.src_decl,
6067 .namespace = parent_block.namespace,6070 .namespace = parent_block.namespace,
6068 .instructions = .{},6071 .instructions = .{},
6069 .label = &label,6072 .label = &label,
...@@ -6079,6 +6082,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt...@@ -6079,6 +6082,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
6079 .runtime_index = parent_block.runtime_index,6082 .runtime_index = parent_block.runtime_index,
6080 .error_return_trace_index = parent_block.error_return_trace_index,6083 .error_return_trace_index = parent_block.error_return_trace_index,
6081 .src_base_inst = parent_block.src_base_inst,6084 .src_base_inst = parent_block.src_base_inst,
6085 .type_name_ctx = parent_block.type_name_ctx,
6082 };6086 };
60836087
6084 defer child_block.instructions.deinit(gpa);6088 defer child_block.instructions.deinit(gpa);
...@@ -6726,7 +6730,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -6726,7 +6730,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
6726 .no_embedded_nulls,6730 .no_embedded_nulls,
6727 );6731 );
6728 const decl_index = try sema.lookupIdentifier(block, src, decl_name);6732 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);
6730 return sema.analyzeDeclRef(decl_index);6734 return sema.analyzeDeclRef(decl_index);
6731}6735}
67326736
...@@ -7695,7 +7699,6 @@ fn analyzeCall(...@@ -7695,7 +7699,6 @@ fn analyzeCall(
7695 var child_block: Block = .{7699 var child_block: Block = .{
7696 .parent = null,7700 .parent = null,
7697 .sema = sema,7701 .sema = sema,
7698 .src_decl = module_fn.owner_decl,
7699 .namespace = fn_owner_decl.src_namespace,7702 .namespace = fn_owner_decl.src_namespace,
7700 .instructions = .{},7703 .instructions = .{},
7701 .label = null,7704 .label = null,
...@@ -7708,6 +7711,7 @@ fn analyzeCall(...@@ -7708,6 +7711,7 @@ fn analyzeCall(
7708 .runtime_loop = block.runtime_loop,7711 .runtime_loop = block.runtime_loop,
7709 .runtime_index = block.runtime_index,7712 .runtime_index = block.runtime_index,
7710 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,7713 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
7714 .type_name_ctx = fn_owner_decl.name,
7711 };7715 };
77127716
7713 const merges = &child_block.inlining.?.merges;7717 const merges = &child_block.inlining.?.merges;
...@@ -8217,12 +8221,12 @@ fn instantiateGenericCall(...@@ -8217,12 +8221,12 @@ fn instantiateGenericCall(
8217 var child_block: Block = .{8221 var child_block: Block = .{
8218 .parent = null,8222 .parent = null,
8219 .sema = &child_sema,8223 .sema = &child_sema,
8220 .src_decl = generic_owner_func.owner_decl,
8221 .namespace = namespace_index,8224 .namespace = namespace_index,
8222 .instructions = .{},8225 .instructions = .{},
8223 .inlining = null,8226 .inlining = null,
8224 .is_comptime = true,8227 .is_comptime = true,
8225 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,8228 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
8229 .type_name_ctx = fn_owner_decl.name,
8226 };8230 };
8227 defer child_block.instructions.deinit(gpa);8231 defer child_block.instructions.deinit(gpa);
82288232
...@@ -8366,7 +8370,7 @@ fn instantiateGenericCall(...@@ -8366,7 +8370,7 @@ fn instantiateGenericCall(
8366 const callee = mod.funcInfo(callee_index);8370 const callee = mod.funcInfo(callee_index);
8367 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);8371 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
8371 // Make a runtime call to the new function, making sure to omit the comptime args.8375 // Make a runtime call to the new function, making sure to omit the comptime args.
8372 const func_ty = Type.fromInterned(callee.ty);8376 const func_ty = Type.fromInterned(callee.ty);
...@@ -9346,7 +9350,7 @@ fn zirFunc(...@@ -9346,7 +9350,7 @@ fn zirFunc(
9346 // If this instruction has a body it means it's the type of the `owner_decl`9350 // If this instruction has a body it means it's the type of the `owner_decl`
9347 // otherwise it's a function type without a `callconv` attribute and should9351 // otherwise it's a function type without a `callconv` attribute and should
9348 // never be `.C`.9352 // 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)
9350 .C9354 .C
9351 else9355 else
9352 .Unspecified;9356 .Unspecified;
...@@ -11595,7 +11599,6 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11595,7 +11599,6 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11595 var child_block: Block = .{11599 var child_block: Block = .{
11596 .parent = block,11600 .parent = block,
11597 .sema = sema,11601 .sema = sema,
11598 .src_decl = block.src_decl,
11599 .namespace = block.namespace,11602 .namespace = block.namespace,
11600 .instructions = .{},11603 .instructions = .{},
11601 .label = &label,11604 .label = &label,
...@@ -11610,6 +11613,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11610,6 +11613,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11610 .error_return_trace_index = block.error_return_trace_index,11613 .error_return_trace_index = block.error_return_trace_index,
11611 .want_safety = block.want_safety,11614 .want_safety = block.want_safety,
11612 .src_base_inst = block.src_base_inst,11615 .src_base_inst = block.src_base_inst,
11616 .type_name_ctx = block.type_name_ctx,
11613 };11617 };
11614 const merges = &child_block.label.?.merges;11618 const merges = &child_block.label.?.merges;
11615 defer child_block.instructions.deinit(gpa);11619 defer child_block.instructions.deinit(gpa);
...@@ -12327,7 +12331,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12327,7 +12331,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12327 var child_block: Block = .{12331 var child_block: Block = .{
12328 .parent = block,12332 .parent = block,
12329 .sema = sema,12333 .sema = sema,
12330 .src_decl = block.src_decl,
12331 .namespace = block.namespace,12334 .namespace = block.namespace,
12332 .instructions = .{},12335 .instructions = .{},
12333 .label = &label,12336 .label = &label,
...@@ -12342,6 +12345,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12342,6 +12345,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12342 .want_safety = block.want_safety,12345 .want_safety = block.want_safety,
12343 .error_return_trace_index = block.error_return_trace_index,12346 .error_return_trace_index = block.error_return_trace_index,
12344 .src_base_inst = block.src_base_inst,12347 .src_base_inst = block.src_base_inst,
12348 .type_name_ctx = block.type_name_ctx,
12345 };12349 };
12346 const merges = &child_block.label.?.merges;12350 const merges = &child_block.label.?.merges;
12347 defer child_block.instructions.deinit(gpa);12351 defer child_block.instructions.deinit(gpa);
...@@ -18843,7 +18847,6 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -18843,7 +18847,6 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
18843 var child_block: Block = .{18847 var child_block: Block = .{
18844 .parent = block,18848 .parent = block,
18845 .sema = sema,18849 .sema = sema,
18846 .src_decl = block.src_decl,
18847 .namespace = block.namespace,18850 .namespace = block.namespace,
18848 .instructions = .{},18851 .instructions = .{},
18849 .inlining = block.inlining,18852 .inlining = block.inlining,
...@@ -18852,6 +18855,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -18852,6 +18855,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
18852 .want_safety = false,18855 .want_safety = false,
18853 .error_return_trace_index = block.error_return_trace_index,18856 .error_return_trace_index = block.error_return_trace_index,
18854 .src_base_inst = block.src_base_inst,18857 .src_base_inst = block.src_base_inst,
18858 .type_name_ctx = block.type_name_ctx,
18855 };18859 };
18856 defer child_block.instructions.deinit(sema.gpa);18860 defer child_block.instructions.deinit(sema.gpa);
1885718861
...@@ -18922,7 +18926,6 @@ fn zirTypeofPeer(...@@ -18922,7 +18926,6 @@ fn zirTypeofPeer(
18922 var child_block: Block = .{18926 var child_block: Block = .{
18923 .parent = block,18927 .parent = block,
18924 .sema = sema,18928 .sema = sema,
18925 .src_decl = block.src_decl,
18926 .namespace = block.namespace,18929 .namespace = block.namespace,
18927 .instructions = .{},18930 .instructions = .{},
18928 .inlining = block.inlining,18931 .inlining = block.inlining,
...@@ -18932,6 +18935,7 @@ fn zirTypeofPeer(...@@ -18932,6 +18935,7 @@ fn zirTypeofPeer(
18932 .runtime_loop = block.runtime_loop,18935 .runtime_loop = block.runtime_loop,
18933 .runtime_index = block.runtime_index,18936 .runtime_index = block.runtime_index,
18934 .src_base_inst = block.src_base_inst,18937 .src_base_inst = block.src_base_inst,
18938 .type_name_ctx = block.type_name_ctx,
18935 };18939 };
18936 defer child_block.instructions.deinit(sema.gpa);18940 defer child_block.instructions.deinit(sema.gpa);
18937 // Ignore the result, we only care about the instructions in `args`.18941 // 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...@@ -19398,13 +19402,13 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label
19398 .block = .{19402 .block = .{
19399 .parent = block,19403 .parent = block,
19400 .sema = sema,19404 .sema = sema,
19401 .src_decl = block.src_decl,
19402 .namespace = block.namespace,19405 .namespace = block.namespace,
19403 .instructions = .{},19406 .instructions = .{},
19404 .label = &labeled_block.label,19407 .label = &labeled_block.label,
19405 .inlining = block.inlining,19408 .inlining = block.inlining,
19406 .is_comptime = block.is_comptime,19409 .is_comptime = block.is_comptime,
19407 .src_base_inst = block.src_base_inst,19410 .src_base_inst = block.src_base_inst,
19411 .type_name_ctx = block.type_name_ctx,
19408 },19412 },
19409 };19413 };
19410 sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block);19414 sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block);
...@@ -21201,7 +21205,7 @@ fn zirReify(...@@ -21201,7 +21205,7 @@ fn zirReify(
21201 const gpa = sema.gpa;21205 const gpa = sema.gpa;
21202 const ip = &mod.intern_pool;21206 const ip = &mod.intern_pool;
21203 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);21207 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;
21205 const src = block.nodeOffset(extra.node);21209 const src = block.nodeOffset(extra.node);
21206 const type_info_ty = try sema.getBuiltinType("Type");21210 const type_info_ty = try sema.getBuiltinType("Type");
21207 const uncasted_operand = try sema.resolveInst(extra.operand);21211 const uncasted_operand = try sema.resolveInst(extra.operand);
...@@ -21521,7 +21525,7 @@ fn zirReify(...@@ -21521,7 +21525,7 @@ fn zirReify(
21521 .needed_comptime_reason = "struct fields must be comptime-known",21525 .needed_comptime_reason = "struct fields must be comptime-known",
21522 });21526 });
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);
21525 },21529 },
21526 .Enum => {21530 .Enum => {
21527 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21531 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
...@@ -21550,7 +21554,7 @@ fn zirReify(...@@ -21550,7 +21554,7 @@ fn zirReify(
21550 .needed_comptime_reason = "enum fields must be comptime-known",21554 .needed_comptime_reason = "enum fields must be comptime-known",
21551 });21555 });
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);
21554 },21558 },
21555 .Opaque => {21559 .Opaque => {
21556 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21560 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
...@@ -21581,6 +21585,7 @@ fn zirReify(...@@ -21581,6 +21585,7 @@ fn zirReify(
21581 name_strategy,21585 name_strategy,
21582 "opaque",21586 "opaque",
21583 inst,21587 inst,
21588 extra.src_line,
21584 );21589 );
21585 mod.declPtr(new_decl_index).owns_tv = true;21590 mod.declPtr(new_decl_index).owns_tv = true;
21586 errdefer mod.abortAnonDecl(new_decl_index);21591 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -21617,7 +21622,7 @@ fn zirReify(...@@ -21617,7 +21622,7 @@ fn zirReify(
21617 .needed_comptime_reason = "union fields must be comptime-known",21622 .needed_comptime_reason = "union fields must be comptime-known",
21618 });21623 });
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);
21621 },21626 },
21622 .Fn => {21627 .Fn => {
21623 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21628 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
...@@ -21719,6 +21724,7 @@ fn reifyEnum(...@@ -21719,6 +21724,7 @@ fn reifyEnum(
21719 is_exhaustive: bool,21724 is_exhaustive: bool,
21720 fields_val: Value,21725 fields_val: Value,
21721 name_strategy: Zir.Inst.NameStrategy,21726 name_strategy: Zir.Inst.NameStrategy,
21727 src_line: u32,
21722) CompileError!Air.Inst.Ref {21728) CompileError!Air.Inst.Ref {
21723 const mod = sema.mod;21729 const mod = sema.mod;
21724 const gpa = sema.gpa;21730 const gpa = sema.gpa;
...@@ -21780,6 +21786,7 @@ fn reifyEnum(...@@ -21780,6 +21786,7 @@ fn reifyEnum(
21780 name_strategy,21786 name_strategy,
21781 "enum",21787 "enum",
21782 inst,21788 inst,
21789 src_line,
21783 );21790 );
21784 mod.declPtr(new_decl_index).owns_tv = true;21791 mod.declPtr(new_decl_index).owns_tv = true;
21785 errdefer mod.abortAnonDecl(new_decl_index);21792 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -21843,6 +21850,7 @@ fn reifyUnion(...@@ -21843,6 +21850,7 @@ fn reifyUnion(
21843 opt_tag_type_val: Value,21850 opt_tag_type_val: Value,
21844 fields_val: Value,21851 fields_val: Value,
21845 name_strategy: Zir.Inst.NameStrategy,21852 name_strategy: Zir.Inst.NameStrategy,
21853 src_line: u32,
21846) CompileError!Air.Inst.Ref {21854) CompileError!Air.Inst.Ref {
21847 const mod = sema.mod;21855 const mod = sema.mod;
21848 const gpa = sema.gpa;21856 const gpa = sema.gpa;
...@@ -21926,6 +21934,7 @@ fn reifyUnion(...@@ -21926,6 +21934,7 @@ fn reifyUnion(
21926 name_strategy,21934 name_strategy,
21927 "union",21935 "union",
21928 inst,21936 inst,
21937 src_line,
21929 );21938 );
21930 mod.declPtr(new_decl_index).owns_tv = true;21939 mod.declPtr(new_decl_index).owns_tv = true;
21931 errdefer mod.abortAnonDecl(new_decl_index);21940 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -22021,7 +22030,7 @@ fn reifyUnion(...@@ -22021,7 +22030,7 @@ fn reifyUnion(
22021 }22030 }
22022 }22031 }
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);
22025 break :tag_ty .{ enum_tag_ty, false };22034 break :tag_ty .{ enum_tag_ty, false };
22026 };22035 };
22027 errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error22036 errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error
...@@ -22082,6 +22091,7 @@ fn reifyStruct(...@@ -22082,6 +22091,7 @@ fn reifyStruct(
22082 fields_val: Value,22091 fields_val: Value,
22083 name_strategy: Zir.Inst.NameStrategy,22092 name_strategy: Zir.Inst.NameStrategy,
22084 is_tuple: bool,22093 is_tuple: bool,
22094 src_line: u32,
22085) CompileError!Air.Inst.Ref {22095) CompileError!Air.Inst.Ref {
22086 const mod = sema.mod;22096 const mod = sema.mod;
22087 const gpa = sema.gpa;22097 const gpa = sema.gpa;
...@@ -22182,6 +22192,7 @@ fn reifyStruct(...@@ -22182,6 +22192,7 @@ fn reifyStruct(
22182 name_strategy,22192 name_strategy,
22183 "struct",22193 "struct",
22184 inst,22194 inst,
22195 src_line,
22185 );22196 );
22186 mod.declPtr(new_decl_index).owns_tv = true;22197 mod.declPtr(new_decl_index).owns_tv = true;
22187 errdefer mod.abortAnonDecl(new_decl_index);22198 errdefer mod.abortAnonDecl(new_decl_index);
...@@ -26903,12 +26914,12 @@ fn addSafetyCheck(...@@ -26903,12 +26914,12 @@ fn addSafetyCheck(
26903 var fail_block: Block = .{26914 var fail_block: Block = .{
26904 .parent = parent_block,26915 .parent = parent_block,
26905 .sema = sema,26916 .sema = sema,
26906 .src_decl = parent_block.src_decl,
26907 .namespace = parent_block.namespace,26917 .namespace = parent_block.namespace,
26908 .instructions = .{},26918 .instructions = .{},
26909 .inlining = parent_block.inlining,26919 .inlining = parent_block.inlining,
26910 .is_comptime = false,26920 .is_comptime = false,
26911 .src_base_inst = parent_block.src_base_inst,26921 .src_base_inst = parent_block.src_base_inst,
26922 .type_name_ctx = parent_block.type_name_ctx,
26912 };26923 };
2691326924
26914 defer fail_block.instructions.deinit(gpa);26925 defer fail_block.instructions.deinit(gpa);
...@@ -27012,12 +27023,12 @@ fn panicUnwrapError(...@@ -27012,12 +27023,12 @@ fn panicUnwrapError(
27012 var fail_block: Block = .{27023 var fail_block: Block = .{
27013 .parent = parent_block,27024 .parent = parent_block,
27014 .sema = sema,27025 .sema = sema,
27015 .src_decl = parent_block.src_decl,
27016 .namespace = parent_block.namespace,27026 .namespace = parent_block.namespace,
27017 .instructions = .{},27027 .instructions = .{},
27018 .inlining = parent_block.inlining,27028 .inlining = parent_block.inlining,
27019 .is_comptime = false,27029 .is_comptime = false,
27020 .src_base_inst = parent_block.src_base_inst,27030 .src_base_inst = parent_block.src_base_inst,
27031 .type_name_ctx = parent_block.type_name_ctx,
27021 };27032 };
2702227033
27023 defer fail_block.instructions.deinit(gpa);27034 defer fail_block.instructions.deinit(gpa);
...@@ -27129,12 +27140,12 @@ fn safetyCheckFormatted(...@@ -27129,12 +27140,12 @@ fn safetyCheckFormatted(
27129 var fail_block: Block = .{27140 var fail_block: Block = .{
27130 .parent = parent_block,27141 .parent = parent_block,
27131 .sema = sema,27142 .sema = sema,
27132 .src_decl = parent_block.src_decl,
27133 .namespace = parent_block.namespace,27143 .namespace = parent_block.namespace,
27134 .instructions = .{},27144 .instructions = .{},
27135 .inlining = parent_block.inlining,27145 .inlining = parent_block.inlining,
27136 .is_comptime = false,27146 .is_comptime = false,
27137 .src_base_inst = parent_block.src_base_inst,27147 .src_base_inst = parent_block.src_base_inst,
27148 .type_name_ctx = parent_block.type_name_ctx,
27138 };27149 };
2713927150
27140 defer fail_block.instructions.deinit(gpa);27151 defer fail_block.instructions.deinit(gpa);
...@@ -27682,7 +27693,7 @@ fn fieldCallBind(...@@ -27682,7 +27693,7 @@ fn fieldCallBind(
27682 const decl_idx = (try sema.namespaceLookup(block, src, namespace, field_name)) orelse27693 const decl_idx = (try sema.namespaceLookup(block, src, namespace, field_name)) orelse
27683 break :found_decl null;27694 break :found_decl null;
2768427695
27685 try sema.addReferencedBy(block, src, decl_idx);27696 try sema.addReferencedBy(src, decl_idx);
27686 const decl_val = try sema.analyzeDeclVal(block, src, decl_idx);27697 const decl_val = try sema.analyzeDeclVal(block, src, decl_idx);
27687 const decl_type = sema.typeOf(decl_val);27698 const decl_type = sema.typeOf(decl_val);
27688 if (mod.typeToFunc(decl_type)) |func_type| f: {27699 if (mod.typeToFunc(decl_type)) |func_type| f: {
...@@ -27838,7 +27849,7 @@ fn namespaceLookupRef(...@@ -27838,7 +27849,7 @@ fn namespaceLookupRef(
27838 decl_name: InternPool.NullTerminatedString,27849 decl_name: InternPool.NullTerminatedString,
27839) CompileError!?Air.Inst.Ref {27850) CompileError!?Air.Inst.Ref {
27840 const decl = (try sema.namespaceLookup(block, src, opt_namespace, decl_name)) orelse return null;27851 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);
27842 return try sema.analyzeDeclRef(decl);27853 return try sema.analyzeDeclRef(decl);
27843}27854}
2784427855
...@@ -31757,7 +31768,7 @@ fn analyzeDeclVal(...@@ -31757,7 +31768,7 @@ fn analyzeDeclVal(
31757 src: LazySrcLoc,31768 src: LazySrcLoc,
31758 decl_index: InternPool.DeclIndex,31769 decl_index: InternPool.DeclIndex,
31759) CompileError!Air.Inst.Ref {31770) CompileError!Air.Inst.Ref {
31760 try sema.addReferencedBy(block, src, decl_index);31771 try sema.addReferencedBy(src, decl_index);
31761 if (sema.decl_val_table.get(decl_index)) |result| {31772 if (sema.decl_val_table.get(decl_index)) |result| {
31762 return result;31773 return result;
31763 }31774 }
...@@ -31773,13 +31784,14 @@ fn analyzeDeclVal(...@@ -31773,13 +31784,14 @@ fn analyzeDeclVal(
3177331784
31774fn addReferencedBy(31785fn addReferencedBy(
31775 sema: *Sema,31786 sema: *Sema,
31776 block: *Block,
31777 src: LazySrcLoc,31787 src: LazySrcLoc,
31778 decl_index: InternPool.DeclIndex,31788 decl_index: InternPool.DeclIndex,
31779) !void {31789) !void {
31780 if (sema.mod.comp.reference_trace == 0) return;31790 if (sema.mod.comp.reference_trace == 0) return;
31781 try sema.mod.reference_table.put(sema.gpa, decl_index, .{31791 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,
31783 .src = src,31795 .src = src,
31784 });31796 });
31785}31797}
...@@ -35181,12 +35193,12 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co...@@ -35181,12 +35193,12 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
35181 var block: Block = .{35193 var block: Block = .{
35182 .parent = null,35194 .parent = null,
35183 .sema = &sema,35195 .sema = &sema,
35184 .src_decl = decl_index,
35185 .namespace = struct_type.namespace.unwrap() orelse decl.src_namespace,35196 .namespace = struct_type.namespace.unwrap() orelse decl.src_namespace,
35186 .instructions = .{},35197 .instructions = .{},
35187 .inlining = null,35198 .inlining = null,
35188 .is_comptime = true,35199 .is_comptime = true,
35189 .src_base_inst = struct_type.zir_index.unwrap().?,35200 .src_base_inst = struct_type.zir_index.unwrap().?,
35201 .type_name_ctx = decl.name,
35190 };35202 };
35191 defer assert(block.instructions.items.len == 0);35203 defer assert(block.instructions.items.len == 0);
3519235204
...@@ -36036,12 +36048,12 @@ fn semaStructFields(...@@ -36036,12 +36048,12 @@ fn semaStructFields(
36036 var block_scope: Block = .{36048 var block_scope: Block = .{
36037 .parent = null,36049 .parent = null,
36038 .sema = &sema,36050 .sema = &sema,
36039 .src_decl = decl_index,
36040 .namespace = namespace_index,36051 .namespace = namespace_index,
36041 .instructions = .{},36052 .instructions = .{},
36042 .inlining = null,36053 .inlining = null,
36043 .is_comptime = true,36054 .is_comptime = true,
36044 .src_base_inst = struct_type.zir_index.unwrap().?,36055 .src_base_inst = struct_type.zir_index.unwrap().?,
36056 .type_name_ctx = decl.name,
36045 };36057 };
36046 defer assert(block_scope.instructions.items.len == 0);36058 defer assert(block_scope.instructions.items.len == 0);
3604736059
...@@ -36247,12 +36259,12 @@ fn semaStructFieldInits(...@@ -36247,12 +36259,12 @@ fn semaStructFieldInits(
36247 var block_scope: Block = .{36259 var block_scope: Block = .{
36248 .parent = null,36260 .parent = null,
36249 .sema = &sema,36261 .sema = &sema,
36250 .src_decl = decl_index,
36251 .namespace = namespace_index,36262 .namespace = namespace_index,
36252 .instructions = .{},36263 .instructions = .{},
36253 .inlining = null,36264 .inlining = null,
36254 .is_comptime = true,36265 .is_comptime = true,
36255 .src_base_inst = struct_type.zir_index.unwrap().?,36266 .src_base_inst = struct_type.zir_index.unwrap().?,
36267 .type_name_ctx = decl.name,
36256 };36268 };
36257 defer assert(block_scope.instructions.items.len == 0);36269 defer assert(block_scope.instructions.items.len == 0);
3625836270
...@@ -36359,7 +36371,8 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36359,7 +36371,8 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36359 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;36371 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;
36360 assert(extended.opcode == .union_decl);36372 assert(extended.opcode == .union_decl);
36361 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);36373 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
36364 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {36377 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {
36365 const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);36378 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...@@ -36421,12 +36434,12 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36421 var block_scope: Block = .{36434 var block_scope: Block = .{
36422 .parent = null,36435 .parent = null,
36423 .sema = &sema,36436 .sema = &sema,
36424 .src_decl = decl_index,
36425 .namespace = union_type.namespace.unwrap().?,36437 .namespace = union_type.namespace.unwrap().?,
36426 .instructions = .{},36438 .instructions = .{},
36427 .inlining = null,36439 .inlining = null,
36428 .is_comptime = true,36440 .is_comptime = true,
36429 .src_base_inst = union_type.zir_index,36441 .src_base_inst = union_type.zir_index,
36442 .type_name_ctx = decl.name,
36430 };36443 };
36431 defer assert(block_scope.instructions.items.len == 0);36444 defer assert(block_scope.instructions.items.len == 0);
3643236445
...@@ -36711,10 +36724,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36711,10 +36724,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36711 return sema.failWithOwnedErrorMsg(&block_scope, msg);36724 return sema.failWithOwnedErrorMsg(&block_scope, msg);
36712 }36725 }
36713 } else if (enum_field_vals.count() > 0) {36726 } 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);
36715 union_type.tagTypePtr(ip).* = enum_ty;36728 union_type.tagTypePtr(ip).* = enum_ty;
36716 } else {36729 } 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);
36718 union_type.tagTypePtr(ip).* = enum_ty;36731 union_type.tagTypePtr(ip).* = enum_ty;
36719 }36732 }
36720}36733}
...@@ -36732,12 +36745,12 @@ fn generateUnionTagTypeNumbered(...@@ -36732,12 +36745,12 @@ fn generateUnionTagTypeNumbered(
36732 enum_field_names: []const InternPool.NullTerminatedString,36745 enum_field_names: []const InternPool.NullTerminatedString,
36733 enum_field_vals: []const InternPool.Index,36746 enum_field_vals: []const InternPool.Index,
36734 union_owner_decl: *Module.Decl,36747 union_owner_decl: *Module.Decl,
36748 src_line: u32,
36735) !InternPool.Index {36749) !InternPool.Index {
36736 const mod = sema.mod;36750 const mod = sema.mod;
36737 const gpa = sema.gpa;36751 const gpa = sema.gpa;
36738 const ip = &mod.intern_pool;36752 const ip = &mod.intern_pool;
3673936753
36740 const src_decl = mod.declPtr(block.src_decl);
36741 const new_decl_index = try mod.allocateNewDecl(block.namespace);36754 const new_decl_index = try mod.allocateNewDecl(block.namespace);
36742 errdefer mod.destroyDecl(new_decl_index);36755 errdefer mod.destroyDecl(new_decl_index);
36743 const fqn = try union_owner_decl.fullyQualifiedName(mod);36756 const fqn = try union_owner_decl.fullyQualifiedName(mod);
...@@ -36749,7 +36762,7 @@ fn generateUnionTagTypeNumbered(...@@ -36749,7 +36762,7 @@ fn generateUnionTagTypeNumbered(
36749 );36762 );
36750 try mod.initNewAnonDecl(36763 try mod.initNewAnonDecl(
36751 new_decl_index,36764 new_decl_index,
36752 src_decl.src_line,36765 src_line,
36753 Value.@"unreachable",36766 Value.@"unreachable",
36754 name,36767 name,
36755 );36768 );
...@@ -36782,6 +36795,7 @@ fn generateUnionTagTypeSimple(...@@ -36782,6 +36795,7 @@ fn generateUnionTagTypeSimple(
36782 block: *Block,36795 block: *Block,
36783 enum_field_names: []const InternPool.NullTerminatedString,36796 enum_field_names: []const InternPool.NullTerminatedString,
36784 union_owner_decl: *Module.Decl,36797 union_owner_decl: *Module.Decl,
36798 src_line: u32,
36785) !InternPool.Index {36799) !InternPool.Index {
36786 const mod = sema.mod;36800 const mod = sema.mod;
36787 const ip = &mod.intern_pool;36801 const ip = &mod.intern_pool;
...@@ -36789,7 +36803,6 @@ fn generateUnionTagTypeSimple(...@@ -36789,7 +36803,6 @@ fn generateUnionTagTypeSimple(
3678936803
36790 const new_decl_index = new_decl_index: {36804 const new_decl_index = new_decl_index: {
36791 const fqn = try union_owner_decl.fullyQualifiedName(mod);36805 const fqn = try union_owner_decl.fullyQualifiedName(mod);
36792 const src_decl = mod.declPtr(block.src_decl);
36793 const new_decl_index = try mod.allocateNewDecl(block.namespace);36806 const new_decl_index = try mod.allocateNewDecl(block.namespace);
36794 errdefer mod.destroyDecl(new_decl_index);36807 errdefer mod.destroyDecl(new_decl_index);
36795 const name = try ip.getOrPutStringFmt(36808 const name = try ip.getOrPutStringFmt(
...@@ -36800,7 +36813,7 @@ fn generateUnionTagTypeSimple(...@@ -36800,7 +36813,7 @@ fn generateUnionTagTypeSimple(
36800 );36813 );
36801 try mod.initNewAnonDecl(36814 try mod.initNewAnonDecl(
36802 new_decl_index,36815 new_decl_index,
36803 src_decl.src_line,36816 src_line,
36804 Value.@"unreachable",36817 Value.@"unreachable",
36805 name,36818 name,
36806 );36819 );
...@@ -36835,7 +36848,6 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {...@@ -36835,7 +36848,6 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
36835 var block: Block = .{36848 var block: Block = .{
36836 .parent = null,36849 .parent = null,
36837 .sema = sema,36850 .sema = sema,
36838 .src_decl = sema.owner_decl_index,
36839 .namespace = sema.owner_decl.src_namespace,36851 .namespace = sema.owner_decl.src_namespace,
36840 .instructions = .{},36852 .instructions = .{},
36841 .inlining = null,36853 .inlining = null,
...@@ -36853,6 +36865,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {...@@ -36853,6 +36865,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
36853 else => unreachable,36865 else => unreachable,
36854 }36866 }
36855 },36867 },
36868 .type_name_ctx = sema.owner_decl.name,
36856 };36869 };
36857 defer block.instructions.deinit(sema.gpa);36870 defer block.instructions.deinit(sema.gpa);
3685836871
...@@ -36898,7 +36911,6 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {...@@ -36898,7 +36911,6 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
36898 var block: Block = .{36911 var block: Block = .{
36899 .parent = null,36912 .parent = null,
36900 .sema = sema,36913 .sema = sema,
36901 .src_decl = sema.owner_decl_index,
36902 .namespace = sema.owner_decl.src_namespace,36914 .namespace = sema.owner_decl.src_namespace,
36903 .instructions = .{},36915 .instructions = .{},
36904 .inlining = null,36916 .inlining = null,
...@@ -36916,6 +36928,7 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {...@@ -36916,6 +36928,7 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
36916 else => unreachable,36928 else => unreachable,
36917 }36929 }
36918 },36930 },
36931 .type_name_ctx = sema.owner_decl.name,
36919 };36932 };
36920 defer block.instructions.deinit(sema.gpa);36933 defer block.instructions.deinit(sema.gpa);
3692136934
src/crash_report.zig+2-9
...@@ -81,7 +81,7 @@ fn dumpStatusReport() !void {...@@ -81,7 +81,7 @@ fn dumpStatusReport() !void {
81 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod);81 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod);
8282
83 try stderr.writeAll("Analyzing ");83 try stderr.writeAll("Analyzing ");
84 try writeFullyQualifiedDeclWithFile(mod, block.src_decl, stderr);84 try writeFilePath(file, stderr);
85 try stderr.writeAll("\n");85 try stderr.writeAll("\n");
8686
87 print_zir.renderInstructionContext(87 print_zir.renderInstructionContext(
...@@ -105,7 +105,7 @@ fn dumpStatusReport() !void {...@@ -105,7 +105,7 @@ fn dumpStatusReport() !void {
105 fba.reset();105 fba.reset();
106 try stderr.writeAll(" in ");106 try stderr.writeAll(" in ");
107 const cur_block_file, const cur_block_src_base_node = Module.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, mod);107 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);
109 try stderr.writeAll("\n > ");109 try stderr.writeAll("\n > ");
110 print_zir.renderSingleInstruction(110 print_zir.renderSingleInstruction(
111 allocator,111 allocator,
...@@ -140,13 +140,6 @@ fn writeFilePath(file: *Module.File, writer: anytype) !void {...@@ -140,13 +140,6 @@ fn writeFilePath(file: *Module.File, writer: anytype) !void {
140 try writer.writeAll(file.sub_file_path);140 try writer.writeAll(file.sub_file_path);
141}141}
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
150pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn {143pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn {
151 PanicSwitch.preDispatch();144 PanicSwitch.preDispatch();
152 @setCold(true);145 @setCold(true);
src/main.zig+3
...@@ -5965,6 +5965,7 @@ fn cmdAstCheck(...@@ -5965,6 +5965,7 @@ fn cmdAstCheck(
5965 .zir = undefined,5965 .zir = undefined,
5966 .mod = undefined,5966 .mod = undefined,
5967 .root_decl = .none,5967 .root_decl = .none,
5968 .path_digest = undefined,
5968 };5969 };
5969 if (zig_source_file) |file_name| {5970 if (zig_source_file) |file_name| {
5970 var f = fs.cwd().openFile(file_name, .{}) catch |err| {5971 var f = fs.cwd().openFile(file_name, .{}) catch |err| {
...@@ -6283,6 +6284,7 @@ fn cmdDumpZir(...@@ -6283,6 +6284,7 @@ fn cmdDumpZir(
6283 .zir = try Module.loadZirCache(gpa, f),6284 .zir = try Module.loadZirCache(gpa, f),
6284 .mod = undefined,6285 .mod = undefined,
6285 .root_decl = .none,6286 .root_decl = .none,
6287 .path_digest = undefined,
6286 };6288 };
6287 defer file.zir.deinit(gpa);6289 defer file.zir.deinit(gpa);
62886290
...@@ -6353,6 +6355,7 @@ fn cmdChangelist(...@@ -6353,6 +6355,7 @@ fn cmdChangelist(
6353 .zir = undefined,6355 .zir = undefined,
6354 .mod = undefined,6356 .mod = undefined,
6355 .root_decl = .none,6357 .root_decl = .none,
6358 .path_digest = undefined,
6356 };6359 };
63576360
6358 file.mod = try Package.Module.createLimited(arena, .{6361 file.mod = try Package.Module.createLimited(arena, .{
src/print_zir.zig+8-1
...@@ -569,7 +569,6 @@ const Writer = struct {...@@ -569,7 +569,6 @@ const Writer = struct {
569 .wasm_memory_size,569 .wasm_memory_size,
570 .int_from_error,570 .int_from_error,
571 .error_from_int,571 .error_from_int,
572 .reify,
573 .c_va_copy,572 .c_va_copy,
574 .c_va_end,573 .c_va_end,
575 .work_item_id,574 .work_item_id,
...@@ -582,6 +581,14 @@ const Writer = struct {...@@ -582,6 +581,14 @@ const Writer = struct {
582 try self.writeSrcNode(stream, inst_data.node);581 try self.writeSrcNode(stream, inst_data.node);
583 },582 },
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
585 .builtin_extern,592 .builtin_extern,
586 .c_define,593 .c_define,
587 .error_cast,594 .error_cast,