authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-08 16:52:59-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:42:30-07:00
log275652f620541919087bc92da0d2f9e97c66d3c0
tree0b19398252ef29e6b0a6c6758ac90f564a235f13
parente94a81c951905a6b5bcf2a6028589ac1e33d1edd

stage2: move opaque types to InternPool


21 files changed, 935 insertions(+), 808 deletions(-)

src/Compilation.zig+11-13
......@@ -2048,7 +2048,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
20482048 assert(decl.deletion_flag);
20492049 assert(decl.dependants.count() == 0);
20502050 const is_anon = if (decl.zir_decl_index == 0) blk: {
2051 break :blk decl.src_namespace.anon_decls.swapRemove(decl_index);
2051 break :blk module.namespacePtr(decl.src_namespace).anon_decls.swapRemove(decl_index);
20522052 } else false;
20532053
20542054 try module.clearDecl(decl_index, null);
......@@ -2530,8 +2530,7 @@ pub fn totalErrorCount(self: *Compilation) u32 {
25302530 // the previous parse success, including compile errors, but we cannot
25312531 // emit them until the file succeeds parsing.
25322532 for (module.failed_decls.keys()) |key| {
2533 const decl = module.declPtr(key);
2534 if (decl.getFileScope().okToReportErrors()) {
2533 if (module.declFileScope(key).okToReportErrors()) {
25352534 total += 1;
25362535 if (module.cimport_errors.get(key)) |errors| {
25372536 total += errors.len;
......@@ -2540,8 +2539,7 @@ pub fn totalErrorCount(self: *Compilation) u32 {
25402539 }
25412540 if (module.emit_h) |emit_h| {
25422541 for (emit_h.failed_decls.keys()) |key| {
2543 const decl = module.declPtr(key);
2544 if (decl.getFileScope().okToReportErrors()) {
2542 if (module.declFileScope(key).okToReportErrors()) {
25452543 total += 1;
25462544 }
25472545 }
......@@ -2644,10 +2642,10 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
26442642 {
26452643 var it = module.failed_decls.iterator();
26462644 while (it.next()) |entry| {
2647 const decl = module.declPtr(entry.key_ptr.*);
2645 const decl_index = entry.key_ptr.*;
26482646 // Skip errors for Decls within files that had a parse failure.
26492647 // We'll try again once parsing succeeds.
2650 if (decl.getFileScope().okToReportErrors()) {
2648 if (module.declFileScope(decl_index).okToReportErrors()) {
26512649 try addModuleErrorMsg(&bundle, entry.value_ptr.*.*);
26522650 if (module.cimport_errors.get(entry.key_ptr.*)) |cimport_errors| for (cimport_errors) |c_error| {
26532651 try bundle.addRootErrorMessage(.{
......@@ -2669,10 +2667,10 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
26692667 if (module.emit_h) |emit_h| {
26702668 var it = emit_h.failed_decls.iterator();
26712669 while (it.next()) |entry| {
2672 const decl = module.declPtr(entry.key_ptr.*);
2670 const decl_index = entry.key_ptr.*;
26732671 // Skip errors for Decls within files that had a parse failure.
26742672 // We'll try again once parsing succeeds.
2675 if (decl.getFileScope().okToReportErrors()) {
2673 if (module.declFileScope(decl_index).okToReportErrors()) {
26762674 try addModuleErrorMsg(&bundle, entry.value_ptr.*.*);
26772675 }
26782676 }
......@@ -2710,7 +2708,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
27102708 const values = module.compile_log_decls.values();
27112709 // First one will be the error; subsequent ones will be notes.
27122710 const err_decl = module.declPtr(keys[0]);
2713 const src_loc = err_decl.nodeOffsetSrcLoc(values[0]);
2711 const src_loc = err_decl.nodeOffsetSrcLoc(values[0], module);
27142712 const err_msg = Module.ErrorMsg{
27152713 .src_loc = src_loc,
27162714 .msg = "found compile log statement",
......@@ -2721,7 +2719,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
27212719 for (keys[1..], 0..) |key, i| {
27222720 const note_decl = module.declPtr(key);
27232721 err_msg.notes[i] = .{
2724 .src_loc = note_decl.nodeOffsetSrcLoc(values[i + 1]),
2722 .src_loc = note_decl.nodeOffsetSrcLoc(values[i + 1], module),
27252723 .msg = "also here",
27262724 };
27272725 }
......@@ -3235,7 +3233,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v
32353233 try module.failed_decls.ensureUnusedCapacity(gpa, 1);
32363234 module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
32373235 gpa,
3238 decl.srcLoc(),
3236 decl.srcLoc(module),
32393237 "unable to update line number: {s}",
32403238 .{@errorName(err)},
32413239 ));
......@@ -3848,7 +3846,7 @@ fn reportRetryableEmbedFileError(
38483846 const mod = comp.bin_file.options.module.?;
38493847 const gpa = mod.gpa;
38503848
3851 const src_loc: Module.SrcLoc = mod.declPtr(embed_file.owner_decl).srcLoc();
3849 const src_loc: Module.SrcLoc = mod.declPtr(embed_file.owner_decl).srcLoc(mod);
38523850
38533851 const err_msg = if (embed_file.pkg.root_src_directory.path) |dir_path|
38543852 try Module.ErrorMsg.create(
src/InternPool.zig+54-19
......@@ -17,7 +17,8 @@ const BigIntMutable = std.math.big.int.Mutable;
1717const Limb = std.math.big.Limb;
1818
1919const InternPool = @This();
20const DeclIndex = enum(u32) { _ };
20const DeclIndex = @import("Module.zig").Decl.Index;
21const NamespaceIndex = @import("Module.zig").Namespace.Index;
2122
2223const KeyAdapter = struct {
2324 intern_pool: *const InternPool,
......@@ -48,7 +49,7 @@ pub const Key = union(enum) {
4849 extern_func: struct {
4950 ty: Index,
5051 /// The Decl that corresponds to the function itself.
51 owner_decl: DeclIndex,
52 decl: DeclIndex,
5253 /// Library name if specified.
5354 /// For example `extern "c" fn write(...) usize` would have 'c' as library name.
5455 /// Index into the string table bytes.
......@@ -62,6 +63,7 @@ pub const Key = union(enum) {
6263 tag: BigIntConst,
6364 },
6465 struct_type: StructType,
66 opaque_type: OpaqueType,
6567
6668 union_type: struct {
6769 fields_len: u32,
......@@ -116,6 +118,13 @@ pub const Key = union(enum) {
116118 // TODO move Module.Struct data to InternPool
117119 };
118120
121 pub const OpaqueType = struct {
122 /// The Decl that corresponds to the opaque itself.
123 decl: DeclIndex,
124 /// Represents the declarations inside this opaque.
125 namespace: NamespaceIndex,
126 };
127
119128 pub const Int = struct {
120129 ty: Index,
121130 storage: Storage,
......@@ -221,6 +230,7 @@ pub const Key = union(enum) {
221230 _ = union_type;
222231 @panic("TODO");
223232 },
233 .opaque_type => |opaque_type| std.hash.autoHash(hasher, opaque_type.decl),
224234 }
225235 }
226236
......@@ -338,6 +348,11 @@ pub const Key = union(enum) {
338348 _ = b_info;
339349 @panic("TODO");
340350 },
351
352 .opaque_type => |a_info| {
353 const b_info = b.opaque_type;
354 return a_info.decl == b_info.decl;
355 },
341356 }
342357 }
343358
......@@ -352,6 +367,7 @@ pub const Key = union(enum) {
352367 .simple_type,
353368 .struct_type,
354369 .union_type,
370 .opaque_type,
355371 => return .type_type,
356372
357373 inline .ptr,
......@@ -770,10 +786,13 @@ pub const Tag = enum(u8) {
770786 /// are auto-numbered, and there are no declarations.
771787 /// data is payload index to `EnumSimple`.
772788 type_enum_simple,
773
774789 /// A type that can be represented with only an enum tag.
775790 /// data is SimpleType enum value.
776791 simple_type,
792 /// An opaque type.
793 /// data is index of Key.OpaqueType in extra.
794 type_opaque,
795
777796 /// A value that can be represented with only an enum tag.
778797 /// data is SimpleValue enum value.
779798 simple_value,
......@@ -986,7 +1005,7 @@ pub const ErrorUnion = struct {
9861005/// 0. field name: null-terminated string index for each fields_len; declaration order
9871006pub const EnumSimple = struct {
9881007 /// The Decl that corresponds to the enum itself.
989 owner_decl: DeclIndex,
1008 decl: DeclIndex,
9901009 /// An integer type which is used for the numerical value of the enum. This
9911010 /// is inferred by Zig to be the smallest power of two unsigned int that
9921011 /// fits the number of fields. It is stored here to avoid unnecessary
......@@ -1146,6 +1165,9 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {
11461165
11471166 .type_error_union => @panic("TODO"),
11481167 .type_enum_simple => @panic("TODO"),
1168
1169 .type_opaque => .{ .opaque_type = ip.extraData(Key.OpaqueType, data) },
1170
11491171 .simple_internal => switch (@intToEnum(SimpleInternal, data)) {
11501172 .type_empty_struct => .{ .struct_type = .{
11511173 .fields_len = 0,
......@@ -1335,6 +1357,29 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
13351357 .data = @enumToInt(simple_value),
13361358 });
13371359 },
1360
1361 .struct_type => |struct_type| {
1362 if (struct_type.fields_len != 0) {
1363 @panic("TODO"); // handle structs other than empty_struct
1364 }
1365 ip.items.appendAssumeCapacity(.{
1366 .tag = .simple_internal,
1367 .data = @enumToInt(SimpleInternal.type_empty_struct),
1368 });
1369 },
1370
1371 .union_type => |union_type| {
1372 _ = union_type;
1373 @panic("TODO");
1374 },
1375
1376 .opaque_type => |opaque_type| {
1377 ip.items.appendAssumeCapacity(.{
1378 .tag = .type_opaque,
1379 .data = try ip.addExtra(gpa, opaque_type),
1380 });
1381 },
1382
13381383 .extern_func => @panic("TODO"),
13391384
13401385 .ptr => |ptr| switch (ptr.addr) {
......@@ -1504,21 +1549,6 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
15041549 const tag: Tag = if (enum_tag.tag.positive) .enum_tag_positive else .enum_tag_negative;
15051550 try addInt(ip, gpa, enum_tag.ty, tag, enum_tag.tag.limbs);
15061551 },
1507
1508 .struct_type => |struct_type| {
1509 if (struct_type.fields_len != 0) {
1510 @panic("TODO"); // handle structs other than empty_struct
1511 }
1512 ip.items.appendAssumeCapacity(.{
1513 .tag = .simple_internal,
1514 .data = @enumToInt(SimpleInternal.type_empty_struct),
1515 });
1516 },
1517
1518 .union_type => |union_type| {
1519 _ = union_type;
1520 @panic("TODO");
1521 },
15221552 }
15231553 return @intToEnum(Index, ip.items.len - 1);
15241554}
......@@ -1548,6 +1578,8 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
15481578 ip.extra.appendAssumeCapacity(switch (field.type) {
15491579 u32 => @field(extra, field.name),
15501580 Index => @enumToInt(@field(extra, field.name)),
1581 DeclIndex => @enumToInt(@field(extra, field.name)),
1582 NamespaceIndex => @enumToInt(@field(extra, field.name)),
15511583 i32 => @bitCast(u32, @field(extra, field.name)),
15521584 Pointer.Flags => @bitCast(u32, @field(extra, field.name)),
15531585 Pointer.PackedOffset => @bitCast(u32, @field(extra, field.name)),
......@@ -1603,6 +1635,8 @@ fn extraData(ip: InternPool, comptime T: type, index: usize) T {
16031635 @field(result, field.name) = switch (field.type) {
16041636 u32 => int32,
16051637 Index => @intToEnum(Index, int32),
1638 DeclIndex => @intToEnum(DeclIndex, int32),
1639 NamespaceIndex => @intToEnum(NamespaceIndex, int32),
16061640 i32 => @bitCast(i32, int32),
16071641 Pointer.Flags => @bitCast(Pointer.Flags, int32),
16081642 Pointer.PackedOffset => @bitCast(Pointer.PackedOffset, int32),
......@@ -1824,6 +1858,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void {
18241858 .type_optional => 0,
18251859 .type_error_union => @sizeOf(ErrorUnion),
18261860 .type_enum_simple => @sizeOf(EnumSimple),
1861 .type_opaque => @sizeOf(Key.OpaqueType),
18271862 .simple_type => 0,
18281863 .simple_value => 0,
18291864 .simple_internal => 0,
src/Module.zig+239-156
......@@ -185,6 +185,11 @@ allocated_decls: std.SegmentedList(Decl, 0) = .{},
185185/// When a Decl object is freed from `allocated_decls`, it is pushed into this stack.
186186decls_free_list: ArrayListUnmanaged(Decl.Index) = .{},
187187
188/// Same pattern as with `allocated_decls`.
189allocated_namespaces: std.SegmentedList(Namespace, 0) = .{},
190/// Same pattern as with `decls_free_list`.
191namespaces_free_list: ArrayListUnmanaged(Namespace.Index) = .{},
192
188193global_assembly: std.AutoHashMapUnmanaged(Decl.Index, []u8) = .{},
189194
190195reference_table: std.AutoHashMapUnmanaged(Decl.Index, struct {
......@@ -363,7 +368,7 @@ pub const Export = struct {
363368 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {
364369 const src_decl = mod.declPtr(exp.src_decl);
365370 return .{
366 .file_scope = src_decl.getFileScope(),
371 .file_scope = src_decl.getFileScope(mod),
367372 .parent_decl_node = src_decl.src_node,
368373 .lazy = exp.src,
369374 };
......@@ -494,7 +499,7 @@ pub const Decl = struct {
494499 /// Reference to externally owned memory.
495500 /// In the case of the Decl corresponding to a file, this is
496501 /// the namespace of the struct, since there is no parent.
497 src_namespace: *Namespace,
502 src_namespace: Namespace.Index,
498503
499504 /// The scope which lexically contains this decl. A decl must depend
500505 /// on its lexical parent, in order to ensure that this pointer is valid.
......@@ -691,8 +696,8 @@ pub const Decl = struct {
691696
692697 /// This name is relative to the containing namespace of the decl.
693698 /// The memory is owned by the containing File ZIR.
694 pub fn getName(decl: Decl) ?[:0]const u8 {
695 const zir = decl.getFileScope().zir;
699 pub fn getName(decl: Decl, mod: *Module) ?[:0]const u8 {
700 const zir = decl.getFileScope(mod).zir;
696701 return decl.getNameZir(zir);
697702 }
698703
......@@ -703,8 +708,8 @@ pub const Decl = struct {
703708 return zir.nullTerminatedString(name_index);
704709 }
705710
706 pub fn contentsHash(decl: Decl) std.zig.SrcHash {
707 const zir = decl.getFileScope().zir;
711 pub fn contentsHash(decl: Decl, mod: *Module) std.zig.SrcHash {
712 const zir = decl.getFileScope(mod).zir;
708713 return decl.contentsHashZir(zir);
709714 }
710715
......@@ -715,31 +720,31 @@ pub const Decl = struct {
715720 return contents_hash;
716721 }
717722
718 pub fn zirBlockIndex(decl: *const Decl) Zir.Inst.Index {
723 pub fn zirBlockIndex(decl: *const Decl, mod: *Module) Zir.Inst.Index {
719724 assert(decl.zir_decl_index != 0);
720 const zir = decl.getFileScope().zir;
725 const zir = decl.getFileScope(mod).zir;
721726 return zir.extra[decl.zir_decl_index + 6];
722727 }
723728
724 pub fn zirAlignRef(decl: Decl) Zir.Inst.Ref {
729 pub fn zirAlignRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
725730 if (!decl.has_align) return .none;
726731 assert(decl.zir_decl_index != 0);
727 const zir = decl.getFileScope().zir;
732 const zir = decl.getFileScope(mod).zir;
728733 return @intToEnum(Zir.Inst.Ref, zir.extra[decl.zir_decl_index + 8]);
729734 }
730735
731 pub fn zirLinksectionRef(decl: Decl) Zir.Inst.Ref {
736 pub fn zirLinksectionRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
732737 if (!decl.has_linksection_or_addrspace) return .none;
733738 assert(decl.zir_decl_index != 0);
734 const zir = decl.getFileScope().zir;
739 const zir = decl.getFileScope(mod).zir;
735740 const extra_index = decl.zir_decl_index + 8 + @boolToInt(decl.has_align);
736741 return @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
737742 }
738743
739 pub fn zirAddrspaceRef(decl: Decl) Zir.Inst.Ref {
744 pub fn zirAddrspaceRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
740745 if (!decl.has_linksection_or_addrspace) return .none;
741746 assert(decl.zir_decl_index != 0);
742 const zir = decl.getFileScope().zir;
747 const zir = decl.getFileScope(mod).zir;
743748 const extra_index = decl.zir_decl_index + 8 + @boolToInt(decl.has_align) + 1;
744749 return @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
745750 }
......@@ -764,25 +769,25 @@ pub const Decl = struct {
764769 return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(node_index));
765770 }
766771
767 pub fn srcLoc(decl: Decl) SrcLoc {
768 return decl.nodeOffsetSrcLoc(0);
772 pub fn srcLoc(decl: Decl, mod: *Module) SrcLoc {
773 return decl.nodeOffsetSrcLoc(0, mod);
769774 }
770775
771 pub fn nodeOffsetSrcLoc(decl: Decl, node_offset: i32) SrcLoc {
776 pub fn nodeOffsetSrcLoc(decl: Decl, node_offset: i32, mod: *Module) SrcLoc {
772777 return .{
773 .file_scope = decl.getFileScope(),
778 .file_scope = decl.getFileScope(mod),
774779 .parent_decl_node = decl.src_node,
775780 .lazy = LazySrcLoc.nodeOffset(node_offset),
776781 };
777782 }
778783
779 pub fn srcToken(decl: Decl) Ast.TokenIndex {
780 const tree = &decl.getFileScope().tree;
784 pub fn srcToken(decl: Decl, mod: *Module) Ast.TokenIndex {
785 const tree = &decl.getFileScope(mod).tree;
781786 return tree.firstToken(decl.src_node);
782787 }
783788
784 pub fn srcByteOffset(decl: Decl) u32 {
785 const tree = &decl.getFileScope().tree;
789 pub fn srcByteOffset(decl: Decl, mod: *Module) u32 {
790 const tree = &decl.getFileScope(mod).tree;
786791 return tree.tokens.items(.start)[decl.srcToken()];
787792 }
788793
......@@ -791,12 +796,12 @@ pub const Decl = struct {
791796 if (decl.name_fully_qualified) {
792797 return writer.writeAll(unqualified_name);
793798 }
794 return decl.src_namespace.renderFullyQualifiedName(mod, unqualified_name, writer);
799 return mod.namespacePtr(decl.src_namespace).renderFullyQualifiedName(mod, unqualified_name, writer);
795800 }
796801
797802 pub fn renderFullyQualifiedDebugName(decl: Decl, mod: *Module, writer: anytype) !void {
798803 const unqualified_name = mem.sliceTo(decl.name, 0);
799 return decl.src_namespace.renderFullyQualifiedDebugName(mod, unqualified_name, writer);
804 return mod.namespacePtr(decl.src_namespace).renderFullyQualifiedDebugName(mod, unqualified_name, writer);
800805 }
801806
802807 pub fn getFullyQualifiedName(decl: Decl, mod: *Module) ![:0]u8 {
......@@ -877,32 +882,39 @@ pub const Decl = struct {
877882 /// Gets the namespace that this Decl creates by being a struct, union,
878883 /// enum, or opaque.
879884 /// Only returns it if the Decl is the owner.
880 pub fn getInnerNamespace(decl: *Decl) ?*Namespace {
881 if (!decl.owns_tv) return null;
882 const ty = (decl.val.castTag(.ty) orelse return null).data;
883 switch (ty.tag()) {
884 .@"struct" => {
885 const struct_obj = ty.castTag(.@"struct").?.data;
886 return &struct_obj.namespace;
887 },
888 .enum_full, .enum_nonexhaustive => {
889 const enum_obj = ty.cast(Type.Payload.EnumFull).?.data;
890 return &enum_obj.namespace;
891 },
892 .empty_struct => {
893 return ty.castTag(.empty_struct).?.data;
894 },
895 .@"opaque" => {
896 const opaque_obj = ty.cast(Type.Payload.Opaque).?.data;
897 return &opaque_obj.namespace;
898 },
899 .@"union", .union_safety_tagged, .union_tagged => {
900 const union_obj = ty.cast(Type.Payload.Union).?.data;
901 return &union_obj.namespace;
902 },
885 pub fn getInnerNamespaceIndex(decl: *Decl, mod: *Module) Namespace.OptionalIndex {
886 if (!decl.owns_tv) return .none;
887 if (decl.val.ip_index == .none) {
888 const ty = (decl.val.castTag(.ty) orelse return .none).data;
889 switch (ty.tag()) {
890 .@"struct" => {
891 const struct_obj = ty.castTag(.@"struct").?.data;
892 return struct_obj.namespace.toOptional();
893 },
894 .enum_full, .enum_nonexhaustive => {
895 const enum_obj = ty.cast(Type.Payload.EnumFull).?.data;
896 return enum_obj.namespace.toOptional();
897 },
898 .empty_struct => {
899 @panic("TODO");
900 },
901 .@"union", .union_safety_tagged, .union_tagged => {
902 const union_obj = ty.cast(Type.Payload.Union).?.data;
903 return union_obj.namespace.toOptional();
904 },
903905
904 else => return null,
906 else => return .none,
907 }
905908 }
909 return switch (mod.intern_pool.indexToKey(decl.val.ip_index)) {
910 .opaque_type => |opaque_type| opaque_type.namespace.toOptional(),
911 else => .none,
912 };
913 }
914
915 /// Same as `getInnerNamespaceIndex` but additionally obtains the pointer.
916 pub fn getInnerNamespace(decl: *Decl, mod: *Module) ?*Namespace {
917 return if (getInnerNamespaceIndex(decl, mod).unwrap()) |i| mod.namespacePtr(i) else null;
906918 }
907919
908920 pub fn dump(decl: *Decl) void {
......@@ -920,8 +932,8 @@ pub const Decl = struct {
920932 std.debug.print("\n", .{});
921933 }
922934
923 pub fn getFileScope(decl: Decl) *File {
924 return decl.src_namespace.file_scope;
935 pub fn getFileScope(decl: Decl, mod: *Module) *File {
936 return mod.namespacePtr(decl.src_namespace).file_scope;
925937 }
926938
927939 pub fn removeDependant(decl: *Decl, other: Decl.Index) void {
......@@ -974,7 +986,7 @@ pub const ErrorSet = struct {
974986 pub fn srcLoc(self: ErrorSet, mod: *Module) SrcLoc {
975987 const owner_decl = mod.declPtr(self.owner_decl);
976988 return .{
977 .file_scope = owner_decl.getFileScope(),
989 .file_scope = owner_decl.getFileScope(mod),
978990 .parent_decl_node = owner_decl.src_node,
979991 .lazy = LazySrcLoc.nodeOffset(0),
980992 };
......@@ -1000,7 +1012,7 @@ pub const Struct = struct {
10001012 /// Set of field names in declaration order.
10011013 fields: Fields,
10021014 /// Represents the declarations inside this struct.
1003 namespace: Namespace,
1015 namespace: Namespace.Index,
10041016 /// The Decl that corresponds to the struct itself.
10051017 owner_decl: Decl.Index,
10061018 /// Index of the struct_decl ZIR instruction.
......@@ -1101,7 +1113,7 @@ pub const Struct = struct {
11011113 pub fn srcLoc(s: Struct, mod: *Module) SrcLoc {
11021114 const owner_decl = mod.declPtr(s.owner_decl);
11031115 return .{
1104 .file_scope = owner_decl.getFileScope(),
1116 .file_scope = owner_decl.getFileScope(mod),
11051117 .parent_decl_node = owner_decl.src_node,
11061118 .lazy = LazySrcLoc.nodeOffset(0),
11071119 };
......@@ -1110,7 +1122,7 @@ pub const Struct = struct {
11101122 pub fn fieldSrcLoc(s: Struct, mod: *Module, query: FieldSrcQuery) SrcLoc {
11111123 @setCold(true);
11121124 const owner_decl = mod.declPtr(s.owner_decl);
1113 const file = owner_decl.getFileScope();
1125 const file = owner_decl.getFileScope(mod);
11141126 const tree = file.getTree(mod.gpa) catch |err| {
11151127 // In this case we emit a warning + a less precise source location.
11161128 log.warn("unable to load {s}: {s}", .{
......@@ -1224,7 +1236,7 @@ pub const EnumSimple = struct {
12241236 pub fn srcLoc(self: EnumSimple, mod: *Module) SrcLoc {
12251237 const owner_decl = mod.declPtr(self.owner_decl);
12261238 return .{
1227 .file_scope = owner_decl.getFileScope(),
1239 .file_scope = owner_decl.getFileScope(mod),
12281240 .parent_decl_node = owner_decl.src_node,
12291241 .lazy = LazySrcLoc.nodeOffset(0),
12301242 };
......@@ -1253,7 +1265,7 @@ pub const EnumNumbered = struct {
12531265 pub fn srcLoc(self: EnumNumbered, mod: *Module) SrcLoc {
12541266 const owner_decl = mod.declPtr(self.owner_decl);
12551267 return .{
1256 .file_scope = owner_decl.getFileScope(),
1268 .file_scope = owner_decl.getFileScope(mod),
12571269 .parent_decl_node = owner_decl.src_node,
12581270 .lazy = LazySrcLoc.nodeOffset(0),
12591271 };
......@@ -1275,7 +1287,7 @@ pub const EnumFull = struct {
12751287 /// If this hash map is empty, it means the enum tags are auto-numbered.
12761288 values: ValueMap,
12771289 /// Represents the declarations inside this enum.
1278 namespace: Namespace,
1290 namespace: Namespace.Index,
12791291 /// true if zig inferred this tag type, false if user specified it
12801292 tag_ty_inferred: bool,
12811293
......@@ -1285,7 +1297,7 @@ pub const EnumFull = struct {
12851297 pub fn srcLoc(self: EnumFull, mod: *Module) SrcLoc {
12861298 const owner_decl = mod.declPtr(self.owner_decl);
12871299 return .{
1288 .file_scope = owner_decl.getFileScope(),
1300 .file_scope = owner_decl.getFileScope(mod),
12891301 .parent_decl_node = owner_decl.src_node,
12901302 .lazy = LazySrcLoc.nodeOffset(0),
12911303 };
......@@ -1294,7 +1306,7 @@ pub const EnumFull = struct {
12941306 pub fn fieldSrcLoc(e: EnumFull, mod: *Module, query: FieldSrcQuery) SrcLoc {
12951307 @setCold(true);
12961308 const owner_decl = mod.declPtr(e.owner_decl);
1297 const file = owner_decl.getFileScope();
1309 const file = owner_decl.getFileScope(mod);
12981310 const tree = file.getTree(mod.gpa) catch |err| {
12991311 // In this case we emit a warning + a less precise source location.
13001312 log.warn("unable to load {s}: {s}", .{
......@@ -1323,7 +1335,7 @@ pub const Union = struct {
13231335 /// Set of field names in declaration order.
13241336 fields: Fields,
13251337 /// Represents the declarations inside this union.
1326 namespace: Namespace,
1338 namespace: Namespace.Index,
13271339 /// The Decl that corresponds to the union itself.
13281340 owner_decl: Decl.Index,
13291341 /// Index of the union_decl ZIR instruction.
......@@ -1371,7 +1383,7 @@ pub const Union = struct {
13711383 pub fn srcLoc(self: Union, mod: *Module) SrcLoc {
13721384 const owner_decl = mod.declPtr(self.owner_decl);
13731385 return .{
1374 .file_scope = owner_decl.getFileScope(),
1386 .file_scope = owner_decl.getFileScope(mod),
13751387 .parent_decl_node = owner_decl.src_node,
13761388 .lazy = LazySrcLoc.nodeOffset(0),
13771389 };
......@@ -1380,7 +1392,7 @@ pub const Union = struct {
13801392 pub fn fieldSrcLoc(u: Union, mod: *Module, query: FieldSrcQuery) SrcLoc {
13811393 @setCold(true);
13821394 const owner_decl = mod.declPtr(u.owner_decl);
1383 const file = owner_decl.getFileScope();
1395 const file = owner_decl.getFileScope(mod);
13841396 const tree = file.getTree(mod.gpa) catch |err| {
13851397 // In this case we emit a warning + a less precise source location.
13861398 log.warn("unable to load {s}: {s}", .{
......@@ -1563,26 +1575,6 @@ pub const Union = struct {
15631575 }
15641576};
15651577
1566pub const Opaque = struct {
1567 /// The Decl that corresponds to the opaque itself.
1568 owner_decl: Decl.Index,
1569 /// Represents the declarations inside this opaque.
1570 namespace: Namespace,
1571
1572 pub fn srcLoc(self: Opaque, mod: *Module) SrcLoc {
1573 const owner_decl = mod.declPtr(self.owner_decl);
1574 return .{
1575 .file_scope = owner_decl.getFileScope(),
1576 .parent_decl_node = owner_decl.src_node,
1577 .lazy = LazySrcLoc.nodeOffset(0),
1578 };
1579 }
1580
1581 pub fn getFullyQualifiedName(s: *Opaque, mod: *Module) ![:0]u8 {
1582 return mod.declPtr(s.owner_decl).getFullyQualifiedName(mod);
1583 }
1584};
1585
15861578/// Some extern function struct memory is owned by the Decl's TypedValue.Managed
15871579/// arena allocator.
15881580pub const ExternFn = struct {
......@@ -1759,7 +1751,7 @@ pub const Fn = struct {
17591751 }
17601752
17611753 pub fn isAnytypeParam(func: Fn, mod: *Module, index: u32) bool {
1762 const file = mod.declPtr(func.owner_decl).getFileScope();
1754 const file = mod.declPtr(func.owner_decl).getFileScope(mod);
17631755
17641756 const tags = file.zir.instructions.items(.tag);
17651757
......@@ -1774,7 +1766,7 @@ pub const Fn = struct {
17741766 }
17751767
17761768 pub fn getParamName(func: Fn, mod: *Module, index: u32) [:0]const u8 {
1777 const file = mod.declPtr(func.owner_decl).getFileScope();
1769 const file = mod.declPtr(func.owner_decl).getFileScope(mod);
17781770
17791771 const tags = file.zir.instructions.items(.tag);
17801772 const data = file.zir.instructions.items(.data);
......@@ -1797,7 +1789,7 @@ pub const Fn = struct {
17971789
17981790 pub fn hasInferredErrorSet(func: Fn, mod: *Module) bool {
17991791 const owner_decl = mod.declPtr(func.owner_decl);
1800 const zir = owner_decl.getFileScope().zir;
1792 const zir = owner_decl.getFileScope(mod).zir;
18011793 const zir_tags = zir.instructions.items(.tag);
18021794 switch (zir_tags[func.zir_body_inst]) {
18031795 .func => return false,
......@@ -1851,7 +1843,7 @@ pub const DeclAdapter = struct {
18511843
18521844/// The container that structs, enums, unions, and opaques have.
18531845pub const Namespace = struct {
1854 parent: ?*Namespace,
1846 parent: OptionalIndex,
18551847 file_scope: *File,
18561848 /// Will be a struct, enum, union, or opaque.
18571849 ty: Type,
......@@ -1869,6 +1861,28 @@ pub const Namespace = struct {
18691861 /// Value is whether the usingnamespace decl is marked `pub`.
18701862 usingnamespace_set: std.AutoHashMapUnmanaged(Decl.Index, bool) = .{},
18711863
1864 pub const Index = enum(u32) {
1865 _,
1866
1867 pub fn toOptional(i: Index) OptionalIndex {
1868 return @intToEnum(OptionalIndex, @enumToInt(i));
1869 }
1870 };
1871
1872 pub const OptionalIndex = enum(u32) {
1873 none = std.math.maxInt(u32),
1874 _,
1875
1876 pub fn init(oi: ?Index) OptionalIndex {
1877 return @intToEnum(OptionalIndex, @enumToInt(oi orelse return .none));
1878 }
1879
1880 pub fn unwrap(oi: OptionalIndex) ?Index {
1881 if (oi == .none) return null;
1882 return @intToEnum(Index, @enumToInt(oi));
1883 }
1884 };
1885
18721886 const DeclContext = struct {
18731887 module: *Module,
18741888
......@@ -1955,10 +1969,10 @@ pub const Namespace = struct {
19551969 name: []const u8,
19561970 writer: anytype,
19571971 ) @TypeOf(writer).Error!void {
1958 if (ns.parent) |parent| {
1959 const decl_index = ns.getDeclIndex();
1972 if (ns.parent.unwrap()) |parent| {
1973 const decl_index = ns.getDeclIndex(mod);
19601974 const decl = mod.declPtr(decl_index);
1961 try parent.renderFullyQualifiedName(mod, mem.sliceTo(decl.name, 0), writer);
1975 try mod.namespacePtr(parent).renderFullyQualifiedName(mod, mem.sliceTo(decl.name, 0), writer);
19621976 } else {
19631977 try ns.file_scope.renderFullyQualifiedName(writer);
19641978 }
......@@ -1976,10 +1990,10 @@ pub const Namespace = struct {
19761990 writer: anytype,
19771991 ) @TypeOf(writer).Error!void {
19781992 var separator_char: u8 = '.';
1979 if (ns.parent) |parent| {
1980 const decl_index = ns.getDeclIndex();
1993 if (ns.parent.unwrap()) |parent| {
1994 const decl_index = ns.getDeclIndex(mod);
19811995 const decl = mod.declPtr(decl_index);
1982 try parent.renderFullyQualifiedDebugName(mod, mem.sliceTo(decl.name, 0), writer);
1996 try mod.namespacePtr(parent).renderFullyQualifiedDebugName(mod, mem.sliceTo(decl.name, 0), writer);
19831997 } else {
19841998 try ns.file_scope.renderFullyQualifiedDebugName(writer);
19851999 separator_char = ':';
......@@ -1990,8 +2004,8 @@ pub const Namespace = struct {
19902004 }
19912005 }
19922006
1993 pub fn getDeclIndex(ns: Namespace) Decl.Index {
1994 return ns.ty.getOwnerDecl();
2007 pub fn getDeclIndex(ns: Namespace, mod: *Module) Decl.Index {
2008 return ns.ty.getOwnerDecl(mod);
19952009 }
19962010};
19972011
......@@ -3320,7 +3334,7 @@ pub const LazySrcLoc = union(enum) {
33203334 }
33213335
33223336 /// Upgrade to a `SrcLoc` based on the `Decl` provided.
3323 pub fn toSrcLoc(lazy: LazySrcLoc, decl: *Decl) SrcLoc {
3337 pub fn toSrcLoc(lazy: LazySrcLoc, decl: *Decl, mod: *Module) SrcLoc {
33243338 return switch (lazy) {
33253339 .unneeded,
33263340 .entire_file,
......@@ -3328,7 +3342,7 @@ pub const LazySrcLoc = union(enum) {
33283342 .token_abs,
33293343 .node_abs,
33303344 => .{
3331 .file_scope = decl.getFileScope(),
3345 .file_scope = decl.getFileScope(mod),
33323346 .parent_decl_node = 0,
33333347 .lazy = lazy,
33343348 },
......@@ -3394,7 +3408,7 @@ pub const LazySrcLoc = union(enum) {
33943408 .for_input,
33953409 .for_capture_from_input,
33963410 => .{
3397 .file_scope = decl.getFileScope(),
3411 .file_scope = decl.getFileScope(mod),
33983412 .parent_decl_node = decl.src_node,
33993413 .lazy = lazy,
34003414 },
......@@ -3555,6 +3569,9 @@ pub fn deinit(mod: *Module) void {
35553569 mod.global_assembly.deinit(gpa);
35563570 mod.reference_table.deinit(gpa);
35573571
3572 mod.namespaces_free_list.deinit(gpa);
3573 mod.allocated_namespaces.deinit(gpa);
3574
35583575 mod.string_literal_table.deinit(gpa);
35593576 mod.string_literal_bytes.deinit(gpa);
35603577
......@@ -3575,8 +3592,9 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {
35753592 gpa.free(kv.value);
35763593 }
35773594 if (decl.has_tv) {
3578 if (decl.getInnerNamespace()) |namespace| {
3579 namespace.destroyDecls(mod);
3595 if (decl.getInnerNamespaceIndex(mod).unwrap()) |i| {
3596 mod.namespacePtr(i).destroyDecls(mod);
3597 mod.destroyNamespace(i);
35803598 }
35813599 }
35823600 decl.clearValues(mod);
......@@ -3596,16 +3614,21 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {
35963614 }
35973615}
35983616
3599pub fn declPtr(mod: *Module, decl_index: Decl.Index) *Decl {
3600 return mod.allocated_decls.at(@enumToInt(decl_index));
3617pub fn declPtr(mod: *Module, index: Decl.Index) *Decl {
3618 return mod.allocated_decls.at(@enumToInt(index));
3619}
3620
3621pub fn namespacePtr(mod: *Module, index: Namespace.Index) *Namespace {
3622 return mod.allocated_namespaces.at(@enumToInt(index));
36013623}
36023624
36033625/// Returns true if and only if the Decl is the top level struct associated with a File.
36043626pub fn declIsRoot(mod: *Module, decl_index: Decl.Index) bool {
36053627 const decl = mod.declPtr(decl_index);
3606 if (decl.src_namespace.parent != null)
3628 const namespace = mod.namespacePtr(decl.src_namespace);
3629 if (namespace.parent != .none)
36073630 return false;
3608 return decl_index == decl.src_namespace.getDeclIndex();
3631 return decl_index == namespace.getDeclIndex(mod);
36093632}
36103633
36113634fn freeExportList(gpa: Allocator, export_list: *ArrayListUnmanaged(*Export)) void {
......@@ -4076,7 +4099,7 @@ fn updateZirRefs(mod: *Module, file: *File, old_zir: Zir) !void {
40764099 };
40774100 }
40784101
4079 if (decl.getInnerNamespace()) |namespace| {
4102 if (decl.getInnerNamespace(mod)) |namespace| {
40804103 for (namespace.decls.keys()) |sub_decl| {
40814104 try decl_stack.append(gpa, sub_decl);
40824105 }
......@@ -4306,7 +4329,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
43064329 try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1);
43074330 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
43084331 mod.gpa,
4309 decl.srcLoc(),
4332 decl.srcLoc(mod),
43104333 "unable to analyze: {s}",
43114334 .{@errorName(e)},
43124335 ));
......@@ -4437,7 +4460,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void {
44374460 decl_index,
44384461 try Module.ErrorMsg.create(
44394462 gpa,
4440 decl.srcLoc(),
4463 decl.srcLoc(mod),
44414464 "invalid liveness: {s}",
44424465 .{@errorName(err)},
44434466 ),
......@@ -4460,7 +4483,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void {
44604483 try mod.failed_decls.ensureUnusedCapacity(gpa, 1);
44614484 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
44624485 gpa,
4463 decl.srcLoc(),
4486 decl.srcLoc(mod),
44644487 "unable to codegen: {s}",
44654488 .{@errorName(err)},
44664489 ));
......@@ -4586,13 +4609,13 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
45864609 .status = .none,
45874610 .known_non_opv = undefined,
45884611 .is_tuple = undefined, // set below
4589 .namespace = .{
4590 .parent = null,
4612 .namespace = try mod.createNamespace(.{
4613 .parent = .none,
45914614 .ty = struct_ty,
45924615 .file_scope = file,
4593 },
4616 }),
45944617 };
4595 const new_decl_index = try mod.allocateNewDecl(&struct_obj.namespace, 0, null);
4618 const new_decl_index = try mod.allocateNewDecl(struct_obj.namespace, 0, null);
45964619 const new_decl = mod.declPtr(new_decl_index);
45974620 file.root_decl = new_decl_index.toOptional();
45984621 struct_obj.owner_decl = new_decl_index;
......@@ -4688,12 +4711,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
46884711
46894712 const decl = mod.declPtr(decl_index);
46904713
4691 if (decl.getFileScope().status != .success_zir) {
4714 if (decl.getFileScope(mod).status != .success_zir) {
46924715 return error.AnalysisFail;
46934716 }
46944717
46954718 const gpa = mod.gpa;
4696 const zir = decl.getFileScope().zir;
4719 const zir = decl.getFileScope(mod).zir;
46974720 const zir_datas = zir.instructions.items(.data);
46984721
46994722 decl.analysis = .in_progress;
......@@ -4767,7 +4790,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
47674790 block_scope.params.deinit(gpa);
47684791 }
47694792
4770 const zir_block_index = decl.zirBlockIndex();
4793 const zir_block_index = decl.zirBlockIndex(mod);
47714794 const inst_data = zir_datas[zir_block_index].pl_node;
47724795 const extra = zir.extraData(Zir.Inst.Block, inst_data.payload_index);
47734796 const body = zir.extra[extra.end..][0..extra.data.body_len];
......@@ -4792,7 +4815,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
47924815 });
47934816 }
47944817 const ty = try decl_tv.val.toType().copy(decl_arena_allocator);
4795 if (ty.getNamespace() == null) {
4818 if (ty.getNamespace(mod) == null) {
47964819 return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)});
47974820 }
47984821
......@@ -4895,12 +4918,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
48954918 decl.ty = try decl_tv.ty.copy(decl_arena_allocator);
48964919 decl.val = try decl_tv.val.copy(decl_arena_allocator);
48974920 decl.@"align" = blk: {
4898 const align_ref = decl.zirAlignRef();
4921 const align_ref = decl.zirAlignRef(mod);
48994922 if (align_ref == .none) break :blk 0;
49004923 break :blk try sema.resolveAlign(&block_scope, align_src, align_ref);
49014924 };
49024925 decl.@"linksection" = blk: {
4903 const linksection_ref = decl.zirLinksectionRef();
4926 const linksection_ref = decl.zirLinksectionRef(mod);
49044927 if (linksection_ref == .none) break :blk null;
49054928 const bytes = try sema.resolveConstString(&block_scope, section_src, linksection_ref, "linksection must be comptime-known");
49064929 if (mem.indexOfScalar(u8, bytes, 0) != null) {
......@@ -4921,7 +4944,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
49214944 };
49224945
49234946 const target = sema.mod.getTarget();
4924 break :blk switch (decl.zirAddrspaceRef()) {
4947 break :blk switch (decl.zirAddrspaceRef(mod)) {
49254948 .none => switch (addrspace_ctx) {
49264949 .function => target_util.defaultAddressSpace(target, .function),
49274950 .variable => target_util.defaultAddressSpace(target, .global_mutable),
......@@ -5273,7 +5296,7 @@ pub fn detectEmbedFileUpdate(mod: *Module, embed_file: *EmbedFile) !void {
52735296
52745297pub fn scanNamespace(
52755298 mod: *Module,
5276 namespace: *Namespace,
5299 namespace_index: Namespace.Index,
52775300 extra_start: usize,
52785301 decls_len: u32,
52795302 parent_decl: *Decl,
......@@ -5282,6 +5305,7 @@ pub fn scanNamespace(
52825305 defer tracy.end();
52835306
52845307 const gpa = mod.gpa;
5308 const namespace = mod.namespacePtr(namespace_index);
52855309 const zir = namespace.file_scope.zir;
52865310
52875311 try mod.comp.work_queue.ensureUnusedCapacity(decls_len);
......@@ -5294,7 +5318,7 @@ pub fn scanNamespace(
52945318 var decl_i: u32 = 0;
52955319 var scan_decl_iter: ScanDeclIter = .{
52965320 .module = mod,
5297 .namespace = namespace,
5321 .namespace_index = namespace_index,
52985322 .parent_decl = parent_decl,
52995323 };
53005324 while (decl_i < decls_len) : (decl_i += 1) {
......@@ -5317,7 +5341,7 @@ pub fn scanNamespace(
53175341
53185342const ScanDeclIter = struct {
53195343 module: *Module,
5320 namespace: *Namespace,
5344 namespace_index: Namespace.Index,
53215345 parent_decl: *Decl,
53225346 usingnamespace_index: usize = 0,
53235347 comptime_index: usize = 0,
......@@ -5329,7 +5353,8 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
53295353 defer tracy.end();
53305354
53315355 const mod = iter.module;
5332 const namespace = iter.namespace;
5356 const namespace_index = iter.namespace_index;
5357 const namespace = mod.namespacePtr(namespace_index);
53335358 const gpa = mod.gpa;
53345359 const zir = namespace.file_scope.zir;
53355360
......@@ -5404,7 +5429,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
54045429 );
54055430 const comp = mod.comp;
54065431 if (!gop.found_existing) {
5407 const new_decl_index = try mod.allocateNewDecl(namespace, decl_node, iter.parent_decl.src_scope);
5432 const new_decl_index = try mod.allocateNewDecl(namespace_index, decl_node, iter.parent_decl.src_scope);
54085433 const new_decl = mod.declPtr(new_decl_index);
54095434 new_decl.kind = kind;
54105435 new_decl.name = decl_name;
......@@ -5456,7 +5481,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
54565481 const decl = mod.declPtr(decl_index);
54575482 if (kind == .@"test") {
54585483 const src_loc = SrcLoc{
5459 .file_scope = decl.getFileScope(),
5484 .file_scope = decl.getFileScope(mod),
54605485 .parent_decl_node = decl.src_node,
54615486 .lazy = .{ .token_offset = 1 },
54625487 };
......@@ -5564,7 +5589,7 @@ pub fn clearDecl(
55645589 if (decl.ty.isFnOrHasRuntimeBits(mod)) {
55655590 mod.comp.bin_file.freeDecl(decl_index);
55665591 }
5567 if (decl.getInnerNamespace()) |namespace| {
5592 if (decl.getInnerNamespace(mod)) |namespace| {
55685593 try namespace.deleteAllDecls(mod, outdated_decls);
55695594 }
55705595 }
......@@ -5584,7 +5609,7 @@ pub fn deleteUnusedDecl(mod: *Module, decl_index: Decl.Index) void {
55845609 log.debug("deleteUnusedDecl {d} ({s})", .{ decl_index, decl.name });
55855610
55865611 assert(!mod.declIsRoot(decl_index));
5587 assert(decl.src_namespace.anon_decls.swapRemove(decl_index));
5612 assert(mod.namespacePtr(decl.src_namespace).anon_decls.swapRemove(decl_index));
55885613
55895614 const dependants = decl.dependants.keys();
55905615 for (dependants) |dep| {
......@@ -5612,7 +5637,7 @@ pub fn abortAnonDecl(mod: *Module, decl_index: Decl.Index) void {
56125637 log.debug("abortAnonDecl {*} ({s})", .{ decl, decl.name });
56135638
56145639 assert(!mod.declIsRoot(decl_index));
5615 assert(decl.src_namespace.anon_decls.swapRemove(decl_index));
5640 assert(mod.namespacePtr(decl.src_namespace).anon_decls.swapRemove(decl_index));
56165641
56175642 // An aborted decl must not have dependants -- they must have
56185643 // been aborted first and removed from this list.
......@@ -5689,7 +5714,7 @@ pub fn analyzeFnBody(mod: *Module, func: *Fn, arena: Allocator) SemaError!Air {
56895714 .gpa = gpa,
56905715 .arena = arena,
56915716 .perm_arena = decl_arena_allocator,
5692 .code = decl.getFileScope().zir,
5717 .code = decl.getFileScope(mod).zir,
56935718 .owner_decl = decl,
56945719 .owner_decl_index = decl_index,
56955720 .func = func,
......@@ -5920,9 +5945,34 @@ fn markOutdatedDecl(mod: *Module, decl_index: Decl.Index) !void {
59205945 decl.analysis = .outdated;
59215946}
59225947
5948pub const CreateNamespaceOptions = struct {
5949 parent: Namespace.OptionalIndex,
5950 file_scope: *File,
5951 ty: Type,
5952};
5953
5954pub fn createNamespace(mod: *Module, options: CreateNamespaceOptions) !Namespace.Index {
5955 if (mod.namespaces_free_list.popOrNull()) |index| return index;
5956 const ptr = try mod.allocated_namespaces.addOne(mod.gpa);
5957 ptr.* = .{
5958 .parent = options.parent,
5959 .file_scope = options.file_scope,
5960 .ty = options.ty,
5961 };
5962 return @intToEnum(Namespace.Index, mod.allocated_namespaces.len - 1);
5963}
5964
5965pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void {
5966 mod.namespacePtr(index).* = undefined;
5967 mod.namespaces_free_list.append(mod.gpa, index) catch {
5968 // In order to keep `destroyNamespace` a non-fallible function, we ignore memory
5969 // allocation failures here, instead leaking the Namespace until garbage collection.
5970 };
5971}
5972
59235973pub fn allocateNewDecl(
59245974 mod: *Module,
5925 namespace: *Namespace,
5975 namespace: Namespace.Index,
59265976 src_node: Ast.Node.Index,
59275977 src_scope: ?*CaptureScope,
59285978) !Decl.Index {
......@@ -6004,7 +6054,7 @@ pub fn createAnonymousDecl(mod: *Module, block: *Sema.Block, typed_value: TypedV
60046054pub fn createAnonymousDeclFromDecl(
60056055 mod: *Module,
60066056 src_decl: *Decl,
6007 namespace: *Namespace,
6057 namespace: Namespace.Index,
60086058 src_scope: ?*CaptureScope,
60096059 tv: TypedValue,
60106060) !Decl.Index {
......@@ -6022,7 +6072,7 @@ pub fn initNewAnonDecl(
60226072 mod: *Module,
60236073 new_decl_index: Decl.Index,
60246074 src_line: u32,
6025 namespace: *Namespace,
6075 namespace: Namespace.Index,
60266076 typed_value: TypedValue,
60276077 name: [:0]u8,
60286078) !void {
......@@ -6040,7 +6090,7 @@ pub fn initNewAnonDecl(
60406090 new_decl.analysis = .complete;
60416091 new_decl.generation = mod.generation;
60426092
6043 try namespace.anon_decls.putNoClobber(mod.gpa, new_decl_index, {});
6093 try mod.namespacePtr(namespace).anon_decls.putNoClobber(mod.gpa, new_decl_index, {});
60446094
60456095 // The Decl starts off with alive=false and the codegen backend will set alive=true
60466096 // if the Decl is referenced by an instruction or another constant. Otherwise,
......@@ -6110,16 +6160,17 @@ pub const SwitchProngSrc = union(enum) {
61106160 /// the LazySrcLoc in order to emit a compile error.
61116161 pub fn resolve(
61126162 prong_src: SwitchProngSrc,
6113 gpa: Allocator,
6163 mod: *Module,
61146164 decl: *Decl,
61156165 switch_node_offset: i32,
61166166 range_expand: RangeExpand,
61176167 ) LazySrcLoc {
61186168 @setCold(true);
6119 const tree = decl.getFileScope().getTree(gpa) catch |err| {
6169 const gpa = mod.gpa;
6170 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
61206171 // In this case we emit a warning + a less precise source location.
61216172 log.warn("unable to load {s}: {s}", .{
6122 decl.getFileScope().sub_file_path, @errorName(err),
6173 decl.getFileScope(mod).sub_file_path, @errorName(err),
61236174 });
61246175 return LazySrcLoc.nodeOffset(0);
61256176 };
......@@ -6203,11 +6254,12 @@ pub const PeerTypeCandidateSrc = union(enum) {
62036254
62046255 pub fn resolve(
62056256 self: PeerTypeCandidateSrc,
6206 gpa: Allocator,
6257 mod: *Module,
62076258 decl: *Decl,
62086259 candidate_i: usize,
62096260 ) ?LazySrcLoc {
62106261 @setCold(true);
6262 const gpa = mod.gpa;
62116263
62126264 switch (self) {
62136265 .none => {
......@@ -6229,10 +6281,10 @@ pub const PeerTypeCandidateSrc = union(enum) {
62296281 else => {},
62306282 }
62316283
6232 const tree = decl.getFileScope().getTree(gpa) catch |err| {
6284 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
62336285 // In this case we emit a warning + a less precise source location.
62346286 log.warn("unable to load {s}: {s}", .{
6235 decl.getFileScope().sub_file_path, @errorName(err),
6287 decl.getFileScope(mod).sub_file_path, @errorName(err),
62366288 });
62376289 return LazySrcLoc.nodeOffset(0);
62386290 };
......@@ -6291,15 +6343,16 @@ fn queryFieldSrc(
62916343
62926344pub fn paramSrc(
62936345 func_node_offset: i32,
6294 gpa: Allocator,
6346 mod: *Module,
62956347 decl: *Decl,
62966348 param_i: usize,
62976349) LazySrcLoc {
62986350 @setCold(true);
6299 const tree = decl.getFileScope().getTree(gpa) catch |err| {
6351 const gpa = mod.gpa;
6352 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
63006353 // In this case we emit a warning + a less precise source location.
63016354 log.warn("unable to load {s}: {s}", .{
6302 decl.getFileScope().sub_file_path, @errorName(err),
6355 decl.getFileScope(mod).sub_file_path, @errorName(err),
63036356 });
63046357 return LazySrcLoc.nodeOffset(0);
63056358 };
......@@ -6321,19 +6374,20 @@ pub fn paramSrc(
63216374}
63226375
63236376pub fn argSrc(
6377 mod: *Module,
63246378 call_node_offset: i32,
6325 gpa: Allocator,
63266379 decl: *Decl,
63276380 start_arg_i: usize,
63286381 bound_arg_src: ?LazySrcLoc,
63296382) LazySrcLoc {
6383 @setCold(true);
6384 const gpa = mod.gpa;
63306385 if (start_arg_i == 0 and bound_arg_src != null) return bound_arg_src.?;
63316386 const arg_i = start_arg_i - @boolToInt(bound_arg_src != null);
6332 @setCold(true);
6333 const tree = decl.getFileScope().getTree(gpa) catch |err| {
6387 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
63346388 // In this case we emit a warning + a less precise source location.
63356389 log.warn("unable to load {s}: {s}", .{
6336 decl.getFileScope().sub_file_path, @errorName(err),
6390 decl.getFileScope(mod).sub_file_path, @errorName(err),
63376391 });
63386392 return LazySrcLoc.nodeOffset(0);
63396393 };
......@@ -6347,7 +6401,7 @@ pub fn argSrc(
63476401 const node_datas = tree.nodes.items(.data);
63486402 const call_args_node = tree.extra_data[node_datas[node].rhs - 1];
63496403 const call_args_offset = decl.nodeIndexToRelative(call_args_node);
6350 return initSrc(call_args_offset, gpa, decl, arg_i);
6404 return mod.initSrc(call_args_offset, decl, arg_i);
63516405 },
63526406 else => unreachable,
63536407 };
......@@ -6355,16 +6409,17 @@ pub fn argSrc(
63556409}
63566410
63576411pub fn initSrc(
6412 mod: *Module,
63586413 init_node_offset: i32,
6359 gpa: Allocator,
63606414 decl: *Decl,
63616415 init_index: usize,
63626416) LazySrcLoc {
63636417 @setCold(true);
6364 const tree = decl.getFileScope().getTree(gpa) catch |err| {
6418 const gpa = mod.gpa;
6419 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
63656420 // In this case we emit a warning + a less precise source location.
63666421 log.warn("unable to load {s}: {s}", .{
6367 decl.getFileScope().sub_file_path, @errorName(err),
6422 decl.getFileScope(mod).sub_file_path, @errorName(err),
63686423 });
63696424 return LazySrcLoc.nodeOffset(0);
63706425 };
......@@ -6400,12 +6455,13 @@ pub fn initSrc(
64006455 }
64016456}
64026457
6403pub fn optionsSrc(gpa: Allocator, decl: *Decl, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc {
6458pub fn optionsSrc(mod: *Module, decl: *Decl, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc {
64046459 @setCold(true);
6405 const tree = decl.getFileScope().getTree(gpa) catch |err| {
6460 const gpa = mod.gpa;
6461 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
64066462 // In this case we emit a warning + a less precise source location.
64076463 log.warn("unable to load {s}: {s}", .{
6408 decl.getFileScope().sub_file_path, @errorName(err),
6464 decl.getFileScope(mod).sub_file_path, @errorName(err),
64096465 });
64106466 return LazySrcLoc.nodeOffset(0);
64116467 };
......@@ -6471,7 +6527,10 @@ pub fn processOutdatedAndDeletedDecls(mod: *Module) !void {
64716527
64726528 // Remove from the namespace it resides in, preserving declaration order.
64736529 assert(decl.zir_decl_index != 0);
6474 _ = decl.src_namespace.decls.orderedRemoveAdapted(@as([]const u8, mem.sliceTo(decl.name, 0)), DeclAdapter{ .mod = mod });
6530 _ = mod.namespacePtr(decl.src_namespace).decls.orderedRemoveAdapted(
6531 @as([]const u8, mem.sliceTo(decl.name, 0)),
6532 DeclAdapter{ .mod = mod },
6533 );
64756534
64766535 try mod.clearDecl(decl_index, &outdated_decls);
64776536 mod.destroyDecl(decl_index);
......@@ -6541,8 +6600,11 @@ pub fn populateTestFunctions(
65416600 const builtin_pkg = mod.main_pkg.table.get("builtin").?;
65426601 const builtin_file = (mod.importPkg(builtin_pkg) catch unreachable).file;
65436602 const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?);
6544 const builtin_namespace = root_decl.src_namespace;
6545 const decl_index = builtin_namespace.decls.getKeyAdapted(@as([]const u8, "test_functions"), DeclAdapter{ .mod = mod }).?;
6603 const builtin_namespace = mod.namespacePtr(root_decl.src_namespace);
6604 const decl_index = builtin_namespace.decls.getKeyAdapted(
6605 @as([]const u8, "test_functions"),
6606 DeclAdapter{ .mod = mod },
6607 ).?;
65466608 {
65476609 // We have to call `ensureDeclAnalyzed` here in case `builtin.test_functions`
65486610 // was not referenced by start code.
......@@ -6673,7 +6735,7 @@ pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void {
66736735 try mod.failed_decls.ensureUnusedCapacity(gpa, 1);
66746736 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
66756737 gpa,
6676 decl.srcLoc(),
6738 decl.srcLoc(mod),
66776739 "unable to codegen: {s}",
66786740 .{@errorName(err)},
66796741 ));
......@@ -7138,3 +7200,24 @@ pub fn atomicPtrAlignment(
71387200
71397201 return 0;
71407202}
7203
7204pub fn opaqueSrcLoc(mod: *Module, opaque_type: InternPool.Key.OpaqueType) SrcLoc {
7205 const owner_decl = mod.declPtr(opaque_type.decl);
7206 return .{
7207 .file_scope = owner_decl.getFileScope(mod),
7208 .parent_decl_node = owner_decl.src_node,
7209 .lazy = LazySrcLoc.nodeOffset(0),
7210 };
7211}
7212
7213pub fn opaqueFullyQualifiedName(mod: *Module, opaque_type: InternPool.Key.OpaqueType) ![:0]u8 {
7214 return mod.declPtr(opaque_type.decl).getFullyQualifiedName(mod);
7215}
7216
7217pub fn declFileScope(mod: *Module, decl_index: Decl.Index) *File {
7218 return mod.declPtr(decl_index).getFileScope(mod);
7219}
7220
7221pub fn namespaceDeclIndex(mod: *Module, namespace_index: Namespace.Index) Decl.Index {
7222 return mod.namespacePtr(namespace_index).getDeclIndex(mod);
7223}
src/Sema.zig+325-312
......@@ -227,7 +227,7 @@ pub const Block = struct {
227227 sema: *Sema,
228228 /// The namespace to use for lookups from this source block
229229 /// When analyzing fields, this is different from src_decl.src_namespace.
230 namespace: *Namespace,
230 namespace: Namespace.Index,
231231 /// The AIR instructions generated for this block.
232232 instructions: std.ArrayListUnmanaged(Air.Inst.Index),
233233 // `param` instructions are collected here to be used by the `func` instruction.
......@@ -286,6 +286,7 @@ pub const Block = struct {
286286
287287 fn explain(cr: ComptimeReason, sema: *Sema, msg: ?*Module.ErrorMsg) !void {
288288 const parent = msg orelse return;
289 const mod = sema.mod;
289290 const prefix = "expression is evaluated at comptime because ";
290291 switch (cr) {
291292 .c_import => |ci| {
......@@ -293,12 +294,12 @@ pub const Block = struct {
293294 },
294295 .comptime_ret_ty => |rt| {
295296 const src_loc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| blk: {
296 var src_loc = fn_decl.srcLoc();
297 var src_loc = fn_decl.srcLoc(mod);
297298 src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 };
298299 break :blk src_loc;
299300 } else blk: {
300301 const src_decl = sema.mod.declPtr(rt.block.src_decl);
301 break :blk rt.func_src.toSrcLoc(src_decl);
302 break :blk rt.func_src.toSrcLoc(src_decl, mod);
302303 };
303304 if (rt.return_ty.isGenericPoison()) {
304305 return sema.mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});
......@@ -399,8 +400,8 @@ pub const Block = struct {
399400 };
400401 }
401402
402 pub fn getFileScope(block: *Block) *Module.File {
403 return block.namespace.file_scope;
403 pub fn getFileScope(block: *Block, mod: *Module) *Module.File {
404 return mod.namespacePtr(block.namespace).file_scope;
404405 }
405406
406407 fn addTy(
......@@ -876,6 +877,7 @@ fn analyzeBodyInner(
876877 wip_captures.deinit();
877878 };
878879
880 const mod = sema.mod;
879881 const map = &sema.inst_map;
880882 const tags = sema.code.instructions.items(.tag);
881883 const datas = sema.code.instructions.items(.data);
......@@ -896,7 +898,7 @@ fn analyzeBodyInner(
896898 crash_info.setBodyIndex(i);
897899 const inst = body[i];
898900 std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{
899 sema.mod.declPtr(block.src_decl).src_namespace.file_scope.sub_file_path, inst,
901 mod.namespacePtr(mod.declPtr(block.src_decl).src_namespace).file_scope.sub_file_path, inst,
900902 });
901903 const air_inst: Air.Inst.Ref = switch (tags[inst]) {
902904 // zig fmt: off
......@@ -1574,7 +1576,6 @@ fn analyzeBodyInner(
15741576 },
15751577 .condbr => blk: {
15761578 if (!block.is_comptime) break sema.zirCondbr(block, inst);
1577 const mod = sema.mod;
15781579 // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220
15791580 const inst_data = datas[inst].pl_node;
15801581 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
......@@ -1597,7 +1598,6 @@ fn analyzeBodyInner(
15971598 }
15981599 },
15991600 .condbr_inline => blk: {
1600 const mod = sema.mod;
16011601 const inst_data = datas[inst].pl_node;
16021602 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
16031603 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
......@@ -1622,7 +1622,6 @@ fn analyzeBodyInner(
16221622 },
16231623 .@"try" => blk: {
16241624 if (!block.is_comptime) break :blk try sema.zirTry(block, inst);
1625 const mod = sema.mod;
16261625 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
16271626 const src = inst_data.src();
16281627 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -1632,7 +1631,7 @@ fn analyzeBodyInner(
16321631 const err_union_ty = sema.typeOf(err_union);
16331632 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
16341633 return sema.fail(block, operand_src, "expected error union type, found '{}'", .{
1635 err_union_ty.fmt(sema.mod),
1634 err_union_ty.fmt(mod),
16361635 });
16371636 }
16381637 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union);
......@@ -1654,7 +1653,6 @@ fn analyzeBodyInner(
16541653 },
16551654 .try_ptr => blk: {
16561655 if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst);
1657 const mod = sema.mod;
16581656 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
16591657 const src = inst_data.src();
16601658 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -1713,7 +1711,7 @@ fn analyzeBodyInner(
17131711 const noreturn_inst = block.instructions.popOrNull();
17141712 while (dbg_block_begins > 0) {
17151713 dbg_block_begins -= 1;
1716 if (block.is_comptime or sema.mod.comp.bin_file.options.strip) continue;
1714 if (block.is_comptime or mod.comp.bin_file.options.strip) continue;
17171715
17181716 _ = try block.addInst(.{
17191717 .tag = .dbg_block_end,
......@@ -2172,7 +2170,7 @@ fn errNote(
21722170) error{OutOfMemory}!void {
21732171 const mod = sema.mod;
21742172 const src_decl = mod.declPtr(block.src_decl);
2175 return mod.errNoteNonLazy(src.toSrcLoc(src_decl), parent, format, args);
2173 return mod.errNoteNonLazy(src.toSrcLoc(src_decl, mod), parent, format, args);
21762174}
21772175
21782176fn addFieldErrNote(
......@@ -2185,19 +2183,19 @@ fn addFieldErrNote(
21852183) !void {
21862184 @setCold(true);
21872185 const mod = sema.mod;
2188 const decl_index = container_ty.getOwnerDecl();
2186 const decl_index = container_ty.getOwnerDecl(mod);
21892187 const decl = mod.declPtr(decl_index);
21902188
21912189 const field_src = blk: {
2192 const tree = decl.getFileScope().getTree(sema.gpa) catch |err| {
2190 const tree = decl.getFileScope(mod).getTree(sema.gpa) catch |err| {
21932191 log.err("unable to load AST to report compile error: {s}", .{@errorName(err)});
2194 break :blk decl.srcLoc();
2192 break :blk decl.srcLoc(mod);
21952193 };
21962194
21972195 const container_node = decl.relativeToNodeIndex(0);
21982196 const node_tags = tree.nodes.items(.tag);
21992197 var buf: [2]std.zig.Ast.Node.Index = undefined;
2200 const container_decl = tree.fullContainerDecl(&buf, container_node) orelse break :blk decl.srcLoc();
2198 const container_decl = tree.fullContainerDecl(&buf, container_node) orelse break :blk decl.srcLoc(mod);
22012199
22022200 var it_index: usize = 0;
22032201 for (container_decl.ast.members) |member_node| {
......@@ -2207,7 +2205,7 @@ fn addFieldErrNote(
22072205 .container_field,
22082206 => {
22092207 if (it_index == field_index) {
2210 break :blk decl.nodeOffsetSrcLoc(decl.nodeIndexToRelative(member_node));
2208 break :blk decl.nodeOffsetSrcLoc(decl.nodeIndexToRelative(member_node), mod);
22112209 }
22122210 it_index += 1;
22132211 },
......@@ -2228,7 +2226,7 @@ fn errMsg(
22282226) error{OutOfMemory}!*Module.ErrorMsg {
22292227 const mod = sema.mod;
22302228 const src_decl = mod.declPtr(block.src_decl);
2231 return Module.ErrorMsg.create(sema.gpa, src.toSrcLoc(src_decl), format, args);
2229 return Module.ErrorMsg.create(sema.gpa, src.toSrcLoc(src_decl, mod), format, args);
22322230}
22332231
22342232pub fn fail(
......@@ -2287,7 +2285,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
22872285 if (gop.found_existing) break;
22882286 if (cur_reference_trace < max_references) {
22892287 const decl = sema.mod.declPtr(ref.referencer);
2290 try reference_stack.append(.{ .decl = decl.name, .src_loc = ref.src.toSrcLoc(decl) });
2288 try reference_stack.append(.{ .decl = decl.name, .src_loc = ref.src.toSrcLoc(decl, mod) });
22912289 }
22922290 referenced_by = ref.referencer;
22932291 }
......@@ -2664,7 +2662,7 @@ pub fn analyzeStructDecl(
26642662 }
26652663 }
26662664
2667 _ = try sema.mod.scanNamespace(&struct_obj.namespace, extra_index, decls_len, new_decl);
2665 _ = try sema.mod.scanNamespace(struct_obj.namespace, extra_index, decls_len, new_decl);
26682666}
26692667
26702668fn zirStructDecl(
......@@ -2702,15 +2700,12 @@ fn zirStructDecl(
27022700 .status = .none,
27032701 .known_non_opv = undefined,
27042702 .is_tuple = small.is_tuple,
2705 .namespace = .{
2706 .parent = block.namespace,
2703 .namespace = try mod.createNamespace(.{
2704 .parent = block.namespace.toOptional(),
27072705 .ty = struct_ty,
2708 .file_scope = block.getFileScope(),
2709 },
2706 .file_scope = block.getFileScope(mod),
2707 }),
27102708 };
2711 std.log.scoped(.module).debug("create struct {*} owned by {*} ({s})", .{
2712 &struct_obj.namespace, new_decl, new_decl.name,
2713 });
27142709 try sema.analyzeStructDecl(new_decl, inst, struct_obj);
27152710 try new_decl.finalizeNewArena(&new_decl_arena);
27162711 return sema.analyzeDeclVal(block, src, new_decl_index);
......@@ -2887,15 +2882,12 @@ fn zirEnumDecl(
28872882 .tag_ty_inferred = true,
28882883 .fields = .{},
28892884 .values = .{},
2890 .namespace = .{
2891 .parent = block.namespace,
2885 .namespace = try mod.createNamespace(.{
2886 .parent = block.namespace.toOptional(),
28922887 .ty = enum_ty,
2893 .file_scope = block.getFileScope(),
2894 },
2888 .file_scope = block.getFileScope(mod),
2889 }),
28952890 };
2896 std.log.scoped(.module).debug("create enum {*} owned by {*} ({s})", .{
2897 &enum_obj.namespace, new_decl, new_decl.name,
2898 });
28992891
29002892 try new_decl.finalizeNewArena(&new_decl_arena);
29012893 const decl_val = try sema.analyzeDeclVal(block, src, new_decl_index);
......@@ -2905,7 +2897,7 @@ fn zirEnumDecl(
29052897 const decl_arena_allocator = new_decl.value_arena.?.acquire(gpa, &decl_arena);
29062898 defer new_decl.value_arena.?.release(&decl_arena);
29072899
2908 extra_index = try mod.scanNamespace(&enum_obj.namespace, extra_index, decls_len, new_decl);
2900 extra_index = try mod.scanNamespace(enum_obj.namespace, extra_index, decls_len, new_decl);
29092901
29102902 const body = sema.code.extra[extra_index..][0..body_len];
29112903 extra_index += body.len;
......@@ -2944,7 +2936,7 @@ fn zirEnumDecl(
29442936 .parent = null,
29452937 .sema = sema,
29462938 .src_decl = new_decl_index,
2947 .namespace = &enum_obj.namespace,
2939 .namespace = enum_obj.namespace,
29482940 .wip_capture_scope = wip_captures.scope,
29492941 .instructions = .{},
29502942 .inlining = null,
......@@ -3164,17 +3156,14 @@ fn zirUnionDecl(
31643156 .zir_index = inst,
31653157 .layout = small.layout,
31663158 .status = .none,
3167 .namespace = .{
3168 .parent = block.namespace,
3159 .namespace = try mod.createNamespace(.{
3160 .parent = block.namespace.toOptional(),
31693161 .ty = union_ty,
3170 .file_scope = block.getFileScope(),
3171 },
3162 .file_scope = block.getFileScope(mod),
3163 }),
31723164 };
3173 std.log.scoped(.module).debug("create union {*} owned by {*} ({s})", .{
3174 &union_obj.namespace, new_decl, new_decl.name,
3175 });
31763165
3177 _ = try mod.scanNamespace(&union_obj.namespace, extra_index, decls_len, new_decl);
3166 _ = try mod.scanNamespace(union_obj.namespace, extra_index, decls_len, new_decl);
31783167
31793168 try new_decl.finalizeNewArena(&new_decl_arena);
31803169 return sema.analyzeDeclVal(block, src, new_decl_index);
......@@ -3208,37 +3197,37 @@ fn zirOpaqueDecl(
32083197
32093198 var new_decl_arena = std.heap.ArenaAllocator.init(gpa);
32103199 errdefer new_decl_arena.deinit();
3211 const new_decl_arena_allocator = new_decl_arena.allocator();
32123200
3213 const opaque_obj = try new_decl_arena_allocator.create(Module.Opaque);
3214 const opaque_ty_payload = try new_decl_arena_allocator.create(Type.Payload.Opaque);
3215 opaque_ty_payload.* = .{
3216 .base = .{ .tag = .@"opaque" },
3217 .data = opaque_obj,
3218 };
3219 const opaque_ty = Type.initPayload(&opaque_ty_payload.base);
3220 const opaque_val = try Value.Tag.ty.create(new_decl_arena_allocator, opaque_ty);
3201 // Because these three things each reference each other, `undefined`
3202 // placeholders are used in two places before being set after the opaque
3203 // type gains an InternPool index.
3204
32213205 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
32223206 .ty = Type.type,
3223 .val = opaque_val,
3207 .val = undefined,
32243208 }, small.name_strategy, "opaque", inst);
32253209 const new_decl = mod.declPtr(new_decl_index);
32263210 new_decl.owns_tv = true;
32273211 errdefer mod.abortAnonDecl(new_decl_index);
32283212
3229 opaque_obj.* = .{
3230 .owner_decl = new_decl_index,
3231 .namespace = .{
3232 .parent = block.namespace,
3233 .ty = opaque_ty,
3234 .file_scope = block.getFileScope(),
3235 },
3236 };
3237 std.log.scoped(.module).debug("create opaque {*} owned by {*} ({s})", .{
3238 &opaque_obj.namespace, new_decl, new_decl.name,
3213 const new_namespace_index = try mod.createNamespace(.{
3214 .parent = block.namespace.toOptional(),
3215 .ty = undefined,
3216 .file_scope = block.getFileScope(mod),
32393217 });
3218 const new_namespace = mod.namespacePtr(new_namespace_index);
3219 errdefer @panic("TODO error handling");
3220
3221 const opaque_ty = try mod.intern_pool.get(gpa, .{ .opaque_type = .{
3222 .decl = new_decl_index,
3223 .namespace = new_namespace_index,
3224 } });
3225 errdefer @panic("TODO error handling");
3226
3227 new_decl.val = opaque_ty.toValue();
3228 new_namespace.ty = opaque_ty.toType();
32403229
3241 extra_index = try mod.scanNamespace(&opaque_obj.namespace, extra_index, decls_len, new_decl);
3230 extra_index = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl);
32423231
32433232 try new_decl.finalizeNewArena(&new_decl_arena);
32443233 return sema.analyzeDeclVal(block, src, new_decl_index);
......@@ -4848,7 +4837,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
48484837 errdefer msg.destroy(sema.gpa);
48494838
48504839 const src_decl = sema.mod.declPtr(block.src_decl);
4851 try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl), elem_ty);
4840 try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), elem_ty);
48524841 break :msg msg;
48534842 };
48544843 return sema.failWithOwnedErrorMsg(msg);
......@@ -4870,7 +4859,7 @@ fn failWithBadMemberAccess(
48704859 .Enum => "enum",
48714860 else => unreachable,
48724861 };
4873 if (agg_ty.getOwnerDeclOrNull()) |some| if (sema.mod.declIsRoot(some)) {
4862 if (agg_ty.getOwnerDeclOrNull(mod)) |some| if (sema.mod.declIsRoot(some)) {
48744863 return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{
48754864 agg_ty.fmt(sema.mod), field_name,
48764865 });
......@@ -5632,7 +5621,7 @@ fn analyzeBlockBody(
56325621 try sema.errNote(child_block, runtime_src, msg, "runtime control flow here", .{});
56335622
56345623 const child_src_decl = mod.declPtr(child_block.src_decl);
5635 try sema.explainWhyTypeIsComptime(msg, type_src.toSrcLoc(child_src_decl), resolved_ty);
5624 try sema.explainWhyTypeIsComptime(msg, type_src.toSrcLoc(child_src_decl, mod), resolved_ty);
56365625
56375626 break :msg msg;
56385627 };
......@@ -5703,6 +5692,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
57035692 const tracy = trace(@src());
57045693 defer tracy.end();
57055694
5695 const mod = sema.mod;
57065696 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
57075697 const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;
57085698 const src = inst_data.src();
......@@ -5711,7 +5701,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
57115701 const decl_name = sema.code.nullTerminatedString(extra.decl_name);
57125702 const decl_index = if (extra.namespace != .none) index_blk: {
57135703 const container_ty = try sema.resolveType(block, operand_src, extra.namespace);
5714 const container_namespace = container_ty.getNamespace().?;
5704 const container_namespace = container_ty.getNamespaceIndex(mod).unwrap().?;
57155705
57165706 const maybe_index = try sema.lookupInNamespace(block, operand_src, container_namespace, decl_name, false);
57175707 break :index_blk maybe_index orelse
......@@ -5725,8 +5715,8 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
57255715 else => |e| return e,
57265716 };
57275717 {
5728 try sema.mod.ensureDeclAnalyzed(decl_index);
5729 const exported_decl = sema.mod.declPtr(decl_index);
5718 try mod.ensureDeclAnalyzed(decl_index);
5719 const exported_decl = mod.declPtr(decl_index);
57305720 if (exported_decl.val.castTag(.function)) |some| {
57315721 return sema.analyzeExport(block, src, options, some.data.owner_decl);
57325722 }
......@@ -5789,7 +5779,7 @@ pub fn analyzeExport(
57895779 errdefer msg.destroy(sema.gpa);
57905780
57915781 const src_decl = sema.mod.declPtr(block.src_decl);
5792 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), exported_decl.ty, .other);
5782 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), exported_decl.ty, .other);
57935783
57945784 try sema.addDeclaredHereNote(msg, exported_decl.ty);
57955785 break :msg msg;
......@@ -6075,12 +6065,13 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
60756065}
60766066
60776067fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: []const u8) !Decl.Index {
6068 const mod = sema.mod;
60786069 var namespace = block.namespace;
60796070 while (true) {
60806071 if (try sema.lookupInNamespace(block, src, namespace, name, false)) |decl_index| {
60816072 return decl_index;
60826073 }
6083 namespace = namespace.parent orelse break;
6074 namespace = mod.namespacePtr(namespace).parent.unwrap() orelse break;
60846075 }
60856076 unreachable; // AstGen detects use of undeclared identifier errors.
60866077}
......@@ -6091,13 +6082,14 @@ fn lookupInNamespace(
60916082 sema: *Sema,
60926083 block: *Block,
60936084 src: LazySrcLoc,
6094 namespace: *Namespace,
6085 namespace_index: Namespace.Index,
60956086 ident_name: []const u8,
60966087 observe_usingnamespace: bool,
60976088) CompileError!?Decl.Index {
60986089 const mod = sema.mod;
60996090
6100 const namespace_decl_index = namespace.getDeclIndex();
6091 const namespace = mod.namespacePtr(namespace_index);
6092 const namespace_decl_index = namespace.getDeclIndex(mod);
61016093 const namespace_decl = sema.mod.declPtr(namespace_decl_index);
61026094 if (namespace_decl.analysis == .file_failure) {
61036095 try mod.declareDeclDependency(sema.owner_decl_index, namespace_decl_index);
......@@ -6105,7 +6097,7 @@ fn lookupInNamespace(
61056097 }
61066098
61076099 if (observe_usingnamespace and namespace.usingnamespace_set.count() != 0) {
6108 const src_file = block.namespace.file_scope;
6100 const src_file = mod.namespacePtr(block.namespace).file_scope;
61096101
61106102 const gpa = sema.gpa;
61116103 var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Namespace, bool) = .{};
......@@ -6124,7 +6116,7 @@ fn lookupInNamespace(
61246116 // Skip decls which are not marked pub, which are in a different
61256117 // file than the `a.b`/`@hasDecl` syntax.
61266118 const decl = mod.declPtr(decl_index);
6127 if (decl.is_pub or (src_file == decl.getFileScope() and checked_namespaces.values()[check_i])) {
6119 if (decl.is_pub or (src_file == decl.getFileScope(mod) and checked_namespaces.values()[check_i])) {
61286120 try candidates.append(gpa, decl_index);
61296121 }
61306122 }
......@@ -6135,15 +6127,15 @@ fn lookupInNamespace(
61356127 if (sub_usingnamespace_decl_index == sema.owner_decl_index) continue;
61366128 const sub_usingnamespace_decl = mod.declPtr(sub_usingnamespace_decl_index);
61376129 const sub_is_pub = entry.value_ptr.*;
6138 if (!sub_is_pub and src_file != sub_usingnamespace_decl.getFileScope()) {
6130 if (!sub_is_pub and src_file != sub_usingnamespace_decl.getFileScope(mod)) {
61396131 // Skip usingnamespace decls which are not marked pub, which are in
61406132 // a different file than the `a.b`/`@hasDecl` syntax.
61416133 continue;
61426134 }
61436135 try sema.ensureDeclAnalyzed(sub_usingnamespace_decl_index);
61446136 const ns_ty = sub_usingnamespace_decl.val.castTag(.ty).?.data;
6145 const sub_ns = ns_ty.getNamespace().?;
6146 try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScope());
6137 const sub_ns = ns_ty.getNamespace(mod).?;
6138 try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScope(mod));
61476139 }
61486140 }
61496141
......@@ -6171,7 +6163,7 @@ fn lookupInNamespace(
61716163 errdefer msg.destroy(gpa);
61726164 for (candidates.items) |candidate_index| {
61736165 const candidate = mod.declPtr(candidate_index);
6174 const src_loc = candidate.srcLoc();
6166 const src_loc = candidate.srcLoc(mod);
61756167 try mod.errNoteNonLazy(src_loc, msg, "declared here", .{});
61766168 }
61776169 break :msg msg;
......@@ -6532,7 +6524,7 @@ fn checkCallArgumentCount(
65326524 );
65336525 errdefer msg.destroy(sema.gpa);
65346526
6535 if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(), msg, "function declared here", .{});
6527 if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{});
65366528 break :msg msg;
65376529 };
65386530 return sema.failWithOwnedErrorMsg(msg);
......@@ -6669,7 +6661,7 @@ fn analyzeCall(
66696661 );
66706662 errdefer msg.destroy(sema.gpa);
66716663
6672 if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(), msg, "function declared here", .{});
6664 if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{});
66736665 break :msg msg;
66746666 };
66756667 return sema.failWithOwnedErrorMsg(msg);
......@@ -6811,7 +6803,7 @@ fn analyzeCall(
68116803 // than create a child one.
68126804 const parent_zir = sema.code;
68136805 const fn_owner_decl = mod.declPtr(module_fn.owner_decl);
6814 sema.code = fn_owner_decl.getFileScope().zir;
6806 sema.code = fn_owner_decl.getFileScope(mod).zir;
68156807 defer sema.code = parent_zir;
68166808
68176809 try mod.declareDeclDependencyType(sema.owner_decl_index, module_fn.owner_decl, .function_body);
......@@ -6911,7 +6903,7 @@ fn analyzeCall(
69116903 try sema.analyzeInlineCallArg(
69126904 block,
69136905 &child_block,
6914 Module.argSrc(call_src.node_offset.x, sema.gpa, decl, arg_i, bound_arg_src),
6906 mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src),
69156907 inst,
69166908 new_fn_info,
69176909 &arg_i,
......@@ -7098,7 +7090,7 @@ fn analyzeCall(
70987090 const decl = sema.mod.declPtr(block.src_decl);
70997091 _ = try sema.analyzeCallArg(
71007092 block,
7101 Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src),
7093 mod.argSrc(call_src.node_offset.x, decl, i, bound_arg_src),
71027094 param_ty,
71037095 uncasted_arg,
71047096 opts,
......@@ -7114,7 +7106,7 @@ fn analyzeCall(
71147106 _ = try sema.coerceVarArgParam(
71157107 block,
71167108 uncasted_arg,
7117 Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src),
7109 mod.argSrc(call_src.node_offset.x, decl, i, bound_arg_src),
71187110 );
71197111 unreachable;
71207112 },
......@@ -7406,7 +7398,8 @@ fn instantiateGenericCall(
74067398 // can match against `uncasted_args` rather than doing the work below to create a
74077399 // generic Scope only to junk it if it matches an existing instantiation.
74087400 const fn_owner_decl = mod.declPtr(module_fn.owner_decl);
7409 const namespace = fn_owner_decl.src_namespace;
7401 const namespace_index = fn_owner_decl.src_namespace;
7402 const namespace = mod.namespacePtr(namespace_index);
74107403 const fn_zir = namespace.file_scope.zir;
74117404 const fn_info = fn_zir.getFnInfo(module_fn.zir_body_inst);
74127405 const zir_tags = fn_zir.instructions.items(.tag);
......@@ -7456,7 +7449,7 @@ fn instantiateGenericCall(
74567449 const arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, uncasted_args[i]) catch |err| switch (err) {
74577450 error.NeededSourceLocation => {
74587451 const decl = sema.mod.declPtr(block.src_decl);
7459 const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src);
7452 const arg_src = mod.argSrc(call_src.node_offset.x, decl, i, bound_arg_src);
74607453 _ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[i]);
74617454 unreachable;
74627455 },
......@@ -7519,9 +7512,9 @@ fn instantiateGenericCall(
75197512 try namespace.anon_decls.ensureUnusedCapacity(gpa, 1);
75207513
75217514 // Create a Decl for the new function.
7522 const src_decl_index = namespace.getDeclIndex();
7515 const src_decl_index = namespace.getDeclIndex(mod);
75237516 const src_decl = mod.declPtr(src_decl_index);
7524 const new_decl_index = try mod.allocateNewDecl(namespace, fn_owner_decl.src_node, src_decl.src_scope);
7517 const new_decl_index = try mod.allocateNewDecl(namespace_index, fn_owner_decl.src_node, src_decl.src_scope);
75257518 const new_decl = mod.declPtr(new_decl_index);
75267519 // TODO better names for generic function instantiations
75277520 const decl_name = try std.fmt.allocPrintZ(gpa, "{s}__anon_{d}", .{
......@@ -7559,7 +7552,7 @@ fn instantiateGenericCall(
75597552 uncasted_args,
75607553 module_fn,
75617554 new_module_func,
7562 namespace,
7555 namespace_index,
75637556 func_ty_info,
75647557 call_src,
75657558 bound_arg_src,
......@@ -7631,7 +7624,7 @@ fn instantiateGenericCall(
76317624 const decl = sema.mod.declPtr(block.src_decl);
76327625 _ = try sema.analyzeGenericCallArg(
76337626 block,
7634 Module.argSrc(call_src.node_offset.x, sema.gpa, decl, total_i, bound_arg_src),
7627 mod.argSrc(call_src.node_offset.x, decl, total_i, bound_arg_src),
76357628 uncasted_args[total_i],
76367629 comptime_args[total_i],
76377630 runtime_args,
......@@ -7692,7 +7685,7 @@ fn resolveGenericInstantiationType(
76927685 uncasted_args: []const Air.Inst.Ref,
76937686 module_fn: *Module.Fn,
76947687 new_module_func: *Module.Fn,
7695 namespace: *Namespace,
7688 namespace: Namespace.Index,
76967689 func_ty_info: Type.Payload.Function.Data,
76977690 call_src: LazySrcLoc,
76987691 bound_arg_src: ?LazySrcLoc,
......@@ -7779,7 +7772,7 @@ fn resolveGenericInstantiationType(
77797772 const arg_val = sema.resolveConstValue(block, .unneeded, arg, "") catch |err| switch (err) {
77807773 error.NeededSourceLocation => {
77817774 const decl = sema.mod.declPtr(block.src_decl);
7782 const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, arg_i, bound_arg_src);
7775 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);
77837776 _ = try sema.resolveConstValue(block, arg_src, arg, "argument to parameter with comptime-only type must be comptime-known");
77847777 unreachable;
77857778 },
......@@ -8987,7 +8980,7 @@ fn funcCommon(
89878980 const decl = sema.mod.declPtr(block.src_decl);
89888981 try sema.analyzeParameter(
89898982 block,
8990 Module.paramSrc(src_node_offset, sema.gpa, decl, i),
8983 Module.paramSrc(src_node_offset, mod, decl, i),
89918984 param,
89928985 comptime_params,
89938986 i,
......@@ -9050,7 +9043,7 @@ fn funcCommon(
90509043 errdefer msg.destroy(sema.gpa);
90519044
90529045 const src_decl = sema.mod.declPtr(block.src_decl);
9053 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src.toSrcLoc(src_decl), return_type, .ret_ty);
9046 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src.toSrcLoc(src_decl, mod), return_type, .ret_ty);
90549047
90559048 try sema.addDeclaredHereNote(msg, return_type);
90569049 break :msg msg;
......@@ -9070,7 +9063,7 @@ fn funcCommon(
90709063 "function with comptime-only return type '{}' requires all parameters to be comptime",
90719064 .{return_type.fmt(sema.mod)},
90729065 );
9073 try sema.explainWhyTypeIsComptime(msg, ret_ty_src.toSrcLoc(sema.owner_decl), return_type);
9066 try sema.explainWhyTypeIsComptime(msg, ret_ty_src.toSrcLoc(sema.owner_decl, mod), return_type);
90749067
90759068 const tags = sema.code.instructions.items(.tag);
90769069 const data = sema.code.instructions.items(.data);
......@@ -9278,7 +9271,7 @@ fn analyzeParameter(
92789271 errdefer msg.destroy(sema.gpa);
92799272
92809273 const src_decl = mod.declPtr(block.src_decl);
9281 try sema.explainWhyTypeIsNotExtern(msg, param_src.toSrcLoc(src_decl), param.ty, .param_ty);
9274 try sema.explainWhyTypeIsNotExtern(msg, param_src.toSrcLoc(src_decl, mod), param.ty, .param_ty);
92829275
92839276 try sema.addDeclaredHereNote(msg, param.ty);
92849277 break :msg msg;
......@@ -9293,7 +9286,7 @@ fn analyzeParameter(
92939286 errdefer msg.destroy(sema.gpa);
92949287
92959288 const src_decl = mod.declPtr(block.src_decl);
9296 try sema.explainWhyTypeIsComptime(msg, param_src.toSrcLoc(src_decl), param.ty);
9289 try sema.explainWhyTypeIsComptime(msg, param_src.toSrcLoc(src_decl, mod), param.ty);
92979290
92989291 try sema.addDeclaredHereNote(msg, param.ty);
92999292 break :msg msg;
......@@ -10233,15 +10226,15 @@ fn zirSwitchCapture(
1023310226 if (!field.ty.eql(first_field.ty, sema.mod)) {
1023410227 const msg = msg: {
1023510228 const raw_capture_src = Module.SwitchProngSrc{ .multi_capture = capture_info.prong_index };
10236 const capture_src = raw_capture_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first);
10229 const capture_src = raw_capture_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first);
1023710230
1023810231 const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{});
1023910232 errdefer msg.destroy(sema.gpa);
1024010233
1024110234 const raw_first_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 0 } };
10242 const first_item_src = raw_first_item_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first);
10235 const first_item_src = raw_first_item_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first);
1024310236 const raw_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 1 + @intCast(u32, i) } };
10244 const item_src = raw_item_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first);
10237 const item_src = raw_item_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first);
1024510238 try sema.errNote(block, first_item_src, msg, "type '{}' here", .{first_field.ty.fmt(sema.mod)});
1024610239 try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(sema.mod)});
1024710240 break :msg msg;
......@@ -11265,7 +11258,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1126511258 error.NeededSourceLocation => {
1126611259 const case_src = Module.SwitchProngSrc{ .range = .{ .prong = multi_i, .item = range_i } };
1126711260 const decl = mod.declPtr(case_block.src_decl);
11268 try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none));
11261 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
1126911262 unreachable;
1127011263 },
1127111264 else => return err,
......@@ -11301,7 +11294,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1130111294 error.NeededSourceLocation => {
1130211295 const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } };
1130311296 const decl = mod.declPtr(case_block.src_decl);
11304 try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none));
11297 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
1130511298 unreachable;
1130611299 },
1130711300 else => return err,
......@@ -11724,6 +11717,7 @@ fn resolveSwitchItemVal(
1172411717 switch_prong_src: Module.SwitchProngSrc,
1172511718 range_expand: Module.SwitchProngSrc.RangeExpand,
1172611719) CompileError!TypedValue {
11720 const mod = sema.mod;
1172711721 const item = try sema.resolveInst(item_ref);
1172811722 const item_ty = sema.typeOf(item);
1172911723 // Constructing a LazySrcLoc is costly because we only have the switch AST node.
......@@ -11734,7 +11728,7 @@ fn resolveSwitchItemVal(
1173411728 return TypedValue{ .ty = item_ty, .val = val };
1173511729 } else |err| switch (err) {
1173611730 error.NeededSourceLocation => {
11737 const src = switch_prong_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_node_offset, range_expand);
11731 const src = switch_prong_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_node_offset, range_expand);
1173811732 _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known");
1173911733 unreachable;
1174011734 },
......@@ -11752,10 +11746,11 @@ fn validateSwitchRange(
1175211746 src_node_offset: i32,
1175311747 switch_prong_src: Module.SwitchProngSrc,
1175411748) CompileError!void {
11749 const mod = sema.mod;
1175511750 const first_val = (try sema.resolveSwitchItemVal(block, first_ref, src_node_offset, switch_prong_src, .first)).val;
1175611751 const last_val = (try sema.resolveSwitchItemVal(block, last_ref, src_node_offset, switch_prong_src, .last)).val;
11757 if (first_val.compareScalar(.gt, last_val, operand_ty, sema.mod)) {
11758 const src = switch_prong_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), src_node_offset, .first);
11752 if (first_val.compareScalar(.gt, last_val, operand_ty, mod)) {
11753 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), src_node_offset, .first);
1175911754 return sema.fail(block, src, "range start value is greater than the end value", .{});
1176011755 }
1176111756 const maybe_prev_src = try range_set.add(first_val, last_val, operand_ty, switch_prong_src);
......@@ -11821,10 +11816,10 @@ fn validateSwitchDupe(
1182111816 src_node_offset: i32,
1182211817) CompileError!void {
1182311818 const prev_prong_src = maybe_prev_src orelse return;
11824 const gpa = sema.gpa;
11819 const mod = sema.mod;
1182511820 const block_src_decl = sema.mod.declPtr(block.src_decl);
11826 const src = switch_prong_src.resolve(gpa, block_src_decl, src_node_offset, .none);
11827 const prev_src = prev_prong_src.resolve(gpa, block_src_decl, src_node_offset, .none);
11821 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
11822 const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
1182811823 const msg = msg: {
1182911824 const msg = try sema.errMsg(
1183011825 block,
......@@ -11863,7 +11858,7 @@ fn validateSwitchItemBool(
1186311858 }
1186411859 if (true_count.* + false_count.* > 2) {
1186511860 const block_src_decl = sema.mod.declPtr(block.src_decl);
11866 const src = switch_prong_src.resolve(sema.gpa, block_src_decl, src_node_offset, .none);
11861 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
1186711862 return sema.fail(block, src, "duplicate switch value", .{});
1186811863 }
1186911864}
......@@ -12068,6 +12063,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1206812063}
1206912064
1207012065fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
12066 const mod = sema.mod;
1207112067 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1207212068 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1207312069 const src = inst_data.src();
......@@ -12078,10 +12074,11 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1207812074
1207912075 try sema.checkNamespaceType(block, lhs_src, container_type);
1208012076
12081 const namespace = container_type.getNamespace() orelse return Air.Inst.Ref.bool_false;
12077 const namespace = container_type.getNamespaceIndex(mod).unwrap() orelse
12078 return Air.Inst.Ref.bool_false;
1208212079 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| {
12083 const decl = sema.mod.declPtr(decl_index);
12084 if (decl.is_pub or decl.getFileScope() == block.getFileScope()) {
12080 const decl = mod.declPtr(decl_index);
12081 if (decl.is_pub or decl.getFileScope(mod) == block.getFileScope(mod)) {
1208512082 return Air.Inst.Ref.bool_true;
1208612083 }
1208712084 }
......@@ -12097,12 +12094,12 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1209712094 const operand_src = inst_data.src();
1209812095 const operand = inst_data.get(sema.code);
1209912096
12100 const result = mod.importFile(block.getFileScope(), operand) catch |err| switch (err) {
12097 const result = mod.importFile(block.getFileScope(mod), operand) catch |err| switch (err) {
1210112098 error.ImportOutsidePkgPath => {
1210212099 return sema.fail(block, operand_src, "import of file outside package path: '{s}'", .{operand});
1210312100 },
1210412101 error.PackageNotFound => {
12105 const name = try block.getFileScope().pkg.getName(sema.gpa, mod.*);
12102 const name = try block.getFileScope(mod).pkg.getName(sema.gpa, mod.*);
1210612103 defer sema.gpa.free(name);
1210712104 return sema.fail(block, operand_src, "no package named '{s}' available within package '{s}'", .{ operand, name });
1210812105 },
......@@ -12128,7 +12125,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1212812125 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1212912126 const name = try sema.resolveConstString(block, operand_src, inst_data.operand, "file path name must be comptime-known");
1213012127
12131 const embed_file = mod.embedFile(block.getFileScope(), name) catch |err| switch (err) {
12128 const embed_file = mod.embedFile(block.getFileScope(mod), name) catch |err| switch (err) {
1213212129 error.ImportOutsidePkgPath => {
1213312130 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});
1213412131 },
......@@ -15666,7 +15663,8 @@ fn zirThis(
1566615663 block: *Block,
1566715664 extended: Zir.Inst.Extended.InstData,
1566815665) CompileError!Air.Inst.Ref {
15669 const this_decl_index = block.namespace.getDeclIndex();
15666 const mod = sema.mod;
15667 const this_decl_index = mod.namespaceDeclIndex(block.namespace);
1567015668 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));
1567115669 return sema.analyzeDeclVal(block, src, this_decl_index);
1567215670}
......@@ -15698,9 +15696,10 @@ fn zirClosureGet(
1569815696 block: *Block,
1569915697 inst: Zir.Inst.Index,
1570015698) CompileError!Air.Inst.Ref {
15699 const mod = sema.mod;
1570115700 // TODO CLOSURE: Test this with inline functions
1570215701 const inst_data = sema.code.instructions.items(.data)[inst].inst_node;
15703 var scope: *CaptureScope = sema.mod.declPtr(block.src_decl).src_scope.?;
15702 var scope: *CaptureScope = mod.declPtr(block.src_decl).src_scope.?;
1570415703 // Note: The target closure must be in this scope list.
1570515704 // If it's not here, the zir is invalid, or the list is broken.
1570615705 const tv = while (true) {
......@@ -15725,8 +15724,8 @@ fn zirClosureGet(
1572515724 if (tv.val.ip_index == .unreachable_value and !block.is_typeof and sema.func == null) {
1572615725 const msg = msg: {
1572715726 const name = name: {
15728 const file = sema.owner_decl.getFileScope();
15729 const tree = file.getTree(sema.mod.gpa) catch |err| {
15727 const file = sema.owner_decl.getFileScope(mod);
15728 const tree = file.getTree(mod.gpa) catch |err| {
1573015729 // In this case we emit a warning + a less precise source location.
1573115730 log.warn("unable to load {s}: {s}", .{
1573215731 file.sub_file_path, @errorName(err),
......@@ -15753,8 +15752,8 @@ fn zirClosureGet(
1575315752 if (tv.val.ip_index == .unreachable_value and !block.is_typeof and !block.is_comptime and sema.func != null) {
1575415753 const msg = msg: {
1575515754 const name = name: {
15756 const file = sema.owner_decl.getFileScope();
15757 const tree = file.getTree(sema.mod.gpa) catch |err| {
15755 const file = sema.owner_decl.getFileScope(mod);
15756 const tree = file.getTree(mod.gpa) catch |err| {
1575815757 // In this case we emit a warning + a less precise source location.
1575915758 log.warn("unable to load {s}: {s}", .{
1576015759 file.sub_file_path, @errorName(err),
......@@ -15825,7 +15824,7 @@ fn zirBuiltinSrc(
1582515824 const extra = sema.code.extraData(Zir.Inst.Src, extended.operand).data;
1582615825 const src = LazySrcLoc.nodeOffset(extra.node);
1582715826 const func = sema.func orelse return sema.fail(block, src, "@src outside function", .{});
15828 const fn_owner_decl = sema.mod.declPtr(func.owner_decl);
15827 const fn_owner_decl = mod.declPtr(func.owner_decl);
1582915828
1583015829 const func_name_val = blk: {
1583115830 var anon_decl = try block.startAnonDecl();
......@@ -15844,7 +15843,7 @@ fn zirBuiltinSrc(
1584415843 var anon_decl = try block.startAnonDecl();
1584515844 defer anon_decl.deinit();
1584615845 // The compiler must not call realpath anywhere.
15847 const name = try fn_owner_decl.getFileScope().fullPathZ(anon_decl.arena());
15846 const name = try fn_owner_decl.getFileScope(mod).fullPathZ(anon_decl.arena());
1584815847 const new_decl = try anon_decl.finish(
1584915848 try Type.array(anon_decl.arena(), name.len, try mod.intValue(Type.u8, 0), Type.u8, mod),
1585015849 try Value.Tag.bytes.create(anon_decl.arena(), name[0 .. name.len + 1]),
......@@ -15980,22 +15979,22 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1598015979 const fn_info_decl_index = (try sema.namespaceLookup(
1598115980 block,
1598215981 src,
15983 type_info_ty.getNamespace().?,
15982 type_info_ty.getNamespaceIndex(mod).unwrap().?,
1598415983 "Fn",
1598515984 )).?;
15986 try sema.mod.declareDeclDependency(sema.owner_decl_index, fn_info_decl_index);
15985 try mod.declareDeclDependency(sema.owner_decl_index, fn_info_decl_index);
1598715986 try sema.ensureDeclAnalyzed(fn_info_decl_index);
15988 const fn_info_decl = sema.mod.declPtr(fn_info_decl_index);
15987 const fn_info_decl = mod.declPtr(fn_info_decl_index);
1598915988 const fn_ty = fn_info_decl.val.toType();
1599015989 const param_info_decl_index = (try sema.namespaceLookup(
1599115990 block,
1599215991 src,
15993 fn_ty.getNamespace().?,
15992 fn_ty.getNamespaceIndex(mod).unwrap().?,
1599415993 "Param",
1599515994 )).?;
15996 try sema.mod.declareDeclDependency(sema.owner_decl_index, param_info_decl_index);
15995 try mod.declareDeclDependency(sema.owner_decl_index, param_info_decl_index);
1599715996 try sema.ensureDeclAnalyzed(param_info_decl_index);
15998 const param_info_decl = sema.mod.declPtr(param_info_decl_index);
15997 const param_info_decl = mod.declPtr(param_info_decl_index);
1599915998 const param_ty = param_info_decl.val.toType();
1600015999 const new_decl = try params_anon_decl.finish(
1600116000 try Type.Tag.array.create(params_anon_decl.arena(), .{
......@@ -16169,12 +16168,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1616916168 const set_field_ty_decl_index = (try sema.namespaceLookup(
1617016169 block,
1617116170 src,
16172 type_info_ty.getNamespace().?,
16171 type_info_ty.getNamespaceIndex(mod).unwrap().?,
1617316172 "Error",
1617416173 )).?;
16175 try sema.mod.declareDeclDependency(sema.owner_decl_index, set_field_ty_decl_index);
16174 try mod.declareDeclDependency(sema.owner_decl_index, set_field_ty_decl_index);
1617616175 try sema.ensureDeclAnalyzed(set_field_ty_decl_index);
16177 const set_field_ty_decl = sema.mod.declPtr(set_field_ty_decl_index);
16176 const set_field_ty_decl = mod.declPtr(set_field_ty_decl_index);
1617816177 break :t try set_field_ty_decl.val.toType().copy(fields_anon_decl.arena());
1617916178 };
1618016179
......@@ -16277,12 +16276,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1627716276 const enum_field_ty_decl_index = (try sema.namespaceLookup(
1627816277 block,
1627916278 src,
16280 type_info_ty.getNamespace().?,
16279 type_info_ty.getNamespaceIndex(mod).unwrap().?,
1628116280 "EnumField",
1628216281 )).?;
16283 try sema.mod.declareDeclDependency(sema.owner_decl_index, enum_field_ty_decl_index);
16282 try mod.declareDeclDependency(sema.owner_decl_index, enum_field_ty_decl_index);
1628416283 try sema.ensureDeclAnalyzed(enum_field_ty_decl_index);
16285 const enum_field_ty_decl = sema.mod.declPtr(enum_field_ty_decl_index);
16284 const enum_field_ty_decl = mod.declPtr(enum_field_ty_decl_index);
1628616285 break :t try enum_field_ty_decl.val.toType().copy(fields_anon_decl.arena());
1628716286 };
1628816287
......@@ -16336,7 +16335,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1633616335 break :v try Value.Tag.decl_ref.create(sema.arena, new_decl);
1633716336 };
1633816337
16339 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace());
16338 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(mod));
1634016339
1634116340 const field_values = try sema.arena.create([4]Value);
1634216341 field_values.* = .{
......@@ -16368,12 +16367,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1636816367 const union_field_ty_decl_index = (try sema.namespaceLookup(
1636916368 block,
1637016369 src,
16371 type_info_ty.getNamespace().?,
16370 type_info_ty.getNamespaceIndex(mod).unwrap().?,
1637216371 "UnionField",
1637316372 )).?;
16374 try sema.mod.declareDeclDependency(sema.owner_decl_index, union_field_ty_decl_index);
16373 try mod.declareDeclDependency(sema.owner_decl_index, union_field_ty_decl_index);
1637516374 try sema.ensureDeclAnalyzed(union_field_ty_decl_index);
16376 const union_field_ty_decl = sema.mod.declPtr(union_field_ty_decl_index);
16375 const union_field_ty_decl = mod.declPtr(union_field_ty_decl_index);
1637716376 break :t try union_field_ty_decl.val.toType().copy(fields_anon_decl.arena());
1637816377 };
1637916378
......@@ -16434,7 +16433,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1643416433 });
1643516434 };
1643616435
16437 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespace());
16436 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespace(mod));
1643816437
1643916438 const enum_tag_ty_val = if (union_ty.unionTagType()) |tag_ty| v: {
1644016439 const ty_val = try Value.Tag.ty.create(sema.arena, tag_ty);
......@@ -16475,12 +16474,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1647516474 const struct_field_ty_decl_index = (try sema.namespaceLookup(
1647616475 block,
1647716476 src,
16478 type_info_ty.getNamespace().?,
16477 type_info_ty.getNamespaceIndex(mod).unwrap().?,
1647916478 "StructField",
1648016479 )).?;
16481 try sema.mod.declareDeclDependency(sema.owner_decl_index, struct_field_ty_decl_index);
16480 try mod.declareDeclDependency(sema.owner_decl_index, struct_field_ty_decl_index);
1648216481 try sema.ensureDeclAnalyzed(struct_field_ty_decl_index);
16483 const struct_field_ty_decl = sema.mod.declPtr(struct_field_ty_decl_index);
16482 const struct_field_ty_decl = mod.declPtr(struct_field_ty_decl_index);
1648416483 break :t try struct_field_ty_decl.val.toType().copy(fields_anon_decl.arena());
1648516484 };
1648616485 const struct_ty = try sema.resolveTypeFields(ty);
......@@ -16597,7 +16596,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1659716596 });
1659816597 };
1659916598
16600 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, struct_ty.getNamespace());
16599 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, struct_ty.getNamespace(mod));
1660116600
1660216601 const backing_integer_val = blk: {
1660316602 if (layout == .Packed) {
......@@ -16640,7 +16639,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1664016639 // TODO: look into memoizing this result.
1664116640
1664216641 const opaque_ty = try sema.resolveTypeFields(ty);
16643 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, opaque_ty.getNamespace());
16642 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, opaque_ty.getNamespace(mod));
1664416643
1664516644 const field_values = try sema.arena.create([1]Value);
1664616645 field_values.* = .{
......@@ -16676,7 +16675,7 @@ fn typeInfoDecls(
1667616675 const declaration_ty_decl_index = (try sema.namespaceLookup(
1667716676 block,
1667816677 src,
16679 type_info_ty.getNamespace().?,
16678 type_info_ty.getNamespaceIndex(mod).unwrap().?,
1668016679 "Declaration",
1668116680 )).?;
1668216681 try mod.declareDeclDependency(sema.owner_decl_index, declaration_ty_decl_index);
......@@ -16730,7 +16729,7 @@ fn typeInfoNamespaceDecls(
1673016729 if (decl.kind == .@"usingnamespace") {
1673116730 if (decl.analysis == .in_progress) continue;
1673216731 try mod.ensureDeclAnalyzed(decl_index);
16733 const new_ns = decl.val.toType().getNamespace().?;
16732 const new_ns = decl.val.toType().getNamespace(mod).?;
1673416733 try sema.typeInfoNamespaceDecls(block, decls_anon_decl, new_ns, decl_vals, seen_namespaces);
1673516734 continue;
1673616735 }
......@@ -17750,7 +17749,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1775017749 errdefer msg.destroy(sema.gpa);
1775117750
1775217751 const src_decl = sema.mod.declPtr(block.src_decl);
17753 try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src.toSrcLoc(src_decl), elem_ty, .other);
17752 try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src.toSrcLoc(src_decl, mod), elem_ty, .other);
1775417753
1775517754 try sema.addDeclaredHereNote(msg, elem_ty);
1775617755 break :msg msg;
......@@ -18006,6 +18005,7 @@ fn finishStructInit(
1800618005 struct_ty: Type,
1800718006 is_ref: bool,
1800818007) CompileError!Air.Inst.Ref {
18008 const mod = sema.mod;
1800918009 const gpa = sema.gpa;
1801018010
1801118011 var root_msg: ?*Module.ErrorMsg = null;
......@@ -18118,8 +18118,8 @@ fn finishStructInit(
1811818118
1811918119 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
1812018120 error.NeededSourceLocation => {
18121 const decl = sema.mod.declPtr(block.src_decl);
18122 const field_src = Module.initSrc(dest_src.node_offset.x, sema.gpa, decl, runtime_index);
18121 const decl = mod.declPtr(block.src_decl);
18122 const field_src = mod.initSrc(dest_src.node_offset.x, decl, runtime_index);
1812318123 try sema.requireRuntimeBlock(block, dest_src, field_src);
1812418124 unreachable;
1812518125 },
......@@ -18158,11 +18158,11 @@ fn zirStructInitAnon(
1815818158 if (gop.found_existing) {
1815918159 const msg = msg: {
1816018160 const decl = sema.mod.declPtr(block.src_decl);
18161 const field_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, i);
18161 const field_src = mod.initSrc(src.node_offset.x, decl, i);
1816218162 const msg = try sema.errMsg(block, field_src, "duplicate field", .{});
1816318163 errdefer msg.destroy(sema.gpa);
1816418164
18165 const prev_source = Module.initSrc(src.node_offset.x, sema.gpa, decl, gop.value_ptr.*);
18165 const prev_source = mod.initSrc(src.node_offset.x, decl, gop.value_ptr.*);
1816618166 try sema.errNote(block, prev_source, msg, "other field here", .{});
1816718167 break :msg msg;
1816818168 };
......@@ -18175,7 +18175,7 @@ fn zirStructInitAnon(
1817518175 if (types[i].zigTypeTag(mod) == .Opaque) {
1817618176 const msg = msg: {
1817718177 const decl = sema.mod.declPtr(block.src_decl);
18178 const field_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, i);
18178 const field_src = mod.initSrc(src.node_offset.x, decl, i);
1817918179 const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
1818018180 errdefer msg.destroy(sema.gpa);
1818118181
......@@ -18208,7 +18208,7 @@ fn zirStructInitAnon(
1820818208 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
1820918209 error.NeededSourceLocation => {
1821018210 const decl = sema.mod.declPtr(block.src_decl);
18211 const field_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index);
18211 const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index);
1821218212 try sema.requireRuntimeBlock(block, src, field_src);
1821318213 unreachable;
1821418214 },
......@@ -18283,7 +18283,7 @@ fn zirArrayInit(
1828318283 resolved_args[i] = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) {
1828418284 error.NeededSourceLocation => {
1828518285 const decl = sema.mod.declPtr(block.src_decl);
18286 const elem_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, i);
18286 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
1828718287 _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
1828818288 unreachable;
1828918289 },
......@@ -18315,7 +18315,7 @@ fn zirArrayInit(
1831518315 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
1831618316 error.NeededSourceLocation => {
1831718317 const decl = sema.mod.declPtr(block.src_decl);
18318 const elem_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index);
18318 const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index);
1831918319 try sema.requireRuntimeBlock(block, src, elem_src);
1832018320 unreachable;
1832118321 },
......@@ -18724,7 +18724,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1872418724 enum_ty.fmt(mod),
1872518725 });
1872618726 }
18727 const enum_decl_index = enum_ty.getOwnerDecl();
18727 const enum_decl_index = enum_ty.getOwnerDecl(mod);
1872818728 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);
1872918729 if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| {
1873018730 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {
......@@ -18734,7 +18734,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1873418734 val.fmtValue(enum_ty, sema.mod), enum_decl.name,
1873518735 });
1873618736 errdefer msg.destroy(sema.gpa);
18737 try mod.errNoteNonLazy(enum_decl.srcLoc(), msg, "declared here", .{});
18737 try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{});
1873818738 break :msg msg;
1873918739 };
1874018740 return sema.failWithOwnedErrorMsg(msg);
......@@ -18760,6 +18760,7 @@ fn zirReify(
1876018760 inst: Zir.Inst.Index,
1876118761) CompileError!Air.Inst.Ref {
1876218762 const mod = sema.mod;
18763 const gpa = sema.gpa;
1876318764 const name_strategy = @intToEnum(Zir.Inst.NameStrategy, extended.small);
1876418765 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
1876518766 const src = LazySrcLoc.nodeOffset(extra.node);
......@@ -18887,10 +18888,10 @@ fn zirReify(
1888718888 if (!try sema.validateExternType(elem_ty, .other)) {
1888818889 const msg = msg: {
1888918890 const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
18890 errdefer msg.destroy(sema.gpa);
18891 errdefer msg.destroy(gpa);
1889118892
1889218893 const src_decl = mod.declPtr(block.src_decl);
18893 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), elem_ty, .other);
18894 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), elem_ty, .other);
1889418895
1889518896 try sema.addDeclaredHereNote(msg, elem_ty);
1889618897 break :msg msg;
......@@ -19043,7 +19044,6 @@ fn zirReify(
1904319044 return sema.fail(block, src, "reified enums must have no decls", .{});
1904419045 }
1904519046
19046 const gpa = sema.gpa;
1904719047 var new_decl_arena = std.heap.ArenaAllocator.init(gpa);
1904819048 errdefer new_decl_arena.deinit();
1904919049 const new_decl_arena_allocator = new_decl_arena.allocator();
......@@ -19076,11 +19076,11 @@ fn zirReify(
1907619076 .tag_ty_inferred = false,
1907719077 .fields = .{},
1907819078 .values = .{},
19079 .namespace = .{
19080 .parent = block.namespace,
19079 .namespace = try mod.createNamespace(.{
19080 .parent = block.namespace.toOptional(),
1908119081 .ty = enum_ty,
19082 .file_scope = block.getFileScope(),
19083 },
19082 .file_scope = block.getFileScope(mod),
19083 }),
1908419084 };
1908519085
1908619086 // Enum tag type
......@@ -19164,34 +19164,37 @@ fn zirReify(
1916419164 return sema.fail(block, src, "reified opaque must have no decls", .{});
1916519165 }
1916619166
19167 var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa);
19167 var new_decl_arena = std.heap.ArenaAllocator.init(gpa);
1916819168 errdefer new_decl_arena.deinit();
19169 const new_decl_arena_allocator = new_decl_arena.allocator();
1917019169
19171 const opaque_obj = try new_decl_arena_allocator.create(Module.Opaque);
19172 const opaque_ty_payload = try new_decl_arena_allocator.create(Type.Payload.Opaque);
19173 opaque_ty_payload.* = .{
19174 .base = .{ .tag = .@"opaque" },
19175 .data = opaque_obj,
19176 };
19177 const opaque_ty = Type.initPayload(&opaque_ty_payload.base);
19178 const opaque_val = try Value.Tag.ty.create(new_decl_arena_allocator, opaque_ty);
19170 // Because these three things each reference each other,
19171 // `undefined` placeholders are used in two places before being set
19172 // after the opaque type gains an InternPool index.
19173
1917919174 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
1918019175 .ty = Type.type,
19181 .val = opaque_val,
19176 .val = undefined,
1918219177 }, name_strategy, "opaque", inst);
1918319178 const new_decl = mod.declPtr(new_decl_index);
1918419179 new_decl.owns_tv = true;
1918519180 errdefer mod.abortAnonDecl(new_decl_index);
1918619181
19187 opaque_obj.* = .{
19188 .owner_decl = new_decl_index,
19189 .namespace = .{
19190 .parent = block.namespace,
19191 .ty = opaque_ty,
19192 .file_scope = block.getFileScope(),
19193 },
19194 };
19182 const new_namespace_index = try mod.createNamespace(.{
19183 .parent = block.namespace.toOptional(),
19184 .ty = undefined,
19185 .file_scope = block.getFileScope(mod),
19186 });
19187 const new_namespace = mod.namespacePtr(new_namespace_index);
19188 errdefer @panic("TODO error handling");
19189
19190 const opaque_ty = try mod.intern_pool.get(gpa, .{ .opaque_type = .{
19191 .decl = new_decl_index,
19192 .namespace = new_namespace_index,
19193 } });
19194 errdefer @panic("TODO error handling");
19195
19196 new_decl.val = opaque_ty.toValue();
19197 new_namespace.ty = opaque_ty.toType();
1919519198
1919619199 try new_decl.finalizeNewArena(&new_decl_arena);
1919719200 return sema.analyzeDeclVal(block, src, new_decl_index);
......@@ -19214,7 +19217,7 @@ fn zirReify(
1921419217 }
1921519218 const layout = layout_val.toEnum(std.builtin.Type.ContainerLayout);
1921619219
19217 var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa);
19220 var new_decl_arena = std.heap.ArenaAllocator.init(gpa);
1921819221 errdefer new_decl_arena.deinit();
1921919222 const new_decl_arena_allocator = new_decl_arena.allocator();
1922019223
......@@ -19248,11 +19251,11 @@ fn zirReify(
1924819251 .zir_index = inst,
1924919252 .layout = layout,
1925019253 .status = .have_field_types,
19251 .namespace = .{
19252 .parent = block.namespace,
19254 .namespace = try mod.createNamespace(.{
19255 .parent = block.namespace.toOptional(),
1925319256 .ty = union_ty,
19254 .file_scope = block.getFileScope(),
19255 },
19257 .file_scope = block.getFileScope(mod),
19258 }),
1925619259 };
1925719260
1925819261 // Tag type
......@@ -19301,7 +19304,7 @@ fn zirReify(
1930119304 if (!enum_has_field) {
1930219305 const msg = msg: {
1930319306 const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ field_name, union_obj.tag_ty.fmt(mod) });
19304 errdefer msg.destroy(sema.gpa);
19307 errdefer msg.destroy(gpa);
1930519308 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);
1930619309 break :msg msg;
1930719310 };
......@@ -19324,7 +19327,7 @@ fn zirReify(
1932419327 if (field_ty.zigTypeTag(mod) == .Opaque) {
1932519328 const msg = msg: {
1932619329 const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
19327 errdefer msg.destroy(sema.gpa);
19330 errdefer msg.destroy(gpa);
1932819331
1932919332 try sema.addDeclaredHereNote(msg, field_ty);
1933019333 break :msg msg;
......@@ -19334,10 +19337,10 @@ fn zirReify(
1933419337 if (union_obj.layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) {
1933519338 const msg = msg: {
1933619339 const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
19337 errdefer msg.destroy(sema.gpa);
19340 errdefer msg.destroy(gpa);
1933819341
1933919342 const src_decl = mod.declPtr(block.src_decl);
19340 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), field_ty, .union_field);
19343 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), field_ty, .union_field);
1934119344
1934219345 try sema.addDeclaredHereNote(msg, field_ty);
1934319346 break :msg msg;
......@@ -19346,10 +19349,10 @@ fn zirReify(
1934619349 } else if (union_obj.layout == .Packed and !(validatePackedType(field_ty, mod))) {
1934719350 const msg = msg: {
1934819351 const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
19349 errdefer msg.destroy(sema.gpa);
19352 errdefer msg.destroy(gpa);
1935019353
1935119354 const src_decl = mod.declPtr(block.src_decl);
19352 try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl), field_ty);
19355 try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl, mod), field_ty);
1935319356
1935419357 try sema.addDeclaredHereNote(msg, field_ty);
1935519358 break :msg msg;
......@@ -19362,7 +19365,7 @@ fn zirReify(
1936219365 if (names.count() > 0) {
1936319366 const msg = msg: {
1936419367 const msg = try sema.errMsg(block, src, "enum field(s) missing in union", .{});
19365 errdefer msg.destroy(sema.gpa);
19368 errdefer msg.destroy(gpa);
1936619369
1936719370 const enum_ty = union_obj.tag_ty;
1936819371 for (names.keys()) |field_name| {
......@@ -19513,11 +19516,11 @@ fn reifyStruct(
1951319516 .status = .have_field_types,
1951419517 .known_non_opv = false,
1951519518 .is_tuple = is_tuple,
19516 .namespace = .{
19517 .parent = block.namespace,
19519 .namespace = try mod.createNamespace(.{
19520 .parent = block.namespace.toOptional(),
1951819521 .ty = struct_ty,
19519 .file_scope = block.getFileScope(),
19520 },
19522 .file_scope = block.getFileScope(mod),
19523 }),
1952119524 };
1952219525
1952319526 // Fields
......@@ -19629,7 +19632,7 @@ fn reifyStruct(
1962919632 errdefer msg.destroy(sema.gpa);
1963019633
1963119634 const src_decl = sema.mod.declPtr(block.src_decl);
19632 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), field_ty, .struct_field);
19635 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), field_ty, .struct_field);
1963319636
1963419637 try sema.addDeclaredHereNote(msg, field_ty);
1963519638 break :msg msg;
......@@ -19641,7 +19644,7 @@ fn reifyStruct(
1964119644 errdefer msg.destroy(sema.gpa);
1964219645
1964319646 const src_decl = sema.mod.declPtr(block.src_decl);
19644 try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl), field_ty);
19647 try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl, mod), field_ty);
1964519648
1964619649 try sema.addDeclaredHereNote(msg, field_ty);
1964719650 break :msg msg;
......@@ -19741,6 +19744,7 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In
1974119744}
1974219745
1974319746fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
19747 const mod = sema.mod;
1974419748 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
1974519749 const src = LazySrcLoc.nodeOffset(extra.node);
1974619750 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
......@@ -19755,7 +19759,7 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
1975519759 errdefer msg.destroy(sema.gpa);
1975619760
1975719761 const src_decl = sema.mod.declPtr(block.src_decl);
19758 try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl), arg_ty, .param_ty);
19762 try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl, mod), arg_ty, .param_ty);
1975919763
1976019764 try sema.addDeclaredHereNote(msg, arg_ty);
1976119765 break :msg msg;
......@@ -21006,7 +21010,8 @@ fn checkVectorizableBinaryOperands(
2100621010
2100721011fn maybeOptionsSrc(sema: *Sema, block: *Block, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc {
2100821012 if (base_src == .unneeded) return .unneeded;
21009 return Module.optionsSrc(sema.gpa, sema.mod.declPtr(block.src_decl), base_src, wanted);
21013 const mod = sema.mod;
21014 return mod.optionsSrc(sema.mod.declPtr(block.src_decl), base_src, wanted);
2101021015}
2101121016
2101221017fn resolveExportOptions(
......@@ -23067,7 +23072,7 @@ fn zirBuiltinExtern(
2306723072 const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)});
2306823073 errdefer msg.destroy(sema.gpa);
2306923074 const src_decl = sema.mod.declPtr(block.src_decl);
23070 try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl), ty, .other);
23075 try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl, mod), ty, .other);
2307123076 break :msg msg;
2307223077 };
2307323078 return sema.failWithOwnedErrorMsg(msg);
......@@ -23087,9 +23092,9 @@ fn zirBuiltinExtern(
2308723092
2308823093 // TODO check duplicate extern
2308923094
23090 const new_decl_index = try sema.mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null);
23091 errdefer sema.mod.destroyDecl(new_decl_index);
23092 const new_decl = sema.mod.declPtr(new_decl_index);
23095 const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null);
23096 errdefer mod.destroyDecl(new_decl_index);
23097 const new_decl = mod.declPtr(new_decl_index);
2309323098 new_decl.name = try sema.gpa.dupeZ(u8, options.name);
2309423099
2309523100 {
......@@ -23117,12 +23122,12 @@ fn zirBuiltinExtern(
2311723122 new_decl.@"linksection" = null;
2311823123 new_decl.has_tv = true;
2311923124 new_decl.analysis = .complete;
23120 new_decl.generation = sema.mod.generation;
23125 new_decl.generation = mod.generation;
2312123126
2312223127 try new_decl.finalizeNewArena(&new_decl_arena);
2312323128 }
2312423129
23125 try sema.mod.declareDeclDependency(sema.owner_decl_index, new_decl_index);
23130 try mod.declareDeclDependency(sema.owner_decl_index, new_decl_index);
2312623131 try sema.ensureDeclAnalyzed(new_decl_index);
2312723132
2312823133 const ref = try Value.Tag.decl_ref.create(sema.arena, new_decl_index);
......@@ -23209,7 +23214,7 @@ fn validateVarType(
2320923214 const msg = try sema.errMsg(block, src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)});
2321023215 errdefer msg.destroy(sema.gpa);
2321123216 const src_decl = mod.declPtr(block.src_decl);
23212 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), var_ty, .other);
23217 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), var_ty, .other);
2321323218 break :msg msg;
2321423219 };
2321523220 return sema.failWithOwnedErrorMsg(msg);
......@@ -23222,7 +23227,7 @@ fn validateVarType(
2322223227 errdefer msg.destroy(sema.gpa);
2322323228
2322423229 const src_decl = mod.declPtr(block.src_decl);
23225 try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl), var_ty);
23230 try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), var_ty);
2322623231 if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) {
2322723232 try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
2322823233 }
......@@ -23939,11 +23944,12 @@ fn safetyPanic(
2393923944 block: *Block,
2394023945 panic_id: PanicId,
2394123946) CompileError!void {
23947 const mod = sema.mod;
2394223948 const panic_messages_ty = try sema.getBuiltinType("panic_messages");
2394323949 const msg_decl_index = (try sema.namespaceLookup(
2394423950 block,
2394523951 sema.src,
23946 panic_messages_ty.getNamespace().?,
23952 panic_messages_ty.getNamespaceIndex(mod).unwrap().?,
2394723953 @tagName(panic_id),
2394823954 )).?;
2394923955
......@@ -24006,7 +24012,7 @@ fn fieldVal(
2400624012 );
2400724013 } else if (mem.eql(u8, field_name, "ptr") and is_pointer_to) {
2400824014 const ptr_info = object_ty.ptrInfo(mod);
24009 const result_ty = try Type.ptr(sema.arena, sema.mod, .{
24015 const result_ty = try Type.ptr(sema.arena, mod, .{
2401024016 .pointee_type = ptr_info.pointee_type.childType(mod),
2401124017 .sentinel = ptr_info.sentinel,
2401224018 .@"align" = ptr_info.@"align",
......@@ -24025,7 +24031,7 @@ fn fieldVal(
2402524031 block,
2402624032 field_name_src,
2402724033 "no member named '{s}' in '{}'",
24028 .{ field_name, object_ty.fmt(sema.mod) },
24034 .{ field_name, object_ty.fmt(mod) },
2402924035 );
2403024036 }
2403124037 },
......@@ -24049,7 +24055,7 @@ fn fieldVal(
2404924055 block,
2405024056 field_name_src,
2405124057 "no member named '{s}' in '{}'",
24052 .{ field_name, object_ty.fmt(sema.mod) },
24058 .{ field_name, object_ty.fmt(mod) },
2405324059 );
2405424060 }
2405524061 }
......@@ -24071,14 +24077,14 @@ fn fieldVal(
2407124077 }
2407224078 const msg = msg: {
2407324079 const msg = try sema.errMsg(block, src, "no error named '{s}' in '{}'", .{
24074 field_name, child_type.fmt(sema.mod),
24080 field_name, child_type.fmt(mod),
2407524081 });
2407624082 errdefer msg.destroy(sema.gpa);
2407724083 try sema.addDeclaredHereNote(msg, child_type);
2407824084 break :msg msg;
2407924085 };
2408024086 return sema.failWithOwnedErrorMsg(msg);
24081 } else (try sema.mod.getErrorValue(field_name)).key;
24087 } else (try mod.getErrorValue(field_name)).key;
2408224088
2408324089 return sema.addConstant(
2408424090 if (!child_type.isAnyError())
......@@ -24089,7 +24095,7 @@ fn fieldVal(
2408924095 );
2409024096 },
2409124097 .Union => {
24092 if (child_type.getNamespace()) |namespace| {
24098 if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| {
2409324099 if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| {
2409424100 return inst;
2409524101 }
......@@ -24107,7 +24113,7 @@ fn fieldVal(
2410724113 return sema.failWithBadMemberAccess(block, union_ty, field_name_src, field_name);
2410824114 },
2410924115 .Enum => {
24110 if (child_type.getNamespace()) |namespace| {
24116 if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| {
2411124117 if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| {
2411224118 return inst;
2411324119 }
......@@ -24119,7 +24125,7 @@ fn fieldVal(
2411924125 return sema.addConstant(try child_type.copy(arena), enum_val);
2412024126 },
2412124127 .Struct, .Opaque => {
24122 if (child_type.getNamespace()) |namespace| {
24128 if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| {
2412324129 if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| {
2412424130 return inst;
2412524131 }
......@@ -24128,7 +24134,7 @@ fn fieldVal(
2412824134 },
2412924135 else => {
2413024136 const msg = msg: {
24131 const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(sema.mod)});
24137 const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(mod)});
2413224138 errdefer msg.destroy(sema.gpa);
2413324139 if (child_type.isSlice(mod)) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{});
2413424140 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{});
......@@ -24174,7 +24180,7 @@ fn fieldPtr(
2417424180 const object_ptr_ty = sema.typeOf(object_ptr);
2417524181 const object_ty = switch (object_ptr_ty.zigTypeTag(mod)) {
2417624182 .Pointer => object_ptr_ty.childType(mod),
24177 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty.fmt(sema.mod)}),
24183 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty.fmt(mod)}),
2417824184 };
2417924185
2418024186 // Zig allows dereferencing a single pointer during field lookup. Note that
......@@ -24202,7 +24208,7 @@ fn fieldPtr(
2420224208 block,
2420324209 field_name_src,
2420424210 "no member named '{s}' in '{}'",
24205 .{ field_name, object_ty.fmt(sema.mod) },
24211 .{ field_name, object_ty.fmt(mod) },
2420624212 );
2420724213 }
2420824214 },
......@@ -24218,7 +24224,7 @@ fn fieldPtr(
2421824224 const buf = try sema.arena.create(Type.SlicePtrFieldTypeBuffer);
2421924225 const slice_ptr_ty = inner_ty.slicePtrFieldType(buf, mod);
2422024226
24221 const result_ty = try Type.ptr(sema.arena, sema.mod, .{
24227 const result_ty = try Type.ptr(sema.arena, mod, .{
2422224228 .pointee_type = slice_ptr_ty,
2422324229 .mutable = attr_ptr_ty.ptrIsMutable(mod),
2422424230 .@"volatile" = attr_ptr_ty.isVolatilePtr(mod),
......@@ -24239,7 +24245,7 @@ fn fieldPtr(
2423924245
2424024246 return block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr);
2424124247 } else if (mem.eql(u8, field_name, "len")) {
24242 const result_ty = try Type.ptr(sema.arena, sema.mod, .{
24248 const result_ty = try Type.ptr(sema.arena, mod, .{
2424324249 .pointee_type = Type.usize,
2424424250 .mutable = attr_ptr_ty.ptrIsMutable(mod),
2424524251 .@"volatile" = attr_ptr_ty.isVolatilePtr(mod),
......@@ -24264,7 +24270,7 @@ fn fieldPtr(
2426424270 block,
2426524271 field_name_src,
2426624272 "no member named '{s}' in '{}'",
24267 .{ field_name, object_ty.fmt(sema.mod) },
24273 .{ field_name, object_ty.fmt(mod) },
2426824274 );
2426924275 }
2427024276 },
......@@ -24287,9 +24293,9 @@ fn fieldPtr(
2428724293 break :blk entry.key_ptr.*;
2428824294 }
2428924295 return sema.fail(block, src, "no error named '{s}' in '{}'", .{
24290 field_name, child_type.fmt(sema.mod),
24296 field_name, child_type.fmt(mod),
2429124297 });
24292 } else (try sema.mod.getErrorValue(field_name)).key;
24298 } else (try mod.getErrorValue(field_name)).key;
2429324299
2429424300 var anon_decl = try block.startAnonDecl();
2429524301 defer anon_decl.deinit();
......@@ -24303,7 +24309,7 @@ fn fieldPtr(
2430324309 ));
2430424310 },
2430524311 .Union => {
24306 if (child_type.getNamespace()) |namespace| {
24312 if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| {
2430724313 if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| {
2430824314 return inst;
2430924315 }
......@@ -24324,7 +24330,7 @@ fn fieldPtr(
2432424330 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2432524331 },
2432624332 .Enum => {
24327 if (child_type.getNamespace()) |namespace| {
24333 if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| {
2432824334 if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| {
2432924335 return inst;
2433024336 }
......@@ -24342,14 +24348,14 @@ fn fieldPtr(
2434224348 ));
2434324349 },
2434424350 .Struct, .Opaque => {
24345 if (child_type.getNamespace()) |namespace| {
24351 if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| {
2434624352 if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| {
2434724353 return inst;
2434824354 }
2434924355 }
2435024356 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2435124357 },
24352 else => return sema.fail(block, src, "type '{}' has no members", .{child_type.fmt(sema.mod)}),
24358 else => return sema.fail(block, src, "type '{}' has no members", .{child_type.fmt(mod)}),
2435324359 }
2435424360 },
2435524361 .Struct => {
......@@ -24398,7 +24404,7 @@ fn fieldCallBind(
2439824404 const inner_ty = if (raw_ptr_ty.zigTypeTag(mod) == .Pointer and (raw_ptr_ty.ptrSize(mod) == .One or raw_ptr_ty.ptrSize(mod) == .C))
2439924405 raw_ptr_ty.childType(mod)
2440024406 else
24401 return sema.fail(block, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty.fmt(sema.mod)});
24407 return sema.fail(block, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty.fmt(mod)});
2440224408
2440324409 // Optionally dereference a second pointer to get the concrete type.
2440424410 const is_double_ptr = inner_ty.zigTypeTag(mod) == .Pointer and inner_ty.ptrSize(mod) == .One;
......@@ -24458,7 +24464,7 @@ fn fieldCallBind(
2445824464 // If we get here, we need to look for a decl in the struct type instead.
2445924465 const found_decl = switch (concrete_ty.zigTypeTag(mod)) {
2446024466 .Struct, .Opaque, .Union, .Enum => found_decl: {
24461 if (concrete_ty.getNamespace()) |namespace| {
24467 if (concrete_ty.getNamespaceIndex(mod).unwrap()) |namespace| {
2446224468 if (try sema.namespaceLookup(block, src, namespace, field_name)) |decl_idx| {
2446324469 try sema.addReferencedBy(block, src, decl_idx);
2446424470 const decl_val = try sema.analyzeDeclVal(block, src, decl_idx);
......@@ -24472,7 +24478,7 @@ fn fieldCallBind(
2447224478 first_param_type.zigTypeTag(mod) == .Pointer and
2447324479 (first_param_type.ptrSize(mod) == .One or
2447424480 first_param_type.ptrSize(mod) == .C) and
24475 first_param_type.childType(mod).eql(concrete_ty, sema.mod)))
24481 first_param_type.childType(mod).eql(concrete_ty, mod)))
2447624482 {
2447724483 // zig fmt: on
2447824484 // Note that if the param type is generic poison, we know that it must
......@@ -24484,7 +24490,7 @@ fn fieldCallBind(
2448424490 .func_inst = decl_val,
2448524491 .arg0_inst = object_ptr,
2448624492 } };
24487 } else if (first_param_type.eql(concrete_ty, sema.mod)) {
24493 } else if (first_param_type.eql(concrete_ty, mod)) {
2448824494 const deref = try sema.analyzeLoad(block, src, object_ptr, src);
2448924495 return .{ .method = .{
2449024496 .func_inst = decl_val,
......@@ -24492,7 +24498,7 @@ fn fieldCallBind(
2449224498 } };
2449324499 } else if (first_param_type.zigTypeTag(mod) == .Optional) {
2449424500 const child = first_param_type.optionalChild(mod);
24495 if (child.eql(concrete_ty, sema.mod)) {
24501 if (child.eql(concrete_ty, mod)) {
2449624502 const deref = try sema.analyzeLoad(block, src, object_ptr, src);
2449724503 return .{ .method = .{
2449824504 .func_inst = decl_val,
......@@ -24500,7 +24506,7 @@ fn fieldCallBind(
2450024506 } };
2450124507 } else if (child.zigTypeTag(mod) == .Pointer and
2450224508 child.ptrSize(mod) == .One and
24503 child.childType(mod).eql(concrete_ty, sema.mod))
24509 child.childType(mod).eql(concrete_ty, mod))
2450424510 {
2450524511 return .{ .method = .{
2450624512 .func_inst = decl_val,
......@@ -24508,7 +24514,7 @@ fn fieldCallBind(
2450824514 } };
2450924515 }
2451024516 } else if (first_param_type.zigTypeTag(mod) == .ErrorUnion and
24511 first_param_type.errorUnionPayload().eql(concrete_ty, sema.mod))
24517 first_param_type.errorUnionPayload().eql(concrete_ty, mod))
2451224518 {
2451324519 const deref = try sema.analyzeLoad(block, src, object_ptr, src);
2451424520 return .{ .method = .{
......@@ -24526,12 +24532,12 @@ fn fieldCallBind(
2452624532 };
2452724533
2452824534 const msg = msg: {
24529 const msg = try sema.errMsg(block, src, "no field or member function named '{s}' in '{}'", .{ field_name, concrete_ty.fmt(sema.mod) });
24535 const msg = try sema.errMsg(block, src, "no field or member function named '{s}' in '{}'", .{ field_name, concrete_ty.fmt(mod) });
2453024536 errdefer msg.destroy(sema.gpa);
2453124537 try sema.addDeclaredHereNote(msg, concrete_ty);
2453224538 if (found_decl) |decl_idx| {
24533 const decl = sema.mod.declPtr(decl_idx);
24534 try sema.mod.errNoteNonLazy(decl.srcLoc(), msg, "'{s}' is not a member function", .{field_name});
24539 const decl = mod.declPtr(decl_idx);
24540 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{s}' is not a member function", .{field_name});
2453524541 }
2453624542 break :msg msg;
2453724543 };
......@@ -24549,7 +24555,7 @@ fn finishFieldCallBind(
2454924555) CompileError!ResolvedFieldCallee {
2455024556 const mod = sema.mod;
2455124557 const arena = sema.arena;
24552 const ptr_field_ty = try Type.ptr(arena, sema.mod, .{
24558 const ptr_field_ty = try Type.ptr(arena, mod, .{
2455324559 .pointee_type = field_ty,
2455424560 .mutable = ptr_ty.ptrIsMutable(mod),
2455524561 .@"addrspace" = ptr_ty.ptrAddressSpace(mod),
......@@ -24583,19 +24589,20 @@ fn namespaceLookup(
2458324589 sema: *Sema,
2458424590 block: *Block,
2458524591 src: LazySrcLoc,
24586 namespace: *Namespace,
24592 namespace: Namespace.Index,
2458724593 decl_name: []const u8,
2458824594) CompileError!?Decl.Index {
24595 const mod = sema.mod;
2458924596 const gpa = sema.gpa;
2459024597 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| {
24591 const decl = sema.mod.declPtr(decl_index);
24592 if (!decl.is_pub and decl.getFileScope() != block.getFileScope()) {
24598 const decl = mod.declPtr(decl_index);
24599 if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) {
2459324600 const msg = msg: {
2459424601 const msg = try sema.errMsg(block, src, "'{s}' is not marked 'pub'", .{
2459524602 decl_name,
2459624603 });
2459724604 errdefer msg.destroy(gpa);
24598 try sema.mod.errNoteNonLazy(decl.srcLoc(), msg, "declared here", .{});
24605 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{});
2459924606 break :msg msg;
2460024607 };
2460124608 return sema.failWithOwnedErrorMsg(msg);
......@@ -24609,7 +24616,7 @@ fn namespaceLookupRef(
2460924616 sema: *Sema,
2461024617 block: *Block,
2461124618 src: LazySrcLoc,
24612 namespace: *Namespace,
24619 namespace: Namespace.Index,
2461324620 decl_name: []const u8,
2461424621) CompileError!?Air.Inst.Ref {
2461524622 const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null;
......@@ -24621,7 +24628,7 @@ fn namespaceLookupVal(
2462124628 sema: *Sema,
2462224629 block: *Block,
2462324630 src: LazySrcLoc,
24624 namespace: *Namespace,
24631 namespace: Namespace.Index,
2462524632 decl_name: []const u8,
2462624633) CompileError!?Air.Inst.Ref {
2462724634 const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null;
......@@ -24692,7 +24699,7 @@ fn structFieldPtrByIndex(
2469224699 .@"addrspace" = struct_ptr_ty_info.@"addrspace",
2469324700 };
2469424701
24695 const target = sema.mod.getTarget();
24702 const target = mod.getTarget();
2469624703
2469724704 if (struct_obj.layout == .Packed) {
2469824705 comptime assert(Type.packed_struct_layout_version == 2);
......@@ -24746,7 +24753,7 @@ fn structFieldPtrByIndex(
2474624753 ptr_ty_data.@"align" = field.abi_align;
2474724754 }
2474824755
24749 const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, ptr_ty_data);
24756 const ptr_field_ty = try Type.ptr(sema.arena, mod, ptr_ty_data);
2475024757
2475124758 if (field.is_comptime) {
2475224759 const val = try Value.Tag.comptime_field_ptr.create(sema.arena, .{
......@@ -24848,16 +24855,17 @@ fn tupleFieldIndex(
2484824855 field_name: []const u8,
2484924856 field_name_src: LazySrcLoc,
2485024857) CompileError!u32 {
24858 const mod = sema.mod;
2485124859 assert(!std.mem.eql(u8, field_name, "len"));
2485224860 if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| {
2485324861 if (field_index < tuple_ty.structFieldCount()) return field_index;
2485424862 return sema.fail(block, field_name_src, "index '{s}' out of bounds of tuple '{}'", .{
24855 field_name, tuple_ty.fmt(sema.mod),
24863 field_name, tuple_ty.fmt(mod),
2485624864 });
2485724865 } else |_| {}
2485824866
2485924867 return sema.fail(block, field_name_src, "no field named '{s}' in tuple '{}'", .{
24860 field_name, tuple_ty.fmt(sema.mod),
24868 field_name, tuple_ty.fmt(mod),
2486124869 });
2486224870}
2486324871
......@@ -24913,7 +24921,7 @@ fn unionFieldPtr(
2491324921 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
2491424922 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
2491524923 const field = union_obj.fields.values()[field_index];
24916 const ptr_field_ty = try Type.ptr(arena, sema.mod, .{
24924 const ptr_field_ty = try Type.ptr(arena, mod, .{
2491724925 .pointee_type = field.ty,
2491824926 .mutable = union_ptr_ty.ptrIsMutable(mod),
2491924927 .@"volatile" = union_ptr_ty.isVolatilePtr(mod),
......@@ -24947,7 +24955,7 @@ fn unionFieldPtr(
2494724955 .data = enum_field_index,
2494824956 };
2494924957 const field_tag = Value.initPayload(&field_tag_buf.base);
24950 const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, sema.mod);
24958 const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, mod);
2495124959 if (!tag_matches) {
2495224960 const msg = msg: {
2495324961 const active_index = tag_and_val.tag.castTag(.enum_field_index).?.data;
......@@ -25017,7 +25025,7 @@ fn unionFieldVal(
2501725025 .data = enum_field_index,
2501825026 };
2501925027 const field_tag = Value.initPayload(&field_tag_buf.base);
25020 const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, sema.mod);
25028 const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, mod);
2502125029 switch (union_obj.layout) {
2502225030 .Auto => {
2502325031 if (tag_matches) {
......@@ -25038,7 +25046,7 @@ fn unionFieldVal(
2503825046 if (tag_matches) {
2503925047 return sema.addConstant(field.ty, tag_and_val.val);
2504025048 } else {
25041 const old_ty = union_ty.unionFieldType(tag_and_val.tag, sema.mod);
25049 const old_ty = union_ty.unionFieldType(tag_and_val.tag, mod);
2504225050 if (try sema.bitCastVal(block, src, tag_and_val.val, old_ty, field.ty, 0)) |new_val| {
2504325051 return sema.addConstant(field.ty, new_val);
2504425052 }
......@@ -25079,7 +25087,7 @@ fn elemPtr(
2507925087
2508025088 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(mod)) {
2508125089 .Pointer => indexable_ptr_ty.childType(mod),
25082 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{}'", .{indexable_ptr_ty.fmt(sema.mod)}),
25090 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{}'", .{indexable_ptr_ty.fmt(mod)}),
2508325091 };
2508425092 try checkIndexable(sema, block, src, indexable_ty);
2508525093
......@@ -25124,7 +25132,7 @@ fn elemPtrOneLayerOnly(
2512425132 const ptr_val = maybe_ptr_val orelse break :rs indexable_src;
2512525133 const index_val = maybe_index_val orelse break :rs elem_index_src;
2512625134 const index = @intCast(usize, index_val.toUnsignedInt(mod));
25127 const elem_ptr = try ptr_val.elemPtr(indexable_ty, sema.arena, index, sema.mod);
25135 const elem_ptr = try ptr_val.elemPtr(indexable_ty, sema.arena, index, mod);
2512825136 const result_ty = try sema.elemPtrType(indexable_ty, index);
2512925137 return sema.addConstant(result_ty, elem_ptr);
2513025138 };
......@@ -25170,7 +25178,7 @@ fn elemVal(
2517025178 const indexable_val = maybe_indexable_val orelse break :rs indexable_src;
2517125179 const index_val = maybe_index_val orelse break :rs elem_index_src;
2517225180 const index = @intCast(usize, index_val.toUnsignedInt(mod));
25173 const elem_ptr_val = try indexable_val.elemPtr(indexable_ty, sema.arena, index, sema.mod);
25181 const elem_ptr_val = try indexable_val.elemPtr(indexable_ty, sema.arena, index, mod);
2517425182 if (try sema.pointerDeref(block, indexable_src, elem_ptr_val, indexable_ty)) |elem_val| {
2517525183 return sema.addConstant(indexable_ty.elemType2(mod), elem_val);
2517625184 }
......@@ -25209,6 +25217,7 @@ fn validateRuntimeElemAccess(
2520925217 parent_ty: Type,
2521025218 parent_src: LazySrcLoc,
2521125219) CompileError!void {
25220 const mod = sema.mod;
2521225221 const valid_rt = try sema.validateRunTimeType(elem_ty, false);
2521325222 if (!valid_rt) {
2521425223 const msg = msg: {
......@@ -25216,12 +25225,12 @@ fn validateRuntimeElemAccess(
2521625225 block,
2521725226 elem_index_src,
2521825227 "values of type '{}' must be comptime-known, but index value is runtime-known",
25219 .{parent_ty.fmt(sema.mod)},
25228 .{parent_ty.fmt(mod)},
2522025229 );
2522125230 errdefer msg.destroy(sema.gpa);
2522225231
25223 const src_decl = sema.mod.declPtr(block.src_decl);
25224 try sema.explainWhyTypeIsComptime(msg, parent_src.toSrcLoc(src_decl), parent_ty);
25232 const src_decl = mod.declPtr(block.src_decl);
25233 try sema.explainWhyTypeIsComptime(msg, parent_src.toSrcLoc(src_decl, mod), parent_ty);
2522525234
2522625235 break :msg msg;
2522725236 };
......@@ -25255,7 +25264,7 @@ fn tupleFieldPtr(
2525525264 }
2525625265
2525725266 const field_ty = tuple_ty.structFieldType(field_index);
25258 const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, .{
25267 const ptr_field_ty = try Type.ptr(sema.arena, mod, .{
2525925268 .pointee_type = field_ty,
2526025269 .mutable = tuple_ptr_ty.ptrIsMutable(mod),
2526125270 .@"volatile" = tuple_ptr_ty.isVolatilePtr(mod),
......@@ -25431,7 +25440,7 @@ fn elemPtrArray(
2543125440 return sema.addConstUndef(elem_ptr_ty);
2543225441 }
2543325442 if (offset) |index| {
25434 const elem_ptr = try array_ptr_val.elemPtr(array_ptr_ty, sema.arena, index, sema.mod);
25443 const elem_ptr = try array_ptr_val.elemPtr(array_ptr_ty, sema.arena, index, mod);
2543525444 return sema.addConstant(elem_ptr_ty, elem_ptr);
2543625445 }
2543725446 }
......@@ -25476,7 +25485,7 @@ fn elemValSlice(
2547625485
2547725486 if (maybe_slice_val) |slice_val| {
2547825487 runtime_src = elem_index_src;
25479 const slice_len = slice_val.sliceLen(sema.mod);
25488 const slice_len = slice_val.sliceLen(mod);
2548025489 const slice_len_s = slice_len + @boolToInt(slice_sent);
2548125490 if (slice_len_s == 0) {
2548225491 return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{});
......@@ -25487,7 +25496,7 @@ fn elemValSlice(
2548725496 const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else "";
2548825497 return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label });
2548925498 }
25490 const elem_ptr_val = try slice_val.elemPtr(slice_ty, sema.arena, index, sema.mod);
25499 const elem_ptr_val = try slice_val.elemPtr(slice_ty, sema.arena, index, mod);
2549125500 if (try sema.pointerDeref(block, slice_src, elem_ptr_val, slice_ty)) |elem_val| {
2549225501 return sema.addConstant(elem_ty, elem_val);
2549325502 }
......@@ -25500,7 +25509,7 @@ fn elemValSlice(
2550025509 try sema.requireRuntimeBlock(block, src, runtime_src);
2550125510 if (oob_safety and block.wantSafety()) {
2550225511 const len_inst = if (maybe_slice_val) |slice_val|
25503 try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod))
25512 try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(mod))
2550425513 else
2550525514 try block.addTyOp(.slice_len, Type.usize, slice);
2550625515 const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt;
......@@ -25537,7 +25546,7 @@ fn elemPtrSlice(
2553725546 if (slice_val.isUndef()) {
2553825547 return sema.addConstUndef(elem_ptr_ty);
2553925548 }
25540 const slice_len = slice_val.sliceLen(sema.mod);
25549 const slice_len = slice_val.sliceLen(mod);
2554125550 const slice_len_s = slice_len + @boolToInt(slice_sent);
2554225551 if (slice_len_s == 0) {
2554325552 return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{});
......@@ -25547,7 +25556,7 @@ fn elemPtrSlice(
2554725556 const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else "";
2554825557 return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label });
2554925558 }
25550 const elem_ptr_val = try slice_val.elemPtr(slice_ty, sema.arena, index, sema.mod);
25559 const elem_ptr_val = try slice_val.elemPtr(slice_ty, sema.arena, index, mod);
2555125560 return sema.addConstant(elem_ptr_ty, elem_ptr_val);
2555225561 }
2555325562 }
......@@ -25560,7 +25569,7 @@ fn elemPtrSlice(
2556025569 const len_inst = len: {
2556125570 if (maybe_undef_slice_val) |slice_val|
2556225571 if (!slice_val.isUndef())
25563 break :len try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod));
25572 break :len try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(mod));
2556425573 break :len try block.addTyOp(.slice_len, Type.usize, slice);
2556525574 };
2556625575 const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt;
......@@ -25602,16 +25611,17 @@ const CoerceOpts = struct {
2560225611
2560325612 fn get(info: @This(), sema: *Sema) !?Module.SrcLoc {
2560425613 if (info.func_inst == .none) return null;
25614 const mod = sema.mod;
2560525615 const fn_decl = (try sema.funcDeclSrc(info.func_inst)) orelse return null;
25606 const param_src = Module.paramSrc(0, sema.gpa, fn_decl, info.param_i);
25616 const param_src = Module.paramSrc(0, mod, fn_decl, info.param_i);
2560725617 if (param_src == .node_offset_param) {
2560825618 return Module.SrcLoc{
25609 .file_scope = fn_decl.getFileScope(),
25619 .file_scope = fn_decl.getFileScope(mod),
2561025620 .parent_decl_node = fn_decl.src_node,
2561125621 .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param),
2561225622 };
2561325623 }
25614 return param_src.toSrcLoc(fn_decl);
25624 return param_src.toSrcLoc(fn_decl, mod);
2561525625 }
2561625626 } = .{},
2561725627};
......@@ -25625,13 +25635,13 @@ fn coerceExtra(
2562525635 opts: CoerceOpts,
2562625636) CoersionError!Air.Inst.Ref {
2562725637 if (dest_ty_unresolved.isGenericPoison()) return inst;
25638 const mod = sema.mod;
2562825639 const dest_ty_src = inst_src; // TODO better source location
2562925640 const dest_ty = try sema.resolveTypeFields(dest_ty_unresolved);
2563025641 const inst_ty = try sema.resolveTypeFields(sema.typeOf(inst));
25631 const mod = sema.mod;
25632 const target = sema.mod.getTarget();
25642 const target = mod.getTarget();
2563325643 // If the types are the same, we can return the operand.
25634 if (dest_ty.eql(inst_ty, sema.mod))
25644 if (dest_ty.eql(inst_ty, mod))
2563525645 return inst;
2563625646
2563725647 const arena = sema.arena;
......@@ -26254,7 +26264,7 @@ fn coerceExtra(
2625426264
2625526265 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
2625626266 const src_decl = sema.mod.declPtr(sema.func.?.owner_decl);
26257 try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl), msg, "'noreturn' declared here", .{});
26267 try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "'noreturn' declared here", .{});
2625826268 break :msg msg;
2625926269 };
2626026270 return sema.failWithOwnedErrorMsg(msg);
......@@ -26287,9 +26297,9 @@ fn coerceExtra(
2628726297 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
2628826298 const src_decl = sema.mod.declPtr(sema.func.?.owner_decl);
2628926299 if (inst_ty.isError(mod) and !dest_ty.isError(mod)) {
26290 try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl), msg, "function cannot return an error", .{});
26300 try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "function cannot return an error", .{});
2629126301 } else {
26292 try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl), msg, "function return type declared here", .{});
26302 try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "function return type declared here", .{});
2629326303 }
2629426304 }
2629526305
......@@ -27246,7 +27256,7 @@ fn coerceVarArgParam(
2724627256 errdefer msg.destroy(sema.gpa);
2724727257
2724827258 const src_decl = sema.mod.declPtr(block.src_decl);
27249 try sema.explainWhyTypeIsNotExtern(msg, inst_src.toSrcLoc(src_decl), coerced_ty, .param_ty);
27259 try sema.explainWhyTypeIsNotExtern(msg, inst_src.toSrcLoc(src_decl, mod), coerced_ty, .param_ty);
2725027260
2725127261 try sema.addDeclaredHereNote(msg, coerced_ty);
2725227262 break :msg msg;
......@@ -29186,13 +29196,14 @@ fn addReferencedBy(
2918629196}
2918729197
2918829198fn ensureDeclAnalyzed(sema: *Sema, decl_index: Decl.Index) CompileError!void {
29189 const decl = sema.mod.declPtr(decl_index);
29199 const mod = sema.mod;
29200 const decl = mod.declPtr(decl_index);
2919029201 if (decl.analysis == .in_progress) {
29191 const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(), "dependency loop detected", .{});
29202 const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(mod), "dependency loop detected", .{});
2919229203 return sema.failWithOwnedErrorMsg(msg);
2919329204 }
2919429205
29195 sema.mod.ensureDeclAnalyzed(decl_index) catch |err| {
29206 mod.ensureDeclAnalyzed(decl_index) catch |err| {
2919629207 if (sema.owner_func) |owner_func| {
2919729208 owner_func.state = .dependency_failure;
2919829209 } else {
......@@ -31015,12 +31026,12 @@ fn resolvePeerTypes(
3101531026 // At this point, we hit a compile error. We need to recover
3101631027 // the source locations.
3101731028 const chosen_src = candidate_srcs.resolve(
31018 sema.gpa,
31029 mod,
3101931030 mod.declPtr(block.src_decl),
3102031031 chosen_i,
3102131032 );
3102231033 const candidate_src = candidate_srcs.resolve(
31023 sema.gpa,
31034 mod,
3102431035 mod.declPtr(block.src_decl),
3102531036 candidate_i + 1,
3102631037 );
......@@ -31315,7 +31326,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
3131531326 const decl_arena_allocator = decl.value_arena.?.acquire(gpa, &decl_arena);
3131631327 defer decl.value_arena.?.release(&decl_arena);
3131731328
31318 const zir = struct_obj.namespace.file_scope.zir;
31329 const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir;
3131931330 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
3132031331 assert(extended.opcode == .struct_decl);
3132131332 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
......@@ -31353,7 +31364,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
3135331364 .parent = null,
3135431365 .sema = &sema,
3135531366 .src_decl = decl_index,
31356 .namespace = &struct_obj.namespace,
31367 .namespace = struct_obj.namespace,
3135731368 .wip_capture_scope = wip_captures.scope,
3135831369 .instructions = .{},
3135931370 .inlining = null,
......@@ -31399,7 +31410,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
3139931410 .parent = null,
3140031411 .sema = &sema,
3140131412 .src_decl = decl_index,
31402 .namespace = &struct_obj.namespace,
31413 .namespace = struct_obj.namespace,
3140331414 .wip_capture_scope = undefined,
3140431415 .instructions = .{},
3140531416 .inlining = null,
......@@ -31522,7 +31533,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3152231533 .error_set_single,
3152331534 .error_set_inferred,
3152431535 .error_set_merged,
31525 .@"opaque",
3152631536 .enum_simple,
3152731537 => false,
3152831538
......@@ -31678,6 +31688,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3167831688 },
3167931689 .struct_type => @panic("TODO"),
3168031690 .union_type => @panic("TODO"),
31691 .opaque_type => false,
3168131692
3168231693 // values, not types
3168331694 .simple_value => unreachable,
......@@ -31991,6 +32002,8 @@ fn resolveInferredErrorSet(
3199132002 return sema.fail(block, src, "unable to resolve inferred error set", .{});
3199232003 }
3199332004
32005 const mod = sema.mod;
32006
3199432007 // In order to ensure that all dependencies are properly added to the set, we
3199532008 // need to ensure the function body is analyzed of the inferred error set.
3199632009 // However, in the case of comptime/inline function calls with inferred error sets,
......@@ -32011,7 +32024,7 @@ fn resolveInferredErrorSet(
3201132024 const msg = try sema.errMsg(block, src, "unable to resolve inferred error set of generic function", .{});
3201232025 errdefer msg.destroy(sema.gpa);
3201332026
32014 try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(), msg, "generic function declared here", .{});
32027 try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(mod), msg, "generic function declared here", .{});
3201532028 break :msg msg;
3201632029 };
3201732030 return sema.failWithOwnedErrorMsg(msg);
......@@ -32049,7 +32062,7 @@ fn resolveInferredErrorSetTy(
3204932062fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void {
3205032063 const gpa = mod.gpa;
3205132064 const decl_index = struct_obj.owner_decl;
32052 const zir = struct_obj.namespace.file_scope.zir;
32065 const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir;
3205332066 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
3205432067 assert(extended.opcode == .struct_decl);
3205532068 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
......@@ -32123,7 +32136,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3212332136 .parent = null,
3212432137 .sema = &sema,
3212532138 .src_decl = decl_index,
32126 .namespace = &struct_obj.namespace,
32139 .namespace = struct_obj.namespace,
3212732140 .wip_capture_scope = wip_captures.scope,
3212832141 .instructions = .{},
3212932142 .inlining = null,
......@@ -32393,7 +32406,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3239332406
3239432407 const gpa = mod.gpa;
3239532408 const decl_index = union_obj.owner_decl;
32396 const zir = union_obj.namespace.file_scope.zir;
32409 const zir = mod.namespacePtr(union_obj.namespace).file_scope.zir;
3239732410 const extended = zir.instructions.items(.data)[union_obj.zir_index].extended;
3239832411 assert(extended.opcode == .union_decl);
3239932412 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);
......@@ -32463,7 +32476,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3246332476 .parent = null,
3246432477 .sema = &sema,
3246532478 .src_decl = decl_index,
32466 .namespace = &union_obj.namespace,
32479 .namespace = union_obj.namespace,
3246732480 .wip_capture_scope = wip_captures.scope,
3246832481 .instructions = .{},
3246932482 .inlining = null,
......@@ -32665,7 +32678,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3266532678
3266632679 const prev_field_index = union_obj.fields.getIndex(field_name).?;
3266732680 const prev_field_src = union_obj.fieldSrcLoc(sema.mod, .{ .index = prev_field_index }).lazy;
32668 try sema.mod.errNoteNonLazy(prev_field_src.toSrcLoc(decl), msg, "other field here", .{});
32681 try sema.mod.errNoteNonLazy(prev_field_src.toSrcLoc(decl, mod), msg, "other field here", .{});
3266932682 try sema.errNote(&block_scope, src, msg, "union declared here", .{});
3267032683 break :msg msg;
3267132684 };
......@@ -32929,7 +32942,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
3292932942 const opt_ty_decl = (try sema.namespaceLookup(
3293032943 &block,
3293132944 src,
32932 builtin_ty.getNamespace().?,
32945 builtin_ty.getNamespaceIndex(mod).unwrap().?,
3293332946 name,
3293432947 )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name});
3293532948 return sema.analyzeDeclVal(&block, src, opt_ty_decl);
......@@ -32984,7 +32997,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3298432997 .function,
3298532998 .array_sentinel,
3298632999 .error_set_inferred,
32987 .@"opaque",
3298833000 .anyframe_T,
3298933001 .pointer,
3299033002 => return null,
......@@ -33123,7 +33135,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3312333135 .inferred_alloc_mut => unreachable,
3312433136 },
3312533137
33126 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
33138 else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
3312733139 .int_type => |int_type| {
3312833140 if (int_type.bits == 0) {
3312933141 return try mod.intValue(ty, 0);
......@@ -33131,7 +33143,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3313133143 return null;
3313233144 }
3313333145 },
33134 .ptr_type => return null,
33146 .ptr_type => null,
3313533147 .array_type => |array_type| {
3313633148 if (array_type.len == 0)
3313733149 return Value.initTag(.empty_array);
......@@ -33152,7 +33164,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3315233164 return null;
3315333165 }
3315433166 },
33155 .error_union_type => return null,
33167 .error_union_type => null,
3315633168 .simple_type => |t| switch (t) {
3315733169 .f16,
3315833170 .f32,
......@@ -33190,18 +33202,19 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3319033202 .export_options,
3319133203 .extern_options,
3319233204 .type_info,
33193 => return null,
33205 => null,
3319433206
33195 .void => return Value.void,
33196 .noreturn => return Value.@"unreachable",
33197 .null => return Value.null,
33198 .undefined => return Value.undef,
33207 .void => Value.void,
33208 .noreturn => Value.@"unreachable",
33209 .null => Value.null,
33210 .undefined => Value.undef,
3319933211
3320033212 .generic_poison => return error.GenericPoison,
3320133213 .var_args_param => unreachable,
3320233214 },
3320333215 .struct_type => @panic("TODO"),
3320433216 .union_type => @panic("TODO"),
33217 .opaque_type => null,
3320533218
3320633219 // values, not types
3320733220 .simple_value => unreachable,
......@@ -33606,7 +33619,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3360633619 .error_set_single,
3360733620 .error_set_inferred,
3360833621 .error_set_merged,
33609 .@"opaque",
3361033622 .enum_simple,
3361133623 => false,
3361233624
......@@ -33772,6 +33784,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3377233784 },
3377333785 .struct_type => @panic("TODO"),
3377433786 .union_type => @panic("TODO"),
33787 .opaque_type => false,
3377533788
3377633789 // values, not types
3377733790 .simple_value => unreachable,
src/arch/wasm/CodeGen.zig+3-2
......@@ -764,8 +764,9 @@ pub fn deinit(func: *CodeGen) void {
764764
765765/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig
766766fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {
767 const mod = func.bin_file.base.options.module.?;
767768 const src = LazySrcLoc.nodeOffset(0);
768 const src_loc = src.toSrcLoc(func.decl);
769 const src_loc = src.toSrcLoc(func.decl, mod);
769770 func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args);
770771 return error.CodegenFail;
771772}
......@@ -6799,7 +6800,7 @@ fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
67996800
68006801fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
68016802 const mod = func.bin_file.base.options.module.?;
6802 const enum_decl_index = enum_ty.getOwnerDecl();
6803 const enum_decl_index = enum_ty.getOwnerDecl(mod);
68036804
68046805 var arena_allocator = std.heap.ArenaAllocator.init(func.gpa);
68056806 defer arena_allocator.deinit();
src/arch/wasm/Emit.zig+1-1
......@@ -254,7 +254,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
254254 @setCold(true);
255255 std.debug.assert(emit.error_msg == null);
256256 const mod = emit.bin_file.base.options.module.?;
257 emit.error_msg = try Module.ErrorMsg.create(emit.bin_file.base.allocator, mod.declPtr(emit.decl_index).srcLoc(), format, args);
257 emit.error_msg = try Module.ErrorMsg.create(emit.bin_file.base.allocator, mod.declPtr(emit.decl_index).srcLoc(mod), format, args);
258258 return error.EmitFail;
259259}
260260
src/arch/x86_64/CodeGen.zig+9-6
......@@ -112,10 +112,10 @@ const Owner = union(enum) {
112112 mod_fn: *const Module.Fn,
113113 lazy_sym: link.File.LazySymbol,
114114
115 fn getDecl(owner: Owner) Module.Decl.Index {
115 fn getDecl(owner: Owner, mod: *Module) Module.Decl.Index {
116116 return switch (owner) {
117117 .mod_fn => |mod_fn| mod_fn.owner_decl,
118 .lazy_sym => |lazy_sym| lazy_sym.ty.getOwnerDecl(),
118 .lazy_sym => |lazy_sym| lazy_sym.ty.getOwnerDecl(mod),
119119 };
120120 }
121121
......@@ -7926,6 +7926,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
79267926}
79277927
79287928fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void {
7929 const mod = self.bin_file.options.module.?;
79297930 switch (self.debug_output) {
79307931 .dwarf => |dw| {
79317932 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) {
......@@ -7944,7 +7945,7 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void {
79447945 // TODO: this might need adjusting like the linkers do.
79457946 // Instead of flattening the owner and passing Decl.Index here we may
79467947 // want to special case LazySymbol in DWARF linker too.
7947 try dw.genArgDbgInfo(name, ty, self.owner.getDecl(), loc);
7948 try dw.genArgDbgInfo(name, ty, self.owner.getDecl(mod), loc);
79487949 },
79497950 .plan9 => {},
79507951 .none => {},
......@@ -7958,6 +7959,7 @@ fn genVarDbgInfo(
79587959 mcv: MCValue,
79597960 name: [:0]const u8,
79607961) !void {
7962 const mod = self.bin_file.options.module.?;
79617963 const is_ptr = switch (tag) {
79627964 .dbg_var_ptr => true,
79637965 .dbg_var_val => false,
......@@ -7988,7 +7990,7 @@ fn genVarDbgInfo(
79887990 // TODO: this might need adjusting like the linkers do.
79897991 // Instead of flattening the owner and passing Decl.Index here we may
79907992 // want to special case LazySymbol in DWARF linker too.
7991 try dw.genVarDbgInfo(name, ty, self.owner.getDecl(), is_ptr, loc);
7993 try dw.genVarDbgInfo(name, ty, self.owner.getDecl(mod), is_ptr, loc);
79927994 },
79937995 .plan9 => {},
79947996 .none => {},
......@@ -10936,7 +10938,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
1093610938 try self.genLazySymbolRef(
1093710939 .call,
1093810940 .rax,
10939 link.File.LazySymbol.initDecl(.code, enum_ty.getOwnerDecl(), mod),
10941 link.File.LazySymbol.initDecl(.code, enum_ty.getOwnerDecl(mod), mod),
1094010942 );
1094110943
1094210944 return self.finishAir(inst, dst_mcv, .{ un_op, .none, .none });
......@@ -11651,7 +11653,8 @@ fn limitImmediateType(self: *Self, operand: Air.Inst.Ref, comptime T: type) !MCV
1165111653}
1165211654
1165311655fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {
11654 return switch (try codegen.genTypedValue(self.bin_file, self.src_loc, arg_tv, self.owner.getDecl())) {
11656 const mod = self.bin_file.options.module.?;
11657 return switch (try codegen.genTypedValue(self.bin_file, self.src_loc, arg_tv, self.owner.getDecl(mod))) {
1165511658 .mcv => |mcv| switch (mcv) {
1165611659 .none => .none,
1165711660 .undef => .undef,
src/codegen/c.zig+4-2
......@@ -524,8 +524,9 @@ pub const DeclGen = struct {
524524
525525 fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {
526526 @setCold(true);
527 const mod = dg.module;
527528 const src = LazySrcLoc.nodeOffset(0);
528 const src_loc = src.toSrcLoc(dg.decl.?);
529 const src_loc = src.toSrcLoc(dg.decl.?, mod);
529530 dg.error_msg = try Module.ErrorMsg.create(dg.gpa, src_loc, format, args);
530531 return error.AnalysisFail;
531532 }
......@@ -6484,6 +6485,7 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
64846485}
64856486
64866487fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue {
6488 const mod = f.object.dg.module;
64876489 const un_op = f.air.instructions.items(.data)[inst].un_op;
64886490
64896491 const inst_ty = f.typeOfIndex(inst);
......@@ -6495,7 +6497,7 @@ fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue {
64956497 const local = try f.allocLocal(inst, inst_ty);
64966498 try f.writeCValue(writer, local, .Other);
64976499 try writer.print(" = {s}(", .{
6498 try f.getLazyFnName(.{ .tag_name = enum_ty.getOwnerDecl() }, .{ .tag_name = enum_ty }),
6500 try f.getLazyFnName(.{ .tag_name = enum_ty.getOwnerDecl(mod) }, .{ .tag_name = enum_ty }),
64996501 });
65006502 try f.writeCValue(writer, operand, .Other);
65016503 try writer.writeAll(");\n");
src/codegen/c/type.zig+4-4
......@@ -1538,7 +1538,7 @@ pub const CType = extern union {
15381538 .forward, .forward_parameter => {
15391539 self.storage = .{ .fwd = .{
15401540 .base = .{ .tag = if (is_struct) .fwd_struct else .fwd_union },
1541 .data = ty.getOwnerDecl(),
1541 .data = ty.getOwnerDecl(mod),
15421542 } };
15431543 self.value = .{ .cty = initPayload(&self.storage.fwd) };
15441544 },
......@@ -1985,7 +1985,7 @@ pub const CType = extern union {
19851985 const unnamed_pl = try arena.create(Payload.Unnamed);
19861986 unnamed_pl.* = .{ .base = .{ .tag = t }, .data = .{
19871987 .fields = fields_pl,
1988 .owner_decl = ty.getOwnerDecl(),
1988 .owner_decl = ty.getOwnerDecl(mod),
19891989 .id = if (ty.unionTagTypeSafety()) |_| 0 else unreachable,
19901990 } };
19911991 return initPayload(unnamed_pl);
......@@ -2124,7 +2124,7 @@ pub const CType = extern union {
21242124 .forward, .forward_parameter, .complete, .parameter, .global => unreachable,
21252125 .payload => if (ty.unionTagTypeSafety()) |_| {
21262126 const data = cty.cast(Payload.Unnamed).?.data;
2127 return ty.getOwnerDecl() == data.owner_decl and data.id == 0;
2127 return ty.getOwnerDecl(mod) == data.owner_decl and data.id == 0;
21282128 } else unreachable,
21292129 },
21302130
......@@ -2242,7 +2242,7 @@ pub const CType = extern union {
22422242 => switch (self.kind) {
22432243 .forward, .forward_parameter, .complete, .parameter, .global => unreachable,
22442244 .payload => if (ty.unionTagTypeSafety()) |_| {
2245 autoHash(hasher, ty.getOwnerDecl());
2245 autoHash(hasher, ty.getOwnerDecl(mod));
22462246 autoHash(hasher, @as(u32, 0));
22472247 } else unreachable,
22482248 },
src/codegen/llvm.zig+33-33
......@@ -1177,7 +1177,7 @@ pub const Object = struct {
11771177 var di_scope: ?*llvm.DIScope = null;
11781178
11791179 if (dg.object.di_builder) |dib| {
1180 di_file = try dg.object.getDIFile(gpa, decl.src_namespace.file_scope);
1180 di_file = try dg.object.getDIFile(gpa, mod.namespacePtr(decl.src_namespace).file_scope);
11811181
11821182 const line_number = decl.src_line + 1;
11831183 const is_internal_linkage = decl.val.tag() != .extern_fn and
......@@ -1505,7 +1505,7 @@ pub const Object = struct {
15051505 return di_type;
15061506 },
15071507 .Enum => {
1508 const owner_decl_index = ty.getOwnerDecl();
1508 const owner_decl_index = ty.getOwnerDecl(mod);
15091509 const owner_decl = o.module.declPtr(owner_decl_index);
15101510
15111511 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -1558,7 +1558,7 @@ pub const Object = struct {
15581558 @panic("TODO implement bigint debug enumerators to llvm int for 32-bit compiler builds");
15591559 }
15601560
1561 const di_file = try o.getDIFile(gpa, owner_decl.src_namespace.file_scope);
1561 const di_file = try o.getDIFile(gpa, mod.namespacePtr(owner_decl.src_namespace).file_scope);
15621562 const di_scope = try o.namespaceToDebugScope(owner_decl.src_namespace);
15631563
15641564 const name = try ty.nameAlloc(gpa, o.module);
......@@ -1737,13 +1737,13 @@ pub const Object = struct {
17371737 }
17381738 const name = try ty.nameAlloc(gpa, o.module);
17391739 defer gpa.free(name);
1740 const owner_decl_index = ty.getOwnerDecl();
1740 const owner_decl_index = ty.getOwnerDecl(mod);
17411741 const owner_decl = o.module.declPtr(owner_decl_index);
17421742 const opaque_di_ty = dib.createForwardDeclType(
17431743 DW.TAG.structure_type,
17441744 name,
17451745 try o.namespaceToDebugScope(owner_decl.src_namespace),
1746 try o.getDIFile(gpa, owner_decl.src_namespace.file_scope),
1746 try o.getDIFile(gpa, mod.namespacePtr(owner_decl.src_namespace).file_scope),
17471747 owner_decl.src_node + 1,
17481748 );
17491749 // The recursive call to `lowerDebugType` va `namespaceToDebugScope`
......@@ -2085,7 +2085,7 @@ pub const Object = struct {
20852085 // into. Therefore we can satisfy this by making an empty namespace,
20862086 // rather than changing the frontend to unnecessarily resolve the
20872087 // struct field types.
2088 const owner_decl_index = ty.getOwnerDecl();
2088 const owner_decl_index = ty.getOwnerDecl(mod);
20892089 const struct_di_ty = try o.makeEmptyNamespaceDIType(owner_decl_index);
20902090 dib.replaceTemporary(fwd_decl, struct_di_ty);
20912091 // The recursive call to `lowerDebugType` via `makeEmptyNamespaceDIType`
......@@ -2096,7 +2096,7 @@ pub const Object = struct {
20962096 }
20972097
20982098 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) {
2099 const owner_decl_index = ty.getOwnerDecl();
2099 const owner_decl_index = ty.getOwnerDecl(mod);
21002100 const struct_di_ty = try o.makeEmptyNamespaceDIType(owner_decl_index);
21012101 dib.replaceTemporary(fwd_decl, struct_di_ty);
21022102 // The recursive call to `lowerDebugType` via `makeEmptyNamespaceDIType`
......@@ -2162,7 +2162,7 @@ pub const Object = struct {
21622162 },
21632163 .Union => {
21642164 const compile_unit_scope = o.di_compile_unit.?.toScope();
2165 const owner_decl_index = ty.getOwnerDecl();
2165 const owner_decl_index = ty.getOwnerDecl(mod);
21662166
21672167 const name = try ty.nameAlloc(gpa, o.module);
21682168 defer gpa.free(name);
......@@ -2395,8 +2395,10 @@ pub const Object = struct {
23952395 }
23962396 }
23972397
2398 fn namespaceToDebugScope(o: *Object, namespace: *const Module.Namespace) !*llvm.DIScope {
2399 if (namespace.parent == null) {
2398 fn namespaceToDebugScope(o: *Object, namespace_index: Module.Namespace.Index) !*llvm.DIScope {
2399 const mod = o.module;
2400 const namespace = mod.namespacePtr(namespace_index);
2401 if (namespace.parent == .none) {
24002402 const di_file = try o.getDIFile(o.gpa, namespace.file_scope);
24012403 return di_file.toScope();
24022404 }
......@@ -2408,12 +2410,13 @@ pub const Object = struct {
24082410 /// Assertion `!isa<DIType>(Scope) && "shouldn't make a namespace scope for a type"'
24092411 /// when targeting CodeView (Windows).
24102412 fn makeEmptyNamespaceDIType(o: *Object, decl_index: Module.Decl.Index) !*llvm.DIType {
2411 const decl = o.module.declPtr(decl_index);
2413 const mod = o.module;
2414 const decl = mod.declPtr(decl_index);
24122415 const fields: [0]*llvm.DIType = .{};
24132416 return o.di_builder.?.createStructType(
24142417 try o.namespaceToDebugScope(decl.src_namespace),
24152418 decl.name, // TODO use fully qualified name
2416 try o.getDIFile(o.gpa, decl.src_namespace.file_scope),
2419 try o.getDIFile(o.gpa, mod.namespacePtr(decl.src_namespace).file_scope),
24172420 decl.src_line + 1,
24182421 0, // size in bits
24192422 0, // align in bits
......@@ -2434,14 +2437,14 @@ pub const Object = struct {
24342437 const std_file = (mod.importPkg(std_pkg) catch unreachable).file;
24352438
24362439 const builtin_str: []const u8 = "builtin";
2437 const std_namespace = mod.declPtr(std_file.root_decl.unwrap().?).src_namespace;
2440 const std_namespace = mod.namespacePtr(mod.declPtr(std_file.root_decl.unwrap().?).src_namespace);
24382441 const builtin_decl = std_namespace.decls
24392442 .getKeyAdapted(builtin_str, Module.DeclAdapter{ .mod = mod }).?;
24402443
24412444 const stack_trace_str: []const u8 = "StackTrace";
24422445 // buffer is only used for int_type, `builtin` is a struct.
24432446 const builtin_ty = mod.declPtr(builtin_decl).val.toType();
2444 const builtin_namespace = builtin_ty.getNamespace().?;
2447 const builtin_namespace = builtin_ty.getNamespace(mod).?;
24452448 const stack_trace_decl_index = builtin_namespace.decls
24462449 .getKeyAdapted(stack_trace_str, Module.DeclAdapter{ .mod = mod }).?;
24472450 const stack_trace_decl = mod.declPtr(stack_trace_decl_index);
......@@ -2464,7 +2467,8 @@ pub const DeclGen = struct {
24642467 fn todo(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
24652468 @setCold(true);
24662469 assert(self.err_msg == null);
2467 const src_loc = LazySrcLoc.nodeOffset(0).toSrcLoc(self.decl);
2470 const mod = self.module;
2471 const src_loc = LazySrcLoc.nodeOffset(0).toSrcLoc(self.decl, mod);
24682472 self.err_msg = try Module.ErrorMsg.create(self.gpa, src_loc, "TODO (LLVM): " ++ format, args);
24692473 return error.CodegenFail;
24702474 }
......@@ -2536,7 +2540,7 @@ pub const DeclGen = struct {
25362540 }
25372541
25382542 if (dg.object.di_builder) |dib| {
2539 const di_file = try dg.object.getDIFile(dg.gpa, decl.src_namespace.file_scope);
2543 const di_file = try dg.object.getDIFile(dg.gpa, mod.namespacePtr(decl.src_namespace).file_scope);
25402544
25412545 const line_number = decl.src_line + 1;
25422546 const is_internal_linkage = !dg.module.decl_exports.contains(decl_index);
......@@ -2837,15 +2841,11 @@ pub const DeclGen = struct {
28372841 .Opaque => {
28382842 if (t.ip_index == .anyopaque_type) return dg.context.intType(8);
28392843
2840 const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = dg.module });
2844 const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = mod });
28412845 if (gop.found_existing) return gop.value_ptr.*;
28422846
2843 // The Type memory is ephemeral; since we want to store a longer-lived
2844 // reference, we need to copy it here.
2845 gop.key_ptr.* = try t.copy(dg.object.type_map_arena.allocator());
2846
2847 const opaque_obj = t.castTag(.@"opaque").?.data;
2848 const name = try opaque_obj.getFullyQualifiedName(dg.module);
2847 const opaque_type = mod.intern_pool.indexToKey(t.ip_index).opaque_type;
2848 const name = try mod.opaqueFullyQualifiedName(opaque_type);
28492849 defer gpa.free(name);
28502850
28512851 const llvm_struct_ty = dg.context.structCreateNamed(name);
......@@ -2931,7 +2931,7 @@ pub const DeclGen = struct {
29312931 },
29322932 .ErrorSet => return dg.context.intType(16),
29332933 .Struct => {
2934 const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = dg.module });
2934 const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = mod });
29352935 if (gop.found_existing) return gop.value_ptr.*;
29362936
29372937 // The Type memory is ephemeral; since we want to store a longer-lived
......@@ -2999,7 +2999,7 @@ pub const DeclGen = struct {
29992999 return int_llvm_ty;
30003000 }
30013001
3002 const name = try struct_obj.getFullyQualifiedName(dg.module);
3002 const name = try struct_obj.getFullyQualifiedName(mod);
30033003 defer gpa.free(name);
30043004
30053005 const llvm_struct_ty = dg.context.structCreateNamed(name);
......@@ -3057,7 +3057,7 @@ pub const DeclGen = struct {
30573057 return llvm_struct_ty;
30583058 },
30593059 .Union => {
3060 const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = dg.module });
3060 const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = mod });
30613061 if (gop.found_existing) return gop.value_ptr.*;
30623062
30633063 // The Type memory is ephemeral; since we want to store a longer-lived
......@@ -3080,7 +3080,7 @@ pub const DeclGen = struct {
30803080 return enum_tag_llvm_ty;
30813081 }
30823082
3083 const name = try union_obj.getFullyQualifiedName(dg.module);
3083 const name = try union_obj.getFullyQualifiedName(mod);
30843084 defer gpa.free(name);
30853085
30863086 const llvm_union_ty = dg.context.structCreateNamed(name);
......@@ -6131,7 +6131,7 @@ pub const FuncGen = struct {
61316131 const func = self.air.values[ty_pl.payload].castTag(.function).?.data;
61326132 const decl_index = func.owner_decl;
61336133 const decl = mod.declPtr(decl_index);
6134 const di_file = try self.dg.object.getDIFile(self.gpa, decl.src_namespace.file_scope);
6134 const di_file = try self.dg.object.getDIFile(self.gpa, mod.namespacePtr(decl.src_namespace).file_scope);
61356135 self.di_file = di_file;
61366136 const line_number = decl.src_line + 1;
61376137 const cur_debug_location = self.builder.getCurrentDebugLocation2();
......@@ -6193,7 +6193,7 @@ pub const FuncGen = struct {
61936193 const func = self.air.values[ty_pl.payload].castTag(.function).?.data;
61946194 const mod = self.dg.module;
61956195 const decl = mod.declPtr(func.owner_decl);
6196 const di_file = try self.dg.object.getDIFile(self.gpa, decl.src_namespace.file_scope);
6196 const di_file = try self.dg.object.getDIFile(self.gpa, mod.namespacePtr(decl.src_namespace).file_scope);
61976197 self.di_file = di_file;
61986198 const old = self.dbg_inlined.pop();
61996199 self.di_scope = old.scope;
......@@ -8853,7 +8853,8 @@ pub const FuncGen = struct {
88538853 }
88548854
88558855 fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value {
8856 const enum_decl = enum_ty.getOwnerDecl();
8856 const mod = self.dg.module;
8857 const enum_decl = enum_ty.getOwnerDecl(mod);
88578858
88588859 // TODO: detect when the type changes and re-emit this function.
88598860 const gop = try self.dg.object.named_enum_map.getOrPut(self.dg.gpa, enum_decl);
......@@ -8864,7 +8865,6 @@ pub const FuncGen = struct {
88648865 defer arena_allocator.deinit();
88658866 const arena = arena_allocator.allocator();
88668867
8867 const mod = self.dg.module;
88688868 const fqn = try mod.declPtr(enum_decl).getFullyQualifiedName(mod);
88698869 defer self.gpa.free(fqn);
88708870 const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_is_named_enum_value_{s}", .{fqn});
......@@ -8931,7 +8931,8 @@ pub const FuncGen = struct {
89318931 }
89328932
89338933 fn getEnumTagNameFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value {
8934 const enum_decl = enum_ty.getOwnerDecl();
8934 const mod = self.dg.module;
8935 const enum_decl = enum_ty.getOwnerDecl(mod);
89358936
89368937 // TODO: detect when the type changes and re-emit this function.
89378938 const gop = try self.dg.object.decl_map.getOrPut(self.dg.gpa, enum_decl);
......@@ -8942,7 +8943,6 @@ pub const FuncGen = struct {
89428943 defer arena_allocator.deinit();
89438944 const arena = arena_allocator.allocator();
89448945
8945 const mod = self.dg.module;
89468946 const fqn = try mod.declPtr(enum_decl).getFullyQualifiedName(mod);
89478947 defer self.gpa.free(fqn);
89488948 const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{s}", .{fqn});
src/codegen/spirv.zig+8-3
......@@ -218,8 +218,9 @@ pub const DeclGen = struct {
218218
219219 pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
220220 @setCold(true);
221 const mod = self.module;
221222 const src = LazySrcLoc.nodeOffset(0);
222 const src_loc = src.toSrcLoc(self.module.declPtr(self.decl_index));
223 const src_loc = src.toSrcLoc(self.module.declPtr(self.decl_index), mod);
223224 assert(self.error_msg == null);
224225 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args);
225226 return error.CodegenFail;
......@@ -2775,7 +2776,10 @@ pub const DeclGen = struct {
27752776
27762777 fn airDbgStmt(self: *DeclGen, inst: Air.Inst.Index) !void {
27772778 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;
2778 const src_fname_id = try self.spv.resolveSourceFileName(self.module.declPtr(self.decl_index));
2779 const src_fname_id = try self.spv.resolveSourceFileName(
2780 self.module,
2781 self.module.declPtr(self.decl_index),
2782 );
27792783 try self.func.body.emit(self.spv.gpa, .OpLine, .{
27802784 .file = src_fname_id,
27812785 .line = dbg_stmt.line,
......@@ -3192,6 +3196,7 @@ pub const DeclGen = struct {
31923196 }
31933197
31943198 fn airAssembly(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3199 const mod = self.module;
31953200 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
31963201 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
31973202
......@@ -3274,7 +3279,7 @@ pub const DeclGen = struct {
32743279 assert(as.errors.items.len != 0);
32753280 assert(self.error_msg == null);
32763281 const loc = LazySrcLoc.nodeOffset(0);
3277 const src_loc = loc.toSrcLoc(self.module.declPtr(self.decl_index));
3282 const src_loc = loc.toSrcLoc(self.module.declPtr(self.decl_index), mod);
32783283 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
32793284 const notes = try self.module.gpa.alloc(Module.ErrorMsg, as.errors.items.len);
32803285
src/codegen/spirv/Module.zig+2-2
......@@ -390,8 +390,8 @@ pub fn addFunction(self: *Module, decl_index: Decl.Index, func: Fn) !void {
390390/// Fetch the result-id of an OpString instruction that encodes the path of the source
391391/// file of the decl. This function may also emit an OpSource with source-level information regarding
392392/// the decl.
393pub fn resolveSourceFileName(self: *Module, decl: *ZigDecl) !IdRef {
394 const path = decl.getFileScope().sub_file_path;
393pub fn resolveSourceFileName(self: *Module, zig_module: *ZigModule, zig_decl: *ZigDecl) !IdRef {
394 const path = zig_decl.getFileScope(zig_module).sub_file_path;
395395 const result = try self.source_file_names.getOrPut(self.gpa, path);
396396 if (!result.found_existing) {
397397 const file_result_id = self.allocId();
src/crash_report.zig+4-4
......@@ -99,7 +99,7 @@ fn dumpStatusReport() !void {
9999 allocator,
100100 anal.body,
101101 anal.body_index,
102 block.namespace.file_scope,
102 mod.namespacePtr(block.namespace).file_scope,
103103 block_src_decl.src_node,
104104 6, // indent
105105 stderr,
......@@ -108,7 +108,7 @@ fn dumpStatusReport() !void {
108108 else => |e| return e,
109109 };
110110 try stderr.writeAll(" For full context, use the command\n zig ast-check -t ");
111 try writeFilePath(block.namespace.file_scope, stderr);
111 try writeFilePath(mod.namespacePtr(block.namespace).file_scope, stderr);
112112 try stderr.writeAll("\n\n");
113113
114114 var parent = anal.parent;
......@@ -121,7 +121,7 @@ fn dumpStatusReport() !void {
121121 print_zir.renderSingleInstruction(
122122 allocator,
123123 curr.body[curr.body_index],
124 curr.block.namespace.file_scope,
124 mod.namespacePtr(curr.block.namespace).file_scope,
125125 curr_block_src_decl.src_node,
126126 6, // indent
127127 stderr,
......@@ -148,7 +148,7 @@ fn writeFilePath(file: *Module.File, stream: anytype) !void {
148148}
149149
150150fn writeFullyQualifiedDeclWithFile(mod: *Module, decl: *Decl, stream: anytype) !void {
151 try writeFilePath(decl.getFileScope(), stream);
151 try writeFilePath(decl.getFileScope(mod), stream);
152152 try stream.writeAll(": ");
153153 try decl.renderFullyQualifiedDebugName(mod, stream);
154154}
src/link.zig+2-2
......@@ -1129,8 +1129,8 @@ pub const File = struct {
11291129 Type.anyerror };
11301130 }
11311131
1132 pub fn getDecl(self: LazySymbol) Module.Decl.OptionalIndex {
1133 return Module.Decl.OptionalIndex.init(self.ty.getOwnerDeclOrNull());
1132 pub fn getDecl(self: LazySymbol, mod: *Module) Module.Decl.OptionalIndex {
1133 return Module.Decl.OptionalIndex.init(self.ty.getOwnerDeclOrNull(mod));
11341134 }
11351135 };
11361136
src/link/Coff.zig+34-33
......@@ -1032,20 +1032,20 @@ fn freeAtom(self: *Coff, atom_index: Atom.Index) void {
10321032 self.getAtomPtr(atom_index).sym_index = 0;
10331033}
10341034
1035pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
1035pub fn updateFunc(self: *Coff, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
10361036 if (build_options.skip_non_native and builtin.object_format != .coff) {
10371037 @panic("Attempted to compile for object format that was disabled by build configuration");
10381038 }
10391039 if (build_options.have_llvm) {
10401040 if (self.llvm_object) |llvm_object| {
1041 return llvm_object.updateFunc(module, func, air, liveness);
1041 return llvm_object.updateFunc(mod, func, air, liveness);
10421042 }
10431043 }
10441044 const tracy = trace(@src());
10451045 defer tracy.end();
10461046
10471047 const decl_index = func.owner_decl;
1048 const decl = module.declPtr(decl_index);
1048 const decl = mod.declPtr(decl_index);
10491049
10501050 const atom_index = try self.getOrCreateAtomForDecl(decl_index);
10511051 self.freeUnnamedConsts(decl_index);
......@@ -1056,7 +1056,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live
10561056
10571057 const res = try codegen.generateFunction(
10581058 &self.base,
1059 decl.srcLoc(),
1059 decl.srcLoc(mod),
10601060 func,
10611061 air,
10621062 liveness,
......@@ -1067,7 +1067,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live
10671067 .ok => code_buffer.items,
10681068 .fail => |em| {
10691069 decl.analysis = .codegen_failure;
1070 try module.failed_decls.put(module.gpa, decl_index, em);
1070 try mod.failed_decls.put(mod.gpa, decl_index, em);
10711071 return;
10721072 },
10731073 };
......@@ -1076,7 +1076,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live
10761076
10771077 // Since we updated the vaddr and the size, each corresponding export
10781078 // symbol also needs to be updated.
1079 return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index));
1079 return self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index));
10801080}
10811081
10821082pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.Index) !u32 {
......@@ -1110,7 +1110,7 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In
11101110 sym.section_number = @intToEnum(coff.SectionNumber, self.rdata_section_index.? + 1);
11111111 }
11121112
1113 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), tv, &code_buffer, .none, .{
1113 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), tv, &code_buffer, .none, .{
11141114 .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?,
11151115 });
11161116 var code = switch (res) {
......@@ -1141,19 +1141,19 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In
11411141
11421142pub fn updateDecl(
11431143 self: *Coff,
1144 module: *Module,
1144 mod: *Module,
11451145 decl_index: Module.Decl.Index,
11461146) link.File.UpdateDeclError!void {
11471147 if (build_options.skip_non_native and builtin.object_format != .coff) {
11481148 @panic("Attempted to compile for object format that was disabled by build configuration");
11491149 }
11501150 if (build_options.have_llvm) {
1151 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(module, decl_index);
1151 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
11521152 }
11531153 const tracy = trace(@src());
11541154 defer tracy.end();
11551155
1156 const decl = module.declPtr(decl_index);
1156 const decl = mod.declPtr(decl_index);
11571157
11581158 if (decl.val.tag() == .extern_fn) {
11591159 return; // TODO Should we do more when front-end analyzed extern decl?
......@@ -1173,7 +1173,7 @@ pub fn updateDecl(
11731173 defer code_buffer.deinit();
11741174
11751175 const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
1176 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
1176 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
11771177 .ty = decl.ty,
11781178 .val = decl_val,
11791179 }, &code_buffer, .none, .{
......@@ -1183,7 +1183,7 @@ pub fn updateDecl(
11831183 .ok => code_buffer.items,
11841184 .fail => |em| {
11851185 decl.analysis = .codegen_failure;
1186 try module.failed_decls.put(module.gpa, decl_index, em);
1186 try mod.failed_decls.put(mod.gpa, decl_index, em);
11871187 return;
11881188 },
11891189 };
......@@ -1192,7 +1192,7 @@ pub fn updateDecl(
11921192
11931193 // Since we updated the vaddr and the size, each corresponding export
11941194 // symbol also needs to be updated.
1195 return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index));
1195 return self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index));
11961196}
11971197
11981198fn updateLazySymbolAtom(
......@@ -1217,8 +1217,8 @@ fn updateLazySymbolAtom(
12171217 const atom = self.getAtomPtr(atom_index);
12181218 const local_sym_index = atom.getSymbolIndex().?;
12191219
1220 const src = if (sym.ty.getOwnerDeclOrNull()) |owner_decl|
1221 mod.declPtr(owner_decl).srcLoc()
1220 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|
1221 mod.declPtr(owner_decl).srcLoc(mod)
12221222 else
12231223 Module.SrcLoc{
12241224 .file_scope = undefined,
......@@ -1262,7 +1262,8 @@ fn updateLazySymbolAtom(
12621262}
12631263
12641264pub fn getOrCreateAtomForLazySymbol(self: *Coff, sym: link.File.LazySymbol) !Atom.Index {
1265 const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl());
1265 const mod = self.base.options.module.?;
1266 const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl(mod));
12661267 errdefer _ = if (!gop.found_existing) self.lazy_syms.pop();
12671268 if (!gop.found_existing) gop.value_ptr.* = .{};
12681269 const metadata: struct { atom: *Atom.Index, state: *LazySymbolMetadata.State } = switch (sym.kind) {
......@@ -1277,7 +1278,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *Coff, sym: link.File.LazySymbol) !Ato
12771278 metadata.state.* = .pending_flush;
12781279 const atom = metadata.atom.*;
12791280 // anyerror needs to be deferred until flushModule
1280 if (sym.getDecl() != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) {
1281 if (sym.getDecl(mod) != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) {
12811282 .code => self.text_section_index.?,
12821283 .const_data => self.rdata_section_index.?,
12831284 });
......@@ -1411,7 +1412,7 @@ pub fn freeDecl(self: *Coff, decl_index: Module.Decl.Index) void {
14111412
14121413pub fn updateDeclExports(
14131414 self: *Coff,
1414 module: *Module,
1415 mod: *Module,
14151416 decl_index: Module.Decl.Index,
14161417 exports: []const *Module.Export,
14171418) link.File.UpdateDeclExportsError!void {
......@@ -1423,7 +1424,7 @@ pub fn updateDeclExports(
14231424 // Even in the case of LLVM, we need to notice certain exported symbols in order to
14241425 // detect the default subsystem.
14251426 for (exports) |exp| {
1426 const exported_decl = module.declPtr(exp.exported_decl);
1427 const exported_decl = mod.declPtr(exp.exported_decl);
14271428 if (exported_decl.getFunction() == null) continue;
14281429 const winapi_cc = switch (self.base.options.target.cpu.arch) {
14291430 .x86 => std.builtin.CallingConvention.Stdcall,
......@@ -1433,23 +1434,23 @@ pub fn updateDeclExports(
14331434 if (decl_cc == .C and mem.eql(u8, exp.options.name, "main") and
14341435 self.base.options.link_libc)
14351436 {
1436 module.stage1_flags.have_c_main = true;
1437 mod.stage1_flags.have_c_main = true;
14371438 } else if (decl_cc == winapi_cc and self.base.options.target.os.tag == .windows) {
14381439 if (mem.eql(u8, exp.options.name, "WinMain")) {
1439 module.stage1_flags.have_winmain = true;
1440 mod.stage1_flags.have_winmain = true;
14401441 } else if (mem.eql(u8, exp.options.name, "wWinMain")) {
1441 module.stage1_flags.have_wwinmain = true;
1442 mod.stage1_flags.have_wwinmain = true;
14421443 } else if (mem.eql(u8, exp.options.name, "WinMainCRTStartup")) {
1443 module.stage1_flags.have_winmain_crt_startup = true;
1444 mod.stage1_flags.have_winmain_crt_startup = true;
14441445 } else if (mem.eql(u8, exp.options.name, "wWinMainCRTStartup")) {
1445 module.stage1_flags.have_wwinmain_crt_startup = true;
1446 mod.stage1_flags.have_wwinmain_crt_startup = true;
14461447 } else if (mem.eql(u8, exp.options.name, "DllMainCRTStartup")) {
1447 module.stage1_flags.have_dllmain_crt_startup = true;
1448 mod.stage1_flags.have_dllmain_crt_startup = true;
14481449 }
14491450 }
14501451 }
14511452
1452 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(module, decl_index, exports);
1453 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
14531454 }
14541455
14551456 const tracy = trace(@src());
......@@ -1457,7 +1458,7 @@ pub fn updateDeclExports(
14571458
14581459 const gpa = self.base.allocator;
14591460
1460 const decl = module.declPtr(decl_index);
1461 const decl = mod.declPtr(decl_index);
14611462 const atom_index = try self.getOrCreateAtomForDecl(decl_index);
14621463 const atom = self.getAtom(atom_index);
14631464 const decl_sym = atom.getSymbol(self);
......@@ -1468,12 +1469,12 @@ pub fn updateDeclExports(
14681469
14691470 if (exp.options.section) |section_name| {
14701471 if (!mem.eql(u8, section_name, ".text")) {
1471 try module.failed_exports.putNoClobber(
1472 module.gpa,
1472 try mod.failed_exports.putNoClobber(
1473 mod.gpa,
14731474 exp,
14741475 try Module.ErrorMsg.create(
14751476 gpa,
1476 decl.srcLoc(),
1477 decl.srcLoc(mod),
14771478 "Unimplemented: ExportOptions.section",
14781479 .{},
14791480 ),
......@@ -1483,12 +1484,12 @@ pub fn updateDeclExports(
14831484 }
14841485
14851486 if (exp.options.linkage == .LinkOnce) {
1486 try module.failed_exports.putNoClobber(
1487 module.gpa,
1487 try mod.failed_exports.putNoClobber(
1488 mod.gpa,
14881489 exp,
14891490 try Module.ErrorMsg.create(
14901491 gpa,
1491 decl.srcLoc(),
1492 decl.srcLoc(mod),
14921493 "Unimplemented: GlobalLinkage.LinkOnce",
14931494 .{},
14941495 ),
src/link/Dwarf.zig+1-1
......@@ -2597,7 +2597,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {
25972597
25982598fn addDIFile(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !u28 {
25992599 const decl = mod.declPtr(decl_index);
2600 const file_scope = decl.getFileScope();
2600 const file_scope = decl.getFileScope(mod);
26012601 const gop = try self.di_files.getOrPut(self.allocator, file_scope);
26022602 if (!gop.found_existing) {
26032603 switch (self.bin_file.tag) {
src/link/Elf.zig+33-32
......@@ -2414,7 +2414,8 @@ pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void {
24142414}
24152415
24162416pub fn getOrCreateAtomForLazySymbol(self: *Elf, sym: File.LazySymbol) !Atom.Index {
2417 const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl());
2417 const mod = self.base.options.module.?;
2418 const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl(mod));
24182419 errdefer _ = if (!gop.found_existing) self.lazy_syms.pop();
24192420 if (!gop.found_existing) gop.value_ptr.* = .{};
24202421 const metadata: struct { atom: *Atom.Index, state: *LazySymbolMetadata.State } = switch (sym.kind) {
......@@ -2429,7 +2430,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *Elf, sym: File.LazySymbol) !Atom.Inde
24292430 metadata.state.* = .pending_flush;
24302431 const atom = metadata.atom.*;
24312432 // anyerror needs to be deferred until flushModule
2432 if (sym.getDecl() != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) {
2433 if (sym.getDecl(mod) != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) {
24332434 .code => self.text_section_index.?,
24342435 .const_data => self.rodata_section_index.?,
24352436 });
......@@ -2573,19 +2574,19 @@ fn updateDeclCode(self: *Elf, decl_index: Module.Decl.Index, code: []const u8, s
25732574 return local_sym;
25742575}
25752576
2576pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
2577pub fn updateFunc(self: *Elf, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
25772578 if (build_options.skip_non_native and builtin.object_format != .elf) {
25782579 @panic("Attempted to compile for object format that was disabled by build configuration");
25792580 }
25802581 if (build_options.have_llvm) {
2581 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(module, func, air, liveness);
2582 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func, air, liveness);
25822583 }
25832584
25842585 const tracy = trace(@src());
25852586 defer tracy.end();
25862587
25872588 const decl_index = func.owner_decl;
2588 const decl = module.declPtr(decl_index);
2589 const decl = mod.declPtr(decl_index);
25892590
25902591 const atom_index = try self.getOrCreateAtomForDecl(decl_index);
25912592 self.freeUnnamedConsts(decl_index);
......@@ -2594,28 +2595,28 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven
25942595 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
25952596 defer code_buffer.deinit();
25962597
2597 var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl_index) else null;
2598 var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(mod, decl_index) else null;
25982599 defer if (decl_state) |*ds| ds.deinit();
25992600
26002601 const res = if (decl_state) |*ds|
2601 try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .{
2602 try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .{
26022603 .dwarf = ds,
26032604 })
26042605 else
2605 try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .none);
2606 try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .none);
26062607
26072608 const code = switch (res) {
26082609 .ok => code_buffer.items,
26092610 .fail => |em| {
26102611 decl.analysis = .codegen_failure;
2611 try module.failed_decls.put(module.gpa, decl_index, em);
2612 try mod.failed_decls.put(mod.gpa, decl_index, em);
26122613 return;
26132614 },
26142615 };
26152616 const local_sym = try self.updateDeclCode(decl_index, code, elf.STT_FUNC);
26162617 if (decl_state) |*ds| {
26172618 try self.dwarf.?.commitDeclState(
2618 module,
2619 mod,
26192620 decl_index,
26202621 local_sym.st_value,
26212622 local_sym.st_size,
......@@ -2625,25 +2626,25 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven
26252626
26262627 // Since we updated the vaddr and the size, each corresponding export
26272628 // symbol also needs to be updated.
2628 return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index));
2629 return self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index));
26292630}
26302631
26312632pub fn updateDecl(
26322633 self: *Elf,
2633 module: *Module,
2634 mod: *Module,
26342635 decl_index: Module.Decl.Index,
26352636) File.UpdateDeclError!void {
26362637 if (build_options.skip_non_native and builtin.object_format != .elf) {
26372638 @panic("Attempted to compile for object format that was disabled by build configuration");
26382639 }
26392640 if (build_options.have_llvm) {
2640 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(module, decl_index);
2641 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
26412642 }
26422643
26432644 const tracy = trace(@src());
26442645 defer tracy.end();
26452646
2646 const decl = module.declPtr(decl_index);
2647 const decl = mod.declPtr(decl_index);
26472648
26482649 if (decl.val.tag() == .extern_fn) {
26492650 return; // TODO Should we do more when front-end analyzed extern decl?
......@@ -2662,13 +2663,13 @@ pub fn updateDecl(
26622663 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
26632664 defer code_buffer.deinit();
26642665
2665 var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl_index) else null;
2666 var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(mod, decl_index) else null;
26662667 defer if (decl_state) |*ds| ds.deinit();
26672668
26682669 // TODO implement .debug_info for global variables
26692670 const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
26702671 const res = if (decl_state) |*ds|
2671 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
2672 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
26722673 .ty = decl.ty,
26732674 .val = decl_val,
26742675 }, &code_buffer, .{
......@@ -2677,7 +2678,7 @@ pub fn updateDecl(
26772678 .parent_atom_index = atom.getSymbolIndex().?,
26782679 })
26792680 else
2680 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
2681 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
26812682 .ty = decl.ty,
26822683 .val = decl_val,
26832684 }, &code_buffer, .none, .{
......@@ -2688,7 +2689,7 @@ pub fn updateDecl(
26882689 .ok => code_buffer.items,
26892690 .fail => |em| {
26902691 decl.analysis = .codegen_failure;
2691 try module.failed_decls.put(module.gpa, decl_index, em);
2692 try mod.failed_decls.put(mod.gpa, decl_index, em);
26922693 return;
26932694 },
26942695 };
......@@ -2696,7 +2697,7 @@ pub fn updateDecl(
26962697 const local_sym = try self.updateDeclCode(decl_index, code, elf.STT_OBJECT);
26972698 if (decl_state) |*ds| {
26982699 try self.dwarf.?.commitDeclState(
2699 module,
2700 mod,
27002701 decl_index,
27012702 local_sym.st_value,
27022703 local_sym.st_size,
......@@ -2706,7 +2707,7 @@ pub fn updateDecl(
27062707
27072708 // Since we updated the vaddr and the size, each corresponding export
27082709 // symbol also needs to be updated.
2709 return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index));
2710 return self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index));
27102711}
27112712
27122713fn updateLazySymbolAtom(
......@@ -2735,8 +2736,8 @@ fn updateLazySymbolAtom(
27352736 const atom = self.getAtom(atom_index);
27362737 const local_sym_index = atom.getSymbolIndex().?;
27372738
2738 const src = if (sym.ty.getOwnerDeclOrNull()) |owner_decl|
2739 mod.declPtr(owner_decl).srcLoc()
2739 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|
2740 mod.declPtr(owner_decl).srcLoc(mod)
27402741 else
27412742 Module.SrcLoc{
27422743 .file_scope = undefined,
......@@ -2812,7 +2813,7 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module
28122813
28132814 const atom_index = try self.createAtom();
28142815
2815 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), typed_value, &code_buffer, .{
2816 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), typed_value, &code_buffer, .{
28162817 .none = {},
28172818 }, .{
28182819 .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?,
......@@ -2853,7 +2854,7 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module
28532854
28542855pub fn updateDeclExports(
28552856 self: *Elf,
2856 module: *Module,
2857 mod: *Module,
28572858 decl_index: Module.Decl.Index,
28582859 exports: []const *Module.Export,
28592860) File.UpdateDeclExportsError!void {
......@@ -2861,7 +2862,7 @@ pub fn updateDeclExports(
28612862 @panic("Attempted to compile for object format that was disabled by build configuration");
28622863 }
28632864 if (build_options.have_llvm) {
2864 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(module, decl_index, exports);
2865 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
28652866 }
28662867
28672868 const tracy = trace(@src());
......@@ -2869,7 +2870,7 @@ pub fn updateDeclExports(
28692870
28702871 const gpa = self.base.allocator;
28712872
2872 const decl = module.declPtr(decl_index);
2873 const decl = mod.declPtr(decl_index);
28732874 const atom_index = try self.getOrCreateAtomForDecl(decl_index);
28742875 const atom = self.getAtom(atom_index);
28752876 const decl_sym = atom.getSymbol(self);
......@@ -2881,10 +2882,10 @@ pub fn updateDeclExports(
28812882 for (exports) |exp| {
28822883 if (exp.options.section) |section_name| {
28832884 if (!mem.eql(u8, section_name, ".text")) {
2884 try module.failed_exports.ensureUnusedCapacity(module.gpa, 1);
2885 module.failed_exports.putAssumeCapacityNoClobber(
2885 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
2886 mod.failed_exports.putAssumeCapacityNoClobber(
28862887 exp,
2887 try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: ExportOptions.section", .{}),
2888 try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(mod), "Unimplemented: ExportOptions.section", .{}),
28882889 );
28892890 continue;
28902891 }
......@@ -2900,10 +2901,10 @@ pub fn updateDeclExports(
29002901 },
29012902 .Weak => elf.STB_WEAK,
29022903 .LinkOnce => {
2903 try module.failed_exports.ensureUnusedCapacity(module.gpa, 1);
2904 module.failed_exports.putAssumeCapacityNoClobber(
2904 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
2905 mod.failed_exports.putAssumeCapacityNoClobber(
29052906 exp,
2906 try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: GlobalLinkage.LinkOnce", .{}),
2907 try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(mod), "Unimplemented: GlobalLinkage.LinkOnce", .{}),
29072908 );
29082909 continue;
29092910 },
src/link/MachO.zig+42-42
......@@ -1847,18 +1847,18 @@ fn addStubEntry(self: *MachO, target: SymbolWithLoc) !void {
18471847 self.markRelocsDirtyByTarget(target);
18481848}
18491849
1850pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
1850pub fn updateFunc(self: *MachO, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
18511851 if (build_options.skip_non_native and builtin.object_format != .macho) {
18521852 @panic("Attempted to compile for object format that was disabled by build configuration");
18531853 }
18541854 if (build_options.have_llvm) {
1855 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(module, func, air, liveness);
1855 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func, air, liveness);
18561856 }
18571857 const tracy = trace(@src());
18581858 defer tracy.end();
18591859
18601860 const decl_index = func.owner_decl;
1861 const decl = module.declPtr(decl_index);
1861 const decl = mod.declPtr(decl_index);
18621862
18631863 const atom_index = try self.getOrCreateAtomForDecl(decl_index);
18641864 self.freeUnnamedConsts(decl_index);
......@@ -1868,23 +1868,23 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
18681868 defer code_buffer.deinit();
18691869
18701870 var decl_state = if (self.d_sym) |*d_sym|
1871 try d_sym.dwarf.initDeclState(module, decl_index)
1871 try d_sym.dwarf.initDeclState(mod, decl_index)
18721872 else
18731873 null;
18741874 defer if (decl_state) |*ds| ds.deinit();
18751875
18761876 const res = if (decl_state) |*ds|
1877 try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .{
1877 try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .{
18781878 .dwarf = ds,
18791879 })
18801880 else
1881 try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .none);
1881 try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .none);
18821882
18831883 var code = switch (res) {
18841884 .ok => code_buffer.items,
18851885 .fail => |em| {
18861886 decl.analysis = .codegen_failure;
1887 try module.failed_decls.put(module.gpa, decl_index, em);
1887 try mod.failed_decls.put(mod.gpa, decl_index, em);
18881888 return;
18891889 },
18901890 };
......@@ -1893,7 +1893,7 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
18931893
18941894 if (decl_state) |*ds| {
18951895 try self.d_sym.?.dwarf.commitDeclState(
1896 module,
1896 mod,
18971897 decl_index,
18981898 addr,
18991899 self.getAtom(atom_index).size,
......@@ -1903,7 +1903,7 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
19031903
19041904 // Since we updated the vaddr and the size, each corresponding export symbol also
19051905 // needs to be updated.
1906 try self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index));
1906 try self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index));
19071907}
19081908
19091909pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Module.Decl.Index) !u32 {
......@@ -1912,15 +1912,15 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu
19121912 var code_buffer = std.ArrayList(u8).init(gpa);
19131913 defer code_buffer.deinit();
19141914
1915 const module = self.base.options.module.?;
1915 const mod = self.base.options.module.?;
19161916 const gop = try self.unnamed_const_atoms.getOrPut(gpa, decl_index);
19171917 if (!gop.found_existing) {
19181918 gop.value_ptr.* = .{};
19191919 }
19201920 const unnamed_consts = gop.value_ptr;
19211921
1922 const decl = module.declPtr(decl_index);
1923 const decl_name = try decl.getFullyQualifiedName(module);
1922 const decl = mod.declPtr(decl_index);
1923 const decl_name = try decl.getFullyQualifiedName(mod);
19241924 defer gpa.free(decl_name);
19251925
19261926 const name_str_index = blk: {
......@@ -1935,20 +1935,19 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu
19351935
19361936 const atom_index = try self.createAtom();
19371937
1938 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), typed_value, &code_buffer, .none, .{
1938 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), typed_value, &code_buffer, .none, .{
19391939 .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?,
19401940 });
19411941 var code = switch (res) {
19421942 .ok => code_buffer.items,
19431943 .fail => |em| {
19441944 decl.analysis = .codegen_failure;
1945 try module.failed_decls.put(module.gpa, decl_index, em);
1945 try mod.failed_decls.put(mod.gpa, decl_index, em);
19461946 log.err("{s}", .{em.msg});
19471947 return error.CodegenFail;
19481948 },
19491949 };
19501950
1951 const mod = self.base.options.module.?;
19521951 const required_alignment = typed_value.ty.abiAlignment(mod);
19531952 const atom = self.getAtomPtr(atom_index);
19541953 atom.size = code.len;
......@@ -1972,17 +1971,17 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu
19721971 return atom.getSymbolIndex().?;
19731972}
19741973
1975pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) !void {
1974pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !void {
19761975 if (build_options.skip_non_native and builtin.object_format != .macho) {
19771976 @panic("Attempted to compile for object format that was disabled by build configuration");
19781977 }
19791978 if (build_options.have_llvm) {
1980 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(module, decl_index);
1979 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
19811980 }
19821981 const tracy = trace(@src());
19831982 defer tracy.end();
19841983
1985 const decl = module.declPtr(decl_index);
1984 const decl = mod.declPtr(decl_index);
19861985
19871986 if (decl.val.tag() == .extern_fn) {
19881987 return; // TODO Should we do more when front-end analyzed extern decl?
......@@ -1998,7 +1997,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
19981997 payload.data.is_threadlocal and !self.base.options.single_threaded
19991998 else
20001999 false;
2001 if (is_threadlocal) return self.updateThreadlocalVariable(module, decl_index);
2000 if (is_threadlocal) return self.updateThreadlocalVariable(mod, decl_index);
20022001
20032002 const atom_index = try self.getOrCreateAtomForDecl(decl_index);
20042003 const sym_index = self.getAtom(atom_index).getSymbolIndex().?;
......@@ -2008,14 +2007,14 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
20082007 defer code_buffer.deinit();
20092008
20102009 var decl_state: ?Dwarf.DeclState = if (self.d_sym) |*d_sym|
2011 try d_sym.dwarf.initDeclState(module, decl_index)
2010 try d_sym.dwarf.initDeclState(mod, decl_index)
20122011 else
20132012 null;
20142013 defer if (decl_state) |*ds| ds.deinit();
20152014
20162015 const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
20172016 const res = if (decl_state) |*ds|
2018 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
2017 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
20192018 .ty = decl.ty,
20202019 .val = decl_val,
20212020 }, &code_buffer, .{
......@@ -2024,7 +2023,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
20242023 .parent_atom_index = sym_index,
20252024 })
20262025 else
2027 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
2026 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
20282027 .ty = decl.ty,
20292028 .val = decl_val,
20302029 }, &code_buffer, .none, .{
......@@ -2035,7 +2034,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
20352034 .ok => code_buffer.items,
20362035 .fail => |em| {
20372036 decl.analysis = .codegen_failure;
2038 try module.failed_decls.put(module.gpa, decl_index, em);
2037 try mod.failed_decls.put(mod.gpa, decl_index, em);
20392038 return;
20402039 },
20412040 };
......@@ -2043,7 +2042,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
20432042
20442043 if (decl_state) |*ds| {
20452044 try self.d_sym.?.dwarf.commitDeclState(
2046 module,
2045 mod,
20472046 decl_index,
20482047 addr,
20492048 self.getAtom(atom_index).size,
......@@ -2053,7 +2052,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
20532052
20542053 // Since we updated the vaddr and the size, each corresponding export symbol also
20552054 // needs to be updated.
2056 try self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index));
2055 try self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index));
20572056}
20582057
20592058fn updateLazySymbolAtom(
......@@ -2082,8 +2081,8 @@ fn updateLazySymbolAtom(
20822081 const atom = self.getAtomPtr(atom_index);
20832082 const local_sym_index = atom.getSymbolIndex().?;
20842083
2085 const src = if (sym.ty.getOwnerDeclOrNull()) |owner_decl|
2086 mod.declPtr(owner_decl).srcLoc()
2084 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|
2085 mod.declPtr(owner_decl).srcLoc(mod)
20872086 else
20882087 Module.SrcLoc{
20892088 .file_scope = undefined,
......@@ -2127,7 +2126,8 @@ fn updateLazySymbolAtom(
21272126}
21282127
21292128pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol) !Atom.Index {
2130 const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl());
2129 const mod = self.base.options.module.?;
2130 const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl(mod));
21312131 errdefer _ = if (!gop.found_existing) self.lazy_syms.pop();
21322132 if (!gop.found_existing) gop.value_ptr.* = .{};
21332133 const metadata: struct { atom: *Atom.Index, state: *LazySymbolMetadata.State } = switch (sym.kind) {
......@@ -2145,7 +2145,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol) !Atom.In
21452145 metadata.state.* = .pending_flush;
21462146 const atom = metadata.atom.*;
21472147 // anyerror needs to be deferred until flushModule
2148 if (sym.getDecl() != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) {
2148 if (sym.getDecl(mod) != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) {
21492149 .code => self.text_section_index.?,
21502150 .const_data => self.data_const_section_index.?,
21512151 });
......@@ -2179,7 +2179,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D
21792179 const decl_metadata = self.decls.get(decl_index).?;
21802180 const decl_val = decl.val.castTag(.variable).?.data.init;
21812181 const res = if (decl_state) |*ds|
2182 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
2182 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
21832183 .ty = decl.ty,
21842184 .val = decl_val,
21852185 }, &code_buffer, .{
......@@ -2188,7 +2188,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D
21882188 .parent_atom_index = init_sym_index,
21892189 })
21902190 else
2191 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
2191 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
21922192 .ty = decl.ty,
21932193 .val = decl_val,
21942194 }, &code_buffer, .none, .{
......@@ -2379,7 +2379,7 @@ pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl_index: Module.De
23792379
23802380pub fn updateDeclExports(
23812381 self: *MachO,
2382 module: *Module,
2382 mod: *Module,
23832383 decl_index: Module.Decl.Index,
23842384 exports: []const *Module.Export,
23852385) File.UpdateDeclExportsError!void {
......@@ -2388,7 +2388,7 @@ pub fn updateDeclExports(
23882388 }
23892389 if (build_options.have_llvm) {
23902390 if (self.llvm_object) |llvm_object|
2391 return llvm_object.updateDeclExports(module, decl_index, exports);
2391 return llvm_object.updateDeclExports(mod, decl_index, exports);
23922392 }
23932393
23942394 const tracy = trace(@src());
......@@ -2396,7 +2396,7 @@ pub fn updateDeclExports(
23962396
23972397 const gpa = self.base.allocator;
23982398
2399 const decl = module.declPtr(decl_index);
2399 const decl = mod.declPtr(decl_index);
24002400 const atom_index = try self.getOrCreateAtomForDecl(decl_index);
24012401 const atom = self.getAtom(atom_index);
24022402 const decl_sym = atom.getSymbol(self);
......@@ -2410,12 +2410,12 @@ pub fn updateDeclExports(
24102410
24112411 if (exp.options.section) |section_name| {
24122412 if (!mem.eql(u8, section_name, "__text")) {
2413 try module.failed_exports.putNoClobber(
2414 module.gpa,
2413 try mod.failed_exports.putNoClobber(
2414 mod.gpa,
24152415 exp,
24162416 try Module.ErrorMsg.create(
24172417 gpa,
2418 decl.srcLoc(),
2418 decl.srcLoc(mod),
24192419 "Unimplemented: ExportOptions.section",
24202420 .{},
24212421 ),
......@@ -2425,12 +2425,12 @@ pub fn updateDeclExports(
24252425 }
24262426
24272427 if (exp.options.linkage == .LinkOnce) {
2428 try module.failed_exports.putNoClobber(
2429 module.gpa,
2428 try mod.failed_exports.putNoClobber(
2429 mod.gpa,
24302430 exp,
24312431 try Module.ErrorMsg.create(
24322432 gpa,
2433 decl.srcLoc(),
2433 decl.srcLoc(mod),
24342434 "Unimplemented: GlobalLinkage.LinkOnce",
24352435 .{},
24362436 ),
......@@ -2474,9 +2474,9 @@ pub fn updateDeclExports(
24742474 // TODO: this needs rethinking
24752475 const global = self.getGlobal(exp_name).?;
24762476 if (sym_loc.sym_index != global.sym_index and global.file != null) {
2477 _ = try module.failed_exports.put(module.gpa, exp, try Module.ErrorMsg.create(
2477 _ = try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(
24782478 gpa,
2479 decl.srcLoc(),
2479 decl.srcLoc(mod),
24802480 \\LinkError: symbol '{s}' defined multiple times
24812481 ,
24822482 .{exp_name},
src/link/Plan9.zig+16-16
......@@ -213,14 +213,14 @@ fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void {
213213 const gpa = self.base.allocator;
214214 const mod = self.base.options.module.?;
215215 const decl = mod.declPtr(decl_index);
216 const fn_map_res = try self.fn_decl_table.getOrPut(gpa, decl.getFileScope());
216 const fn_map_res = try self.fn_decl_table.getOrPut(gpa, decl.getFileScope(mod));
217217 if (fn_map_res.found_existing) {
218218 if (try fn_map_res.value_ptr.functions.fetchPut(gpa, decl_index, out)) |old_entry| {
219219 gpa.free(old_entry.value.code);
220220 gpa.free(old_entry.value.lineinfo);
221221 }
222222 } else {
223 const file = decl.getFileScope();
223 const file = decl.getFileScope(mod);
224224 const arena = self.path_arena.allocator();
225225 // each file gets a symbol
226226 fn_map_res.value_ptr.* = .{
......@@ -276,13 +276,13 @@ fn addPathComponents(self: *Plan9, path: []const u8, a: *std.ArrayList(u8)) !voi
276276 }
277277}
278278
279pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
279pub fn updateFunc(self: *Plan9, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
280280 if (build_options.skip_non_native and builtin.object_format != .plan9) {
281281 @panic("Attempted to compile for object format that was disabled by build configuration");
282282 }
283283
284284 const decl_index = func.owner_decl;
285 const decl = module.declPtr(decl_index);
285 const decl = mod.declPtr(decl_index);
286286 self.freeUnnamedConsts(decl_index);
287287
288288 _ = try self.seeDecl(decl_index);
......@@ -298,7 +298,7 @@ pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liv
298298
299299 const res = try codegen.generateFunction(
300300 &self.base,
301 decl.srcLoc(),
301 decl.srcLoc(mod),
302302 func,
303303 air,
304304 liveness,
......@@ -316,7 +316,7 @@ pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liv
316316 .ok => try code_buffer.toOwnedSlice(),
317317 .fail => |em| {
318318 decl.analysis = .codegen_failure;
319 try module.failed_decls.put(module.gpa, decl_index, em);
319 try mod.failed_decls.put(mod.gpa, decl_index, em);
320320 return;
321321 },
322322 };
......@@ -366,7 +366,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I
366366 };
367367 self.syms.items[info.sym_index.?] = sym;
368368
369 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), tv, &code_buffer, .{
369 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), tv, &code_buffer, .{
370370 .none = {},
371371 }, .{
372372 .parent_atom_index = @enumToInt(decl_index),
......@@ -388,8 +388,8 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I
388388 return @intCast(u32, info.got_index.?);
389389}
390390
391pub fn updateDecl(self: *Plan9, module: *Module, decl_index: Module.Decl.Index) !void {
392 const decl = module.declPtr(decl_index);
391pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !void {
392 const decl = mod.declPtr(decl_index);
393393
394394 if (decl.val.tag() == .extern_fn) {
395395 return; // TODO Should we do more when front-end analyzed extern decl?
......@@ -409,7 +409,7 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl_index: Module.Decl.Index)
409409 defer code_buffer.deinit();
410410 const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
411411 // TODO we need the symbol index for symbol in the table of locals for the containing atom
412 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
412 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
413413 .ty = decl.ty,
414414 .val = decl_val,
415415 }, &code_buffer, .{ .none = {} }, .{
......@@ -419,7 +419,7 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl_index: Module.Decl.Index)
419419 .ok => code_buffer.items,
420420 .fail => |em| {
421421 decl.analysis = .codegen_failure;
422 try module.failed_decls.put(module.gpa, decl_index, em);
422 try mod.failed_decls.put(mod.gpa, decl_index, em);
423423 return;
424424 },
425425 };
......@@ -707,7 +707,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
707707 const code = blk: {
708708 const is_fn = source_decl.ty.zigTypeTag(mod) == .Fn;
709709 if (is_fn) {
710 const table = self.fn_decl_table.get(source_decl.getFileScope()).?.functions;
710 const table = self.fn_decl_table.get(source_decl.getFileScope(mod)).?.functions;
711711 const output = table.get(source_decl_index).?;
712712 break :blk output.code;
713713 } else {
......@@ -729,7 +729,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
729729}
730730fn addDeclExports(
731731 self: *Plan9,
732 module: *Module,
732 mod: *Module,
733733 decl_index: Module.Decl.Index,
734734 exports: []const *Module.Export,
735735) !void {
......@@ -740,9 +740,9 @@ fn addDeclExports(
740740 // plan9 does not support custom sections
741741 if (exp.options.section) |section_name| {
742742 if (!mem.eql(u8, section_name, ".text") or !mem.eql(u8, section_name, ".data")) {
743 try module.failed_exports.put(module.gpa, exp, try Module.ErrorMsg.create(
743 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(
744744 self.base.allocator,
745 module.declPtr(decl_index).srcLoc(),
745 mod.declPtr(decl_index).srcLoc(mod),
746746 "plan9 does not support extra sections",
747747 .{},
748748 ));
......@@ -773,7 +773,7 @@ pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void {
773773 const decl = mod.declPtr(decl_index);
774774 const is_fn = (decl.val.tag() == .function);
775775 if (is_fn) {
776 var symidx_and_submap = self.fn_decl_table.get(decl.getFileScope()).?;
776 var symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(mod)).?;
777777 var submap = symidx_and_submap.functions;
778778 if (submap.fetchSwapRemove(decl_index)) |removed_entry| {
779779 self.base.allocator.free(removed_entry.value.code);
src/link/Wasm.zig+7-7
......@@ -1348,7 +1348,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes
13481348 defer code_writer.deinit();
13491349 // const result = try codegen.generateFunction(
13501350 // &wasm.base,
1351 // decl.srcLoc(),
1351 // decl.srcLoc(mod),
13521352 // func,
13531353 // air,
13541354 // liveness,
......@@ -1357,7 +1357,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes
13571357 // );
13581358 const result = try codegen.generateFunction(
13591359 &wasm.base,
1360 decl.srcLoc(),
1360 decl.srcLoc(mod),
13611361 func,
13621362 air,
13631363 liveness,
......@@ -1425,7 +1425,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
14251425
14261426 const res = try codegen.generateSymbol(
14271427 &wasm.base,
1428 decl.srcLoc(),
1428 decl.srcLoc(mod),
14291429 .{ .ty = decl.ty, .val = val },
14301430 &code_writer,
14311431 .none,
......@@ -1554,7 +1554,7 @@ pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: Module.Decl.In
15541554
15551555 const result = try codegen.generateSymbol(
15561556 &wasm.base,
1557 decl.srcLoc(),
1557 decl.srcLoc(mod),
15581558 tv,
15591559 &value_bytes,
15601560 .none,
......@@ -1693,7 +1693,7 @@ pub fn updateDeclExports(
16931693 if (exp.options.section) |section| {
16941694 try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create(
16951695 mod.gpa,
1696 decl.srcLoc(),
1696 decl.srcLoc(mod),
16971697 "Unimplemented: ExportOptions.section '{s}'",
16981698 .{section},
16991699 ));
......@@ -1712,7 +1712,7 @@ pub fn updateDeclExports(
17121712 if (!exp_is_weak and !existing_sym.isWeak()) {
17131713 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(
17141714 mod.gpa,
1715 decl.srcLoc(),
1715 decl.srcLoc(mod),
17161716 \\LinkError: symbol '{s}' defined multiple times
17171717 \\ first definition in '{s}'
17181718 \\ next definition in '{s}'
......@@ -1745,7 +1745,7 @@ pub fn updateDeclExports(
17451745 .LinkOnce => {
17461746 try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create(
17471747 mod.gpa,
1748 decl.srcLoc(),
1748 decl.srcLoc(mod),
17491749 "Unimplemented: LinkOnce",
17501750 .{},
17511751 ));
src/type.zig+103-118
......@@ -42,8 +42,6 @@ pub const Type = struct {
4242 .error_set_merged,
4343 => return .ErrorSet,
4444
45 .@"opaque" => return .Opaque,
46
4745 .function => return .Fn,
4846
4947 .array,
......@@ -87,6 +85,7 @@ pub const Type = struct {
8785 .error_union_type => return .ErrorUnion,
8886 .struct_type => return .Struct,
8987 .union_type => return .Union,
88 .opaque_type => return .Opaque,
9089 .simple_type => |s| switch (s) {
9190 .f16,
9291 .f32,
......@@ -361,12 +360,6 @@ pub const Type = struct {
361360 return true;
362361 },
363362
364 .@"opaque" => {
365 const opaque_obj_a = a.castTag(.@"opaque").?.data;
366 const opaque_obj_b = (b.castTag(.@"opaque") orelse return false).data;
367 return opaque_obj_a == opaque_obj_b;
368 },
369
370363 .function => {
371364 if (b.zigTypeTag(mod) != .Fn) return false;
372365
......@@ -649,12 +642,6 @@ pub const Type = struct {
649642 std.hash.autoHash(hasher, ies);
650643 },
651644
652 .@"opaque" => {
653 std.hash.autoHash(hasher, std.builtin.TypeId.Opaque);
654 const opaque_obj = ty.castTag(.@"opaque").?.data;
655 std.hash.autoHash(hasher, opaque_obj);
656 },
657
658645 .function => {
659646 std.hash.autoHash(hasher, std.builtin.TypeId.Fn);
660647
......@@ -974,7 +961,6 @@ pub const Type = struct {
974961 .enum_simple => return self.copyPayloadShallow(allocator, Payload.EnumSimple),
975962 .enum_numbered => return self.copyPayloadShallow(allocator, Payload.EnumNumbered),
976963 .enum_full, .enum_nonexhaustive => return self.copyPayloadShallow(allocator, Payload.EnumFull),
977 .@"opaque" => return self.copyPayloadShallow(allocator, Payload.Opaque),
978964 }
979965 }
980966
......@@ -1079,12 +1065,6 @@ pub const Type = struct {
10791065 @tagName(t), enum_numbered.owner_decl,
10801066 });
10811067 },
1082 .@"opaque" => {
1083 const opaque_obj = ty.castTag(.@"opaque").?.data;
1084 return writer.print("({s} decl={d})", .{
1085 @tagName(t), opaque_obj.owner_decl,
1086 });
1087 },
10881068
10891069 .function => {
10901070 const payload = ty.castTag(.function).?.data;
......@@ -1303,11 +1283,6 @@ pub const Type = struct {
13031283 const decl = mod.declPtr(enum_numbered.owner_decl);
13041284 try decl.renderFullyQualifiedName(mod, writer);
13051285 },
1306 .@"opaque" => {
1307 const opaque_obj = ty.cast(Payload.Opaque).?.data;
1308 const decl = mod.declPtr(opaque_obj.owner_decl);
1309 try decl.renderFullyQualifiedName(mod, writer);
1310 },
13111286
13121287 .error_set_inferred => {
13131288 const func = ty.castTag(.error_set_inferred).?.data.func;
......@@ -1575,6 +1550,10 @@ pub const Type = struct {
15751550 .simple_type => |s| return writer.writeAll(@tagName(s)),
15761551 .struct_type => @panic("TODO"),
15771552 .union_type => @panic("TODO"),
1553 .opaque_type => |opaque_type| {
1554 const decl = mod.declPtr(opaque_type.decl);
1555 try decl.renderFullyQualifiedName(mod, writer);
1556 },
15781557
15791558 // values, not types
15801559 .simple_value => unreachable,
......@@ -1622,7 +1601,6 @@ pub const Type = struct {
16221601 .none => switch (ty.tag()) {
16231602 .error_set_inferred,
16241603
1625 .@"opaque",
16261604 .error_set_single,
16271605 .error_union,
16281606 .error_set,
......@@ -1759,8 +1737,8 @@ pub const Type = struct {
17591737 .inferred_alloc_const => unreachable,
17601738 .inferred_alloc_mut => unreachable,
17611739 },
1762 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
1763 .int_type => |int_type| return int_type.bits != 0,
1740 else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
1741 .int_type => |int_type| int_type.bits != 0,
17641742 .ptr_type => |ptr_type| {
17651743 // Pointers to zero-bit types still have a runtime address; however, pointers
17661744 // to comptime-only types do not, with the exception of function pointers.
......@@ -1797,7 +1775,7 @@ pub const Type = struct {
17971775 }
17981776 },
17991777 .error_union_type => @panic("TODO"),
1800 .simple_type => |t| return switch (t) {
1778 .simple_type => |t| switch (t) {
18011779 .f16,
18021780 .f32,
18031781 .f64,
......@@ -1848,6 +1826,7 @@ pub const Type = struct {
18481826 },
18491827 .struct_type => @panic("TODO"),
18501828 .union_type => @panic("TODO"),
1829 .opaque_type => true,
18511830
18521831 // values, not types
18531832 .simple_value => unreachable,
......@@ -1876,7 +1855,6 @@ pub const Type = struct {
18761855 .error_set_single,
18771856 .error_set_inferred,
18781857 .error_set_merged,
1879 .@"opaque",
18801858 // These are function bodies, not function pointers.
18811859 .function,
18821860 .enum_simple,
......@@ -1960,6 +1938,7 @@ pub const Type = struct {
19601938 },
19611939 .struct_type => @panic("TODO"),
19621940 .union_type => @panic("TODO"),
1941 .opaque_type => false,
19631942
19641943 // values, not types
19651944 .simple_value => unreachable,
......@@ -2144,8 +2123,6 @@ pub const Type = struct {
21442123 switch (ty.ip_index) {
21452124 .empty_struct_type => return AbiAlignmentAdvanced{ .scalar = 0 },
21462125 .none => switch (ty.tag()) {
2147 .@"opaque" => return AbiAlignmentAdvanced{ .scalar = 1 },
2148
21492126 // represents machine code; not a pointer
21502127 .function => {
21512128 const alignment = ty.castTag(.function).?.data.alignment;
......@@ -2362,6 +2339,7 @@ pub const Type = struct {
23622339 },
23632340 .struct_type => @panic("TODO"),
23642341 .union_type => @panic("TODO"),
2342 .opaque_type => return AbiAlignmentAdvanced{ .scalar = 1 },
23652343
23662344 // values, not types
23672345 .simple_value => unreachable,
......@@ -2536,7 +2514,6 @@ pub const Type = struct {
25362514
25372515 .none => switch (ty.tag()) {
25382516 .function => unreachable, // represents machine code; not a pointer
2539 .@"opaque" => unreachable, // no size available
25402517 .inferred_alloc_const => unreachable,
25412518 .inferred_alloc_mut => unreachable,
25422519
......@@ -2777,6 +2754,7 @@ pub const Type = struct {
27772754 },
27782755 .struct_type => @panic("TODO"),
27792756 .union_type => @panic("TODO"),
2757 .opaque_type => unreachable, // no size available
27802758
27812759 // values, not types
27822760 .simple_value => unreachable,
......@@ -2948,6 +2926,7 @@ pub const Type = struct {
29482926 },
29492927 .struct_type => @panic("TODO"),
29502928 .union_type => @panic("TODO"),
2929 .opaque_type => unreachable,
29512930
29522931 // values, not types
29532932 .simple_value => unreachable,
......@@ -2965,7 +2944,6 @@ pub const Type = struct {
29652944 .empty_struct => unreachable,
29662945 .inferred_alloc_const => unreachable,
29672946 .inferred_alloc_mut => unreachable,
2968 .@"opaque" => unreachable,
29692947
29702948 .@"struct" => {
29712949 const struct_obj = ty.castTag(.@"struct").?.data;
......@@ -3806,6 +3784,7 @@ pub const Type = struct {
38063784 .simple_type => unreachable, // handled via Index enum tag above
38073785 .struct_type => @panic("TODO"),
38083786 .union_type => unreachable,
3787 .opaque_type => unreachable,
38093788
38103789 // values, not types
38113790 .simple_value => unreachable,
......@@ -4004,7 +3983,6 @@ pub const Type = struct {
40043983 .function,
40053984 .array_sentinel,
40063985 .error_set_inferred,
4007 .@"opaque",
40083986 .anyframe_T,
40093987 .pointer,
40103988 => return null,
......@@ -4182,6 +4160,7 @@ pub const Type = struct {
41824160 },
41834161 .struct_type => @panic("TODO"),
41844162 .union_type => @panic("TODO"),
4163 .opaque_type => return null,
41854164
41864165 // values, not types
41874166 .simple_value => unreachable,
......@@ -4208,7 +4187,6 @@ pub const Type = struct {
42084187 .error_set_single,
42094188 .error_set_inferred,
42104189 .error_set_merged,
4211 .@"opaque",
42124190 .enum_simple,
42134191 => false,
42144192
......@@ -4350,6 +4328,7 @@ pub const Type = struct {
43504328 },
43514329 .struct_type => @panic("TODO"),
43524330 .union_type => @panic("TODO"),
4331 .opaque_type => false,
43534332
43544333 // values, not types
43554334 .simple_value => unreachable,
......@@ -4399,21 +4378,31 @@ pub const Type = struct {
43994378 }
44004379
44014380 /// Returns null if the type has no namespace.
4402 pub fn getNamespace(self: Type) ?*Module.Namespace {
4403 return switch (self.tag()) {
4404 .@"struct" => &self.castTag(.@"struct").?.data.namespace,
4405 .enum_full => &self.castTag(.enum_full).?.data.namespace,
4406 .enum_nonexhaustive => &self.castTag(.enum_nonexhaustive).?.data.namespace,
4407 .empty_struct => self.castTag(.empty_struct).?.data,
4408 .@"opaque" => &self.castTag(.@"opaque").?.data.namespace,
4409 .@"union" => &self.castTag(.@"union").?.data.namespace,
4410 .union_safety_tagged => &self.castTag(.union_safety_tagged).?.data.namespace,
4411 .union_tagged => &self.castTag(.union_tagged).?.data.namespace,
4381 pub fn getNamespaceIndex(ty: Type, mod: *Module) Module.Namespace.OptionalIndex {
4382 return switch (ty.ip_index) {
4383 .none => switch (ty.tag()) {
4384 .@"struct" => ty.castTag(.@"struct").?.data.namespace.toOptional(),
4385 .enum_full => ty.castTag(.enum_full).?.data.namespace.toOptional(),
4386 .enum_nonexhaustive => ty.castTag(.enum_nonexhaustive).?.data.namespace.toOptional(),
4387 .empty_struct => @panic("TODO"),
4388 .@"union" => ty.castTag(.@"union").?.data.namespace.toOptional(),
4389 .union_safety_tagged => ty.castTag(.union_safety_tagged).?.data.namespace.toOptional(),
4390 .union_tagged => ty.castTag(.union_tagged).?.data.namespace.toOptional(),
44124391
4413 else => null,
4392 else => .none,
4393 },
4394 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4395 .opaque_type => |opaque_type| opaque_type.namespace.toOptional(),
4396 else => .none,
4397 },
44144398 };
44154399 }
44164400
4401 /// Returns null if the type has no namespace.
4402 pub fn getNamespace(ty: Type, mod: *Module) ?*Module.Namespace {
4403 return if (getNamespaceIndex(ty, mod).unwrap()) |i| mod.namespacePtr(i) else null;
4404 }
4405
44174406 // Works for vectors and vectors of integers.
44184407 pub fn minInt(ty: Type, arena: Allocator, mod: *Module) !Value {
44194408 const scalar = try minIntScalar(ty.scalarType(mod), mod);
......@@ -4911,78 +4900,81 @@ pub const Type = struct {
49114900 }
49124901
49134902 pub fn declSrcLocOrNull(ty: Type, mod: *Module) ?Module.SrcLoc {
4914 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4915 .struct_type => @panic("TODO"),
4916 .union_type => @panic("TODO"),
4917 else => return null,
4918 };
4919 switch (ty.tag()) {
4920 .enum_full, .enum_nonexhaustive => {
4921 const enum_full = ty.cast(Payload.EnumFull).?.data;
4922 return enum_full.srcLoc(mod);
4923 },
4924 .enum_numbered => {
4925 const enum_numbered = ty.castTag(.enum_numbered).?.data;
4926 return enum_numbered.srcLoc(mod);
4927 },
4928 .enum_simple => {
4929 const enum_simple = ty.castTag(.enum_simple).?.data;
4930 return enum_simple.srcLoc(mod);
4931 },
4932 .@"struct" => {
4933 const struct_obj = ty.castTag(.@"struct").?.data;
4934 return struct_obj.srcLoc(mod);
4935 },
4936 .error_set => {
4937 const error_set = ty.castTag(.error_set).?.data;
4938 return error_set.srcLoc(mod);
4939 },
4940 .@"union", .union_safety_tagged, .union_tagged => {
4941 const union_obj = ty.cast(Payload.Union).?.data;
4942 return union_obj.srcLoc(mod);
4903 switch (ty.ip_index) {
4904 .none => switch (ty.tag()) {
4905 .enum_full, .enum_nonexhaustive => {
4906 const enum_full = ty.cast(Payload.EnumFull).?.data;
4907 return enum_full.srcLoc(mod);
4908 },
4909 .enum_numbered => {
4910 const enum_numbered = ty.castTag(.enum_numbered).?.data;
4911 return enum_numbered.srcLoc(mod);
4912 },
4913 .enum_simple => {
4914 const enum_simple = ty.castTag(.enum_simple).?.data;
4915 return enum_simple.srcLoc(mod);
4916 },
4917 .@"struct" => {
4918 const struct_obj = ty.castTag(.@"struct").?.data;
4919 return struct_obj.srcLoc(mod);
4920 },
4921 .error_set => {
4922 const error_set = ty.castTag(.error_set).?.data;
4923 return error_set.srcLoc(mod);
4924 },
4925 .@"union", .union_safety_tagged, .union_tagged => {
4926 const union_obj = ty.cast(Payload.Union).?.data;
4927 return union_obj.srcLoc(mod);
4928 },
4929
4930 else => return null,
49434931 },
4944 .@"opaque" => {
4945 const opaque_obj = ty.cast(Payload.Opaque).?.data;
4946 return opaque_obj.srcLoc(mod);
4932 else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4933 .struct_type => @panic("TODO"),
4934 .union_type => @panic("TODO"),
4935 .opaque_type => |opaque_type| mod.opaqueSrcLoc(opaque_type),
4936 else => null,
49474937 },
4948
4949 else => return null,
49504938 }
49514939 }
49524940
4953 pub fn getOwnerDecl(ty: Type) Module.Decl.Index {
4954 return ty.getOwnerDeclOrNull() orelse unreachable;
4941 pub fn getOwnerDecl(ty: Type, mod: *Module) Module.Decl.Index {
4942 return ty.getOwnerDeclOrNull(mod) orelse unreachable;
49554943 }
49564944
4957 pub fn getOwnerDeclOrNull(ty: Type) ?Module.Decl.Index {
4958 switch (ty.tag()) {
4959 .enum_full, .enum_nonexhaustive => {
4960 const enum_full = ty.cast(Payload.EnumFull).?.data;
4961 return enum_full.owner_decl;
4962 },
4963 .enum_numbered => return ty.castTag(.enum_numbered).?.data.owner_decl,
4964 .enum_simple => {
4965 const enum_simple = ty.castTag(.enum_simple).?.data;
4966 return enum_simple.owner_decl;
4967 },
4968 .@"struct" => {
4969 const struct_obj = ty.castTag(.@"struct").?.data;
4970 return struct_obj.owner_decl;
4971 },
4972 .error_set => {
4973 const error_set = ty.castTag(.error_set).?.data;
4974 return error_set.owner_decl;
4975 },
4976 .@"union", .union_safety_tagged, .union_tagged => {
4977 const union_obj = ty.cast(Payload.Union).?.data;
4978 return union_obj.owner_decl;
4945 pub fn getOwnerDeclOrNull(ty: Type, mod: *Module) ?Module.Decl.Index {
4946 switch (ty.ip_index) {
4947 .none => switch (ty.tag()) {
4948 .enum_full, .enum_nonexhaustive => {
4949 const enum_full = ty.cast(Payload.EnumFull).?.data;
4950 return enum_full.owner_decl;
4951 },
4952 .enum_numbered => return ty.castTag(.enum_numbered).?.data.owner_decl,
4953 .enum_simple => {
4954 const enum_simple = ty.castTag(.enum_simple).?.data;
4955 return enum_simple.owner_decl;
4956 },
4957 .@"struct" => {
4958 const struct_obj = ty.castTag(.@"struct").?.data;
4959 return struct_obj.owner_decl;
4960 },
4961 .error_set => {
4962 const error_set = ty.castTag(.error_set).?.data;
4963 return error_set.owner_decl;
4964 },
4965 .@"union", .union_safety_tagged, .union_tagged => {
4966 const union_obj = ty.cast(Payload.Union).?.data;
4967 return union_obj.owner_decl;
4968 },
4969
4970 else => return null,
49794971 },
4980 .@"opaque" => {
4981 const opaque_obj = ty.cast(Payload.Opaque).?.data;
4982 return opaque_obj.owner_decl;
4972 else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4973 .struct_type => @panic("TODO"),
4974 .union_type => @panic("TODO"),
4975 .opaque_type => |opaque_type| opaque_type.decl,
4976 else => null,
49834977 },
4984
4985 else => return null,
49864978 }
49874979 }
49884980
......@@ -5022,7 +5014,6 @@ pub const Type = struct {
50225014 error_set_inferred,
50235015 error_set_merged,
50245016 empty_struct,
5025 @"opaque",
50265017 @"struct",
50275018 @"union",
50285019 union_safety_tagged,
......@@ -5055,7 +5046,6 @@ pub const Type = struct {
50555046 .function => Payload.Function,
50565047 .error_union => Payload.ErrorUnion,
50575048 .error_set_single => Payload.Name,
5058 .@"opaque" => Payload.Opaque,
50595049 .@"struct" => Payload.Struct,
50605050 .@"union", .union_safety_tagged, .union_tagged => Payload.Union,
50615051 .enum_full, .enum_nonexhaustive => Payload.EnumFull,
......@@ -5336,11 +5326,6 @@ pub const Type = struct {
53365326 data: *Module.Namespace,
53375327 };
53385328
5339 pub const Opaque = struct {
5340 base: Payload = .{ .tag = .@"opaque" },
5341 data: *Module.Opaque,
5342 };
5343
53445329 pub const Struct = struct {
53455330 base: Payload = .{ .tag = .@"struct" },
53465331 data: *Module.Struct,