authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-11-25 15:02:32-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-26 02:24:40-05:00
log2549de80b226cddd0664ce4ad8c40887101f302b
tree9674c446649114e88339256b24ef00660e1a168b
parent7103088e4a51d4362e6665d5949a9677e18fb74a

move Module.Decl.Index and Module.Namespace.Index to InternPool


28 files changed, 299 insertions(+), 295 deletions(-)

src/Air.zig+1-1
......@@ -1043,7 +1043,7 @@ pub const Inst = struct {
10431043 inferred_alloc: InferredAlloc,
10441044
10451045 pub const InferredAllocComptime = struct {
1046 decl_index: Module.Decl.Index,
1046 decl_index: InternPool.DeclIndex,
10471047 alignment: InternPool.Alignment,
10481048 is_const: bool,
10491049 };
src/Compilation.zig+4-4
......@@ -254,19 +254,19 @@ pub const RcIncludes = enum {
254254
255255const Job = union(enum) {
256256 /// Write the constant value for a Decl to the output file.
257 codegen_decl: Module.Decl.Index,
257 codegen_decl: InternPool.DeclIndex,
258258 /// Write the machine code for a function to the output file.
259259 /// This will either be a non-generic `func_decl` or a `func_instance`.
260260 codegen_func: InternPool.Index,
261261 /// Render the .h file snippet for the Decl.
262 emit_h_decl: Module.Decl.Index,
262 emit_h_decl: InternPool.DeclIndex,
263263 /// The Decl needs to be analyzed and possibly export itself.
264264 /// It may have already be analyzed, or it may have been determined
265265 /// to be outdated; in this case perform semantic analysis again.
266 analyze_decl: Module.Decl.Index,
266 analyze_decl: InternPool.DeclIndex,
267267 /// The source file containing the Decl has been updated, and so the
268268 /// Decl may need its line number information updated in the debug info.
269 update_line_number: Module.Decl.Index,
269 update_line_number: InternPool.DeclIndex,
270270 /// The main source file for the module needs to be analyzed.
271271 analyze_mod: *Package.Module,
272272
src/InternPool.zig+106-63
......@@ -32,12 +32,12 @@ string_bytes: std.ArrayListUnmanaged(u8) = .{},
3232/// multi-threaded contention on an atomic counter.
3333allocated_decls: std.SegmentedList(Module.Decl, 0) = .{},
3434/// When a Decl object is freed from `allocated_decls`, it is pushed into this stack.
35decls_free_list: std.ArrayListUnmanaged(Module.Decl.Index) = .{},
35decls_free_list: std.ArrayListUnmanaged(DeclIndex) = .{},
3636
3737/// Same pattern as with `allocated_decls`.
3838allocated_namespaces: std.SegmentedList(Module.Namespace, 0) = .{},
3939/// Same pattern as with `decls_free_list`.
40namespaces_free_list: std.ArrayListUnmanaged(Module.Namespace.Index) = .{},
40namespaces_free_list: std.ArrayListUnmanaged(NamespaceIndex) = .{},
4141
4242/// Some types such as enums, structs, and unions need to store mappings from field names
4343/// to field index, or value to field index. In such cases, they will store the underlying
......@@ -68,7 +68,6 @@ const Hash = std.hash.Wyhash;
6868const InternPool = @This();
6969const Module = @import("Module.zig");
7070const Zir = @import("Zir.zig");
71const Sema = @import("Sema.zig");
7271
7372const KeyAdapter = struct {
7473 intern_pool: *const InternPool,
......@@ -113,6 +112,50 @@ pub const RuntimeIndex = enum(u32) {
113112 }
114113};
115114
115pub const DeclIndex = enum(u32) {
116 _,
117
118 pub fn toOptional(i: DeclIndex) OptionalDeclIndex {
119 return @enumFromInt(@intFromEnum(i));
120 }
121};
122
123pub const OptionalDeclIndex = enum(u32) {
124 none = std.math.maxInt(u32),
125 _,
126
127 pub fn init(oi: ?DeclIndex) OptionalDeclIndex {
128 return @enumFromInt(@intFromEnum(oi orelse return .none));
129 }
130
131 pub fn unwrap(oi: OptionalDeclIndex) ?DeclIndex {
132 if (oi == .none) return null;
133 return @enumFromInt(@intFromEnum(oi));
134 }
135};
136
137pub const NamespaceIndex = enum(u32) {
138 _,
139
140 pub fn toOptional(i: NamespaceIndex) OptionalNamespaceIndex {
141 return @enumFromInt(@intFromEnum(i));
142 }
143};
144
145pub const OptionalNamespaceIndex = enum(u32) {
146 none = std.math.maxInt(u32),
147 _,
148
149 pub fn init(oi: ?NamespaceIndex) OptionalNamespaceIndex {
150 return @enumFromInt(@intFromEnum(oi orelse return .none));
151 }
152
153 pub fn unwrap(oi: OptionalNamespaceIndex) ?NamespaceIndex {
154 if (oi == .none) return null;
155 return @enumFromInt(@intFromEnum(oi));
156 }
157};
158
116159/// An index into `string_bytes`.
117160pub const String = enum(u32) {
118161 _,
......@@ -351,9 +394,9 @@ pub const Key = union(enum) {
351394
352395 pub const OpaqueType = extern struct {
353396 /// The Decl that corresponds to the opaque itself.
354 decl: Module.Decl.Index,
397 decl: DeclIndex,
355398 /// Represents the declarations inside this opaque.
356 namespace: Module.Namespace.Index,
399 namespace: NamespaceIndex,
357400 };
358401
359402 /// Although packed structs and non-packed structs are encoded differently,
......@@ -362,9 +405,9 @@ pub const Key = union(enum) {
362405 pub const StructType = struct {
363406 extra_index: u32,
364407 /// `none` when the struct is `@TypeOf(.{})`.
365 decl: Module.Decl.OptionalIndex,
408 decl: OptionalDeclIndex,
366409 /// `none` when the struct has no declarations.
367 namespace: Module.Namespace.OptionalIndex,
410 namespace: OptionalNamespaceIndex,
368411 /// Index of the struct_decl ZIR instruction.
369412 zir_index: Zir.Inst.Index,
370413 layout: std.builtin.Type.ContainerLayout,
......@@ -718,11 +761,11 @@ pub const Key = union(enum) {
718761 /// * Provide the other fields that do not require chasing the enum type.
719762 pub const UnionType = struct {
720763 /// The Decl that corresponds to the union itself.
721 decl: Module.Decl.Index,
764 decl: DeclIndex,
722765 /// The index of the `Tag.TypeUnion` payload. Ignored by `get`,
723766 /// populated by `indexToKey`.
724767 extra_index: u32,
725 namespace: Module.Namespace.Index,
768 namespace: NamespaceIndex,
726769 flags: Tag.TypeUnion.Flags,
727770 /// The enum that provides the list of field names and values.
728771 enum_tag_ty: Index,
......@@ -796,9 +839,9 @@ pub const Key = union(enum) {
796839
797840 pub const EnumType = struct {
798841 /// The Decl that corresponds to the enum itself.
799 decl: Module.Decl.Index,
842 decl: DeclIndex,
800843 /// Represents the declarations inside this enum.
801 namespace: Module.Namespace.OptionalIndex,
844 namespace: OptionalNamespaceIndex,
802845 /// An integer type which is used for the numerical value of the enum.
803846 /// This field is present regardless of whether the enum has an
804847 /// explicitly provided tag type or auto-numbered.
......@@ -866,9 +909,9 @@ pub const Key = union(enum) {
866909
867910 pub const IncompleteEnumType = struct {
868911 /// Same as corresponding `EnumType` field.
869 decl: Module.Decl.Index,
912 decl: DeclIndex,
870913 /// Same as corresponding `EnumType` field.
871 namespace: Module.Namespace.OptionalIndex,
914 namespace: OptionalNamespaceIndex,
872915 /// The field names and field values are not known yet, but
873916 /// the number of fields must be known ahead of time.
874917 fields_len: u32,
......@@ -961,7 +1004,7 @@ pub const Key = union(enum) {
9611004 pub const Variable = struct {
9621005 ty: Index,
9631006 init: Index,
964 decl: Module.Decl.Index,
1007 decl: DeclIndex,
9651008 lib_name: OptionalNullTerminatedString = .none,
9661009 is_extern: bool = false,
9671010 is_const: bool = false,
......@@ -972,7 +1015,7 @@ pub const Key = union(enum) {
9721015 pub const ExternFunc = struct {
9731016 ty: Index,
9741017 /// The Decl that corresponds to the function itself.
975 decl: Module.Decl.Index,
1018 decl: DeclIndex,
9761019 /// Library name if specified.
9771020 /// For example `extern "c" fn write(...) usize` would have 'c' as library name.
9781021 /// Index into the string table bytes.
......@@ -1008,7 +1051,7 @@ pub const Key = union(enum) {
10081051 /// This will be 0 when the function is not a generic function instantiation.
10091052 branch_quota_extra_index: u32,
10101053 /// The Decl that corresponds to the function itself.
1011 owner_decl: Module.Decl.Index,
1054 owner_decl: DeclIndex,
10121055 /// The ZIR instruction that is a function instruction. Use this to find
10131056 /// the body. We store this rather than the body directly so that when ZIR
10141057 /// is regenerated on update(), we can map this to the new corresponding
......@@ -1130,7 +1173,7 @@ pub const Key = union(enum) {
11301173 pub const Addr = union(enum) {
11311174 const Tag = @typeInfo(Addr).Union.tag_type.?;
11321175
1133 decl: Module.Decl.Index,
1176 decl: DeclIndex,
11341177 mut_decl: MutDecl,
11351178 anon_decl: AnonDecl,
11361179 comptime_field: Index,
......@@ -1141,7 +1184,7 @@ pub const Key = union(enum) {
11411184 field: BaseIndex,
11421185
11431186 pub const MutDecl = struct {
1144 decl: Module.Decl.Index,
1187 decl: DeclIndex,
11451188 runtime_index: RuntimeIndex,
11461189 };
11471190 pub const BaseIndex = struct {
......@@ -1796,9 +1839,9 @@ pub const RequiresComptime = enum(u2) { no, yes, unknown, wip };
17961839// needed by semantic analysis.
17971840pub const UnionType = struct {
17981841 /// The Decl that corresponds to the union itself.
1799 decl: Module.Decl.Index,
1842 decl: DeclIndex,
18001843 /// Represents the declarations inside this union.
1801 namespace: Module.Namespace.Index,
1844 namespace: NamespaceIndex,
18021845 /// The enum tag type.
18031846 enum_tag_ty: Index,
18041847 /// The integer tag type of the enum.
......@@ -2168,7 +2211,7 @@ pub const Index = enum(u32) {
21682211 simple_type: struct { data: SimpleType },
21692212 type_opaque: struct { data: *Key.OpaqueType },
21702213 type_struct: struct { data: *Tag.TypeStruct },
2171 type_struct_ns: struct { data: Module.Namespace.Index },
2214 type_struct_ns: struct { data: NamespaceIndex },
21722215 type_struct_anon: DataIsExtraIndexOfTypeStructAnon,
21732216 type_struct_packed: struct { data: *Tag.TypeStructPacked },
21742217 type_struct_packed_inits: struct { data: *Tag.TypeStructPacked },
......@@ -2609,7 +2652,7 @@ pub const Tag = enum(u8) {
26092652 /// data == 0 represents `@TypeOf(.{})`.
26102653 type_struct,
26112654 /// A non-packed struct type that has only a namespace; no fields.
2612 /// data is Module.Namespace.Index.
2655 /// data is NamespaceIndex.
26132656 type_struct_ns,
26142657 /// An AnonStructType which stores types, names, and values for fields.
26152658 /// data is extra index of `TypeStructAnon`.
......@@ -2902,7 +2945,7 @@ pub const Tag = enum(u8) {
29022945 ty: Index,
29032946 /// May be `none`.
29042947 init: Index,
2905 decl: Module.Decl.Index,
2948 decl: DeclIndex,
29062949 /// Library name if specified.
29072950 /// For example `extern "c" var stderrp = ...` would have 'c' as library name.
29082951 lib_name: OptionalNullTerminatedString,
......@@ -2931,7 +2974,7 @@ pub const Tag = enum(u8) {
29312974 /// A `none` value marks that the inferred error set is not resolved yet.
29322975 pub const FuncDecl = struct {
29332976 analysis: FuncAnalysis,
2934 owner_decl: Module.Decl.Index,
2977 owner_decl: DeclIndex,
29352978 ty: Index,
29362979 zir_body_inst: Zir.Inst.Index,
29372980 lbrace_line: u32,
......@@ -2948,7 +2991,7 @@ pub const Tag = enum(u8) {
29482991 pub const FuncInstance = struct {
29492992 analysis: FuncAnalysis,
29502993 // Needed by the linker for codegen. Not part of hashing or equality.
2951 owner_decl: Module.Decl.Index,
2994 owner_decl: DeclIndex,
29522995 ty: Index,
29532996 branch_quota: u32,
29542997 /// Points to a `FuncDecl`.
......@@ -3003,8 +3046,8 @@ pub const Tag = enum(u8) {
30033046 size: u32,
30043047 /// Only valid after .have_layout
30053048 padding: u32,
3006 decl: Module.Decl.Index,
3007 namespace: Module.Namespace.Index,
3049 decl: DeclIndex,
3050 namespace: NamespaceIndex,
30083051 /// The enum that provides the list of field names and values.
30093052 tag_ty: Index,
30103053 zir_index: Zir.Inst.Index,
......@@ -3028,10 +3071,10 @@ pub const Tag = enum(u8) {
30283071 /// 1. name: NullTerminatedString for each fields_len
30293072 /// 2. init: Index for each fields_len // if tag is type_struct_packed_inits
30303073 pub const TypeStructPacked = struct {
3031 decl: Module.Decl.Index,
3074 decl: DeclIndex,
30323075 zir_index: Zir.Inst.Index,
30333076 fields_len: u32,
3034 namespace: Module.Namespace.OptionalIndex,
3077 namespace: OptionalNamespaceIndex,
30353078 backing_int_ty: Index,
30363079 names_map: MapIndex,
30373080 flags: Flags,
......@@ -3066,7 +3109,7 @@ pub const Tag = enum(u8) {
30663109 /// 2. if any_default_inits:
30673110 /// init: Index // for each field in declared order
30683111 /// 3. if has_namespace:
3069 /// namespace: Module.Namespace.Index
3112 /// namespace: NamespaceIndex
30703113 /// 4. if any_aligned_fields:
30713114 /// align: Alignment // for each field in declared order
30723115 /// 5. if any_comptime_fields:
......@@ -3075,7 +3118,7 @@ pub const Tag = enum(u8) {
30753118 /// field_index: RuntimeOrder // for each field in runtime order
30763119 /// 7. field_offset: u32 // for each field in declared order, undef until layout_resolved
30773120 pub const TypeStruct = struct {
3078 decl: Module.Decl.Index,
3121 decl: DeclIndex,
30793122 zir_index: Zir.Inst.Index,
30803123 fields_len: u32,
30813124 flags: Flags,
......@@ -3418,9 +3461,9 @@ pub const Array = struct {
34183461/// 1. tag value: Index for each fields_len; declaration order
34193462pub const EnumExplicit = struct {
34203463 /// The Decl that corresponds to the enum itself.
3421 decl: Module.Decl.Index,
3464 decl: DeclIndex,
34223465 /// This may be `none` if there are no declarations.
3423 namespace: Module.Namespace.OptionalIndex,
3466 namespace: OptionalNamespaceIndex,
34243467 /// An integer type which is used for the numerical value of the enum, which
34253468 /// has been explicitly provided by the enum declaration.
34263469 int_tag_type: Index,
......@@ -3437,9 +3480,9 @@ pub const EnumExplicit = struct {
34373480/// 0. field name: NullTerminatedString for each fields_len; declaration order
34383481pub const EnumAuto = struct {
34393482 /// The Decl that corresponds to the enum itself.
3440 decl: Module.Decl.Index,
3483 decl: DeclIndex,
34413484 /// This may be `none` if there are no declarations.
3442 namespace: Module.Namespace.OptionalIndex,
3485 namespace: OptionalNamespaceIndex,
34433486 /// An integer type which is used for the numerical value of the enum, which
34443487 /// was inferred by Zig based on the number of tags.
34453488 int_tag_type: Index,
......@@ -3463,7 +3506,7 @@ pub const PackedU64 = packed struct(u64) {
34633506
34643507pub const PtrDecl = struct {
34653508 ty: Index,
3466 decl: Module.Decl.Index,
3509 decl: DeclIndex,
34673510};
34683511
34693512pub const PtrAnonDecl = struct {
......@@ -3480,7 +3523,7 @@ pub const PtrAnonDeclAligned = struct {
34803523
34813524pub const PtrMutDecl = struct {
34823525 ty: Index,
3483 decl: Module.Decl.Index,
3526 decl: DeclIndex,
34843527 runtime_index: RuntimeIndex,
34853528};
34863529
......@@ -3754,7 +3797,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
37543797
37553798 .type_struct_ns => .{ .struct_type = .{
37563799 .extra_index = 0,
3757 .namespace = @as(Module.Namespace.Index, @enumFromInt(data)).toOptional(),
3800 .namespace = @as(NamespaceIndex, @enumFromInt(data)).toOptional(),
37583801 .decl = .none,
37593802 .zir_index = undefined,
37603803 .layout = .Auto,
......@@ -4280,7 +4323,7 @@ fn extraStructType(ip: *const InternPool, extra_index: u32) Key.StructType {
42804323 };
42814324 const namespace = t: {
42824325 if (!s.data.flags.has_namespace) break :t .none;
4283 const namespace: Module.Namespace.Index = @enumFromInt(ip.extra.items[index]);
4326 const namespace: NamespaceIndex = @enumFromInt(ip.extra.items[index]);
42844327 index += 1;
42854328 break :t namespace.toOptional();
42864329 };
......@@ -5313,8 +5356,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
53135356
53145357pub const UnionTypeInit = struct {
53155358 flags: Tag.TypeUnion.Flags,
5316 decl: Module.Decl.Index,
5317 namespace: Module.Namespace.Index,
5359 decl: DeclIndex,
5360 namespace: NamespaceIndex,
53185361 zir_index: Zir.Inst.Index,
53195362 fields_len: u32,
53205363 enum_tag_ty: Index,
......@@ -5384,8 +5427,8 @@ pub fn getUnionType(ip: *InternPool, gpa: Allocator, ini: UnionTypeInit) Allocat
53845427}
53855428
53865429pub const StructTypeInit = struct {
5387 decl: Module.Decl.Index,
5388 namespace: Module.Namespace.OptionalIndex,
5430 decl: DeclIndex,
5431 namespace: OptionalNamespaceIndex,
53895432 layout: std.builtin.Type.ContainerLayout,
53905433 zir_index: Zir.Inst.Index,
53915434 fields_len: u32,
......@@ -5659,7 +5702,7 @@ pub fn getExternFunc(ip: *InternPool, gpa: Allocator, key: Key.ExternFunc) Alloc
56595702}
56605703
56615704pub const GetFuncDeclKey = struct {
5662 owner_decl: Module.Decl.Index,
5705 owner_decl: DeclIndex,
56635706 ty: Index,
56645707 zir_body_inst: Zir.Inst.Index,
56655708 lbrace_line: u32,
......@@ -5716,7 +5759,7 @@ pub fn getFuncDecl(ip: *InternPool, gpa: Allocator, key: GetFuncDeclKey) Allocat
57165759}
57175760
57185761pub const GetFuncDeclIesKey = struct {
5719 owner_decl: Module.Decl.Index,
5762 owner_decl: DeclIndex,
57205763 param_types: []Index,
57215764 noalias_bits: u32,
57225765 comptime_bits: u32,
......@@ -6321,8 +6364,8 @@ fn getIncompleteEnumExplicit(
63216364}
63226365
63236366pub const GetEnumInit = struct {
6324 decl: Module.Decl.Index,
6325 namespace: Module.Namespace.OptionalIndex,
6367 decl: DeclIndex,
6368 namespace: OptionalNamespaceIndex,
63266369 tag_ty: Index,
63276370 names: []const NullTerminatedString,
63286371 values: []const Index,
......@@ -6484,9 +6527,9 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
64846527 inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {
64856528 ip.extra.appendAssumeCapacity(switch (field.type) {
64866529 Index,
6487 Module.Decl.Index,
6488 Module.Namespace.Index,
6489 Module.Namespace.OptionalIndex,
6530 DeclIndex,
6531 NamespaceIndex,
6532 OptionalNamespaceIndex,
64906533 MapIndex,
64916534 OptionalMapIndex,
64926535 RuntimeIndex,
......@@ -6560,9 +6603,9 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct
65606603 const int32 = ip.extra.items[i + index];
65616604 @field(result, field.name) = switch (field.type) {
65626605 Index,
6563 Module.Decl.Index,
6564 Module.Namespace.Index,
6565 Module.Namespace.OptionalIndex,
6606 DeclIndex,
6607 NamespaceIndex,
6608 OptionalNamespaceIndex,
65666609 MapIndex,
65676610 OptionalMapIndex,
65686611 RuntimeIndex,
......@@ -7554,15 +7597,15 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
75547597 try bw.flush();
75557598}
75567599
7557pub fn declPtr(ip: *InternPool, index: Module.Decl.Index) *Module.Decl {
7600pub fn declPtr(ip: *InternPool, index: DeclIndex) *Module.Decl {
75587601 return ip.allocated_decls.at(@intFromEnum(index));
75597602}
75607603
7561pub fn declPtrConst(ip: *const InternPool, index: Module.Decl.Index) *const Module.Decl {
7604pub fn declPtrConst(ip: *const InternPool, index: DeclIndex) *const Module.Decl {
75627605 return ip.allocated_decls.at(@intFromEnum(index));
75637606}
75647607
7565pub fn namespacePtr(ip: *InternPool, index: Module.Namespace.Index) *Module.Namespace {
7608pub fn namespacePtr(ip: *InternPool, index: NamespaceIndex) *Module.Namespace {
75667609 return ip.allocated_namespaces.at(@intFromEnum(index));
75677610}
75687611
......@@ -7570,7 +7613,7 @@ pub fn createDecl(
75707613 ip: *InternPool,
75717614 gpa: Allocator,
75727615 initialization: Module.Decl,
7573) Allocator.Error!Module.Decl.Index {
7616) Allocator.Error!DeclIndex {
75747617 if (ip.decls_free_list.popOrNull()) |index| {
75757618 ip.allocated_decls.at(@intFromEnum(index)).* = initialization;
75767619 return index;
......@@ -7580,7 +7623,7 @@ pub fn createDecl(
75807623 return @enumFromInt(ip.allocated_decls.len - 1);
75817624}
75827625
7583pub fn destroyDecl(ip: *InternPool, gpa: Allocator, index: Module.Decl.Index) void {
7626pub fn destroyDecl(ip: *InternPool, gpa: Allocator, index: DeclIndex) void {
75847627 ip.declPtr(index).* = undefined;
75857628 ip.decls_free_list.append(gpa, index) catch {
75867629 // In order to keep `destroyDecl` a non-fallible function, we ignore memory
......@@ -7592,7 +7635,7 @@ pub fn createNamespace(
75927635 ip: *InternPool,
75937636 gpa: Allocator,
75947637 initialization: Module.Namespace,
7595) Allocator.Error!Module.Namespace.Index {
7638) Allocator.Error!NamespaceIndex {
75967639 if (ip.namespaces_free_list.popOrNull()) |index| {
75977640 ip.allocated_namespaces.at(@intFromEnum(index)).* = initialization;
75987641 return index;
......@@ -7602,7 +7645,7 @@ pub fn createNamespace(
76027645 return @enumFromInt(ip.allocated_namespaces.len - 1);
76037646}
76047647
7605pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: Module.Namespace.Index) void {
7648pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: NamespaceIndex) void {
76067649 ip.namespacePtr(index).* = .{
76077650 .parent = undefined,
76087651 .file_scope = undefined,
......@@ -7984,7 +8027,7 @@ pub fn isVariable(ip: *const InternPool, val: Index) bool {
79848027 return ip.items.items(.tag)[@intFromEnum(val)] == .variable;
79858028}
79868029
7987pub fn getBackingDecl(ip: *const InternPool, val: Index) Module.Decl.OptionalIndex {
8030pub fn getBackingDecl(ip: *const InternPool, val: Index) OptionalDeclIndex {
79888031 var base = @intFromEnum(val);
79898032 while (true) {
79908033 switch (ip.items.items(.tag)[base]) {
......@@ -8358,7 +8401,7 @@ pub fn funcDeclInfo(ip: *const InternPool, i: Index) Key.Func {
83588401 return extraFuncDecl(ip, datas[@intFromEnum(i)]);
83598402}
83608403
8361pub fn funcDeclOwner(ip: *const InternPool, i: Index) Module.Decl.Index {
8404pub fn funcDeclOwner(ip: *const InternPool, i: Index) DeclIndex {
83628405 return funcDeclInfo(ip, i).owner_decl;
83638406}
83648407
......@@ -8424,7 +8467,7 @@ pub fn anonStructFieldsLen(ip: *const InternPool, i: Index) u32 {
84248467}
84258468
84268469/// Asserts the type is a struct.
8427pub fn structDecl(ip: *const InternPool, i: Index) Module.Decl.OptionalIndex {
8470pub fn structDecl(ip: *const InternPool, i: Index) OptionalDeclIndex {
84288471 return switch (ip.indexToKey(i)) {
84298472 .struct_type => |t| t.decl,
84308473 else => unreachable,
src/Module.zig+4-42
......@@ -464,27 +464,8 @@ pub const Decl = struct {
464464 anon,
465465 };
466466
467 pub const Index = enum(u32) {
468 _,
469
470 pub fn toOptional(i: Index) OptionalIndex {
471 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
472 }
473 };
474
475 pub const OptionalIndex = enum(u32) {
476 none = std.math.maxInt(u32),
477 _,
478
479 pub fn init(oi: ?Index) OptionalIndex {
480 return @as(OptionalIndex, @enumFromInt(@intFromEnum(oi orelse return .none)));
481 }
482
483 pub fn unwrap(oi: OptionalIndex) ?Index {
484 if (oi == .none) return null;
485 return @as(Index, @enumFromInt(@intFromEnum(oi)));
486 }
487 };
467 const Index = InternPool.DeclIndex;
468 const OptionalIndex = InternPool.OptionalDeclIndex;
488469
489470 pub const DepsTable = std.AutoArrayHashMapUnmanaged(Decl.Index, DepType);
490471
......@@ -828,27 +809,8 @@ pub const Namespace = struct {
828809 /// Value is whether the usingnamespace decl is marked `pub`.
829810 usingnamespace_set: std.AutoHashMapUnmanaged(Decl.Index, bool) = .{},
830811
831 pub const Index = enum(u32) {
832 _,
833
834 pub fn toOptional(i: Index) OptionalIndex {
835 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
836 }
837 };
838
839 pub const OptionalIndex = enum(u32) {
840 none = std.math.maxInt(u32),
841 _,
842
843 pub fn init(oi: ?Index) OptionalIndex {
844 return @as(OptionalIndex, @enumFromInt(@intFromEnum(oi orelse return .none)));
845 }
846
847 pub fn unwrap(oi: OptionalIndex) ?Index {
848 if (oi == .none) return null;
849 return @as(Index, @enumFromInt(@intFromEnum(oi)));
850 }
851 };
812 const Index = InternPool.NamespaceIndex;
813 const OptionalIndex = InternPool.OptionalNamespaceIndex;
852814
853815 const DeclContext = struct {
854816 module: *Module,
src/Sema.zig+36-36
......@@ -20,7 +20,7 @@ inst_map: InstMap = .{},
2020/// and `src_decl` of `Block` is the `Decl` of the callee.
2121/// This `Decl` owns the arena memory of this `Sema`.
2222owner_decl: *Decl,
23owner_decl_index: Decl.Index,
23owner_decl_index: InternPool.DeclIndex,
2424/// For an inline or comptime function call, this will be the root parent function
2525/// which contains the callsite. Corresponds to `owner_decl`.
2626/// This could be `none`, a `func_decl`, or a `func_instance`.
......@@ -54,7 +54,7 @@ comptime_break_inst: Zir.Inst.Index = undefined,
5454/// access to the source location set by the previous instruction which did
5555/// contain a mapped source location.
5656src: LazySrcLoc = .{ .token_offset = 0 },
57decl_val_table: std.AutoHashMapUnmanaged(Decl.Index, Air.Inst.Ref) = .{},
57decl_val_table: std.AutoHashMapUnmanaged(InternPool.DeclIndex, Air.Inst.Ref) = .{},
5858/// When doing a generic function instantiation, this array collects a value
5959/// for each parameter of the generic owner. `none` for non-comptime parameters.
6060/// This is a separate array from `block.params` so that it can be passed
......@@ -71,7 +71,7 @@ generic_owner: InternPool.Index = .none,
7171/// declaration site.
7272generic_call_src: LazySrcLoc = .unneeded,
7373/// Corresponds to `generic_call_src`.
74generic_call_decl: Decl.OptionalIndex = .none,
74generic_call_decl: InternPool.OptionalDeclIndex = .none,
7575/// The key is types that must be fully resolved prior to machine code
7676/// generation pass. Types are added to this set when resolving them
7777/// immediately could cause a dependency loop, but they do need to be resolved
......@@ -101,7 +101,7 @@ unresolved_inferred_allocs: std.AutoHashMapUnmanaged(Air.Inst.Index, InferredAll
101101/// TODO: this is a workaround for memory bugs triggered by the removal of
102102/// Decl.value_arena. A better solution needs to be found. Probably this will
103103/// involve transitioning comptime-mutable memory away from using Decls at all.
104comptime_mutable_decls: *std.ArrayList(Decl.Index),
104comptime_mutable_decls: *std.ArrayList(InternPool.DeclIndex),
105105
106106/// This is populated when `@setAlignStack` occurs so that if there is a duplicate
107107/// one encountered, the conflicting source location can be shown.
......@@ -323,7 +323,7 @@ pub const Block = struct {
323323 sema: *Sema,
324324 /// The namespace to use for lookups from this source block
325325 /// When analyzing fields, this is different from src_decl.src_namespace.
326 namespace: Namespace.Index,
326 namespace: InternPool.NamespaceIndex,
327327 /// The AIR instructions generated for this block.
328328 instructions: std.ArrayListUnmanaged(Air.Inst.Index),
329329 // `param` instructions are collected here to be used by the `func` instruction.
......@@ -345,7 +345,7 @@ pub const Block = struct {
345345 /// This Decl is the Decl according to the Zig source code corresponding to this Block.
346346 /// This can vary during inline or comptime function calls. See `Sema.owner_decl`
347347 /// for the one that will be the same for all Block instances.
348 src_decl: Decl.Index,
348 src_decl: InternPool.DeclIndex,
349349 /// Non zero if a non-inline loop or a runtime conditional have been encountered.
350350 /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.
351351 runtime_index: Value.RuntimeIndex = .zero,
......@@ -800,7 +800,7 @@ pub const Block = struct {
800800 }
801801
802802 /// `alignment` value of 0 means to use ABI alignment.
803 pub fn finish(wad: *WipAnonDecl, ty: Type, val: Value, alignment: Alignment) !Decl.Index {
803 pub fn finish(wad: *WipAnonDecl, ty: Type, val: Value, alignment: Alignment) !InternPool.DeclIndex {
804804 const sema = wad.block.sema;
805805 // Do this ahead of time because `createAnonymousDecl` depends on calling
806806 // `type.hasRuntimeBits()`.
......@@ -2505,7 +2505,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.ErrorMsg)
25052505 defer reference_stack.deinit();
25062506
25072507 // Avoid infinite loops.
2508 var seen = std.AutoHashMap(Decl.Index, void).init(gpa);
2508 var seen = std.AutoHashMap(InternPool.DeclIndex, void).init(gpa);
25092509 defer seen.deinit();
25102510
25112511 while (mod.reference_table.get(referenced_by)) |ref| {
......@@ -2652,8 +2652,8 @@ fn analyzeAsInt(
26522652
26532653pub fn getStructType(
26542654 sema: *Sema,
2655 decl: Module.Decl.Index,
2656 namespace: Module.Namespace.Index,
2655 decl: InternPool.DeclIndex,
2656 namespace: InternPool.NamespaceIndex,
26572657 zir_index: Zir.Inst.Index,
26582658) !InternPool.Index {
26592659 const mod = sema.mod;
......@@ -2768,7 +2768,7 @@ fn createAnonymousDeclTypeNamed(
27682768 name_strategy: Zir.Inst.NameStrategy,
27692769 anon_prefix: []const u8,
27702770 inst: ?Zir.Inst.Index,
2771) !Decl.Index {
2771) !InternPool.DeclIndex {
27722772 const mod = sema.mod;
27732773 const ip = &mod.intern_pool;
27742774 const gpa = sema.gpa;
......@@ -6065,7 +6065,7 @@ pub fn analyzeExport(
60656065 block: *Block,
60666066 src: LazySrcLoc,
60676067 options: Module.Export.Options,
6068 exported_decl_index: Decl.Index,
6068 exported_decl_index: InternPool.DeclIndex,
60696069) !void {
60706070 const gpa = sema.gpa;
60716071 const mod = sema.mod;
......@@ -6380,7 +6380,7 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
63806380 return sema.analyzeDeclVal(block, src, decl);
63816381}
63826382
6383fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPool.NullTerminatedString) !Decl.Index {
6383fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPool.NullTerminatedString) !InternPool.DeclIndex {
63846384 const mod = sema.mod;
63856385 var namespace = block.namespace;
63866386 while (true) {
......@@ -6398,10 +6398,10 @@ fn lookupInNamespace(
63986398 sema: *Sema,
63996399 block: *Block,
64006400 src: LazySrcLoc,
6401 namespace_index: Namespace.Index,
6401 namespace_index: InternPool.NamespaceIndex,
64026402 ident_name: InternPool.NullTerminatedString,
64036403 observe_usingnamespace: bool,
6404) CompileError!?Decl.Index {
6404) CompileError!?InternPool.DeclIndex {
64056405 const mod = sema.mod;
64066406
64076407 const namespace = mod.namespacePtr(namespace_index);
......@@ -6419,7 +6419,7 @@ fn lookupInNamespace(
64196419 defer checked_namespaces.deinit(gpa);
64206420
64216421 // Keep track of name conflicts for error notes.
6422 var candidates: std.ArrayListUnmanaged(Decl.Index) = .{};
6422 var candidates: std.ArrayListUnmanaged(InternPool.DeclIndex) = .{};
64236423 defer candidates.deinit(gpa);
64246424
64256425 try checked_namespaces.put(gpa, namespace, namespace.file_scope == src_file);
......@@ -7034,7 +7034,7 @@ const InlineCallSema = struct {
70347034 other_error_return_trace_index_on_fn_entry: Air.Inst.Ref,
70357035 other_generic_owner: InternPool.Index,
70367036 other_generic_call_src: LazySrcLoc,
7037 other_generic_call_decl: Decl.OptionalIndex,
7037 other_generic_call_decl: InternPool.OptionalDeclIndex,
70387038
70397039 /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not
70407040 /// change that. The other parameters contain data for the callee Sema. The other modified
......@@ -7104,7 +7104,7 @@ const InlineCallSema = struct {
71047104 std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map);
71057105 std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner);
71067106 std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src);
7107 std.mem.swap(Decl.OptionalIndex, &ics.sema.generic_call_decl, &ics.other_generic_call_decl);
7107 std.mem.swap(InternPool.OptionalDeclIndex, &ics.sema.generic_call_decl, &ics.other_generic_call_decl);
71087108 std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry);
71097109 // zig fmt: on
71107110 }
......@@ -17825,7 +17825,7 @@ fn typeInfoDecls(
1782517825 block: *Block,
1782617826 src: LazySrcLoc,
1782717827 type_info_ty: Type,
17828 opt_namespace: Module.Namespace.OptionalIndex,
17828 opt_namespace: InternPool.OptionalNamespaceIndex,
1782917829) CompileError!InternPool.Index {
1783017830 const mod = sema.mod;
1783117831 const gpa = sema.gpa;
......@@ -25760,7 +25760,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block) !void {
2576025760/// Backends depend on panic decls being available when lowering safety-checked
2576125761/// instructions. This function ensures the panic function will be available to
2576225762/// be called during that time.
25763fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !Module.Decl.Index {
25763fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternPool.DeclIndex {
2576425764 const mod = sema.mod;
2576525765 const gpa = sema.gpa;
2576625766 if (mod.panic_messages[@intFromEnum(panic_id)].unwrap()) |x| return x;
......@@ -26685,9 +26685,9 @@ fn namespaceLookup(
2668526685 sema: *Sema,
2668626686 block: *Block,
2668726687 src: LazySrcLoc,
26688 namespace: Namespace.Index,
26688 namespace: InternPool.NamespaceIndex,
2668926689 decl_name: InternPool.NullTerminatedString,
26690) CompileError!?Decl.Index {
26690) CompileError!?InternPool.DeclIndex {
2669126691 const mod = sema.mod;
2669226692 const gpa = sema.gpa;
2669326693 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| {
......@@ -26712,7 +26712,7 @@ fn namespaceLookupRef(
2671226712 sema: *Sema,
2671326713 block: *Block,
2671426714 src: LazySrcLoc,
26715 namespace: Namespace.Index,
26715 namespace: InternPool.NamespaceIndex,
2671626716 decl_name: InternPool.NullTerminatedString,
2671726717) CompileError!?Air.Inst.Ref {
2671826718 const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null;
......@@ -26724,7 +26724,7 @@ fn namespaceLookupVal(
2672426724 sema: *Sema,
2672526725 block: *Block,
2672626726 src: LazySrcLoc,
26727 namespace: Namespace.Index,
26727 namespace: InternPool.NamespaceIndex,
2672826728 decl_name: InternPool.NullTerminatedString,
2672926729) CompileError!?Air.Inst.Ref {
2673026730 const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null;
......@@ -31589,7 +31589,7 @@ fn analyzeDeclVal(
3158931589 sema: *Sema,
3159031590 block: *Block,
3159131591 src: LazySrcLoc,
31592 decl_index: Decl.Index,
31592 decl_index: InternPool.DeclIndex,
3159331593) CompileError!Air.Inst.Ref {
3159431594 try sema.addReferencedBy(block, src, decl_index);
3159531595 if (sema.decl_val_table.get(decl_index)) |result| {
......@@ -31609,7 +31609,7 @@ fn addReferencedBy(
3160931609 sema: *Sema,
3161031610 block: *Block,
3161131611 src: LazySrcLoc,
31612 decl_index: Decl.Index,
31612 decl_index: InternPool.DeclIndex,
3161331613) !void {
3161431614 if (sema.mod.comp.reference_trace == 0) return;
3161531615 if (src == .unneeded) {
......@@ -31626,7 +31626,7 @@ fn addReferencedBy(
3162631626 });
3162731627}
3162831628
31629fn ensureDeclAnalyzed(sema: *Sema, decl_index: Decl.Index) CompileError!void {
31629fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) CompileError!void {
3163031630 const mod = sema.mod;
3163131631 const ip = &mod.intern_pool;
3163231632 const decl = mod.declPtr(decl_index);
......@@ -31670,7 +31670,7 @@ fn optRefValue(sema: *Sema, opt_val: ?Value) !Value {
3167031670 } })));
3167131671}
3167231672
31673fn analyzeDeclRef(sema: *Sema, decl_index: Decl.Index) CompileError!Air.Inst.Ref {
31673fn analyzeDeclRef(sema: *Sema, decl_index: InternPool.DeclIndex) CompileError!Air.Inst.Ref {
3167431674 return sema.analyzeDeclRefInner(decl_index, true);
3167531675}
3167631676
......@@ -31678,7 +31678,7 @@ fn analyzeDeclRef(sema: *Sema, decl_index: Decl.Index) CompileError!Air.Inst.Ref
3167831678/// only triggers analysis for function bodies if `analyze_fn_body` is true. If it's possible for a
3167931679/// decl_ref to end up in runtime code, the function body must be analyzed: `analyzeDeclRef` wraps
3168031680/// this function with `analyze_fn_body` set to true.
31681fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: bool) CompileError!Air.Inst.Ref {
31681fn analyzeDeclRefInner(sema: *Sema, decl_index: InternPool.DeclIndex, analyze_fn_body: bool) CompileError!Air.Inst.Ref {
3168231682 const mod = sema.mod;
3168331683 try sema.ensureDeclAnalyzed(decl_index);
3168431684
......@@ -31701,7 +31701,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo
3170131701 } })));
3170231702}
3170331703
31704fn maybeQueueFuncBodyAnalysis(sema: *Sema, decl_index: Decl.Index) !void {
31704fn maybeQueueFuncBodyAnalysis(sema: *Sema, decl_index: InternPool.DeclIndex) !void {
3170531705 const mod = sema.mod;
3170631706 const decl = mod.declPtr(decl_index);
3170731707 const tv = try decl.typedValue();
......@@ -34861,7 +34861,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp
3486134861 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
3486234862 defer analysis_arena.deinit();
3486334863
34864 var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa);
34864 var comptime_mutable_decls = std.ArrayList(InternPool.DeclIndex).init(gpa);
3486534865 defer comptime_mutable_decls.deinit();
3486634866
3486734867 var sema: Sema = .{
......@@ -35683,7 +35683,7 @@ fn semaStructFields(
3568335683 },
3568435684 };
3568535685
35686 var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa);
35686 var comptime_mutable_decls = std.ArrayList(InternPool.DeclIndex).init(gpa);
3568735687 defer comptime_mutable_decls.deinit();
3568835688
3568935689 var sema: Sema = .{
......@@ -35949,7 +35949,7 @@ fn semaStructFieldInits(
3594935949 const zir_index = struct_type.zir_index;
3595035950 const fields_len, const small, var extra_index = structZirInfo(zir, zir_index);
3595135951
35952 var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa);
35952 var comptime_mutable_decls = std.ArrayList(InternPool.DeclIndex).init(gpa);
3595335953 defer comptime_mutable_decls.deinit();
3595435954
3595535955 var sema: Sema = .{
......@@ -36133,7 +36133,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3613336133
3613436134 const decl = mod.declPtr(decl_index);
3613536135
36136 var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa);
36136 var comptime_mutable_decls = std.ArrayList(InternPool.DeclIndex).init(gpa);
3613736137 defer comptime_mutable_decls.deinit();
3613836138
3613936139 var sema: Sema = .{
......@@ -36561,7 +36561,7 @@ fn generateUnionTagTypeSimple(
3656136561 sema: *Sema,
3656236562 block: *Block,
3656336563 enum_field_names: []const InternPool.NullTerminatedString,
36564 maybe_decl_index: Module.Decl.OptionalIndex,
36564 maybe_decl_index: InternPool.OptionalDeclIndex,
3656536565) !InternPool.Index {
3656636566 const mod = sema.mod;
3656736567 const ip = &mod.intern_pool;
......@@ -36630,7 +36630,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
3663036630 return sema.analyzeDeclVal(&block, src, decl_index);
3663136631}
3663236632
36633fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Module.Decl.Index {
36633fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex {
3663436634 const gpa = sema.gpa;
3663536635
3663636636 const src = LazySrcLoc.nodeOffset(0);
src/Zir.zig-3
......@@ -21,9 +21,6 @@ const Ast = std.zig.Ast;
2121
2222const InternPool = @import("InternPool.zig");
2323const Zir = @This();
24const Type = @import("type.zig").Type;
25const Value = @import("value.zig").Value;
26const TypedValue = @import("TypedValue.zig");
2724const Module = @import("Module.zig");
2825const LazySrcLoc = Module.LazySrcLoc;
2926
src/arch/aarch64/CodeGen.zig+1-1
......@@ -52,7 +52,7 @@ bin_file: *link.File,
5252debug_output: DebugInfoOutput,
5353target: *const std.Target,
5454func_index: InternPool.Index,
55owner_decl: Module.Decl.Index,
55owner_decl: InternPool.DeclIndex,
5656err_msg: ?*ErrorMsg,
5757args: []MCValue,
5858ret_mcv: MCValue,
src/arch/wasm/CodeGen.zig+4-4
......@@ -643,7 +643,7 @@ const CodeGen = @This();
643643/// Reference to the function declaration the code
644644/// section belongs to
645645decl: *Decl,
646decl_index: Decl.Index,
646decl_index: InternPool.DeclIndex,
647647/// Current block depth. Used to calculate the relative difference between a break
648648/// and block
649649block_depth: u32 = 0,
......@@ -2194,7 +2194,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
21942194 const fn_info = mod.typeToFunc(fn_ty).?;
21952195 const first_param_sret = firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), mod);
21962196
2197 const callee: ?Decl.Index = blk: {
2197 const callee: ?InternPool.DeclIndex = blk: {
21982198 const func_val = (try func.air.value(pl_op.operand, mod)) orelse break :blk null;
21992199
22002200 if (func_val.getFunction(mod)) |function| {
......@@ -3131,7 +3131,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
31313131 }
31323132}
31333133
3134fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: Module.Decl.Index, offset: u32) InnerError!WValue {
3134fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: InternPool.DeclIndex, offset: u32) InnerError!WValue {
31353135 const mod = func.bin_file.base.options.module.?;
31363136 const decl = mod.declPtr(decl_index);
31373137 try mod.markDeclAlive(decl);
......@@ -3171,7 +3171,7 @@ fn lowerAnonDeclRef(
31713171 } else return WValue{ .memory_offset = .{ .pointer = target_sym_index, .offset = offset } };
31723172}
31733173
3174fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: Module.Decl.Index, offset: u32) InnerError!WValue {
3174fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: InternPool.DeclIndex, offset: u32) InnerError!WValue {
31753175 const mod = func.bin_file.base.options.module.?;
31763176 if (tv.ty.isSlice(mod)) {
31773177 return WValue{ .memory = try func.bin_file.lowerUnnamedConst(tv, decl_index) };
src/arch/wasm/Emit.zig+2-1
......@@ -6,6 +6,7 @@ const std = @import("std");
66const Mir = @import("Mir.zig");
77const link = @import("../../link.zig");
88const Module = @import("../../Module.zig");
9const InternPool = @import("../../InternPool.zig");
910const codegen = @import("../../codegen.zig");
1011const leb128 = std.leb;
1112
......@@ -21,7 +22,7 @@ code: *std.ArrayList(u8),
2122/// List of allocated locals.
2223locals: []const u8,
2324/// The declaration that code is being generated for.
24decl_index: Module.Decl.Index,
25decl_index: InternPool.DeclIndex,
2526
2627// Debug information
2728/// Holds the debug information for this emission
src/arch/x86_64/CodeGen.zig+3-3
......@@ -121,7 +121,7 @@ const Owner = union(enum) {
121121 func_index: InternPool.Index,
122122 lazy_sym: link.File.LazySymbol,
123123
124 fn getDecl(owner: Owner, mod: *Module) Module.Decl.Index {
124 fn getDecl(owner: Owner, mod: *Module) InternPool.DeclIndex {
125125 return switch (owner) {
126126 .func_index => |func_index| mod.funcOwnerDeclIndex(func_index),
127127 .lazy_sym => |lazy_sym| lazy_sym.ty.getOwnerDecl(mod),
......@@ -1048,7 +1048,7 @@ pub fn generateLazy(
10481048
10491049const FormatDeclData = struct {
10501050 mod: *Module,
1051 decl_index: Module.Decl.Index,
1051 decl_index: InternPool.DeclIndex,
10521052};
10531053fn formatDecl(
10541054 data: FormatDeclData,
......@@ -1058,7 +1058,7 @@ fn formatDecl(
10581058) @TypeOf(writer).Error!void {
10591059 try data.mod.declPtr(data.decl_index).renderFullyQualifiedName(data.mod, writer);
10601060}
1061fn fmtDecl(self: *Self, decl_index: Module.Decl.Index) std.fmt.Formatter(formatDecl) {
1061fn fmtDecl(self: *Self, decl_index: InternPool.DeclIndex) std.fmt.Formatter(formatDecl) {
10621062 return .{ .data = .{
10631063 .mod = self.bin_file.options.module.?,
10641064 .decl_index = decl_index,
src/codegen.zig+4-4
......@@ -757,7 +757,7 @@ fn lowerAnonDeclRef(
757757fn lowerDeclRef(
758758 bin_file: *link.File,
759759 src_loc: Module.SrcLoc,
760 decl_index: Module.Decl.Index,
760 decl_index: InternPool.DeclIndex,
761761 code: *std.ArrayList(u8),
762762 debug_output: DebugInfoOutput,
763763 reloc_info: RelocInfo,
......@@ -853,7 +853,7 @@ fn genDeclRef(
853853 bin_file: *link.File,
854854 src_loc: Module.SrcLoc,
855855 tv: TypedValue,
856 ptr_decl_index: Module.Decl.Index,
856 ptr_decl_index: InternPool.DeclIndex,
857857) CodeGenError!GenResult {
858858 const mod = bin_file.options.module.?;
859859 log.debug("genDeclRef: ty = {}, val = {}", .{ tv.ty.fmt(mod), tv.val.fmtValue(tv.ty, mod) });
......@@ -959,7 +959,7 @@ fn genUnnamedConst(
959959 bin_file: *link.File,
960960 src_loc: Module.SrcLoc,
961961 tv: TypedValue,
962 owner_decl_index: Module.Decl.Index,
962 owner_decl_index: InternPool.DeclIndex,
963963) CodeGenError!GenResult {
964964 const mod = bin_file.options.module.?;
965965 log.debug("genUnnamedConst: ty = {}, val = {}", .{ tv.ty.fmt(mod), tv.val.fmtValue(tv.ty, mod) });
......@@ -987,7 +987,7 @@ pub fn genTypedValue(
987987 bin_file: *link.File,
988988 src_loc: Module.SrcLoc,
989989 arg_tv: TypedValue,
990 owner_decl_index: Module.Decl.Index,
990 owner_decl_index: InternPool.DeclIndex,
991991) CodeGenError!GenResult {
992992 const mod = bin_file.options.module.?;
993993 const typed_value = arg_tv;
src/codegen/c.zig+10-10
......@@ -39,8 +39,8 @@ pub const CValue = union(enum) {
3939 /// Index into a tuple's fields
4040 field: usize,
4141 /// By-value
42 decl: Decl.Index,
43 decl_ref: Decl.Index,
42 decl: InternPool.DeclIndex,
43 decl_ref: InternPool.DeclIndex,
4444 /// An undefined value (cannot be dereferenced)
4545 undef: Type,
4646 /// Render the slice as an identifier (using fmtIdent)
......@@ -57,9 +57,9 @@ const BlockData = struct {
5757pub const CValueMap = std.AutoHashMap(Air.Inst.Ref, CValue);
5858
5959pub const LazyFnKey = union(enum) {
60 tag_name: Decl.Index,
61 never_tail: Decl.Index,
62 never_inline: Decl.Index,
60 tag_name: InternPool.DeclIndex,
61 never_tail: InternPool.DeclIndex,
62 never_inline: InternPool.DeclIndex,
6363};
6464pub const LazyFnValue = struct {
6565 fn_name: []const u8,
......@@ -534,7 +534,7 @@ pub const DeclGen = struct {
534534 aligned_anon_decls: std.AutoArrayHashMapUnmanaged(InternPool.Index, Alignment),
535535
536536 pub const Pass = union(enum) {
537 decl: Decl.Index,
537 decl: InternPool.DeclIndex,
538538 anon: InternPool.Index,
539539 flush,
540540 };
......@@ -624,7 +624,7 @@ pub const DeclGen = struct {
624624 writer: anytype,
625625 ty: Type,
626626 val: Value,
627 decl_index: Decl.Index,
627 decl_index: InternPool.DeclIndex,
628628 location: ValueRenderLocation,
629629 ) error{ OutOfMemory, AnalysisFail }!void {
630630 const mod = dg.module;
......@@ -1585,7 +1585,7 @@ pub const DeclGen = struct {
15851585 fn renderFunctionSignature(
15861586 dg: *DeclGen,
15871587 w: anytype,
1588 fn_decl_index: Decl.Index,
1588 fn_decl_index: InternPool.DeclIndex,
15891589 kind: CType.Kind,
15901590 name: union(enum) {
15911591 export_index: u32,
......@@ -1926,7 +1926,7 @@ pub const DeclGen = struct {
19261926 try dg.writeCValue(writer, member);
19271927 }
19281928
1929 fn renderFwdDecl(dg: *DeclGen, decl_index: Decl.Index, variable: InternPool.Key.Variable) !void {
1929 fn renderFwdDecl(dg: *DeclGen, decl_index: InternPool.DeclIndex, variable: InternPool.Key.Variable) !void {
19301930 const decl = dg.module.declPtr(decl_index);
19311931 const fwd = dg.fwd_decl.writer();
19321932 const is_global = dg.declIsGlobal(.{ .ty = decl.ty, .val = decl.val }) or variable.is_extern;
......@@ -1948,7 +1948,7 @@ pub const DeclGen = struct {
19481948 try fwd.writeAll(";\n");
19491949 }
19501950
1951 fn renderDeclName(dg: *DeclGen, writer: anytype, decl_index: Decl.Index, export_index: u32) !void {
1951 fn renderDeclName(dg: *DeclGen, writer: anytype, decl_index: InternPool.DeclIndex, export_index: u32) !void {
19521952 const mod = dg.module;
19531953 const decl = mod.declPtr(decl_index);
19541954 try mod.markDeclAlive(decl);
src/codegen/c/type.zig+3-2
......@@ -7,6 +7,7 @@ const Target = std.Target;
77
88const Alignment = @import("../../InternPool.zig").Alignment;
99const Module = @import("../../Module.zig");
10const InternPool = @import("../../InternPool.zig");
1011const Type = @import("../../type.zig").Type;
1112
1213pub const CType = extern union {
......@@ -238,7 +239,7 @@ pub const CType = extern union {
238239
239240 pub const FwdDecl = struct {
240241 base: Payload,
241 data: Module.Decl.Index,
242 data: InternPool.DeclIndex,
242243 };
243244
244245 pub const Fields = struct {
......@@ -257,7 +258,7 @@ pub const CType = extern union {
257258 base: Payload,
258259 data: struct {
259260 fields: Fields.Data,
260 owner_decl: Module.Decl.Index,
261 owner_decl: InternPool.DeclIndex,
261262 id: u32,
262263 },
263264 };
src/codegen/llvm.zig+12-12
......@@ -809,11 +809,11 @@ pub const Object = struct {
809809 /// version of the name and incorrectly get function not found in the llvm module.
810810 /// * it works for functions not all globals.
811811 /// Therefore, this table keeps track of the mapping.
812 decl_map: std.AutoHashMapUnmanaged(Module.Decl.Index, Builder.Global.Index),
812 decl_map: std.AutoHashMapUnmanaged(InternPool.DeclIndex, Builder.Global.Index),
813813 /// Same deal as `decl_map` but for anonymous declarations, which are always global constants.
814814 anon_decl_map: std.AutoHashMapUnmanaged(InternPool.Index, Builder.Global.Index),
815815 /// Serves the same purpose as `decl_map` but only used for the `is_named_enum_value` instruction.
816 named_enum_map: std.AutoHashMapUnmanaged(Module.Decl.Index, Builder.Function.Index),
816 named_enum_map: std.AutoHashMapUnmanaged(InternPool.DeclIndex, Builder.Function.Index),
817817 /// Maps Zig types to LLVM types. The table memory is backed by the GPA of
818818 /// the compiler.
819819 /// TODO when InternPool garbage collection is implemented, this map needs
......@@ -827,7 +827,7 @@ pub const Object = struct {
827827 /// This map is usually very close to empty. It tracks only the cases when a
828828 /// second extern Decl could not be emitted with the correct name due to a
829829 /// name collision.
830 extern_collisions: std.AutoArrayHashMapUnmanaged(Module.Decl.Index, void),
830 extern_collisions: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, void),
831831
832832 /// Memoizes a null `?usize` value.
833833 null_opt_usize: Builder.Constant,
......@@ -1660,7 +1660,7 @@ pub const Object = struct {
16601660 try o.updateExports(mod, .{ .decl_index = decl_index }, mod.getDeclExports(decl_index));
16611661 }
16621662
1663 pub fn updateDecl(self: *Object, module: *Module, decl_index: Module.Decl.Index) !void {
1663 pub fn updateDecl(self: *Object, module: *Module, decl_index: InternPool.DeclIndex) !void {
16641664 const decl = module.declPtr(decl_index);
16651665 var dg: DeclGen = .{
16661666 .object = self,
......@@ -1893,7 +1893,7 @@ pub const Object = struct {
18931893 }
18941894 }
18951895
1896 pub fn freeDecl(self: *Object, decl_index: Module.Decl.Index) void {
1896 pub fn freeDecl(self: *Object, decl_index: InternPool.DeclIndex) void {
18971897 const global = self.decl_map.get(decl_index) orelse return;
18981898 global.delete(&self.builder);
18991899 }
......@@ -2860,7 +2860,7 @@ pub const Object = struct {
28602860 }
28612861 }
28622862
2863 fn namespaceToDebugScope(o: *Object, namespace_index: Module.Namespace.Index) !*llvm.DIScope {
2863 fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !*llvm.DIScope {
28642864 const mod = o.module;
28652865 const namespace = mod.namespacePtr(namespace_index);
28662866 if (namespace.parent == .none) {
......@@ -2874,7 +2874,7 @@ pub const Object = struct {
28742874 /// This is to be used instead of void for debug info types, to avoid tripping
28752875 /// Assertion `!isa<DIType>(Scope) && "shouldn't make a namespace scope for a type"'
28762876 /// when targeting CodeView (Windows).
2877 fn makeEmptyNamespaceDIType(o: *Object, decl_index: Module.Decl.Index) !*llvm.DIType {
2877 fn makeEmptyNamespaceDIType(o: *Object, decl_index: InternPool.DeclIndex) !*llvm.DIType {
28782878 const mod = o.module;
28792879 const decl = mod.declPtr(decl_index);
28802880 const fields: [0]*llvm.DIType = .{};
......@@ -2932,7 +2932,7 @@ pub const Object = struct {
29322932 /// completed, so if any attributes rely on that, they must be done in updateFunc, not here.
29332933 fn resolveLlvmFunction(
29342934 o: *Object,
2935 decl_index: Module.Decl.Index,
2935 decl_index: InternPool.DeclIndex,
29362936 ) Allocator.Error!Builder.Function.Index {
29372937 const mod = o.module;
29382938 const ip = &mod.intern_pool;
......@@ -3152,7 +3152,7 @@ pub const Object = struct {
31523152
31533153 fn resolveGlobalDecl(
31543154 o: *Object,
3155 decl_index: Module.Decl.Index,
3155 decl_index: InternPool.DeclIndex,
31563156 ) Allocator.Error!Builder.Variable.Index {
31573157 const gop = try o.decl_map.getOrPut(o.gpa, decl_index);
31583158 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable;
......@@ -4330,7 +4330,7 @@ pub const Object = struct {
43304330 return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(mod).bits), bigint);
43314331 }
43324332
4333 fn lowerParentPtrDecl(o: *Object, decl_index: Module.Decl.Index) Allocator.Error!Builder.Constant {
4333 fn lowerParentPtrDecl(o: *Object, decl_index: InternPool.DeclIndex) Allocator.Error!Builder.Constant {
43344334 const mod = o.module;
43354335 const decl = mod.declPtr(decl_index);
43364336 try mod.markDeclAlive(decl);
......@@ -4505,7 +4505,7 @@ pub const Object = struct {
45054505 } else .unneeded, llvm_val, try o.lowerType(ptr_ty));
45064506 }
45074507
4508 fn lowerDeclRefValue(o: *Object, ty: Type, decl_index: Module.Decl.Index) Allocator.Error!Builder.Constant {
4508 fn lowerDeclRefValue(o: *Object, ty: Type, decl_index: InternPool.DeclIndex) Allocator.Error!Builder.Constant {
45094509 const mod = o.module;
45104510
45114511 // In the case of something like:
......@@ -4653,7 +4653,7 @@ pub const Object = struct {
46534653pub const DeclGen = struct {
46544654 object: *Object,
46554655 decl: *Module.Decl,
4656 decl_index: Module.Decl.Index,
4656 decl_index: InternPool.DeclIndex,
46574657 err_msg: ?*Module.ErrorMsg,
46584658
46594659 fn todo(dg: *DeclGen, comptime format: []const u8, args: anytype) Error {
src/codegen/spirv.zig+6-6
......@@ -156,7 +156,7 @@ pub const Object = struct {
156156
157157 /// The Zig module that this object file is generated for.
158158 /// A map of Zig decl indices to SPIR-V decl indices.
159 decl_link: std.AutoHashMapUnmanaged(Decl.Index, SpvModule.Decl.Index) = .{},
159 decl_link: std.AutoHashMapUnmanaged(InternPool.DeclIndex, SpvModule.Decl.Index) = .{},
160160
161161 /// A map of Zig InternPool indices for anonymous decls to SPIR-V decl indices.
162162 anon_decl_link: std.AutoHashMapUnmanaged(struct { InternPool.Index, StorageClass }, SpvModule.Decl.Index) = .{},
......@@ -187,7 +187,7 @@ pub const Object = struct {
187187 fn genDecl(
188188 self: *Object,
189189 mod: *Module,
190 decl_index: Decl.Index,
190 decl_index: InternPool.DeclIndex,
191191 air: Air,
192192 liveness: Liveness,
193193 ) !void {
......@@ -247,14 +247,14 @@ pub const Object = struct {
247247 pub fn updateDecl(
248248 self: *Object,
249249 mod: *Module,
250 decl_index: Decl.Index,
250 decl_index: InternPool.DeclIndex,
251251 ) !void {
252252 try self.genDecl(mod, decl_index, undefined, undefined);
253253 }
254254
255255 /// Fetch or allocate a result id for decl index. This function also marks the decl as alive.
256256 /// Note: Function does not actually generate the decl, it just allocates an index.
257 pub fn resolveDecl(self: *Object, mod: *Module, decl_index: Decl.Index) !SpvModule.Decl.Index {
257 pub fn resolveDecl(self: *Object, mod: *Module, decl_index: InternPool.DeclIndex) !SpvModule.Decl.Index {
258258 const decl = mod.declPtr(decl_index);
259259 try mod.markDeclAlive(decl);
260260
......@@ -289,7 +289,7 @@ const DeclGen = struct {
289289 spv: *SpvModule,
290290
291291 /// The decl we are currently generating code for.
292 decl_index: Decl.Index,
292 decl_index: InternPool.DeclIndex,
293293
294294 /// The intermediate code of the declaration we are currently generating. Note: If
295295 /// the declaration is not a function, this value will be undefined!
......@@ -1115,7 +1115,7 @@ const DeclGen = struct {
11151115 }
11161116 }
11171117
1118 fn constantDeclRef(self: *DeclGen, ty: Type, decl_index: Decl.Index) !IdRef {
1118 fn constantDeclRef(self: *DeclGen, ty: Type, decl_index: InternPool.DeclIndex) !IdRef {
11191119 const mod = self.module;
11201120 const ty_ref = try self.resolveType(ty, .direct);
11211121 const ty_id = self.typeId(ty_ref);
src/link.zig+9-9
......@@ -552,7 +552,7 @@ pub const File = struct {
552552 /// Called from within the CodeGen to lower a local variable instantion as an unnamed
553553 /// constant. Returns the symbol index of the lowered constant in the read-only section
554554 /// of the final binary.
555 pub fn lowerUnnamedConst(base: *File, tv: TypedValue, decl_index: Module.Decl.Index) UpdateDeclError!u32 {
555 pub fn lowerUnnamedConst(base: *File, tv: TypedValue, decl_index: InternPool.DeclIndex) UpdateDeclError!u32 {
556556 if (build_options.only_c) @compileError("unreachable");
557557 switch (base.tag) {
558558 // zig fmt: off
......@@ -591,7 +591,7 @@ pub const File = struct {
591591 }
592592
593593 /// May be called before or after updateExports for any given Decl.
594 pub fn updateDecl(base: *File, module: *Module, decl_index: Module.Decl.Index) UpdateDeclError!void {
594 pub fn updateDecl(base: *File, module: *Module, decl_index: InternPool.DeclIndex) UpdateDeclError!void {
595595 const decl = module.declPtr(decl_index);
596596 assert(decl.has_tv);
597597 if (build_options.only_c) {
......@@ -632,7 +632,7 @@ pub const File = struct {
632632 }
633633 }
634634
635 pub fn updateDeclLineNumber(base: *File, module: *Module, decl_index: Module.Decl.Index) UpdateDeclError!void {
635 pub fn updateDeclLineNumber(base: *File, module: *Module, decl_index: InternPool.DeclIndex) UpdateDeclError!void {
636636 const decl = module.declPtr(decl_index);
637637 assert(decl.has_tv);
638638 if (build_options.only_c) {
......@@ -849,7 +849,7 @@ pub const File = struct {
849849 }
850850
851851 /// Called when a Decl is deleted from the Module.
852 pub fn freeDecl(base: *File, decl_index: Module.Decl.Index) void {
852 pub fn freeDecl(base: *File, decl_index: InternPool.DeclIndex) void {
853853 if (build_options.only_c) {
854854 assert(base.tag == .c);
855855 return @fieldParentPtr(C, "base", base).freeDecl(decl_index);
......@@ -928,7 +928,7 @@ pub const File = struct {
928928 /// `Decl`'s address was not yet resolved, or the containing atom gets moved in virtual memory.
929929 /// May be called before or after updateFunc/updateDecl therefore it is up to the linker to allocate
930930 /// the block/atom.
931 pub fn getDeclVAddr(base: *File, decl_index: Module.Decl.Index, reloc_info: RelocInfo) !u64 {
931 pub fn getDeclVAddr(base: *File, decl_index: InternPool.DeclIndex, reloc_info: RelocInfo) !u64 {
932932 if (build_options.only_c) unreachable;
933933 switch (base.tag) {
934934 .coff => return @fieldParentPtr(Coff, "base", base).getDeclVAddr(decl_index, reloc_info),
......@@ -972,7 +972,7 @@ pub const File = struct {
972972 }
973973 }
974974
975 pub fn deleteDeclExport(base: *File, decl_index: Module.Decl.Index, name: InternPool.NullTerminatedString) !void {
975 pub fn deleteDeclExport(base: *File, decl_index: InternPool.DeclIndex, name: InternPool.NullTerminatedString) !void {
976976 if (build_options.only_c) unreachable;
977977 switch (base.tag) {
978978 .coff => return @fieldParentPtr(Coff, "base", base).deleteDeclExport(decl_index, name),
......@@ -1225,15 +1225,15 @@ pub const File = struct {
12251225 kind: Kind,
12261226 ty: Type,
12271227
1228 pub fn initDecl(kind: Kind, decl: ?Module.Decl.Index, mod: *Module) LazySymbol {
1228 pub fn initDecl(kind: Kind, decl: ?InternPool.DeclIndex, mod: *Module) LazySymbol {
12291229 return .{ .kind = kind, .ty = if (decl) |decl_index|
12301230 mod.declPtr(decl_index).val.toType()
12311231 else
12321232 Type.anyerror };
12331233 }
12341234
1235 pub fn getDecl(self: LazySymbol, mod: *Module) Module.Decl.OptionalIndex {
1236 return Module.Decl.OptionalIndex.init(self.ty.getOwnerDeclOrNull(mod));
1235 pub fn getDecl(self: LazySymbol, mod: *Module) InternPool.OptionalDeclIndex {
1236 return InternPool.OptionalDeclIndex.init(self.ty.getOwnerDeclOrNull(mod));
12371237 }
12381238 };
12391239
src/link/C.zig+4-4
......@@ -24,7 +24,7 @@ base: link.File,
2424/// This linker backend does not try to incrementally link output C source code.
2525/// Instead, it tracks all declarations in this table, and iterates over it
2626/// in the flush function, stitching pre-rendered pieces of C code together.
27decl_table: std.AutoArrayHashMapUnmanaged(Module.Decl.Index, DeclBlock) = .{},
27decl_table: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, DeclBlock) = .{},
2828/// All the string bytes of rendered C code, all squished into one array.
2929/// While in progress, a separate buffer is used, and then when finished, the
3030/// buffer is copied into this one.
......@@ -138,7 +138,7 @@ pub fn deinit(self: *C) void {
138138 self.code_buf.deinit(gpa);
139139}
140140
141pub fn freeDecl(self: *C, decl_index: Module.Decl.Index) void {
141pub fn freeDecl(self: *C, decl_index: InternPool.DeclIndex) void {
142142 const gpa = self.base.allocator;
143143 if (self.decl_table.fetchSwapRemove(decl_index)) |kv| {
144144 var decl_block = kv.value;
......@@ -279,7 +279,7 @@ fn updateAnonDecl(self: *C, module: *Module, i: usize) !void {
279279 };
280280}
281281
282pub fn updateDecl(self: *C, module: *Module, decl_index: Module.Decl.Index) !void {
282pub fn updateDecl(self: *C, module: *Module, decl_index: InternPool.DeclIndex) !void {
283283 const tracy = trace(@src());
284284 defer tracy.end();
285285
......@@ -337,7 +337,7 @@ pub fn updateDecl(self: *C, module: *Module, decl_index: Module.Decl.Index) !voi
337337 gop.value_ptr.fwd_decl = try self.addString(object.dg.fwd_decl.items);
338338}
339339
340pub fn updateDeclLineNumber(self: *C, module: *Module, decl_index: Module.Decl.Index) !void {
340pub fn updateDeclLineNumber(self: *C, module: *Module, decl_index: InternPool.DeclIndex) !void {
341341 // The C backend does not have the ability to fix line numbers without re-generating
342342 // the entire Decl.
343343 _ = self;
src/link/Coff.zig+13-13
......@@ -109,11 +109,11 @@ const HotUpdateState = struct {
109109 loaded_base_address: ?std.os.windows.HMODULE = null,
110110};
111111
112const DeclTable = std.AutoArrayHashMapUnmanaged(Module.Decl.Index, DeclMetadata);
112const DeclTable = std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, DeclMetadata);
113113const AnonDeclTable = std.AutoHashMapUnmanaged(InternPool.Index, DeclMetadata);
114114const RelocTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(Relocation));
115115const BaseRelocationTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(u32));
116const UnnamedConstTable = std.AutoArrayHashMapUnmanaged(Module.Decl.Index, std.ArrayListUnmanaged(Atom.Index));
116const UnnamedConstTable = std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, std.ArrayListUnmanaged(Atom.Index));
117117
118118const default_file_alignment: u16 = 0x200;
119119const default_size_of_stack_reserve: u32 = 0x1000000;
......@@ -144,7 +144,7 @@ const Section = struct {
144144 free_list: std.ArrayListUnmanaged(Atom.Index) = .{},
145145};
146146
147const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, LazySymbolMetadata);
147const LazySymbolTable = std.AutoArrayHashMapUnmanaged(InternPool.OptionalDeclIndex, LazySymbolMetadata);
148148
149149const LazySymbolMetadata = struct {
150150 const State = enum { unused, pending_flush, flushed };
......@@ -1087,7 +1087,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
10871087 return self.updateExports(mod, .{ .decl_index = decl_index }, mod.getDeclExports(decl_index));
10881088}
10891089
1090pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.Index) !u32 {
1090pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: InternPool.DeclIndex) !u32 {
10911091 const gpa = self.base.allocator;
10921092 const mod = self.base.options.module.?;
10931093 const decl = mod.declPtr(decl_index);
......@@ -1157,7 +1157,7 @@ fn lowerConst(self: *Coff, name: []const u8, tv: TypedValue, required_alignment:
11571157pub fn updateDecl(
11581158 self: *Coff,
11591159 mod: *Module,
1160 decl_index: Module.Decl.Index,
1160 decl_index: InternPool.DeclIndex,
11611161) link.File.UpdateDeclError!void {
11621162 if (build_options.skip_non_native and builtin.object_format != .coff) {
11631163 @panic("Attempted to compile for object format that was disabled by build configuration");
......@@ -1302,7 +1302,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *Coff, sym: link.File.LazySymbol) !Ato
13021302 return atom;
13031303}
13041304
1305pub fn getOrCreateAtomForDecl(self: *Coff, decl_index: Module.Decl.Index) !Atom.Index {
1305pub fn getOrCreateAtomForDecl(self: *Coff, decl_index: InternPool.DeclIndex) !Atom.Index {
13061306 const gop = try self.decls.getOrPut(self.base.allocator, decl_index);
13071307 if (!gop.found_existing) {
13081308 gop.value_ptr.* = .{
......@@ -1314,7 +1314,7 @@ pub fn getOrCreateAtomForDecl(self: *Coff, decl_index: Module.Decl.Index) !Atom.
13141314 return gop.value_ptr.atom;
13151315}
13161316
1317fn getDeclOutputSection(self: *Coff, decl_index: Module.Decl.Index) u16 {
1317fn getDeclOutputSection(self: *Coff, decl_index: InternPool.DeclIndex) u16 {
13181318 const decl = self.base.options.module.?.declPtr(decl_index);
13191319 const ty = decl.ty;
13201320 const mod = self.base.options.module.?;
......@@ -1340,7 +1340,7 @@ fn getDeclOutputSection(self: *Coff, decl_index: Module.Decl.Index) u16 {
13401340 return index;
13411341}
13421342
1343fn updateDeclCode(self: *Coff, decl_index: Module.Decl.Index, code: []u8, complex_type: coff.ComplexType) !void {
1343fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, complex_type: coff.ComplexType) !void {
13441344 const mod = self.base.options.module.?;
13451345 const decl = mod.declPtr(decl_index);
13461346
......@@ -1398,7 +1398,7 @@ fn updateDeclCode(self: *Coff, decl_index: Module.Decl.Index, code: []u8, comple
13981398 try self.writeAtom(atom_index, code);
13991399}
14001400
1401fn freeUnnamedConsts(self: *Coff, decl_index: Module.Decl.Index) void {
1401fn freeUnnamedConsts(self: *Coff, decl_index: InternPool.DeclIndex) void {
14021402 const gpa = self.base.allocator;
14031403 const unnamed_consts = self.unnamed_const_atoms.getPtr(decl_index) orelse return;
14041404 for (unnamed_consts.items) |atom_index| {
......@@ -1407,7 +1407,7 @@ fn freeUnnamedConsts(self: *Coff, decl_index: Module.Decl.Index) void {
14071407 unnamed_consts.clearAndFree(gpa);
14081408}
14091409
1410pub fn freeDecl(self: *Coff, decl_index: Module.Decl.Index) void {
1410pub fn freeDecl(self: *Coff, decl_index: InternPool.DeclIndex) void {
14111411 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
14121412
14131413 const mod = self.base.options.module.?;
......@@ -1563,7 +1563,7 @@ pub fn updateExports(
15631563
15641564pub fn deleteDeclExport(
15651565 self: *Coff,
1566 decl_index: Module.Decl.Index,
1566 decl_index: InternPool.DeclIndex,
15671567 name_ip: InternPool.NullTerminatedString,
15681568) void {
15691569 if (self.llvm_object) |_| return;
......@@ -1766,7 +1766,7 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
17661766 assert(!self.imports_count_dirty);
17671767}
17681768
1769pub fn getDeclVAddr(self: *Coff, decl_index: Module.Decl.Index, reloc_info: link.File.RelocInfo) !u64 {
1769pub fn getDeclVAddr(self: *Coff, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
17701770 assert(self.llvm_object == null);
17711771
17721772 const this_atom_index = try self.getOrCreateAtomForDecl(decl_index);
......@@ -1882,7 +1882,7 @@ pub fn getGlobalSymbol(self: *Coff, name: []const u8, lib_name_name: ?[]const u8
18821882 return global_index;
18831883}
18841884
1885pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl_index: Module.Decl.Index) !void {
1885pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl_index: InternPool.DeclIndex) !void {
18861886 _ = self;
18871887 _ = module;
18881888 _ = decl_index;
src/link/Dwarf.zig+9-9
......@@ -35,7 +35,7 @@ di_files: std.AutoArrayHashMapUnmanaged(*const Module.File, void) = .{},
3535
3636global_abbrev_relocs: std.ArrayListUnmanaged(AbbrevRelocation) = .{},
3737
38const AtomTable = std.AutoHashMapUnmanaged(Module.Decl.Index, Atom.Index);
38const AtomTable = std.AutoHashMapUnmanaged(InternPool.DeclIndex, Atom.Index);
3939
4040const Atom = struct {
4141 /// Offset into .debug_info pointing to the tag for this Decl, or
......@@ -555,7 +555,7 @@ pub const DeclState = struct {
555555 self: *DeclState,
556556 name: [:0]const u8,
557557 ty: Type,
558 owner_decl: Module.Decl.Index,
558 owner_decl: InternPool.DeclIndex,
559559 loc: DbgInfoLoc,
560560 ) error{OutOfMemory}!void {
561561 const dbg_info = &self.dbg_info;
......@@ -669,7 +669,7 @@ pub const DeclState = struct {
669669 self: *DeclState,
670670 name: [:0]const u8,
671671 ty: Type,
672 owner_decl: Module.Decl.Index,
672 owner_decl: InternPool.DeclIndex,
673673 is_ptr: bool,
674674 loc: DbgInfoLoc,
675675 ) error{OutOfMemory}!void {
......@@ -1073,7 +1073,7 @@ pub fn deinit(self: *Dwarf) void {
10731073
10741074/// Initializes Decl's state and its matching output buffers.
10751075/// Call this before `commitDeclState`.
1076pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !DeclState {
1076pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclIndex) !DeclState {
10771077 const tracy = trace(@src());
10781078 defer tracy.end();
10791079
......@@ -1191,7 +1191,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)
11911191pub fn commitDeclState(
11921192 self: *Dwarf,
11931193 mod: *Module,
1194 decl_index: Module.Decl.Index,
1194 decl_index: InternPool.DeclIndex,
11951195 sym_addr: u64,
11961196 sym_size: u64,
11971197 decl_state: *DeclState,
......@@ -1640,7 +1640,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons
16401640 }
16411641}
16421642
1643pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !void {
1643pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclIndex) !void {
16441644 const tracy = trace(@src());
16451645 defer tracy.end();
16461646
......@@ -1682,7 +1682,7 @@ pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: Module.Decl.
16821682 }
16831683}
16841684
1685pub fn freeDecl(self: *Dwarf, decl_index: Module.Decl.Index) void {
1685pub fn freeDecl(self: *Dwarf, decl_index: InternPool.DeclIndex) void {
16861686 const gpa = self.allocator;
16871687
16881688 // Free SrcFn atom
......@@ -2627,7 +2627,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {
26272627 }
26282628}
26292629
2630fn addDIFile(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !u28 {
2630fn addDIFile(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclIndex) !u28 {
26312631 const decl = mod.declPtr(decl_index);
26322632 const file_scope = decl.getFileScope(mod);
26332633 const gop = try self.di_files.getOrPut(self.allocator, file_scope);
......@@ -2771,7 +2771,7 @@ fn createAtom(self: *Dwarf, comptime kind: Kind) !Atom.Index {
27712771 return index;
27722772}
27732773
2774fn getOrCreateAtomForDecl(self: *Dwarf, comptime kind: Kind, decl_index: Module.Decl.Index) !Atom.Index {
2774fn getOrCreateAtomForDecl(self: *Dwarf, comptime kind: Kind, decl_index: InternPool.DeclIndex) !Atom.Index {
27752775 switch (kind) {
27762776 .src_fn => {
27772777 const gop = try self.src_fn_decls.getOrPut(self.allocator, decl_index);
src/link/Elf.zig+6-6
......@@ -400,7 +400,7 @@ pub fn deinit(self: *Elf) void {
400400 self.comdat_group_sections.deinit(gpa);
401401}
402402
403pub fn getDeclVAddr(self: *Elf, decl_index: Module.Decl.Index, reloc_info: link.File.RelocInfo) !u64 {
403pub fn getDeclVAddr(self: *Elf, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
404404 assert(self.llvm_object == null);
405405 return self.zigObjectPtr().?.getDeclVAddr(self, decl_index, reloc_info);
406406}
......@@ -3127,7 +3127,7 @@ fn writeElfHeader(self: *Elf) !void {
31273127 try self.base.file.?.pwriteAll(hdr_buf[0..index], 0);
31283128}
31293129
3130pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void {
3130pub fn freeDecl(self: *Elf, decl_index: InternPool.DeclIndex) void {
31313131 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
31323132 return self.zigObjectPtr().?.freeDecl(self, decl_index);
31333133}
......@@ -3143,7 +3143,7 @@ pub fn updateFunc(self: *Elf, mod: *Module, func_index: InternPool.Index, air: A
31433143pub fn updateDecl(
31443144 self: *Elf,
31453145 mod: *Module,
3146 decl_index: Module.Decl.Index,
3146 decl_index: InternPool.DeclIndex,
31473147) link.File.UpdateDeclError!void {
31483148 if (build_options.skip_non_native and builtin.object_format != .elf) {
31493149 @panic("Attempted to compile for object format that was disabled by build configuration");
......@@ -3152,7 +3152,7 @@ pub fn updateDecl(
31523152 return self.zigObjectPtr().?.updateDecl(self, mod, decl_index);
31533153}
31543154
3155pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module.Decl.Index) !u32 {
3155pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: InternPool.DeclIndex) !u32 {
31563156 return self.zigObjectPtr().?.lowerUnnamedConst(self, typed_value, decl_index);
31573157}
31583158
......@@ -3170,14 +3170,14 @@ pub fn updateExports(
31703170 return self.zigObjectPtr().?.updateExports(self, mod, exported, exports);
31713171}
31723172
3173pub fn updateDeclLineNumber(self: *Elf, mod: *Module, decl_index: Module.Decl.Index) !void {
3173pub fn updateDeclLineNumber(self: *Elf, mod: *Module, decl_index: InternPool.DeclIndex) !void {
31743174 if (self.llvm_object) |_| return;
31753175 return self.zigObjectPtr().?.updateDeclLineNumber(mod, decl_index);
31763176}
31773177
31783178pub fn deleteDeclExport(
31793179 self: *Elf,
3180 decl_index: Module.Decl.Index,
3180 decl_index: InternPool.DeclIndex,
31813181 name: InternPool.NullTerminatedString,
31823182) void {
31833183 if (self.llvm_object) |_| return;
src/link/Elf/ZigObject.zig+13-13
......@@ -618,7 +618,7 @@ pub fn codeAlloc(self: ZigObject, elf_file: *Elf, atom_index: Atom.Index) ![]u8
618618pub fn getDeclVAddr(
619619 self: *ZigObject,
620620 elf_file: *Elf,
621 decl_index: Module.Decl.Index,
621 decl_index: InternPool.DeclIndex,
622622 reloc_info: link.File.RelocInfo,
623623) !u64 {
624624 const this_sym_index = try self.getOrCreateMetadataForDecl(elf_file, decl_index);
......@@ -741,7 +741,7 @@ pub fn getOrCreateMetadataForLazySymbol(
741741 return symbol_index;
742742}
743743
744fn freeUnnamedConsts(self: *ZigObject, elf_file: *Elf, decl_index: Module.Decl.Index) void {
744fn freeUnnamedConsts(self: *ZigObject, elf_file: *Elf, decl_index: InternPool.DeclIndex) void {
745745 const unnamed_consts = self.unnamed_consts.getPtr(decl_index) orelse return;
746746 for (unnamed_consts.items) |sym_index| {
747747 self.freeDeclMetadata(elf_file, sym_index);
......@@ -759,7 +759,7 @@ fn freeDeclMetadata(self: *ZigObject, elf_file: *Elf, sym_index: Symbol.Index) v
759759 // TODO free GOT entry here
760760}
761761
762pub fn freeDecl(self: *ZigObject, elf_file: *Elf, decl_index: Module.Decl.Index) void {
762pub fn freeDecl(self: *ZigObject, elf_file: *Elf, decl_index: InternPool.DeclIndex) void {
763763 const mod = elf_file.base.options.module.?;
764764 const decl = mod.declPtr(decl_index);
765765
......@@ -781,7 +781,7 @@ pub fn freeDecl(self: *ZigObject, elf_file: *Elf, decl_index: Module.Decl.Index)
781781pub fn getOrCreateMetadataForDecl(
782782 self: *ZigObject,
783783 elf_file: *Elf,
784 decl_index: Module.Decl.Index,
784 decl_index: InternPool.DeclIndex,
785785) !Symbol.Index {
786786 const gop = try self.decls.getOrPut(elf_file.base.allocator, decl_index);
787787 if (!gop.found_existing) {
......@@ -857,7 +857,7 @@ fn getDeclShdrIndex(
857857fn updateDeclCode(
858858 self: *ZigObject,
859859 elf_file: *Elf,
860 decl_index: Module.Decl.Index,
860 decl_index: InternPool.DeclIndex,
861861 sym_index: Symbol.Index,
862862 shdr_index: u16,
863863 code: []const u8,
......@@ -956,7 +956,7 @@ fn updateDeclCode(
956956fn updateTlv(
957957 self: *ZigObject,
958958 elf_file: *Elf,
959 decl_index: Module.Decl.Index,
959 decl_index: InternPool.DeclIndex,
960960 sym_index: Symbol.Index,
961961 shndx: u16,
962962 code: []const u8,
......@@ -1083,7 +1083,7 @@ pub fn updateDecl(
10831083 self: *ZigObject,
10841084 elf_file: *Elf,
10851085 mod: *Module,
1086 decl_index: Module.Decl.Index,
1086 decl_index: InternPool.DeclIndex,
10871087) link.File.UpdateDeclError!void {
10881088 const tracy = trace(@src());
10891089 defer tracy.end();
......@@ -1249,7 +1249,7 @@ pub fn lowerUnnamedConst(
12491249 self: *ZigObject,
12501250 elf_file: *Elf,
12511251 typed_value: TypedValue,
1252 decl_index: Module.Decl.Index,
1252 decl_index: InternPool.DeclIndex,
12531253) !u32 {
12541254 const gpa = elf_file.base.allocator;
12551255 const mod = elf_file.base.options.module.?;
......@@ -1435,7 +1435,7 @@ pub fn updateExports(
14351435pub fn updateDeclLineNumber(
14361436 self: *ZigObject,
14371437 mod: *Module,
1438 decl_index: Module.Decl.Index,
1438 decl_index: InternPool.DeclIndex,
14391439) !void {
14401440 const tracy = trace(@src());
14411441 defer tracy.end();
......@@ -1453,7 +1453,7 @@ pub fn updateDeclLineNumber(
14531453pub fn deleteDeclExport(
14541454 self: *ZigObject,
14551455 elf_file: *Elf,
1456 decl_index: Module.Decl.Index,
1456 decl_index: InternPool.DeclIndex,
14571457 name: InternPool.NullTerminatedString,
14581458) void {
14591459 const metadata = self.decls.getPtr(decl_index) orelse return;
......@@ -1584,10 +1584,10 @@ const TlsVariable = struct {
15841584};
15851585
15861586const AtomList = std.ArrayListUnmanaged(Atom.Index);
1587const UnnamedConstTable = std.AutoHashMapUnmanaged(Module.Decl.Index, std.ArrayListUnmanaged(Symbol.Index));
1588const DeclTable = std.AutoHashMapUnmanaged(Module.Decl.Index, DeclMetadata);
1587const UnnamedConstTable = std.AutoHashMapUnmanaged(InternPool.DeclIndex, std.ArrayListUnmanaged(Symbol.Index));
1588const DeclTable = std.AutoHashMapUnmanaged(InternPool.DeclIndex, DeclMetadata);
15891589const AnonDeclTable = std.AutoHashMapUnmanaged(InternPool.Index, DeclMetadata);
1590const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, LazySymbolMetadata);
1590const LazySymbolTable = std.AutoArrayHashMapUnmanaged(InternPool.OptionalDeclIndex, LazySymbolMetadata);
15911591const TlsTable = std.AutoArrayHashMapUnmanaged(Atom.Index, TlsVariable);
15921592
15931593const assert = std.debug.assert;
src/link/MachO.zig+14-14
......@@ -2278,7 +2278,7 @@ pub fn updateFunc(self: *MachO, mod: *Module, func_index: InternPool.Index, air:
22782278 try self.updateExports(mod, .{ .decl_index = decl_index }, mod.getDeclExports(decl_index));
22792279}
22802280
2281pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Module.Decl.Index) !u32 {
2281pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: InternPool.DeclIndex) !u32 {
22822282 const gpa = self.base.allocator;
22832283 const mod = self.base.options.module.?;
22842284 const gop = try self.unnamed_const_atoms.getOrPut(gpa, decl_index);
......@@ -2358,7 +2358,7 @@ fn lowerConst(
23582358 return .{ .ok = atom_index };
23592359}
23602360
2361pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !void {
2361pub fn updateDecl(self: *MachO, mod: *Module, decl_index: InternPool.DeclIndex) !void {
23622362 if (build_options.skip_non_native and builtin.object_format != .macho) {
23632363 @panic("Attempted to compile for object format that was disabled by build configuration");
23642364 }
......@@ -2544,7 +2544,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol) !Atom.In
25442544 return atom;
25452545}
25462546
2547fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.Decl.Index) !void {
2547fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: InternPool.DeclIndex) !void {
25482548 const mod = self.base.options.module.?;
25492549 // Lowering a TLV on macOS involves two stages:
25502550 // 1. first we lower the initializer into appopriate section (__thread_data or __thread_bss)
......@@ -2639,7 +2639,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D
26392639 self.markRelocsDirtyByTarget(init_atom_sym_loc);
26402640}
26412641
2642pub fn getOrCreateAtomForDecl(self: *MachO, decl_index: Module.Decl.Index) !Atom.Index {
2642pub fn getOrCreateAtomForDecl(self: *MachO, decl_index: InternPool.DeclIndex) !Atom.Index {
26432643 const gop = try self.decls.getOrPut(self.base.allocator, decl_index);
26442644 if (!gop.found_existing) {
26452645 const sym_index = try self.allocateSymbol();
......@@ -2654,7 +2654,7 @@ pub fn getOrCreateAtomForDecl(self: *MachO, decl_index: Module.Decl.Index) !Atom
26542654 return gop.value_ptr.atom;
26552655}
26562656
2657fn getDeclOutputSection(self: *MachO, decl_index: Module.Decl.Index) u8 {
2657fn getDeclOutputSection(self: *MachO, decl_index: InternPool.DeclIndex) u8 {
26582658 const decl = self.base.options.module.?.declPtr(decl_index);
26592659 const ty = decl.ty;
26602660 const val = decl.val;
......@@ -2693,7 +2693,7 @@ fn getDeclOutputSection(self: *MachO, decl_index: Module.Decl.Index) u8 {
26932693 return sect_id;
26942694}
26952695
2696fn updateDeclCode(self: *MachO, decl_index: Module.Decl.Index, code: []u8) !u64 {
2696fn updateDeclCode(self: *MachO, decl_index: InternPool.DeclIndex, code: []u8) !u64 {
26972697 const gpa = self.base.allocator;
26982698 const mod = self.base.options.module.?;
26992699 const decl = mod.declPtr(decl_index);
......@@ -2764,7 +2764,7 @@ fn updateDeclCode(self: *MachO, decl_index: Module.Decl.Index, code: []u8) !u64
27642764 return atom.getSymbol(self).n_value;
27652765}
27662766
2767pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl_index: Module.Decl.Index) !void {
2767pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl_index: InternPool.DeclIndex) !void {
27682768 if (self.d_sym) |*d_sym| {
27692769 try d_sym.dwarf.updateDeclLineNumber(module, decl_index);
27702770 }
......@@ -2906,7 +2906,7 @@ pub fn updateExports(
29062906
29072907pub fn deleteDeclExport(
29082908 self: *MachO,
2909 decl_index: Module.Decl.Index,
2909 decl_index: InternPool.DeclIndex,
29102910 name: InternPool.NullTerminatedString,
29112911) Allocator.Error!void {
29122912 if (self.llvm_object) |_| return;
......@@ -2940,7 +2940,7 @@ pub fn deleteDeclExport(
29402940 sym_index.* = 0;
29412941}
29422942
2943fn freeUnnamedConsts(self: *MachO, decl_index: Module.Decl.Index) void {
2943fn freeUnnamedConsts(self: *MachO, decl_index: InternPool.DeclIndex) void {
29442944 const gpa = self.base.allocator;
29452945 const unnamed_consts = self.unnamed_const_atoms.getPtr(decl_index) orelse return;
29462946 for (unnamed_consts.items) |atom| {
......@@ -2949,7 +2949,7 @@ fn freeUnnamedConsts(self: *MachO, decl_index: Module.Decl.Index) void {
29492949 unnamed_consts.clearAndFree(gpa);
29502950}
29512951
2952pub fn freeDecl(self: *MachO, decl_index: Module.Decl.Index) void {
2952pub fn freeDecl(self: *MachO, decl_index: InternPool.DeclIndex) void {
29532953 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
29542954 const mod = self.base.options.module.?;
29552955 const decl = mod.declPtr(decl_index);
......@@ -2968,7 +2968,7 @@ pub fn freeDecl(self: *MachO, decl_index: Module.Decl.Index) void {
29682968 }
29692969}
29702970
2971pub fn getDeclVAddr(self: *MachO, decl_index: Module.Decl.Index, reloc_info: File.RelocInfo) !u64 {
2971pub fn getDeclVAddr(self: *MachO, decl_index: InternPool.DeclIndex, reloc_info: File.RelocInfo) !u64 {
29722972 assert(self.llvm_object == null);
29732973
29742974 const this_atom_index = try self.getOrCreateAtomForDecl(decl_index);
......@@ -5667,7 +5667,7 @@ const is_hot_update_compatible = switch (builtin.target.os.tag) {
56675667 else => false,
56685668};
56695669
5670const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, LazySymbolMetadata);
5670const LazySymbolTable = std.AutoArrayHashMapUnmanaged(InternPool.OptionalDeclIndex, LazySymbolMetadata);
56715671
56725672const LazySymbolMetadata = struct {
56735673 const State = enum { unused, pending_flush, flushed };
......@@ -5701,10 +5701,10 @@ const DeclMetadata = struct {
57015701 }
57025702};
57035703
5704const DeclTable = std.AutoArrayHashMapUnmanaged(Module.Decl.Index, DeclMetadata);
5704const DeclTable = std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, DeclMetadata);
57055705const AnonDeclTable = std.AutoHashMapUnmanaged(InternPool.Index, DeclMetadata);
57065706const BindingTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(Atom.Binding));
5707const UnnamedConstTable = std.AutoArrayHashMapUnmanaged(Module.Decl.Index, std.ArrayListUnmanaged(Atom.Index));
5707const UnnamedConstTable = std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, std.ArrayListUnmanaged(Atom.Index));
57085708const RebaseTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(u32));
57095709const RelocationTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(Relocation));
57105710const ActionTable = std.AutoHashMapUnmanaged(u32, RelocFlags);
src/link/NvPtx.zig+2-2
......@@ -70,7 +70,7 @@ pub fn updateFunc(self: *NvPtx, module: *Module, func_index: InternPool.Index, a
7070 try self.llvm_object.updateFunc(module, func_index, air, liveness);
7171}
7272
73pub fn updateDecl(self: *NvPtx, module: *Module, decl_index: Module.Decl.Index) !void {
73pub fn updateDecl(self: *NvPtx, module: *Module, decl_index: InternPool.DeclIndex) !void {
7474 return self.llvm_object.updateDecl(module, decl_index);
7575}
7676
......@@ -86,7 +86,7 @@ pub fn updateExports(
8686 return self.llvm_object.updateExports(module, exported, exports);
8787}
8888
89pub fn freeDecl(self: *NvPtx, decl_index: Module.Decl.Index) void {
89pub fn freeDecl(self: *NvPtx, decl_index: InternPool.DeclIndex) void {
9090 return self.llvm_object.freeDecl(decl_index);
9191}
9292
src/link/Plan9.zig+16-16
......@@ -56,10 +56,10 @@ path_arena: std.heap.ArenaAllocator,
5656/// If we group the decls by file, it makes it really easy to do this (put the symbol in the correct place)
5757fn_decl_table: std.AutoArrayHashMapUnmanaged(
5858 *Module.File,
59 struct { sym_index: u32, functions: std.AutoArrayHashMapUnmanaged(Module.Decl.Index, FnDeclOutput) = .{} },
59 struct { sym_index: u32, functions: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, FnDeclOutput) = .{} },
6060) = .{},
6161/// the code is modified when relocated, so that is why it is mutable
62data_decl_table: std.AutoArrayHashMapUnmanaged(Module.Decl.Index, []u8) = .{},
62data_decl_table: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, []u8) = .{},
6363
6464/// Table of unnamed constants associated with a parent `Decl`.
6565/// We store them here so that we can free the constants whenever the `Decl`
......@@ -102,7 +102,7 @@ got_index_free_list: std.ArrayListUnmanaged(usize) = .{},
102102syms_index_free_list: std.ArrayListUnmanaged(usize) = .{},
103103
104104atoms: std.ArrayListUnmanaged(Atom) = .{},
105decls: std.AutoHashMapUnmanaged(Module.Decl.Index, DeclMetadata) = .{},
105decls: std.AutoHashMapUnmanaged(InternPool.DeclIndex, DeclMetadata) = .{},
106106
107107/// Indices of the three "special" symbols into atoms
108108etext_edata_end_atom_indices: [3]?Atom.Index = .{ null, null, null },
......@@ -129,9 +129,9 @@ const Bases = struct {
129129 data: u64,
130130};
131131
132const UnnamedConstTable = std.AutoHashMapUnmanaged(Module.Decl.Index, std.ArrayListUnmanaged(Atom.Index));
132const UnnamedConstTable = std.AutoHashMapUnmanaged(InternPool.DeclIndex, std.ArrayListUnmanaged(Atom.Index));
133133
134const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, LazySymbolMetadata);
134const LazySymbolTable = std.AutoArrayHashMapUnmanaged(InternPool.OptionalDeclIndex, LazySymbolMetadata);
135135
136136const LazySymbolMetadata = struct {
137137 const State = enum { unused, pending_flush, flushed };
......@@ -168,7 +168,7 @@ pub const Atom = struct {
168168 code_ptr: ?[*]u8,
169169 other: union {
170170 code_len: usize,
171 decl_index: Module.Decl.Index,
171 decl_index: InternPool.DeclIndex,
172172 },
173173 fn fromSlice(slice: []u8) CodePtr {
174174 return .{ .code_ptr = slice.ptr, .other = .{ .code_len = slice.len } };
......@@ -322,7 +322,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Plan9 {
322322 return self;
323323}
324324
325fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void {
325fn putFn(self: *Plan9, decl_index: InternPool.DeclIndex, out: FnDeclOutput) !void {
326326 const gpa = self.base.allocator;
327327 const mod = self.base.options.module.?;
328328 const decl = mod.declPtr(decl_index);
......@@ -447,7 +447,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air:
447447 return self.updateFinish(decl_index);
448448}
449449
450pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.Index) !u32 {
450pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: InternPool.DeclIndex) !u32 {
451451 _ = try self.seeDecl(decl_index);
452452 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
453453 defer code_buffer.deinit();
......@@ -508,7 +508,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I
508508 return new_atom_idx;
509509}
510510
511pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !void {
511pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex) !void {
512512 const decl = mod.declPtr(decl_index);
513513
514514 if (decl.isExtern(mod)) {
......@@ -544,7 +544,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !vo
544544 return self.updateFinish(decl_index);
545545}
546546/// called at the end of update{Decl,Func}
547fn updateFinish(self: *Plan9, decl_index: Module.Decl.Index) !void {
547fn updateFinish(self: *Plan9, decl_index: InternPool.DeclIndex) !void {
548548 const mod = self.base.options.module.?;
549549 const decl = mod.declPtr(decl_index);
550550 const is_fn = (decl.ty.zigTypeTag(mod) == .Fn);
......@@ -982,7 +982,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
982982fn addDeclExports(
983983 self: *Plan9,
984984 mod: *Module,
985 decl_index: Module.Decl.Index,
985 decl_index: InternPool.DeclIndex,
986986 exports: []const *Module.Export,
987987) !void {
988988 const metadata = self.decls.getPtr(decl_index).?;
......@@ -1017,7 +1017,7 @@ fn addDeclExports(
10171017 }
10181018}
10191019
1020pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void {
1020pub fn freeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) void {
10211021 // TODO audit the lifetimes of decls table entries. It's possible to get
10221022 // freeDecl without any updateDecl in between.
10231023 // However that is planned to change, see the TODO comment in Module.zig
......@@ -1063,7 +1063,7 @@ pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void {
10631063 assert(self.relocs.remove(atom_index));
10641064 }
10651065}
1066fn freeUnnamedConsts(self: *Plan9, decl_index: Module.Decl.Index) void {
1066fn freeUnnamedConsts(self: *Plan9, decl_index: InternPool.DeclIndex) void {
10671067 const unnamed_consts = self.unnamed_const_atoms.getPtr(decl_index) orelse return;
10681068 for (unnamed_consts.items) |atom_idx| {
10691069 const atom = self.getAtom(atom_idx);
......@@ -1088,7 +1088,7 @@ fn createAtom(self: *Plan9) !Atom.Index {
10881088 return index;
10891089}
10901090
1091pub fn seeDecl(self: *Plan9, decl_index: Module.Decl.Index) !Atom.Index {
1091pub fn seeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) !Atom.Index {
10921092 const gop = try self.decls.getOrPut(self.base.allocator, decl_index);
10931093 if (!gop.found_existing) {
10941094 const index = try self.createAtom();
......@@ -1428,7 +1428,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
14281428}
14291429
14301430/// Must be called only after a successful call to `updateDecl`.
1431pub fn updateDeclLineNumber(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !void {
1431pub fn updateDeclLineNumber(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex) !void {
14321432 _ = self;
14331433 _ = mod;
14341434 _ = decl_index;
......@@ -1436,7 +1436,7 @@ pub fn updateDeclLineNumber(self: *Plan9, mod: *Module, decl_index: Module.Decl.
14361436
14371437pub fn getDeclVAddr(
14381438 self: *Plan9,
1439 decl_index: Module.Decl.Index,
1439 decl_index: InternPool.DeclIndex,
14401440 reloc_info: link.File.RelocInfo,
14411441) !u64 {
14421442 const mod = self.base.options.module.?;
src/link/SpirV.zig+2-2
......@@ -109,7 +109,7 @@ pub fn updateFunc(self: *SpirV, module: *Module, func_index: InternPool.Index, a
109109 try self.object.updateFunc(module, func_index, air, liveness);
110110}
111111
112pub fn updateDecl(self: *SpirV, module: *Module, decl_index: Module.Decl.Index) !void {
112pub fn updateDecl(self: *SpirV, module: *Module, decl_index: InternPool.DeclIndex) !void {
113113 if (build_options.skip_non_native) {
114114 @panic("Attempted to compile for architecture that was disabled by build configuration");
115115 }
......@@ -144,7 +144,7 @@ pub fn updateExports(
144144 // TODO: Export regular functions, variables, etc using Linkage attributes.
145145}
146146
147pub fn freeDecl(self: *SpirV, decl_index: Module.Decl.Index) void {
147pub fn freeDecl(self: *SpirV, decl_index: InternPool.DeclIndex) void {
148148 _ = self;
149149 _ = decl_index;
150150}
src/link/Wasm.zig+11-11
......@@ -48,7 +48,7 @@ llvm_object: ?*LlvmObject = null,
4848host_name: []const u8 = "env",
4949/// List of all `Decl` that are currently alive.
5050/// Each index maps to the corresponding `Atom.Index`.
51decls: std.AutoHashMapUnmanaged(Module.Decl.Index, Atom.Index) = .{},
51decls: std.AutoHashMapUnmanaged(InternPool.DeclIndex, Atom.Index) = .{},
5252/// Mapping between an `Atom` and its type index representing the Wasm
5353/// type of the function signature.
5454atom_types: std.AutoHashMapUnmanaged(Atom.Index, u32) = .{},
......@@ -598,10 +598,10 @@ fn parseObjectFile(wasm: *Wasm, path: []const u8) !bool {
598598 return true;
599599}
600600
601/// For a given `Module.Decl.Index` returns its corresponding `Atom.Index`.
601/// For a given `InternPool.DeclIndex` returns its corresponding `Atom.Index`.
602602/// When the index was not found, a new `Atom` will be created, and its index will be returned.
603603/// The newly created Atom is empty with default fields as specified by `Atom.empty`.
604pub fn getOrCreateAtomForDecl(wasm: *Wasm, decl_index: Module.Decl.Index) !Atom.Index {
604pub fn getOrCreateAtomForDecl(wasm: *Wasm, decl_index: InternPool.DeclIndex) !Atom.Index {
605605 const gop = try wasm.decls.getOrPut(wasm.base.allocator, decl_index);
606606 if (!gop.found_existing) {
607607 const atom_index = try wasm.createAtom();
......@@ -1427,7 +1427,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func_index: InternPool.Index, air:
14271427
14281428// Generate code for the Decl, storing it in memory to be later written to
14291429// the file on flush().
1430pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !void {
1430pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: InternPool.DeclIndex) !void {
14311431 if (build_options.skip_non_native and builtin.object_format != .wasm) {
14321432 @panic("Attempted to compile for object format that was disabled by build configuration");
14331433 }
......@@ -1479,7 +1479,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
14791479 return wasm.finishUpdateDecl(decl_index, code, .data);
14801480}
14811481
1482pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !void {
1482pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Module, decl_index: InternPool.DeclIndex) !void {
14831483 if (wasm.llvm_object) |_| return;
14841484 if (wasm.dwarf) |*dw| {
14851485 const tracy = trace(@src());
......@@ -1493,7 +1493,7 @@ pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.I
14931493 }
14941494}
14951495
1496fn finishUpdateDecl(wasm: *Wasm, decl_index: Module.Decl.Index, code: []const u8, symbol_tag: Symbol.Tag) !void {
1496fn finishUpdateDecl(wasm: *Wasm, decl_index: InternPool.DeclIndex, code: []const u8, symbol_tag: Symbol.Tag) !void {
14971497 const mod = wasm.base.options.module.?;
14981498 const decl = mod.declPtr(decl_index);
14991499 const atom_index = wasm.decls.get(decl_index).?;
......@@ -1556,7 +1556,7 @@ fn getFunctionSignature(wasm: *const Wasm, loc: SymbolLoc) std.wasm.Type {
15561556/// Lowers a constant typed value to a local symbol and atom.
15571557/// Returns the symbol index of the local
15581558/// The given `decl` is the parent decl whom owns the constant.
1559pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: Module.Decl.Index) !u32 {
1559pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: InternPool.DeclIndex) !u32 {
15601560 const mod = wasm.base.options.module.?;
15611561 assert(tv.ty.zigTypeTag(mod) != .Fn); // cannot create local symbols for functions
15621562 const decl = mod.declPtr(decl_index);
......@@ -1672,7 +1672,7 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !u3
16721672/// Returns the given pointer address
16731673pub fn getDeclVAddr(
16741674 wasm: *Wasm,
1675 decl_index: Module.Decl.Index,
1675 decl_index: InternPool.DeclIndex,
16761676 reloc_info: link.File.RelocInfo,
16771677) !u64 {
16781678 const mod = wasm.base.options.module.?;
......@@ -1780,7 +1780,7 @@ pub fn getAnonDeclVAddr(wasm: *Wasm, decl_val: InternPool.Index, reloc_info: lin
17801780 return target_symbol_index;
17811781}
17821782
1783pub fn deleteDeclExport(wasm: *Wasm, decl_index: Module.Decl.Index) void {
1783pub fn deleteDeclExport(wasm: *Wasm, decl_index: InternPool.DeclIndex) void {
17841784 if (wasm.llvm_object) |_| return;
17851785 const atom_index = wasm.decls.get(decl_index) orelse return;
17861786 const sym_index = wasm.getAtom(atom_index).sym_index;
......@@ -1923,7 +1923,7 @@ pub fn updateExports(
19231923 }
19241924}
19251925
1926pub fn freeDecl(wasm: *Wasm, decl_index: Module.Decl.Index) void {
1926pub fn freeDecl(wasm: *Wasm, decl_index: InternPool.DeclIndex) void {
19271927 if (wasm.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
19281928 const mod = wasm.base.options.module.?;
19291929 const decl = mod.declPtr(decl_index);
......@@ -5012,7 +5012,7 @@ pub fn putOrGetFuncType(wasm: *Wasm, func_type: std.wasm.Type) !u32 {
50125012/// For the given `decl_index`, stores the corresponding type representing the function signature.
50135013/// Asserts declaration has an associated `Atom`.
50145014/// Returns the index into the list of types.
5015pub fn storeDeclType(wasm: *Wasm, decl_index: Module.Decl.Index, func_type: std.wasm.Type) !u32 {
5015pub fn storeDeclType(wasm: *Wasm, decl_index: InternPool.DeclIndex, func_type: std.wasm.Type) !u32 {
50165016 const atom_index = wasm.decls.get(decl_index).?;
50175017 const index = try wasm.putOrGetFuncType(func_type);
50185018 try wasm.atom_types.put(wasm.base.allocator, atom_index, index);
src/type.zig+3-3
......@@ -2778,7 +2778,7 @@ pub const Type = struct {
27782778 }
27792779
27802780 /// Returns null if the type has no namespace.
2781 pub fn getNamespaceIndex(ty: Type, mod: *Module) Module.Namespace.OptionalIndex {
2781 pub fn getNamespaceIndex(ty: Type, mod: *Module) InternPool.OptionalNamespaceIndex {
27822782 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
27832783 .opaque_type => |opaque_type| opaque_type.namespace.toOptional(),
27842784 .struct_type => |struct_type| struct_type.namespace,
......@@ -3123,11 +3123,11 @@ pub const Type = struct {
31233123 };
31243124 }
31253125
3126 pub fn getOwnerDecl(ty: Type, mod: *Module) Module.Decl.Index {
3126 pub fn getOwnerDecl(ty: Type, mod: *Module) InternPool.DeclIndex {
31273127 return ty.getOwnerDeclOrNull(mod) orelse unreachable;
31283128 }
31293129
3130 pub fn getOwnerDeclOrNull(ty: Type, mod: *Module) ?Module.Decl.Index {
3130 pub fn getOwnerDeclOrNull(ty: Type, mod: *Module) ?InternPool.DeclIndex {
31313131 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
31323132 .struct_type => |struct_type| struct_type.decl.unwrap(),
31333133 .union_type => |union_type| union_type.decl,
src/value.zig+1-1
......@@ -1556,7 +1556,7 @@ pub const Value = struct {
15561556 /// Gets the decl referenced by this pointer. If the pointer does not point
15571557 /// to a decl, or if it points to some part of a decl (like field_ptr or element_ptr),
15581558 /// this function returns null.
1559 pub fn pointerDecl(val: Value, mod: *Module) ?Module.Decl.Index {
1559 pub fn pointerDecl(val: Value, mod: *Module) ?InternPool.DeclIndex {
15601560 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
15611561 .variable => |variable| variable.decl,
15621562 .extern_func => |extern_func| extern_func.decl,