Commit 2549de80b2

Meghan Denny <hello@nektro.net>
2023-11-26 00:02:32
move Module.Decl.Index and Module.Namespace.Index to InternPool
1 parent 7103088
src/arch/aarch64/CodeGen.zig
@@ -52,7 +52,7 @@ bin_file: *link.File,
 debug_output: DebugInfoOutput,
 target: *const std.Target,
 func_index: InternPool.Index,
-owner_decl: Module.Decl.Index,
+owner_decl: InternPool.DeclIndex,
 err_msg: ?*ErrorMsg,
 args: []MCValue,
 ret_mcv: MCValue,
src/arch/wasm/CodeGen.zig
@@ -643,7 +643,7 @@ const CodeGen = @This();
 /// Reference to the function declaration the code
 /// section belongs to
 decl: *Decl,
-decl_index: Decl.Index,
+decl_index: InternPool.DeclIndex,
 /// Current block depth. Used to calculate the relative difference between a break
 /// and block
 block_depth: u32 = 0,
@@ -2194,7 +2194,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
     const fn_info = mod.typeToFunc(fn_ty).?;
     const first_param_sret = firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), mod);
 
-    const callee: ?Decl.Index = blk: {
+    const callee: ?InternPool.DeclIndex = blk: {
         const func_val = (try func.air.value(pl_op.operand, mod)) orelse break :blk null;
 
         if (func_val.getFunction(mod)) |function| {
@@ -3131,7 +3131,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
     }
 }
 
-fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: Module.Decl.Index, offset: u32) InnerError!WValue {
+fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: InternPool.DeclIndex, offset: u32) InnerError!WValue {
     const mod = func.bin_file.base.options.module.?;
     const decl = mod.declPtr(decl_index);
     try mod.markDeclAlive(decl);
@@ -3171,7 +3171,7 @@ fn lowerAnonDeclRef(
     } else return WValue{ .memory_offset = .{ .pointer = target_sym_index, .offset = offset } };
 }
 
-fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: Module.Decl.Index, offset: u32) InnerError!WValue {
+fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: InternPool.DeclIndex, offset: u32) InnerError!WValue {
     const mod = func.bin_file.base.options.module.?;
     if (tv.ty.isSlice(mod)) {
         return WValue{ .memory = try func.bin_file.lowerUnnamedConst(tv, decl_index) };
src/arch/wasm/Emit.zig
@@ -6,6 +6,7 @@ const std = @import("std");
 const Mir = @import("Mir.zig");
 const link = @import("../../link.zig");
 const Module = @import("../../Module.zig");
+const InternPool = @import("../../InternPool.zig");
 const codegen = @import("../../codegen.zig");
 const leb128 = std.leb;
 
@@ -21,7 +22,7 @@ code: *std.ArrayList(u8),
 /// List of allocated locals.
 locals: []const u8,
 /// The declaration that code is being generated for.
-decl_index: Module.Decl.Index,
+decl_index: InternPool.DeclIndex,
 
 // Debug information
 /// Holds the debug information for this emission
src/arch/x86_64/CodeGen.zig
@@ -121,7 +121,7 @@ const Owner = union(enum) {
     func_index: InternPool.Index,
     lazy_sym: link.File.LazySymbol,
 
-    fn getDecl(owner: Owner, mod: *Module) Module.Decl.Index {
+    fn getDecl(owner: Owner, mod: *Module) InternPool.DeclIndex {
         return switch (owner) {
             .func_index => |func_index| mod.funcOwnerDeclIndex(func_index),
             .lazy_sym => |lazy_sym| lazy_sym.ty.getOwnerDecl(mod),
@@ -1048,7 +1048,7 @@ pub fn generateLazy(
 
 const FormatDeclData = struct {
     mod: *Module,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
 };
 fn formatDecl(
     data: FormatDeclData,
@@ -1058,7 +1058,7 @@ fn formatDecl(
 ) @TypeOf(writer).Error!void {
     try data.mod.declPtr(data.decl_index).renderFullyQualifiedName(data.mod, writer);
 }
-fn fmtDecl(self: *Self, decl_index: Module.Decl.Index) std.fmt.Formatter(formatDecl) {
+fn fmtDecl(self: *Self, decl_index: InternPool.DeclIndex) std.fmt.Formatter(formatDecl) {
     return .{ .data = .{
         .mod = self.bin_file.options.module.?,
         .decl_index = decl_index,
src/codegen/c/type.zig
@@ -7,6 +7,7 @@ const Target = std.Target;
 
 const Alignment = @import("../../InternPool.zig").Alignment;
 const Module = @import("../../Module.zig");
+const InternPool = @import("../../InternPool.zig");
 const Type = @import("../../type.zig").Type;
 
 pub const CType = extern union {
@@ -238,7 +239,7 @@ pub const CType = extern union {
 
         pub const FwdDecl = struct {
             base: Payload,
-            data: Module.Decl.Index,
+            data: InternPool.DeclIndex,
         };
 
         pub const Fields = struct {
@@ -257,7 +258,7 @@ pub const CType = extern union {
             base: Payload,
             data: struct {
                 fields: Fields.Data,
-                owner_decl: Module.Decl.Index,
+                owner_decl: InternPool.DeclIndex,
                 id: u32,
             },
         };
src/codegen/c.zig
@@ -39,8 +39,8 @@ pub const CValue = union(enum) {
     /// Index into a tuple's fields
     field: usize,
     /// By-value
-    decl: Decl.Index,
-    decl_ref: Decl.Index,
+    decl: InternPool.DeclIndex,
+    decl_ref: InternPool.DeclIndex,
     /// An undefined value (cannot be dereferenced)
     undef: Type,
     /// Render the slice as an identifier (using fmtIdent)
@@ -57,9 +57,9 @@ const BlockData = struct {
 pub const CValueMap = std.AutoHashMap(Air.Inst.Ref, CValue);
 
 pub const LazyFnKey = union(enum) {
-    tag_name: Decl.Index,
-    never_tail: Decl.Index,
-    never_inline: Decl.Index,
+    tag_name: InternPool.DeclIndex,
+    never_tail: InternPool.DeclIndex,
+    never_inline: InternPool.DeclIndex,
 };
 pub const LazyFnValue = struct {
     fn_name: []const u8,
@@ -534,7 +534,7 @@ pub const DeclGen = struct {
     aligned_anon_decls: std.AutoArrayHashMapUnmanaged(InternPool.Index, Alignment),
 
     pub const Pass = union(enum) {
-        decl: Decl.Index,
+        decl: InternPool.DeclIndex,
         anon: InternPool.Index,
         flush,
     };
@@ -624,7 +624,7 @@ pub const DeclGen = struct {
         writer: anytype,
         ty: Type,
         val: Value,
-        decl_index: Decl.Index,
+        decl_index: InternPool.DeclIndex,
         location: ValueRenderLocation,
     ) error{ OutOfMemory, AnalysisFail }!void {
         const mod = dg.module;
@@ -1585,7 +1585,7 @@ pub const DeclGen = struct {
     fn renderFunctionSignature(
         dg: *DeclGen,
         w: anytype,
-        fn_decl_index: Decl.Index,
+        fn_decl_index: InternPool.DeclIndex,
         kind: CType.Kind,
         name: union(enum) {
             export_index: u32,
@@ -1926,7 +1926,7 @@ pub const DeclGen = struct {
         try dg.writeCValue(writer, member);
     }
 
-    fn renderFwdDecl(dg: *DeclGen, decl_index: Decl.Index, variable: InternPool.Key.Variable) !void {
+    fn renderFwdDecl(dg: *DeclGen, decl_index: InternPool.DeclIndex, variable: InternPool.Key.Variable) !void {
         const decl = dg.module.declPtr(decl_index);
         const fwd = dg.fwd_decl.writer();
         const is_global = dg.declIsGlobal(.{ .ty = decl.ty, .val = decl.val }) or variable.is_extern;
@@ -1948,7 +1948,7 @@ pub const DeclGen = struct {
         try fwd.writeAll(";\n");
     }
 
-    fn renderDeclName(dg: *DeclGen, writer: anytype, decl_index: Decl.Index, export_index: u32) !void {
+    fn renderDeclName(dg: *DeclGen, writer: anytype, decl_index: InternPool.DeclIndex, export_index: u32) !void {
         const mod = dg.module;
         const decl = mod.declPtr(decl_index);
         try mod.markDeclAlive(decl);
src/codegen/llvm.zig
@@ -809,11 +809,11 @@ pub const Object = struct {
     ///   version of the name and incorrectly get function not found in the llvm module.
     /// * it works for functions not all globals.
     /// Therefore, this table keeps track of the mapping.
-    decl_map: std.AutoHashMapUnmanaged(Module.Decl.Index, Builder.Global.Index),
+    decl_map: std.AutoHashMapUnmanaged(InternPool.DeclIndex, Builder.Global.Index),
     /// Same deal as `decl_map` but for anonymous declarations, which are always global constants.
     anon_decl_map: std.AutoHashMapUnmanaged(InternPool.Index, Builder.Global.Index),
     /// Serves the same purpose as `decl_map` but only used for the `is_named_enum_value` instruction.
-    named_enum_map: std.AutoHashMapUnmanaged(Module.Decl.Index, Builder.Function.Index),
+    named_enum_map: std.AutoHashMapUnmanaged(InternPool.DeclIndex, Builder.Function.Index),
     /// Maps Zig types to LLVM types. The table memory is backed by the GPA of
     /// the compiler.
     /// TODO when InternPool garbage collection is implemented, this map needs
@@ -827,7 +827,7 @@ pub const Object = struct {
     /// This map is usually very close to empty. It tracks only the cases when a
     /// second extern Decl could not be emitted with the correct name due to a
     /// name collision.
-    extern_collisions: std.AutoArrayHashMapUnmanaged(Module.Decl.Index, void),
+    extern_collisions: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, void),
 
     /// Memoizes a null `?usize` value.
     null_opt_usize: Builder.Constant,
@@ -1660,7 +1660,7 @@ pub const Object = struct {
         try o.updateExports(mod, .{ .decl_index = decl_index }, mod.getDeclExports(decl_index));
     }
 
-    pub fn updateDecl(self: *Object, module: *Module, decl_index: Module.Decl.Index) !void {
+    pub fn updateDecl(self: *Object, module: *Module, decl_index: InternPool.DeclIndex) !void {
         const decl = module.declPtr(decl_index);
         var dg: DeclGen = .{
             .object = self,
@@ -1893,7 +1893,7 @@ pub const Object = struct {
         }
     }
 
-    pub fn freeDecl(self: *Object, decl_index: Module.Decl.Index) void {
+    pub fn freeDecl(self: *Object, decl_index: InternPool.DeclIndex) void {
         const global = self.decl_map.get(decl_index) orelse return;
         global.delete(&self.builder);
     }
@@ -2860,7 +2860,7 @@ pub const Object = struct {
         }
     }
 
-    fn namespaceToDebugScope(o: *Object, namespace_index: Module.Namespace.Index) !*llvm.DIScope {
+    fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !*llvm.DIScope {
         const mod = o.module;
         const namespace = mod.namespacePtr(namespace_index);
         if (namespace.parent == .none) {
@@ -2874,7 +2874,7 @@ pub const Object = struct {
     /// This is to be used instead of void for debug info types, to avoid tripping
     /// Assertion `!isa<DIType>(Scope) && "shouldn't make a namespace scope for a type"'
     /// when targeting CodeView (Windows).
-    fn makeEmptyNamespaceDIType(o: *Object, decl_index: Module.Decl.Index) !*llvm.DIType {
+    fn makeEmptyNamespaceDIType(o: *Object, decl_index: InternPool.DeclIndex) !*llvm.DIType {
         const mod = o.module;
         const decl = mod.declPtr(decl_index);
         const fields: [0]*llvm.DIType = .{};
@@ -2932,7 +2932,7 @@ pub const Object = struct {
     /// completed, so if any attributes rely on that, they must be done in updateFunc, not here.
     fn resolveLlvmFunction(
         o: *Object,
-        decl_index: Module.Decl.Index,
+        decl_index: InternPool.DeclIndex,
     ) Allocator.Error!Builder.Function.Index {
         const mod = o.module;
         const ip = &mod.intern_pool;
@@ -3152,7 +3152,7 @@ pub const Object = struct {
 
     fn resolveGlobalDecl(
         o: *Object,
-        decl_index: Module.Decl.Index,
+        decl_index: InternPool.DeclIndex,
     ) Allocator.Error!Builder.Variable.Index {
         const gop = try o.decl_map.getOrPut(o.gpa, decl_index);
         if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable;
@@ -4330,7 +4330,7 @@ pub const Object = struct {
         return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(mod).bits), bigint);
     }
 
-    fn lowerParentPtrDecl(o: *Object, decl_index: Module.Decl.Index) Allocator.Error!Builder.Constant {
+    fn lowerParentPtrDecl(o: *Object, decl_index: InternPool.DeclIndex) Allocator.Error!Builder.Constant {
         const mod = o.module;
         const decl = mod.declPtr(decl_index);
         try mod.markDeclAlive(decl);
@@ -4505,7 +4505,7 @@ pub const Object = struct {
         } else .unneeded, llvm_val, try o.lowerType(ptr_ty));
     }
 
-    fn lowerDeclRefValue(o: *Object, ty: Type, decl_index: Module.Decl.Index) Allocator.Error!Builder.Constant {
+    fn lowerDeclRefValue(o: *Object, ty: Type, decl_index: InternPool.DeclIndex) Allocator.Error!Builder.Constant {
         const mod = o.module;
 
         // In the case of something like:
@@ -4653,7 +4653,7 @@ pub const Object = struct {
 pub const DeclGen = struct {
     object: *Object,
     decl: *Module.Decl,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     err_msg: ?*Module.ErrorMsg,
 
     fn todo(dg: *DeclGen, comptime format: []const u8, args: anytype) Error {
src/codegen/spirv.zig
@@ -156,7 +156,7 @@ pub const Object = struct {
 
     /// The Zig module that this object file is generated for.
     /// A map of Zig decl indices to SPIR-V decl indices.
-    decl_link: std.AutoHashMapUnmanaged(Decl.Index, SpvModule.Decl.Index) = .{},
+    decl_link: std.AutoHashMapUnmanaged(InternPool.DeclIndex, SpvModule.Decl.Index) = .{},
 
     /// A map of Zig InternPool indices for anonymous decls to SPIR-V decl indices.
     anon_decl_link: std.AutoHashMapUnmanaged(struct { InternPool.Index, StorageClass }, SpvModule.Decl.Index) = .{},
@@ -187,7 +187,7 @@ pub const Object = struct {
     fn genDecl(
         self: *Object,
         mod: *Module,
-        decl_index: Decl.Index,
+        decl_index: InternPool.DeclIndex,
         air: Air,
         liveness: Liveness,
     ) !void {
@@ -247,14 +247,14 @@ pub const Object = struct {
     pub fn updateDecl(
         self: *Object,
         mod: *Module,
-        decl_index: Decl.Index,
+        decl_index: InternPool.DeclIndex,
     ) !void {
         try self.genDecl(mod, decl_index, undefined, undefined);
     }
 
     /// Fetch or allocate a result id for decl index. This function also marks the decl as alive.
     /// Note: Function does not actually generate the decl, it just allocates an index.
-    pub fn resolveDecl(self: *Object, mod: *Module, decl_index: Decl.Index) !SpvModule.Decl.Index {
+    pub fn resolveDecl(self: *Object, mod: *Module, decl_index: InternPool.DeclIndex) !SpvModule.Decl.Index {
         const decl = mod.declPtr(decl_index);
         try mod.markDeclAlive(decl);
 
@@ -289,7 +289,7 @@ const DeclGen = struct {
     spv: *SpvModule,
 
     /// The decl we are currently generating code for.
-    decl_index: Decl.Index,
+    decl_index: InternPool.DeclIndex,
 
     /// The intermediate code of the declaration we are currently generating. Note: If
     /// the declaration is not a function, this value will be undefined!
@@ -1115,7 +1115,7 @@ const DeclGen = struct {
         }
     }
 
-    fn constantDeclRef(self: *DeclGen, ty: Type, decl_index: Decl.Index) !IdRef {
+    fn constantDeclRef(self: *DeclGen, ty: Type, decl_index: InternPool.DeclIndex) !IdRef {
         const mod = self.module;
         const ty_ref = try self.resolveType(ty, .direct);
         const ty_id = self.typeId(ty_ref);
src/link/Elf/ZigObject.zig
@@ -618,7 +618,7 @@ pub fn codeAlloc(self: ZigObject, elf_file: *Elf, atom_index: Atom.Index) ![]u8
 pub fn getDeclVAddr(
     self: *ZigObject,
     elf_file: *Elf,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     reloc_info: link.File.RelocInfo,
 ) !u64 {
     const this_sym_index = try self.getOrCreateMetadataForDecl(elf_file, decl_index);
@@ -741,7 +741,7 @@ pub fn getOrCreateMetadataForLazySymbol(
     return symbol_index;
 }
 
-fn freeUnnamedConsts(self: *ZigObject, elf_file: *Elf, decl_index: Module.Decl.Index) void {
+fn freeUnnamedConsts(self: *ZigObject, elf_file: *Elf, decl_index: InternPool.DeclIndex) void {
     const unnamed_consts = self.unnamed_consts.getPtr(decl_index) orelse return;
     for (unnamed_consts.items) |sym_index| {
         self.freeDeclMetadata(elf_file, sym_index);
@@ -759,7 +759,7 @@ fn freeDeclMetadata(self: *ZigObject, elf_file: *Elf, sym_index: Symbol.Index) v
     // TODO free GOT entry here
 }
 
-pub fn freeDecl(self: *ZigObject, elf_file: *Elf, decl_index: Module.Decl.Index) void {
+pub fn freeDecl(self: *ZigObject, elf_file: *Elf, decl_index: InternPool.DeclIndex) void {
     const mod = elf_file.base.options.module.?;
     const decl = mod.declPtr(decl_index);
 
@@ -781,7 +781,7 @@ pub fn freeDecl(self: *ZigObject, elf_file: *Elf, decl_index: Module.Decl.Index)
 pub fn getOrCreateMetadataForDecl(
     self: *ZigObject,
     elf_file: *Elf,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
 ) !Symbol.Index {
     const gop = try self.decls.getOrPut(elf_file.base.allocator, decl_index);
     if (!gop.found_existing) {
@@ -857,7 +857,7 @@ fn getDeclShdrIndex(
 fn updateDeclCode(
     self: *ZigObject,
     elf_file: *Elf,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     sym_index: Symbol.Index,
     shdr_index: u16,
     code: []const u8,
@@ -956,7 +956,7 @@ fn updateDeclCode(
 fn updateTlv(
     self: *ZigObject,
     elf_file: *Elf,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     sym_index: Symbol.Index,
     shndx: u16,
     code: []const u8,
@@ -1083,7 +1083,7 @@ pub fn updateDecl(
     self: *ZigObject,
     elf_file: *Elf,
     mod: *Module,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
 ) link.File.UpdateDeclError!void {
     const tracy = trace(@src());
     defer tracy.end();
@@ -1249,7 +1249,7 @@ pub fn lowerUnnamedConst(
     self: *ZigObject,
     elf_file: *Elf,
     typed_value: TypedValue,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
 ) !u32 {
     const gpa = elf_file.base.allocator;
     const mod = elf_file.base.options.module.?;
@@ -1435,7 +1435,7 @@ pub fn updateExports(
 pub fn updateDeclLineNumber(
     self: *ZigObject,
     mod: *Module,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
 ) !void {
     const tracy = trace(@src());
     defer tracy.end();
@@ -1453,7 +1453,7 @@ pub fn updateDeclLineNumber(
 pub fn deleteDeclExport(
     self: *ZigObject,
     elf_file: *Elf,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     name: InternPool.NullTerminatedString,
 ) void {
     const metadata = self.decls.getPtr(decl_index) orelse return;
@@ -1584,10 +1584,10 @@ const TlsVariable = struct {
 };
 
 const AtomList = std.ArrayListUnmanaged(Atom.Index);
-const UnnamedConstTable = std.AutoHashMapUnmanaged(Module.Decl.Index, std.ArrayListUnmanaged(Symbol.Index));
-const DeclTable = std.AutoHashMapUnmanaged(Module.Decl.Index, DeclMetadata);
+const UnnamedConstTable = std.AutoHashMapUnmanaged(InternPool.DeclIndex, std.ArrayListUnmanaged(Symbol.Index));
+const DeclTable = std.AutoHashMapUnmanaged(InternPool.DeclIndex, DeclMetadata);
 const AnonDeclTable = std.AutoHashMapUnmanaged(InternPool.Index, DeclMetadata);
-const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, LazySymbolMetadata);
+const LazySymbolTable = std.AutoArrayHashMapUnmanaged(InternPool.OptionalDeclIndex, LazySymbolMetadata);
 const TlsTable = std.AutoArrayHashMapUnmanaged(Atom.Index, TlsVariable);
 
 const assert = std.debug.assert;
src/link/C.zig
@@ -24,7 +24,7 @@ base: link.File,
 /// This linker backend does not try to incrementally link output C source code.
 /// Instead, it tracks all declarations in this table, and iterates over it
 /// in the flush function, stitching pre-rendered pieces of C code together.
-decl_table: std.AutoArrayHashMapUnmanaged(Module.Decl.Index, DeclBlock) = .{},
+decl_table: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, DeclBlock) = .{},
 /// All the string bytes of rendered C code, all squished into one array.
 /// While in progress, a separate buffer is used, and then when finished, the
 /// buffer is copied into this one.
@@ -138,7 +138,7 @@ pub fn deinit(self: *C) void {
     self.code_buf.deinit(gpa);
 }
 
-pub fn freeDecl(self: *C, decl_index: Module.Decl.Index) void {
+pub fn freeDecl(self: *C, decl_index: InternPool.DeclIndex) void {
     const gpa = self.base.allocator;
     if (self.decl_table.fetchSwapRemove(decl_index)) |kv| {
         var decl_block = kv.value;
@@ -279,7 +279,7 @@ fn updateAnonDecl(self: *C, module: *Module, i: usize) !void {
     };
 }
 
-pub fn updateDecl(self: *C, module: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDecl(self: *C, module: *Module, decl_index: InternPool.DeclIndex) !void {
     const tracy = trace(@src());
     defer tracy.end();
 
@@ -337,7 +337,7 @@ pub fn updateDecl(self: *C, module: *Module, decl_index: Module.Decl.Index) !voi
     gop.value_ptr.fwd_decl = try self.addString(object.dg.fwd_decl.items);
 }
 
-pub fn updateDeclLineNumber(self: *C, module: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDeclLineNumber(self: *C, module: *Module, decl_index: InternPool.DeclIndex) !void {
     // The C backend does not have the ability to fix line numbers without re-generating
     // the entire Decl.
     _ = self;
src/link/Coff.zig
@@ -109,11 +109,11 @@ const HotUpdateState = struct {
     loaded_base_address: ?std.os.windows.HMODULE = null,
 };
 
-const DeclTable = std.AutoArrayHashMapUnmanaged(Module.Decl.Index, DeclMetadata);
+const DeclTable = std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, DeclMetadata);
 const AnonDeclTable = std.AutoHashMapUnmanaged(InternPool.Index, DeclMetadata);
 const RelocTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(Relocation));
 const BaseRelocationTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(u32));
-const UnnamedConstTable = std.AutoArrayHashMapUnmanaged(Module.Decl.Index, std.ArrayListUnmanaged(Atom.Index));
+const UnnamedConstTable = std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, std.ArrayListUnmanaged(Atom.Index));
 
 const default_file_alignment: u16 = 0x200;
 const default_size_of_stack_reserve: u32 = 0x1000000;
@@ -144,7 +144,7 @@ const Section = struct {
     free_list: std.ArrayListUnmanaged(Atom.Index) = .{},
 };
 
-const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, LazySymbolMetadata);
+const LazySymbolTable = std.AutoArrayHashMapUnmanaged(InternPool.OptionalDeclIndex, LazySymbolMetadata);
 
 const LazySymbolMetadata = struct {
     const State = enum { unused, pending_flush, flushed };
@@ -1087,7 +1087,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
     return self.updateExports(mod, .{ .decl_index = decl_index }, mod.getDeclExports(decl_index));
 }
 
-pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.Index) !u32 {
+pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: InternPool.DeclIndex) !u32 {
     const gpa = self.base.allocator;
     const mod = self.base.options.module.?;
     const decl = mod.declPtr(decl_index);
@@ -1157,7 +1157,7 @@ fn lowerConst(self: *Coff, name: []const u8, tv: TypedValue, required_alignment:
 pub fn updateDecl(
     self: *Coff,
     mod: *Module,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
 ) link.File.UpdateDeclError!void {
     if (build_options.skip_non_native and builtin.object_format != .coff) {
         @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
     return atom;
 }
 
-pub fn getOrCreateAtomForDecl(self: *Coff, decl_index: Module.Decl.Index) !Atom.Index {
+pub fn getOrCreateAtomForDecl(self: *Coff, decl_index: InternPool.DeclIndex) !Atom.Index {
     const gop = try self.decls.getOrPut(self.base.allocator, decl_index);
     if (!gop.found_existing) {
         gop.value_ptr.* = .{
@@ -1314,7 +1314,7 @@ pub fn getOrCreateAtomForDecl(self: *Coff, decl_index: Module.Decl.Index) !Atom.
     return gop.value_ptr.atom;
 }
 
-fn getDeclOutputSection(self: *Coff, decl_index: Module.Decl.Index) u16 {
+fn getDeclOutputSection(self: *Coff, decl_index: InternPool.DeclIndex) u16 {
     const decl = self.base.options.module.?.declPtr(decl_index);
     const ty = decl.ty;
     const mod = self.base.options.module.?;
@@ -1340,7 +1340,7 @@ fn getDeclOutputSection(self: *Coff, decl_index: Module.Decl.Index) u16 {
     return index;
 }
 
-fn updateDeclCode(self: *Coff, decl_index: Module.Decl.Index, code: []u8, complex_type: coff.ComplexType) !void {
+fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, complex_type: coff.ComplexType) !void {
     const mod = self.base.options.module.?;
     const decl = mod.declPtr(decl_index);
 
@@ -1398,7 +1398,7 @@ fn updateDeclCode(self: *Coff, decl_index: Module.Decl.Index, code: []u8, comple
     try self.writeAtom(atom_index, code);
 }
 
-fn freeUnnamedConsts(self: *Coff, decl_index: Module.Decl.Index) void {
+fn freeUnnamedConsts(self: *Coff, decl_index: InternPool.DeclIndex) void {
     const gpa = self.base.allocator;
     const unnamed_consts = self.unnamed_const_atoms.getPtr(decl_index) orelse return;
     for (unnamed_consts.items) |atom_index| {
@@ -1407,7 +1407,7 @@ fn freeUnnamedConsts(self: *Coff, decl_index: Module.Decl.Index) void {
     unnamed_consts.clearAndFree(gpa);
 }
 
-pub fn freeDecl(self: *Coff, decl_index: Module.Decl.Index) void {
+pub fn freeDecl(self: *Coff, decl_index: InternPool.DeclIndex) void {
     if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
 
     const mod = self.base.options.module.?;
@@ -1563,7 +1563,7 @@ pub fn updateExports(
 
 pub fn deleteDeclExport(
     self: *Coff,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     name_ip: InternPool.NullTerminatedString,
 ) void {
     if (self.llvm_object) |_| return;
@@ -1766,7 +1766,7 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
     assert(!self.imports_count_dirty);
 }
 
-pub fn getDeclVAddr(self: *Coff, decl_index: Module.Decl.Index, reloc_info: link.File.RelocInfo) !u64 {
+pub fn getDeclVAddr(self: *Coff, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
     assert(self.llvm_object == null);
 
     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
     return global_index;
 }
 
-pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl_index: InternPool.DeclIndex) !void {
     _ = self;
     _ = module;
     _ = decl_index;
src/link/Dwarf.zig
@@ -35,7 +35,7 @@ di_files: std.AutoArrayHashMapUnmanaged(*const Module.File, void) = .{},
 
 global_abbrev_relocs: std.ArrayListUnmanaged(AbbrevRelocation) = .{},
 
-const AtomTable = std.AutoHashMapUnmanaged(Module.Decl.Index, Atom.Index);
+const AtomTable = std.AutoHashMapUnmanaged(InternPool.DeclIndex, Atom.Index);
 
 const Atom = struct {
     /// Offset into .debug_info pointing to the tag for this Decl, or
@@ -555,7 +555,7 @@ pub const DeclState = struct {
         self: *DeclState,
         name: [:0]const u8,
         ty: Type,
-        owner_decl: Module.Decl.Index,
+        owner_decl: InternPool.DeclIndex,
         loc: DbgInfoLoc,
     ) error{OutOfMemory}!void {
         const dbg_info = &self.dbg_info;
@@ -669,7 +669,7 @@ pub const DeclState = struct {
         self: *DeclState,
         name: [:0]const u8,
         ty: Type,
-        owner_decl: Module.Decl.Index,
+        owner_decl: InternPool.DeclIndex,
         is_ptr: bool,
         loc: DbgInfoLoc,
     ) error{OutOfMemory}!void {
@@ -1073,7 +1073,7 @@ pub fn deinit(self: *Dwarf) void {
 
 /// Initializes Decl's state and its matching output buffers.
 /// Call this before `commitDeclState`.
-pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !DeclState {
+pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclIndex) !DeclState {
     const tracy = trace(@src());
     defer tracy.end();
 
@@ -1191,7 +1191,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)
 pub fn commitDeclState(
     self: *Dwarf,
     mod: *Module,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     sym_addr: u64,
     sym_size: u64,
     decl_state: *DeclState,
@@ -1640,7 +1640,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons
     }
 }
 
-pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclIndex) !void {
     const tracy = trace(@src());
     defer tracy.end();
 
@@ -1682,7 +1682,7 @@ pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: Module.Decl.
     }
 }
 
-pub fn freeDecl(self: *Dwarf, decl_index: Module.Decl.Index) void {
+pub fn freeDecl(self: *Dwarf, decl_index: InternPool.DeclIndex) void {
     const gpa = self.allocator;
 
     // Free SrcFn atom
@@ -2627,7 +2627,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {
     }
 }
 
-fn addDIFile(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !u28 {
+fn addDIFile(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclIndex) !u28 {
     const decl = mod.declPtr(decl_index);
     const file_scope = decl.getFileScope(mod);
     const gop = try self.di_files.getOrPut(self.allocator, file_scope);
@@ -2771,7 +2771,7 @@ fn createAtom(self: *Dwarf, comptime kind: Kind) !Atom.Index {
     return index;
 }
 
-fn getOrCreateAtomForDecl(self: *Dwarf, comptime kind: Kind, decl_index: Module.Decl.Index) !Atom.Index {
+fn getOrCreateAtomForDecl(self: *Dwarf, comptime kind: Kind, decl_index: InternPool.DeclIndex) !Atom.Index {
     switch (kind) {
         .src_fn => {
             const gop = try self.src_fn_decls.getOrPut(self.allocator, decl_index);
src/link/Elf.zig
@@ -400,7 +400,7 @@ pub fn deinit(self: *Elf) void {
     self.comdat_group_sections.deinit(gpa);
 }
 
-pub fn getDeclVAddr(self: *Elf, decl_index: Module.Decl.Index, reloc_info: link.File.RelocInfo) !u64 {
+pub fn getDeclVAddr(self: *Elf, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
     assert(self.llvm_object == null);
     return self.zigObjectPtr().?.getDeclVAddr(self, decl_index, reloc_info);
 }
@@ -3127,7 +3127,7 @@ fn writeElfHeader(self: *Elf) !void {
     try self.base.file.?.pwriteAll(hdr_buf[0..index], 0);
 }
 
-pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void {
+pub fn freeDecl(self: *Elf, decl_index: InternPool.DeclIndex) void {
     if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
     return self.zigObjectPtr().?.freeDecl(self, decl_index);
 }
@@ -3143,7 +3143,7 @@ pub fn updateFunc(self: *Elf, mod: *Module, func_index: InternPool.Index, air: A
 pub fn updateDecl(
     self: *Elf,
     mod: *Module,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
 ) link.File.UpdateDeclError!void {
     if (build_options.skip_non_native and builtin.object_format != .elf) {
         @panic("Attempted to compile for object format that was disabled by build configuration");
@@ -3152,7 +3152,7 @@ pub fn updateDecl(
     return self.zigObjectPtr().?.updateDecl(self, mod, decl_index);
 }
 
-pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module.Decl.Index) !u32 {
+pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: InternPool.DeclIndex) !u32 {
     return self.zigObjectPtr().?.lowerUnnamedConst(self, typed_value, decl_index);
 }
 
@@ -3170,14 +3170,14 @@ pub fn updateExports(
     return self.zigObjectPtr().?.updateExports(self, mod, exported, exports);
 }
 
-pub fn updateDeclLineNumber(self: *Elf, mod: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDeclLineNumber(self: *Elf, mod: *Module, decl_index: InternPool.DeclIndex) !void {
     if (self.llvm_object) |_| return;
     return self.zigObjectPtr().?.updateDeclLineNumber(mod, decl_index);
 }
 
 pub fn deleteDeclExport(
     self: *Elf,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     name: InternPool.NullTerminatedString,
 ) void {
     if (self.llvm_object) |_| return;
src/link/MachO.zig
@@ -2278,7 +2278,7 @@ pub fn updateFunc(self: *MachO, mod: *Module, func_index: InternPool.Index, air:
     try self.updateExports(mod, .{ .decl_index = decl_index }, mod.getDeclExports(decl_index));
 }
 
-pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Module.Decl.Index) !u32 {
+pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: InternPool.DeclIndex) !u32 {
     const gpa = self.base.allocator;
     const mod = self.base.options.module.?;
     const gop = try self.unnamed_const_atoms.getOrPut(gpa, decl_index);
@@ -2358,7 +2358,7 @@ fn lowerConst(
     return .{ .ok = atom_index };
 }
 
-pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDecl(self: *MachO, mod: *Module, decl_index: InternPool.DeclIndex) !void {
     if (build_options.skip_non_native and builtin.object_format != .macho) {
         @panic("Attempted to compile for object format that was disabled by build configuration");
     }
@@ -2544,7 +2544,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol) !Atom.In
     return atom;
 }
 
-fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.Decl.Index) !void {
+fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: InternPool.DeclIndex) !void {
     const mod = self.base.options.module.?;
     // Lowering a TLV on macOS involves two stages:
     // 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
     self.markRelocsDirtyByTarget(init_atom_sym_loc);
 }
 
-pub fn getOrCreateAtomForDecl(self: *MachO, decl_index: Module.Decl.Index) !Atom.Index {
+pub fn getOrCreateAtomForDecl(self: *MachO, decl_index: InternPool.DeclIndex) !Atom.Index {
     const gop = try self.decls.getOrPut(self.base.allocator, decl_index);
     if (!gop.found_existing) {
         const sym_index = try self.allocateSymbol();
@@ -2654,7 +2654,7 @@ pub fn getOrCreateAtomForDecl(self: *MachO, decl_index: Module.Decl.Index) !Atom
     return gop.value_ptr.atom;
 }
 
-fn getDeclOutputSection(self: *MachO, decl_index: Module.Decl.Index) u8 {
+fn getDeclOutputSection(self: *MachO, decl_index: InternPool.DeclIndex) u8 {
     const decl = self.base.options.module.?.declPtr(decl_index);
     const ty = decl.ty;
     const val = decl.val;
@@ -2693,7 +2693,7 @@ fn getDeclOutputSection(self: *MachO, decl_index: Module.Decl.Index) u8 {
     return sect_id;
 }
 
-fn updateDeclCode(self: *MachO, decl_index: Module.Decl.Index, code: []u8) !u64 {
+fn updateDeclCode(self: *MachO, decl_index: InternPool.DeclIndex, code: []u8) !u64 {
     const gpa = self.base.allocator;
     const mod = self.base.options.module.?;
     const decl = mod.declPtr(decl_index);
@@ -2764,7 +2764,7 @@ fn updateDeclCode(self: *MachO, decl_index: Module.Decl.Index, code: []u8) !u64
     return atom.getSymbol(self).n_value;
 }
 
-pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl_index: InternPool.DeclIndex) !void {
     if (self.d_sym) |*d_sym| {
         try d_sym.dwarf.updateDeclLineNumber(module, decl_index);
     }
@@ -2906,7 +2906,7 @@ pub fn updateExports(
 
 pub fn deleteDeclExport(
     self: *MachO,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     name: InternPool.NullTerminatedString,
 ) Allocator.Error!void {
     if (self.llvm_object) |_| return;
@@ -2940,7 +2940,7 @@ pub fn deleteDeclExport(
     sym_index.* = 0;
 }
 
-fn freeUnnamedConsts(self: *MachO, decl_index: Module.Decl.Index) void {
+fn freeUnnamedConsts(self: *MachO, decl_index: InternPool.DeclIndex) void {
     const gpa = self.base.allocator;
     const unnamed_consts = self.unnamed_const_atoms.getPtr(decl_index) orelse return;
     for (unnamed_consts.items) |atom| {
@@ -2949,7 +2949,7 @@ fn freeUnnamedConsts(self: *MachO, decl_index: Module.Decl.Index) void {
     unnamed_consts.clearAndFree(gpa);
 }
 
-pub fn freeDecl(self: *MachO, decl_index: Module.Decl.Index) void {
+pub fn freeDecl(self: *MachO, decl_index: InternPool.DeclIndex) void {
     if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
     const mod = self.base.options.module.?;
     const decl = mod.declPtr(decl_index);
@@ -2968,7 +2968,7 @@ pub fn freeDecl(self: *MachO, decl_index: Module.Decl.Index) void {
     }
 }
 
-pub fn getDeclVAddr(self: *MachO, decl_index: Module.Decl.Index, reloc_info: File.RelocInfo) !u64 {
+pub fn getDeclVAddr(self: *MachO, decl_index: InternPool.DeclIndex, reloc_info: File.RelocInfo) !u64 {
     assert(self.llvm_object == null);
 
     const this_atom_index = try self.getOrCreateAtomForDecl(decl_index);
@@ -5667,7 +5667,7 @@ const is_hot_update_compatible = switch (builtin.target.os.tag) {
     else => false,
 };
 
-const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, LazySymbolMetadata);
+const LazySymbolTable = std.AutoArrayHashMapUnmanaged(InternPool.OptionalDeclIndex, LazySymbolMetadata);
 
 const LazySymbolMetadata = struct {
     const State = enum { unused, pending_flush, flushed };
@@ -5701,10 +5701,10 @@ const DeclMetadata = struct {
     }
 };
 
-const DeclTable = std.AutoArrayHashMapUnmanaged(Module.Decl.Index, DeclMetadata);
+const DeclTable = std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, DeclMetadata);
 const AnonDeclTable = std.AutoHashMapUnmanaged(InternPool.Index, DeclMetadata);
 const BindingTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(Atom.Binding));
-const UnnamedConstTable = std.AutoArrayHashMapUnmanaged(Module.Decl.Index, std.ArrayListUnmanaged(Atom.Index));
+const UnnamedConstTable = std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, std.ArrayListUnmanaged(Atom.Index));
 const RebaseTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(u32));
 const RelocationTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(Relocation));
 const ActionTable = std.AutoHashMapUnmanaged(u32, RelocFlags);
src/link/NvPtx.zig
@@ -70,7 +70,7 @@ pub fn updateFunc(self: *NvPtx, module: *Module, func_index: InternPool.Index, a
     try self.llvm_object.updateFunc(module, func_index, air, liveness);
 }
 
-pub fn updateDecl(self: *NvPtx, module: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDecl(self: *NvPtx, module: *Module, decl_index: InternPool.DeclIndex) !void {
     return self.llvm_object.updateDecl(module, decl_index);
 }
 
@@ -86,7 +86,7 @@ pub fn updateExports(
     return self.llvm_object.updateExports(module, exported, exports);
 }
 
-pub fn freeDecl(self: *NvPtx, decl_index: Module.Decl.Index) void {
+pub fn freeDecl(self: *NvPtx, decl_index: InternPool.DeclIndex) void {
     return self.llvm_object.freeDecl(decl_index);
 }
 
src/link/Plan9.zig
@@ -56,10 +56,10 @@ path_arena: std.heap.ArenaAllocator,
 /// If we group the decls by file, it makes it really easy to do this (put the symbol in the correct place)
 fn_decl_table: std.AutoArrayHashMapUnmanaged(
     *Module.File,
-    struct { sym_index: u32, functions: std.AutoArrayHashMapUnmanaged(Module.Decl.Index, FnDeclOutput) = .{} },
+    struct { sym_index: u32, functions: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, FnDeclOutput) = .{} },
 ) = .{},
 /// the code is modified when relocated, so that is why it is mutable
-data_decl_table: std.AutoArrayHashMapUnmanaged(Module.Decl.Index, []u8) = .{},
+data_decl_table: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, []u8) = .{},
 
 /// Table of unnamed constants associated with a parent `Decl`.
 /// 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) = .{},
 syms_index_free_list: std.ArrayListUnmanaged(usize) = .{},
 
 atoms: std.ArrayListUnmanaged(Atom) = .{},
-decls: std.AutoHashMapUnmanaged(Module.Decl.Index, DeclMetadata) = .{},
+decls: std.AutoHashMapUnmanaged(InternPool.DeclIndex, DeclMetadata) = .{},
 
 /// Indices of the three "special" symbols into atoms
 etext_edata_end_atom_indices: [3]?Atom.Index = .{ null, null, null },
@@ -129,9 +129,9 @@ const Bases = struct {
     data: u64,
 };
 
-const UnnamedConstTable = std.AutoHashMapUnmanaged(Module.Decl.Index, std.ArrayListUnmanaged(Atom.Index));
+const UnnamedConstTable = std.AutoHashMapUnmanaged(InternPool.DeclIndex, std.ArrayListUnmanaged(Atom.Index));
 
-const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, LazySymbolMetadata);
+const LazySymbolTable = std.AutoArrayHashMapUnmanaged(InternPool.OptionalDeclIndex, LazySymbolMetadata);
 
 const LazySymbolMetadata = struct {
     const State = enum { unused, pending_flush, flushed };
@@ -168,7 +168,7 @@ pub const Atom = struct {
         code_ptr: ?[*]u8,
         other: union {
             code_len: usize,
-            decl_index: Module.Decl.Index,
+            decl_index: InternPool.DeclIndex,
         },
         fn fromSlice(slice: []u8) CodePtr {
             return .{ .code_ptr = slice.ptr, .other = .{ .code_len = slice.len } };
@@ -322,7 +322,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Plan9 {
     return self;
 }
 
-fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void {
+fn putFn(self: *Plan9, decl_index: InternPool.DeclIndex, out: FnDeclOutput) !void {
     const gpa = self.base.allocator;
     const mod = self.base.options.module.?;
     const decl = mod.declPtr(decl_index);
@@ -447,7 +447,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air:
     return self.updateFinish(decl_index);
 }
 
-pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.Index) !u32 {
+pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: InternPool.DeclIndex) !u32 {
     _ = try self.seeDecl(decl_index);
     var code_buffer = std.ArrayList(u8).init(self.base.allocator);
     defer code_buffer.deinit();
@@ -508,7 +508,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I
     return new_atom_idx;
 }
 
-pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex) !void {
     const decl = mod.declPtr(decl_index);
 
     if (decl.isExtern(mod)) {
@@ -544,7 +544,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !vo
     return self.updateFinish(decl_index);
 }
 /// called at the end of update{Decl,Func}
-fn updateFinish(self: *Plan9, decl_index: Module.Decl.Index) !void {
+fn updateFinish(self: *Plan9, decl_index: InternPool.DeclIndex) !void {
     const mod = self.base.options.module.?;
     const decl = mod.declPtr(decl_index);
     const is_fn = (decl.ty.zigTypeTag(mod) == .Fn);
@@ -982,7 +982,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
 fn addDeclExports(
     self: *Plan9,
     mod: *Module,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     exports: []const *Module.Export,
 ) !void {
     const metadata = self.decls.getPtr(decl_index).?;
@@ -1017,7 +1017,7 @@ fn addDeclExports(
     }
 }
 
-pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void {
+pub fn freeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) void {
     // TODO audit the lifetimes of decls table entries. It's possible to get
     // freeDecl without any updateDecl in between.
     // 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 {
         assert(self.relocs.remove(atom_index));
     }
 }
-fn freeUnnamedConsts(self: *Plan9, decl_index: Module.Decl.Index) void {
+fn freeUnnamedConsts(self: *Plan9, decl_index: InternPool.DeclIndex) void {
     const unnamed_consts = self.unnamed_const_atoms.getPtr(decl_index) orelse return;
     for (unnamed_consts.items) |atom_idx| {
         const atom = self.getAtom(atom_idx);
@@ -1088,7 +1088,7 @@ fn createAtom(self: *Plan9) !Atom.Index {
     return index;
 }
 
-pub fn seeDecl(self: *Plan9, decl_index: Module.Decl.Index) !Atom.Index {
+pub fn seeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) !Atom.Index {
     const gop = try self.decls.getOrPut(self.base.allocator, decl_index);
     if (!gop.found_existing) {
         const index = try self.createAtom();
@@ -1428,7 +1428,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
 }
 
 /// Must be called only after a successful call to `updateDecl`.
-pub fn updateDeclLineNumber(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDeclLineNumber(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex) !void {
     _ = self;
     _ = mod;
     _ = decl_index;
@@ -1436,7 +1436,7 @@ pub fn updateDeclLineNumber(self: *Plan9, mod: *Module, decl_index: Module.Decl.
 
 pub fn getDeclVAddr(
     self: *Plan9,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     reloc_info: link.File.RelocInfo,
 ) !u64 {
     const mod = self.base.options.module.?;
src/link/SpirV.zig
@@ -109,7 +109,7 @@ pub fn updateFunc(self: *SpirV, module: *Module, func_index: InternPool.Index, a
     try self.object.updateFunc(module, func_index, air, liveness);
 }
 
-pub fn updateDecl(self: *SpirV, module: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDecl(self: *SpirV, module: *Module, decl_index: InternPool.DeclIndex) !void {
     if (build_options.skip_non_native) {
         @panic("Attempted to compile for architecture that was disabled by build configuration");
     }
@@ -144,7 +144,7 @@ pub fn updateExports(
     // TODO: Export regular functions, variables, etc using Linkage attributes.
 }
 
-pub fn freeDecl(self: *SpirV, decl_index: Module.Decl.Index) void {
+pub fn freeDecl(self: *SpirV, decl_index: InternPool.DeclIndex) void {
     _ = self;
     _ = decl_index;
 }
src/link/Wasm.zig
@@ -48,7 +48,7 @@ llvm_object: ?*LlvmObject = null,
 host_name: []const u8 = "env",
 /// List of all `Decl` that are currently alive.
 /// Each index maps to the corresponding `Atom.Index`.
-decls: std.AutoHashMapUnmanaged(Module.Decl.Index, Atom.Index) = .{},
+decls: std.AutoHashMapUnmanaged(InternPool.DeclIndex, Atom.Index) = .{},
 /// Mapping between an `Atom` and its type index representing the Wasm
 /// type of the function signature.
 atom_types: std.AutoHashMapUnmanaged(Atom.Index, u32) = .{},
@@ -598,10 +598,10 @@ fn parseObjectFile(wasm: *Wasm, path: []const u8) !bool {
     return true;
 }
 
-/// For a given `Module.Decl.Index` returns its corresponding `Atom.Index`.
+/// For a given `InternPool.DeclIndex` returns its corresponding `Atom.Index`.
 /// When the index was not found, a new `Atom` will be created, and its index will be returned.
 /// The newly created Atom is empty with default fields as specified by `Atom.empty`.
-pub fn getOrCreateAtomForDecl(wasm: *Wasm, decl_index: Module.Decl.Index) !Atom.Index {
+pub fn getOrCreateAtomForDecl(wasm: *Wasm, decl_index: InternPool.DeclIndex) !Atom.Index {
     const gop = try wasm.decls.getOrPut(wasm.base.allocator, decl_index);
     if (!gop.found_existing) {
         const atom_index = try wasm.createAtom();
@@ -1427,7 +1427,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func_index: InternPool.Index, air:
 
 // Generate code for the Decl, storing it in memory to be later written to
 // the file on flush().
-pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: InternPool.DeclIndex) !void {
     if (build_options.skip_non_native and builtin.object_format != .wasm) {
         @panic("Attempted to compile for object format that was disabled by build configuration");
     }
@@ -1479,7 +1479,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
     return wasm.finishUpdateDecl(decl_index, code, .data);
 }
 
-pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Module, decl_index: InternPool.DeclIndex) !void {
     if (wasm.llvm_object) |_| return;
     if (wasm.dwarf) |*dw| {
         const tracy = trace(@src());
@@ -1493,7 +1493,7 @@ pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.I
     }
 }
 
-fn finishUpdateDecl(wasm: *Wasm, decl_index: Module.Decl.Index, code: []const u8, symbol_tag: Symbol.Tag) !void {
+fn finishUpdateDecl(wasm: *Wasm, decl_index: InternPool.DeclIndex, code: []const u8, symbol_tag: Symbol.Tag) !void {
     const mod = wasm.base.options.module.?;
     const decl = mod.declPtr(decl_index);
     const atom_index = wasm.decls.get(decl_index).?;
@@ -1556,7 +1556,7 @@ fn getFunctionSignature(wasm: *const Wasm, loc: SymbolLoc) std.wasm.Type {
 /// Lowers a constant typed value to a local symbol and atom.
 /// Returns the symbol index of the local
 /// The given `decl` is the parent decl whom owns the constant.
-pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: Module.Decl.Index) !u32 {
+pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: InternPool.DeclIndex) !u32 {
     const mod = wasm.base.options.module.?;
     assert(tv.ty.zigTypeTag(mod) != .Fn); // cannot create local symbols for functions
     const decl = mod.declPtr(decl_index);
@@ -1672,7 +1672,7 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !u3
 /// Returns the given pointer address
 pub fn getDeclVAddr(
     wasm: *Wasm,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     reloc_info: link.File.RelocInfo,
 ) !u64 {
     const mod = wasm.base.options.module.?;
@@ -1780,7 +1780,7 @@ pub fn getAnonDeclVAddr(wasm: *Wasm, decl_val: InternPool.Index, reloc_info: lin
     return target_symbol_index;
 }
 
-pub fn deleteDeclExport(wasm: *Wasm, decl_index: Module.Decl.Index) void {
+pub fn deleteDeclExport(wasm: *Wasm, decl_index: InternPool.DeclIndex) void {
     if (wasm.llvm_object) |_| return;
     const atom_index = wasm.decls.get(decl_index) orelse return;
     const sym_index = wasm.getAtom(atom_index).sym_index;
@@ -1923,7 +1923,7 @@ pub fn updateExports(
     }
 }
 
-pub fn freeDecl(wasm: *Wasm, decl_index: Module.Decl.Index) void {
+pub fn freeDecl(wasm: *Wasm, decl_index: InternPool.DeclIndex) void {
     if (wasm.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
     const mod = wasm.base.options.module.?;
     const decl = mod.declPtr(decl_index);
@@ -5012,7 +5012,7 @@ pub fn putOrGetFuncType(wasm: *Wasm, func_type: std.wasm.Type) !u32 {
 /// For the given `decl_index`, stores the corresponding type representing the function signature.
 /// Asserts declaration has an associated `Atom`.
 /// Returns the index into the list of types.
-pub fn storeDeclType(wasm: *Wasm, decl_index: Module.Decl.Index, func_type: std.wasm.Type) !u32 {
+pub fn storeDeclType(wasm: *Wasm, decl_index: InternPool.DeclIndex, func_type: std.wasm.Type) !u32 {
     const atom_index = wasm.decls.get(decl_index).?;
     const index = try wasm.putOrGetFuncType(func_type);
     try wasm.atom_types.put(wasm.base.allocator, atom_index, index);
src/Air.zig
@@ -1043,7 +1043,7 @@ pub const Inst = struct {
         inferred_alloc: InferredAlloc,
 
         pub const InferredAllocComptime = struct {
-            decl_index: Module.Decl.Index,
+            decl_index: InternPool.DeclIndex,
             alignment: InternPool.Alignment,
             is_const: bool,
         };
src/codegen.zig
@@ -757,7 +757,7 @@ fn lowerAnonDeclRef(
 fn lowerDeclRef(
     bin_file: *link.File,
     src_loc: Module.SrcLoc,
-    decl_index: Module.Decl.Index,
+    decl_index: InternPool.DeclIndex,
     code: *std.ArrayList(u8),
     debug_output: DebugInfoOutput,
     reloc_info: RelocInfo,
@@ -853,7 +853,7 @@ fn genDeclRef(
     bin_file: *link.File,
     src_loc: Module.SrcLoc,
     tv: TypedValue,
-    ptr_decl_index: Module.Decl.Index,
+    ptr_decl_index: InternPool.DeclIndex,
 ) CodeGenError!GenResult {
     const mod = bin_file.options.module.?;
     log.debug("genDeclRef: ty = {}, val = {}", .{ tv.ty.fmt(mod), tv.val.fmtValue(tv.ty, mod) });
@@ -959,7 +959,7 @@ fn genUnnamedConst(
     bin_file: *link.File,
     src_loc: Module.SrcLoc,
     tv: TypedValue,
-    owner_decl_index: Module.Decl.Index,
+    owner_decl_index: InternPool.DeclIndex,
 ) CodeGenError!GenResult {
     const mod = bin_file.options.module.?;
     log.debug("genUnnamedConst: ty = {}, val = {}", .{ tv.ty.fmt(mod), tv.val.fmtValue(tv.ty, mod) });
@@ -987,7 +987,7 @@ pub fn genTypedValue(
     bin_file: *link.File,
     src_loc: Module.SrcLoc,
     arg_tv: TypedValue,
-    owner_decl_index: Module.Decl.Index,
+    owner_decl_index: InternPool.DeclIndex,
 ) CodeGenError!GenResult {
     const mod = bin_file.options.module.?;
     const typed_value = arg_tv;
src/Compilation.zig
@@ -254,19 +254,19 @@ pub const RcIncludes = enum {
 
 const Job = union(enum) {
     /// Write the constant value for a Decl to the output file.
-    codegen_decl: Module.Decl.Index,
+    codegen_decl: InternPool.DeclIndex,
     /// Write the machine code for a function to the output file.
     /// This will either be a non-generic `func_decl` or a `func_instance`.
     codegen_func: InternPool.Index,
     /// Render the .h file snippet for the Decl.
-    emit_h_decl: Module.Decl.Index,
+    emit_h_decl: InternPool.DeclIndex,
     /// The Decl needs to be analyzed and possibly export itself.
     /// It may have already be analyzed, or it may have been determined
     /// to be outdated; in this case perform semantic analysis again.
-    analyze_decl: Module.Decl.Index,
+    analyze_decl: InternPool.DeclIndex,
     /// The source file containing the Decl has been updated, and so the
     /// Decl may need its line number information updated in the debug info.
-    update_line_number: Module.Decl.Index,
+    update_line_number: InternPool.DeclIndex,
     /// The main source file for the module needs to be analyzed.
     analyze_mod: *Package.Module,
 
src/InternPool.zig
@@ -32,12 +32,12 @@ string_bytes: std.ArrayListUnmanaged(u8) = .{},
 ///    multi-threaded contention on an atomic counter.
 allocated_decls: std.SegmentedList(Module.Decl, 0) = .{},
 /// When a Decl object is freed from `allocated_decls`, it is pushed into this stack.
-decls_free_list: std.ArrayListUnmanaged(Module.Decl.Index) = .{},
+decls_free_list: std.ArrayListUnmanaged(DeclIndex) = .{},
 
 /// Same pattern as with `allocated_decls`.
 allocated_namespaces: std.SegmentedList(Module.Namespace, 0) = .{},
 /// Same pattern as with `decls_free_list`.
-namespaces_free_list: std.ArrayListUnmanaged(Module.Namespace.Index) = .{},
+namespaces_free_list: std.ArrayListUnmanaged(NamespaceIndex) = .{},
 
 /// Some types such as enums, structs, and unions need to store mappings from field names
 /// 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;
 const InternPool = @This();
 const Module = @import("Module.zig");
 const Zir = @import("Zir.zig");
-const Sema = @import("Sema.zig");
 
 const KeyAdapter = struct {
     intern_pool: *const InternPool,
@@ -113,6 +112,50 @@ pub const RuntimeIndex = enum(u32) {
     }
 };
 
+pub const DeclIndex = enum(u32) {
+    _,
+
+    pub fn toOptional(i: DeclIndex) OptionalDeclIndex {
+        return @enumFromInt(@intFromEnum(i));
+    }
+};
+
+pub const OptionalDeclIndex = enum(u32) {
+    none = std.math.maxInt(u32),
+    _,
+
+    pub fn init(oi: ?DeclIndex) OptionalDeclIndex {
+        return @enumFromInt(@intFromEnum(oi orelse return .none));
+    }
+
+    pub fn unwrap(oi: OptionalDeclIndex) ?DeclIndex {
+        if (oi == .none) return null;
+        return @enumFromInt(@intFromEnum(oi));
+    }
+};
+
+pub const NamespaceIndex = enum(u32) {
+    _,
+
+    pub fn toOptional(i: NamespaceIndex) OptionalNamespaceIndex {
+        return @enumFromInt(@intFromEnum(i));
+    }
+};
+
+pub const OptionalNamespaceIndex = enum(u32) {
+    none = std.math.maxInt(u32),
+    _,
+
+    pub fn init(oi: ?NamespaceIndex) OptionalNamespaceIndex {
+        return @enumFromInt(@intFromEnum(oi orelse return .none));
+    }
+
+    pub fn unwrap(oi: OptionalNamespaceIndex) ?NamespaceIndex {
+        if (oi == .none) return null;
+        return @enumFromInt(@intFromEnum(oi));
+    }
+};
+
 /// An index into `string_bytes`.
 pub const String = enum(u32) {
     _,
@@ -351,9 +394,9 @@ pub const Key = union(enum) {
 
     pub const OpaqueType = extern struct {
         /// The Decl that corresponds to the opaque itself.
-        decl: Module.Decl.Index,
+        decl: DeclIndex,
         /// Represents the declarations inside this opaque.
-        namespace: Module.Namespace.Index,
+        namespace: NamespaceIndex,
     };
 
     /// Although packed structs and non-packed structs are encoded differently,
@@ -362,9 +405,9 @@ pub const Key = union(enum) {
     pub const StructType = struct {
         extra_index: u32,
         /// `none` when the struct is `@TypeOf(.{})`.
-        decl: Module.Decl.OptionalIndex,
+        decl: OptionalDeclIndex,
         /// `none` when the struct has no declarations.
-        namespace: Module.Namespace.OptionalIndex,
+        namespace: OptionalNamespaceIndex,
         /// Index of the struct_decl ZIR instruction.
         zir_index: Zir.Inst.Index,
         layout: std.builtin.Type.ContainerLayout,
@@ -718,11 +761,11 @@ pub const Key = union(enum) {
     /// * Provide the other fields that do not require chasing the enum type.
     pub const UnionType = struct {
         /// The Decl that corresponds to the union itself.
-        decl: Module.Decl.Index,
+        decl: DeclIndex,
         /// The index of the `Tag.TypeUnion` payload. Ignored by `get`,
         /// populated by `indexToKey`.
         extra_index: u32,
-        namespace: Module.Namespace.Index,
+        namespace: NamespaceIndex,
         flags: Tag.TypeUnion.Flags,
         /// The enum that provides the list of field names and values.
         enum_tag_ty: Index,
@@ -796,9 +839,9 @@ pub const Key = union(enum) {
 
     pub const EnumType = struct {
         /// The Decl that corresponds to the enum itself.
-        decl: Module.Decl.Index,
+        decl: DeclIndex,
         /// Represents the declarations inside this enum.
-        namespace: Module.Namespace.OptionalIndex,
+        namespace: OptionalNamespaceIndex,
         /// An integer type which is used for the numerical value of the enum.
         /// This field is present regardless of whether the enum has an
         /// explicitly provided tag type or auto-numbered.
@@ -866,9 +909,9 @@ pub const Key = union(enum) {
 
     pub const IncompleteEnumType = struct {
         /// Same as corresponding `EnumType` field.
-        decl: Module.Decl.Index,
+        decl: DeclIndex,
         /// Same as corresponding `EnumType` field.
-        namespace: Module.Namespace.OptionalIndex,
+        namespace: OptionalNamespaceIndex,
         /// The field names and field values are not known yet, but
         /// the number of fields must be known ahead of time.
         fields_len: u32,
@@ -961,7 +1004,7 @@ pub const Key = union(enum) {
     pub const Variable = struct {
         ty: Index,
         init: Index,
-        decl: Module.Decl.Index,
+        decl: DeclIndex,
         lib_name: OptionalNullTerminatedString = .none,
         is_extern: bool = false,
         is_const: bool = false,
@@ -972,7 +1015,7 @@ pub const Key = union(enum) {
     pub const ExternFunc = struct {
         ty: Index,
         /// The Decl that corresponds to the function itself.
-        decl: Module.Decl.Index,
+        decl: DeclIndex,
         /// Library name if specified.
         /// For example `extern "c" fn write(...) usize` would have 'c' as library name.
         /// Index into the string table bytes.
@@ -1008,7 +1051,7 @@ pub const Key = union(enum) {
         /// This will be 0 when the function is not a generic function instantiation.
         branch_quota_extra_index: u32,
         /// The Decl that corresponds to the function itself.
-        owner_decl: Module.Decl.Index,
+        owner_decl: DeclIndex,
         /// The ZIR instruction that is a function instruction. Use this to find
         /// the body. We store this rather than the body directly so that when ZIR
         /// is regenerated on update(), we can map this to the new corresponding
@@ -1130,7 +1173,7 @@ pub const Key = union(enum) {
         pub const Addr = union(enum) {
             const Tag = @typeInfo(Addr).Union.tag_type.?;
 
-            decl: Module.Decl.Index,
+            decl: DeclIndex,
             mut_decl: MutDecl,
             anon_decl: AnonDecl,
             comptime_field: Index,
@@ -1141,7 +1184,7 @@ pub const Key = union(enum) {
             field: BaseIndex,
 
             pub const MutDecl = struct {
-                decl: Module.Decl.Index,
+                decl: DeclIndex,
                 runtime_index: RuntimeIndex,
             };
             pub const BaseIndex = struct {
@@ -1796,9 +1839,9 @@ pub const RequiresComptime = enum(u2) { no, yes, unknown, wip };
 // needed by semantic analysis.
 pub const UnionType = struct {
     /// The Decl that corresponds to the union itself.
-    decl: Module.Decl.Index,
+    decl: DeclIndex,
     /// Represents the declarations inside this union.
-    namespace: Module.Namespace.Index,
+    namespace: NamespaceIndex,
     /// The enum tag type.
     enum_tag_ty: Index,
     /// The integer tag type of the enum.
@@ -2168,7 +2211,7 @@ pub const Index = enum(u32) {
         simple_type: struct { data: SimpleType },
         type_opaque: struct { data: *Key.OpaqueType },
         type_struct: struct { data: *Tag.TypeStruct },
-        type_struct_ns: struct { data: Module.Namespace.Index },
+        type_struct_ns: struct { data: NamespaceIndex },
         type_struct_anon: DataIsExtraIndexOfTypeStructAnon,
         type_struct_packed: struct { data: *Tag.TypeStructPacked },
         type_struct_packed_inits: struct { data: *Tag.TypeStructPacked },
@@ -2609,7 +2652,7 @@ pub const Tag = enum(u8) {
     /// data == 0 represents `@TypeOf(.{})`.
     type_struct,
     /// A non-packed struct type that has only a namespace; no fields.
-    /// data is Module.Namespace.Index.
+    /// data is NamespaceIndex.
     type_struct_ns,
     /// An AnonStructType which stores types, names, and values for fields.
     /// data is extra index of `TypeStructAnon`.
@@ -2902,7 +2945,7 @@ pub const Tag = enum(u8) {
         ty: Index,
         /// May be `none`.
         init: Index,
-        decl: Module.Decl.Index,
+        decl: DeclIndex,
         /// Library name if specified.
         /// For example `extern "c" var stderrp = ...` would have 'c' as library name.
         lib_name: OptionalNullTerminatedString,
@@ -2931,7 +2974,7 @@ pub const Tag = enum(u8) {
     ///    A `none` value marks that the inferred error set is not resolved yet.
     pub const FuncDecl = struct {
         analysis: FuncAnalysis,
-        owner_decl: Module.Decl.Index,
+        owner_decl: DeclIndex,
         ty: Index,
         zir_body_inst: Zir.Inst.Index,
         lbrace_line: u32,
@@ -2948,7 +2991,7 @@ pub const Tag = enum(u8) {
     pub const FuncInstance = struct {
         analysis: FuncAnalysis,
         // Needed by the linker for codegen. Not part of hashing or equality.
-        owner_decl: Module.Decl.Index,
+        owner_decl: DeclIndex,
         ty: Index,
         branch_quota: u32,
         /// Points to a `FuncDecl`.
@@ -3003,8 +3046,8 @@ pub const Tag = enum(u8) {
         size: u32,
         /// Only valid after .have_layout
         padding: u32,
-        decl: Module.Decl.Index,
-        namespace: Module.Namespace.Index,
+        decl: DeclIndex,
+        namespace: NamespaceIndex,
         /// The enum that provides the list of field names and values.
         tag_ty: Index,
         zir_index: Zir.Inst.Index,
@@ -3028,10 +3071,10 @@ pub const Tag = enum(u8) {
     /// 1. name: NullTerminatedString for each fields_len
     /// 2. init: Index for each fields_len // if tag is type_struct_packed_inits
     pub const TypeStructPacked = struct {
-        decl: Module.Decl.Index,
+        decl: DeclIndex,
         zir_index: Zir.Inst.Index,
         fields_len: u32,
-        namespace: Module.Namespace.OptionalIndex,
+        namespace: OptionalNamespaceIndex,
         backing_int_ty: Index,
         names_map: MapIndex,
         flags: Flags,
@@ -3066,7 +3109,7 @@ pub const Tag = enum(u8) {
     /// 2. if any_default_inits:
     ///    init: Index // for each field in declared order
     /// 3. if has_namespace:
-    ///    namespace: Module.Namespace.Index
+    ///    namespace: NamespaceIndex
     /// 4. if any_aligned_fields:
     ///    align: Alignment // for each field in declared order
     /// 5. if any_comptime_fields:
@@ -3075,7 +3118,7 @@ pub const Tag = enum(u8) {
     ///    field_index: RuntimeOrder // for each field in runtime order
     /// 7. field_offset: u32 // for each field in declared order, undef until layout_resolved
     pub const TypeStruct = struct {
-        decl: Module.Decl.Index,
+        decl: DeclIndex,
         zir_index: Zir.Inst.Index,
         fields_len: u32,
         flags: Flags,
@@ -3418,9 +3461,9 @@ pub const Array = struct {
 /// 1. tag value: Index for each fields_len; declaration order
 pub const EnumExplicit = struct {
     /// The Decl that corresponds to the enum itself.
-    decl: Module.Decl.Index,
+    decl: DeclIndex,
     /// This may be `none` if there are no declarations.
-    namespace: Module.Namespace.OptionalIndex,
+    namespace: OptionalNamespaceIndex,
     /// An integer type which is used for the numerical value of the enum, which
     /// has been explicitly provided by the enum declaration.
     int_tag_type: Index,
@@ -3437,9 +3480,9 @@ pub const EnumExplicit = struct {
 /// 0. field name: NullTerminatedString for each fields_len; declaration order
 pub const EnumAuto = struct {
     /// The Decl that corresponds to the enum itself.
-    decl: Module.Decl.Index,
+    decl: DeclIndex,
     /// This may be `none` if there are no declarations.
-    namespace: Module.Namespace.OptionalIndex,
+    namespace: OptionalNamespaceIndex,
     /// An integer type which is used for the numerical value of the enum, which
     /// was inferred by Zig based on the number of tags.
     int_tag_type: Index,
@@ -3463,7 +3506,7 @@ pub const PackedU64 = packed struct(u64) {
 
 pub const PtrDecl = struct {
     ty: Index,
-    decl: Module.Decl.Index,
+    decl: DeclIndex,
 };
 
 pub const PtrAnonDecl = struct {
@@ -3480,7 +3523,7 @@ pub const PtrAnonDeclAligned = struct {
 
 pub const PtrMutDecl = struct {
     ty: Index,
-    decl: Module.Decl.Index,
+    decl: DeclIndex,
     runtime_index: RuntimeIndex,
 };
 
@@ -3754,7 +3797,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
 
         .type_struct_ns => .{ .struct_type = .{
             .extra_index = 0,
-            .namespace = @as(Module.Namespace.Index, @enumFromInt(data)).toOptional(),
+            .namespace = @as(NamespaceIndex, @enumFromInt(data)).toOptional(),
             .decl = .none,
             .zir_index = undefined,
             .layout = .Auto,
@@ -4280,7 +4323,7 @@ fn extraStructType(ip: *const InternPool, extra_index: u32) Key.StructType {
     };
     const namespace = t: {
         if (!s.data.flags.has_namespace) break :t .none;
-        const namespace: Module.Namespace.Index = @enumFromInt(ip.extra.items[index]);
+        const namespace: NamespaceIndex = @enumFromInt(ip.extra.items[index]);
         index += 1;
         break :t namespace.toOptional();
     };
@@ -5313,8 +5356,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
 
 pub const UnionTypeInit = struct {
     flags: Tag.TypeUnion.Flags,
-    decl: Module.Decl.Index,
-    namespace: Module.Namespace.Index,
+    decl: DeclIndex,
+    namespace: NamespaceIndex,
     zir_index: Zir.Inst.Index,
     fields_len: u32,
     enum_tag_ty: Index,
@@ -5384,8 +5427,8 @@ pub fn getUnionType(ip: *InternPool, gpa: Allocator, ini: UnionTypeInit) Allocat
 }
 
 pub const StructTypeInit = struct {
-    decl: Module.Decl.Index,
-    namespace: Module.Namespace.OptionalIndex,
+    decl: DeclIndex,
+    namespace: OptionalNamespaceIndex,
     layout: std.builtin.Type.ContainerLayout,
     zir_index: Zir.Inst.Index,
     fields_len: u32,
@@ -5659,7 +5702,7 @@ pub fn getExternFunc(ip: *InternPool, gpa: Allocator, key: Key.ExternFunc) Alloc
 }
 
 pub const GetFuncDeclKey = struct {
-    owner_decl: Module.Decl.Index,
+    owner_decl: DeclIndex,
     ty: Index,
     zir_body_inst: Zir.Inst.Index,
     lbrace_line: u32,
@@ -5716,7 +5759,7 @@ pub fn getFuncDecl(ip: *InternPool, gpa: Allocator, key: GetFuncDeclKey) Allocat
 }
 
 pub const GetFuncDeclIesKey = struct {
-    owner_decl: Module.Decl.Index,
+    owner_decl: DeclIndex,
     param_types: []Index,
     noalias_bits: u32,
     comptime_bits: u32,
@@ -6321,8 +6364,8 @@ fn getIncompleteEnumExplicit(
 }
 
 pub const GetEnumInit = struct {
-    decl: Module.Decl.Index,
-    namespace: Module.Namespace.OptionalIndex,
+    decl: DeclIndex,
+    namespace: OptionalNamespaceIndex,
     tag_ty: Index,
     names: []const NullTerminatedString,
     values: []const Index,
@@ -6484,9 +6527,9 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
     inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {
         ip.extra.appendAssumeCapacity(switch (field.type) {
             Index,
-            Module.Decl.Index,
-            Module.Namespace.Index,
-            Module.Namespace.OptionalIndex,
+            DeclIndex,
+            NamespaceIndex,
+            OptionalNamespaceIndex,
             MapIndex,
             OptionalMapIndex,
             RuntimeIndex,
@@ -6560,9 +6603,9 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct
         const int32 = ip.extra.items[i + index];
         @field(result, field.name) = switch (field.type) {
             Index,
-            Module.Decl.Index,
-            Module.Namespace.Index,
-            Module.Namespace.OptionalIndex,
+            DeclIndex,
+            NamespaceIndex,
+            OptionalNamespaceIndex,
             MapIndex,
             OptionalMapIndex,
             RuntimeIndex,
@@ -7554,15 +7597,15 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
     try bw.flush();
 }
 
-pub fn declPtr(ip: *InternPool, index: Module.Decl.Index) *Module.Decl {
+pub fn declPtr(ip: *InternPool, index: DeclIndex) *Module.Decl {
     return ip.allocated_decls.at(@intFromEnum(index));
 }
 
-pub fn declPtrConst(ip: *const InternPool, index: Module.Decl.Index) *const Module.Decl {
+pub fn declPtrConst(ip: *const InternPool, index: DeclIndex) *const Module.Decl {
     return ip.allocated_decls.at(@intFromEnum(index));
 }
 
-pub fn namespacePtr(ip: *InternPool, index: Module.Namespace.Index) *Module.Namespace {
+pub fn namespacePtr(ip: *InternPool, index: NamespaceIndex) *Module.Namespace {
     return ip.allocated_namespaces.at(@intFromEnum(index));
 }
 
@@ -7570,7 +7613,7 @@ pub fn createDecl(
     ip: *InternPool,
     gpa: Allocator,
     initialization: Module.Decl,
-) Allocator.Error!Module.Decl.Index {
+) Allocator.Error!DeclIndex {
     if (ip.decls_free_list.popOrNull()) |index| {
         ip.allocated_decls.at(@intFromEnum(index)).* = initialization;
         return index;
@@ -7580,7 +7623,7 @@ pub fn createDecl(
     return @enumFromInt(ip.allocated_decls.len - 1);
 }
 
-pub fn destroyDecl(ip: *InternPool, gpa: Allocator, index: Module.Decl.Index) void {
+pub fn destroyDecl(ip: *InternPool, gpa: Allocator, index: DeclIndex) void {
     ip.declPtr(index).* = undefined;
     ip.decls_free_list.append(gpa, index) catch {
         // In order to keep `destroyDecl` a non-fallible function, we ignore memory
@@ -7592,7 +7635,7 @@ pub fn createNamespace(
     ip: *InternPool,
     gpa: Allocator,
     initialization: Module.Namespace,
-) Allocator.Error!Module.Namespace.Index {
+) Allocator.Error!NamespaceIndex {
     if (ip.namespaces_free_list.popOrNull()) |index| {
         ip.allocated_namespaces.at(@intFromEnum(index)).* = initialization;
         return index;
@@ -7602,7 +7645,7 @@ pub fn createNamespace(
     return @enumFromInt(ip.allocated_namespaces.len - 1);
 }
 
-pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: Module.Namespace.Index) void {
+pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: NamespaceIndex) void {
     ip.namespacePtr(index).* = .{
         .parent = undefined,
         .file_scope = undefined,
@@ -7984,7 +8027,7 @@ pub fn isVariable(ip: *const InternPool, val: Index) bool {
     return ip.items.items(.tag)[@intFromEnum(val)] == .variable;
 }
 
-pub fn getBackingDecl(ip: *const InternPool, val: Index) Module.Decl.OptionalIndex {
+pub fn getBackingDecl(ip: *const InternPool, val: Index) OptionalDeclIndex {
     var base = @intFromEnum(val);
     while (true) {
         switch (ip.items.items(.tag)[base]) {
@@ -8358,7 +8401,7 @@ pub fn funcDeclInfo(ip: *const InternPool, i: Index) Key.Func {
     return extraFuncDecl(ip, datas[@intFromEnum(i)]);
 }
 
-pub fn funcDeclOwner(ip: *const InternPool, i: Index) Module.Decl.Index {
+pub fn funcDeclOwner(ip: *const InternPool, i: Index) DeclIndex {
     return funcDeclInfo(ip, i).owner_decl;
 }
 
@@ -8424,7 +8467,7 @@ pub fn anonStructFieldsLen(ip: *const InternPool, i: Index) u32 {
 }
 
 /// Asserts the type is a struct.
-pub fn structDecl(ip: *const InternPool, i: Index) Module.Decl.OptionalIndex {
+pub fn structDecl(ip: *const InternPool, i: Index) OptionalDeclIndex {
     return switch (ip.indexToKey(i)) {
         .struct_type => |t| t.decl,
         else => unreachable,
src/link.zig
@@ -552,7 +552,7 @@ pub const File = struct {
     /// Called from within the CodeGen to lower a local variable instantion as an unnamed
     /// constant. Returns the symbol index of the lowered constant in the read-only section
     /// of the final binary.
-    pub fn lowerUnnamedConst(base: *File, tv: TypedValue, decl_index: Module.Decl.Index) UpdateDeclError!u32 {
+    pub fn lowerUnnamedConst(base: *File, tv: TypedValue, decl_index: InternPool.DeclIndex) UpdateDeclError!u32 {
         if (build_options.only_c) @compileError("unreachable");
         switch (base.tag) {
             // zig fmt: off
@@ -591,7 +591,7 @@ pub const File = struct {
     }
 
     /// May be called before or after updateExports for any given Decl.
-    pub fn updateDecl(base: *File, module: *Module, decl_index: Module.Decl.Index) UpdateDeclError!void {
+    pub fn updateDecl(base: *File, module: *Module, decl_index: InternPool.DeclIndex) UpdateDeclError!void {
         const decl = module.declPtr(decl_index);
         assert(decl.has_tv);
         if (build_options.only_c) {
@@ -632,7 +632,7 @@ pub const File = struct {
         }
     }
 
-    pub fn updateDeclLineNumber(base: *File, module: *Module, decl_index: Module.Decl.Index) UpdateDeclError!void {
+    pub fn updateDeclLineNumber(base: *File, module: *Module, decl_index: InternPool.DeclIndex) UpdateDeclError!void {
         const decl = module.declPtr(decl_index);
         assert(decl.has_tv);
         if (build_options.only_c) {
@@ -849,7 +849,7 @@ pub const File = struct {
     }
 
     /// Called when a Decl is deleted from the Module.
-    pub fn freeDecl(base: *File, decl_index: Module.Decl.Index) void {
+    pub fn freeDecl(base: *File, decl_index: InternPool.DeclIndex) void {
         if (build_options.only_c) {
             assert(base.tag == .c);
             return @fieldParentPtr(C, "base", base).freeDecl(decl_index);
@@ -928,7 +928,7 @@ pub const File = struct {
     /// `Decl`'s address was not yet resolved, or the containing atom gets moved in virtual memory.
     /// May be called before or after updateFunc/updateDecl therefore it is up to the linker to allocate
     /// the block/atom.
-    pub fn getDeclVAddr(base: *File, decl_index: Module.Decl.Index, reloc_info: RelocInfo) !u64 {
+    pub fn getDeclVAddr(base: *File, decl_index: InternPool.DeclIndex, reloc_info: RelocInfo) !u64 {
         if (build_options.only_c) unreachable;
         switch (base.tag) {
             .coff => return @fieldParentPtr(Coff, "base", base).getDeclVAddr(decl_index, reloc_info),
@@ -972,7 +972,7 @@ pub const File = struct {
         }
     }
 
-    pub fn deleteDeclExport(base: *File, decl_index: Module.Decl.Index, name: InternPool.NullTerminatedString) !void {
+    pub fn deleteDeclExport(base: *File, decl_index: InternPool.DeclIndex, name: InternPool.NullTerminatedString) !void {
         if (build_options.only_c) unreachable;
         switch (base.tag) {
             .coff => return @fieldParentPtr(Coff, "base", base).deleteDeclExport(decl_index, name),
@@ -1225,15 +1225,15 @@ pub const File = struct {
         kind: Kind,
         ty: Type,
 
-        pub fn initDecl(kind: Kind, decl: ?Module.Decl.Index, mod: *Module) LazySymbol {
+        pub fn initDecl(kind: Kind, decl: ?InternPool.DeclIndex, mod: *Module) LazySymbol {
             return .{ .kind = kind, .ty = if (decl) |decl_index|
                 mod.declPtr(decl_index).val.toType()
             else
                 Type.anyerror };
         }
 
-        pub fn getDecl(self: LazySymbol, mod: *Module) Module.Decl.OptionalIndex {
-            return Module.Decl.OptionalIndex.init(self.ty.getOwnerDeclOrNull(mod));
+        pub fn getDecl(self: LazySymbol, mod: *Module) InternPool.OptionalDeclIndex {
+            return InternPool.OptionalDeclIndex.init(self.ty.getOwnerDeclOrNull(mod));
         }
     };
 
src/Module.zig
@@ -464,27 +464,8 @@ pub const Decl = struct {
         anon,
     };
 
-    pub const Index = enum(u32) {
-        _,
-
-        pub fn toOptional(i: Index) OptionalIndex {
-            return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
-        }
-    };
-
-    pub const OptionalIndex = enum(u32) {
-        none = std.math.maxInt(u32),
-        _,
-
-        pub fn init(oi: ?Index) OptionalIndex {
-            return @as(OptionalIndex, @enumFromInt(@intFromEnum(oi orelse return .none)));
-        }
-
-        pub fn unwrap(oi: OptionalIndex) ?Index {
-            if (oi == .none) return null;
-            return @as(Index, @enumFromInt(@intFromEnum(oi)));
-        }
-    };
+    const Index = InternPool.DeclIndex;
+    const OptionalIndex = InternPool.OptionalDeclIndex;
 
     pub const DepsTable = std.AutoArrayHashMapUnmanaged(Decl.Index, DepType);
 
@@ -828,27 +809,8 @@ pub const Namespace = struct {
     /// Value is whether the usingnamespace decl is marked `pub`.
     usingnamespace_set: std.AutoHashMapUnmanaged(Decl.Index, bool) = .{},
 
-    pub const Index = enum(u32) {
-        _,
-
-        pub fn toOptional(i: Index) OptionalIndex {
-            return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
-        }
-    };
-
-    pub const OptionalIndex = enum(u32) {
-        none = std.math.maxInt(u32),
-        _,
-
-        pub fn init(oi: ?Index) OptionalIndex {
-            return @as(OptionalIndex, @enumFromInt(@intFromEnum(oi orelse return .none)));
-        }
-
-        pub fn unwrap(oi: OptionalIndex) ?Index {
-            if (oi == .none) return null;
-            return @as(Index, @enumFromInt(@intFromEnum(oi)));
-        }
-    };
+    const Index = InternPool.NamespaceIndex;
+    const OptionalIndex = InternPool.OptionalNamespaceIndex;
 
     const DeclContext = struct {
         module: *Module,
src/Sema.zig
@@ -20,7 +20,7 @@ inst_map: InstMap = .{},
 /// and `src_decl` of `Block` is the `Decl` of the callee.
 /// This `Decl` owns the arena memory of this `Sema`.
 owner_decl: *Decl,
-owner_decl_index: Decl.Index,
+owner_decl_index: InternPool.DeclIndex,
 /// For an inline or comptime function call, this will be the root parent function
 /// which contains the callsite. Corresponds to `owner_decl`.
 /// This could be `none`, a `func_decl`, or a `func_instance`.
@@ -54,7 +54,7 @@ comptime_break_inst: Zir.Inst.Index = undefined,
 /// access to the source location set by the previous instruction which did
 /// contain a mapped source location.
 src: LazySrcLoc = .{ .token_offset = 0 },
-decl_val_table: std.AutoHashMapUnmanaged(Decl.Index, Air.Inst.Ref) = .{},
+decl_val_table: std.AutoHashMapUnmanaged(InternPool.DeclIndex, Air.Inst.Ref) = .{},
 /// When doing a generic function instantiation, this array collects a value
 /// for each parameter of the generic owner. `none` for non-comptime parameters.
 /// This is a separate array from `block.params` so that it can be passed
@@ -71,7 +71,7 @@ generic_owner: InternPool.Index = .none,
 /// declaration site.
 generic_call_src: LazySrcLoc = .unneeded,
 /// Corresponds to `generic_call_src`.
-generic_call_decl: Decl.OptionalIndex = .none,
+generic_call_decl: InternPool.OptionalDeclIndex = .none,
 /// The key is types that must be fully resolved prior to machine code
 /// generation pass. Types are added to this set when resolving them
 /// 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
 /// TODO: this is a workaround for memory bugs triggered by the removal of
 /// Decl.value_arena. A better solution needs to be found. Probably this will
 /// involve transitioning comptime-mutable memory away from using Decls at all.
-comptime_mutable_decls: *std.ArrayList(Decl.Index),
+comptime_mutable_decls: *std.ArrayList(InternPool.DeclIndex),
 
 /// This is populated when `@setAlignStack` occurs so that if there is a duplicate
 /// one encountered, the conflicting source location can be shown.
@@ -323,7 +323,7 @@ pub const Block = struct {
     sema: *Sema,
     /// The namespace to use for lookups from this source block
     /// When analyzing fields, this is different from src_decl.src_namespace.
-    namespace: Namespace.Index,
+    namespace: InternPool.NamespaceIndex,
     /// The AIR instructions generated for this block.
     instructions: std.ArrayListUnmanaged(Air.Inst.Index),
     // `param` instructions are collected here to be used by the `func` instruction.
@@ -345,7 +345,7 @@ pub const Block = struct {
     /// This Decl is the Decl according to the Zig source code corresponding to this Block.
     /// This can vary during inline or comptime function calls. See `Sema.owner_decl`
     /// for the one that will be the same for all Block instances.
-    src_decl: Decl.Index,
+    src_decl: InternPool.DeclIndex,
     /// Non zero if a non-inline loop or a runtime conditional have been encountered.
     /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.
     runtime_index: Value.RuntimeIndex = .zero,
@@ -800,7 +800,7 @@ pub const Block = struct {
         }
 
         /// `alignment` value of 0 means to use ABI alignment.
-        pub fn finish(wad: *WipAnonDecl, ty: Type, val: Value, alignment: Alignment) !Decl.Index {
+        pub fn finish(wad: *WipAnonDecl, ty: Type, val: Value, alignment: Alignment) !InternPool.DeclIndex {
             const sema = wad.block.sema;
             // Do this ahead of time because `createAnonymousDecl` depends on calling
             // `type.hasRuntimeBits()`.
@@ -2505,7 +2505,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.ErrorMsg)
             defer reference_stack.deinit();
 
             // Avoid infinite loops.
-            var seen = std.AutoHashMap(Decl.Index, void).init(gpa);
+            var seen = std.AutoHashMap(InternPool.DeclIndex, void).init(gpa);
             defer seen.deinit();
 
             while (mod.reference_table.get(referenced_by)) |ref| {
@@ -2652,8 +2652,8 @@ fn analyzeAsInt(
 
 pub fn getStructType(
     sema: *Sema,
-    decl: Module.Decl.Index,
-    namespace: Module.Namespace.Index,
+    decl: InternPool.DeclIndex,
+    namespace: InternPool.NamespaceIndex,
     zir_index: Zir.Inst.Index,
 ) !InternPool.Index {
     const mod = sema.mod;
@@ -2768,7 +2768,7 @@ fn createAnonymousDeclTypeNamed(
     name_strategy: Zir.Inst.NameStrategy,
     anon_prefix: []const u8,
     inst: ?Zir.Inst.Index,
-) !Decl.Index {
+) !InternPool.DeclIndex {
     const mod = sema.mod;
     const ip = &mod.intern_pool;
     const gpa = sema.gpa;
@@ -6065,7 +6065,7 @@ pub fn analyzeExport(
     block: *Block,
     src: LazySrcLoc,
     options: Module.Export.Options,
-    exported_decl_index: Decl.Index,
+    exported_decl_index: InternPool.DeclIndex,
 ) !void {
     const gpa = sema.gpa;
     const mod = sema.mod;
@@ -6380,7 +6380,7 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
     return sema.analyzeDeclVal(block, src, decl);
 }
 
-fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPool.NullTerminatedString) !Decl.Index {
+fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPool.NullTerminatedString) !InternPool.DeclIndex {
     const mod = sema.mod;
     var namespace = block.namespace;
     while (true) {
@@ -6398,10 +6398,10 @@ fn lookupInNamespace(
     sema: *Sema,
     block: *Block,
     src: LazySrcLoc,
-    namespace_index: Namespace.Index,
+    namespace_index: InternPool.NamespaceIndex,
     ident_name: InternPool.NullTerminatedString,
     observe_usingnamespace: bool,
-) CompileError!?Decl.Index {
+) CompileError!?InternPool.DeclIndex {
     const mod = sema.mod;
 
     const namespace = mod.namespacePtr(namespace_index);
@@ -6419,7 +6419,7 @@ fn lookupInNamespace(
         defer checked_namespaces.deinit(gpa);
 
         // Keep track of name conflicts for error notes.
-        var candidates: std.ArrayListUnmanaged(Decl.Index) = .{};
+        var candidates: std.ArrayListUnmanaged(InternPool.DeclIndex) = .{};
         defer candidates.deinit(gpa);
 
         try checked_namespaces.put(gpa, namespace, namespace.file_scope == src_file);
@@ -7034,7 +7034,7 @@ const InlineCallSema = struct {
     other_error_return_trace_index_on_fn_entry: Air.Inst.Ref,
     other_generic_owner: InternPool.Index,
     other_generic_call_src: LazySrcLoc,
-    other_generic_call_decl: Decl.OptionalIndex,
+    other_generic_call_decl: InternPool.OptionalDeclIndex,
 
     /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not
     /// change that. The other parameters contain data for the callee Sema. The other modified
@@ -7104,7 +7104,7 @@ const InlineCallSema = struct {
         std.mem.swap(InstMap,            &ics.sema.inst_map,          &ics.other_inst_map);
         std.mem.swap(InternPool.Index,   &ics.sema.generic_owner,     &ics.other_generic_owner);
         std.mem.swap(LazySrcLoc,         &ics.sema.generic_call_src,  &ics.other_generic_call_src);
-        std.mem.swap(Decl.OptionalIndex, &ics.sema.generic_call_decl, &ics.other_generic_call_decl);
+        std.mem.swap(InternPool.OptionalDeclIndex, &ics.sema.generic_call_decl, &ics.other_generic_call_decl);
         std.mem.swap(Air.Inst.Ref,       &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry);
         // zig fmt: on
     }
@@ -17825,7 +17825,7 @@ fn typeInfoDecls(
     block: *Block,
     src: LazySrcLoc,
     type_info_ty: Type,
-    opt_namespace: Module.Namespace.OptionalIndex,
+    opt_namespace: InternPool.OptionalNamespaceIndex,
 ) CompileError!InternPool.Index {
     const mod = sema.mod;
     const gpa = sema.gpa;
@@ -25760,7 +25760,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block) !void {
 /// Backends depend on panic decls being available when lowering safety-checked
 /// instructions. This function ensures the panic function will be available to
 /// be called during that time.
-fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !Module.Decl.Index {
+fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternPool.DeclIndex {
     const mod = sema.mod;
     const gpa = sema.gpa;
     if (mod.panic_messages[@intFromEnum(panic_id)].unwrap()) |x| return x;
@@ -26685,9 +26685,9 @@ fn namespaceLookup(
     sema: *Sema,
     block: *Block,
     src: LazySrcLoc,
-    namespace: Namespace.Index,
+    namespace: InternPool.NamespaceIndex,
     decl_name: InternPool.NullTerminatedString,
-) CompileError!?Decl.Index {
+) CompileError!?InternPool.DeclIndex {
     const mod = sema.mod;
     const gpa = sema.gpa;
     if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| {
@@ -26712,7 +26712,7 @@ fn namespaceLookupRef(
     sema: *Sema,
     block: *Block,
     src: LazySrcLoc,
-    namespace: Namespace.Index,
+    namespace: InternPool.NamespaceIndex,
     decl_name: InternPool.NullTerminatedString,
 ) CompileError!?Air.Inst.Ref {
     const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null;
@@ -26724,7 +26724,7 @@ fn namespaceLookupVal(
     sema: *Sema,
     block: *Block,
     src: LazySrcLoc,
-    namespace: Namespace.Index,
+    namespace: InternPool.NamespaceIndex,
     decl_name: InternPool.NullTerminatedString,
 ) CompileError!?Air.Inst.Ref {
     const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null;
@@ -31589,7 +31589,7 @@ fn analyzeDeclVal(
     sema: *Sema,
     block: *Block,
     src: LazySrcLoc,
-    decl_index: Decl.Index,
+    decl_index: InternPool.DeclIndex,
 ) CompileError!Air.Inst.Ref {
     try sema.addReferencedBy(block, src, decl_index);
     if (sema.decl_val_table.get(decl_index)) |result| {
@@ -31609,7 +31609,7 @@ fn addReferencedBy(
     sema: *Sema,
     block: *Block,
     src: LazySrcLoc,
-    decl_index: Decl.Index,
+    decl_index: InternPool.DeclIndex,
 ) !void {
     if (sema.mod.comp.reference_trace == 0) return;
     if (src == .unneeded) {
@@ -31626,7 +31626,7 @@ fn addReferencedBy(
     });
 }
 
-fn ensureDeclAnalyzed(sema: *Sema, decl_index: Decl.Index) CompileError!void {
+fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) CompileError!void {
     const mod = sema.mod;
     const ip = &mod.intern_pool;
     const decl = mod.declPtr(decl_index);
@@ -31670,7 +31670,7 @@ fn optRefValue(sema: *Sema, opt_val: ?Value) !Value {
     } })));
 }
 
-fn analyzeDeclRef(sema: *Sema, decl_index: Decl.Index) CompileError!Air.Inst.Ref {
+fn analyzeDeclRef(sema: *Sema, decl_index: InternPool.DeclIndex) CompileError!Air.Inst.Ref {
     return sema.analyzeDeclRefInner(decl_index, true);
 }
 
@@ -31678,7 +31678,7 @@ fn analyzeDeclRef(sema: *Sema, decl_index: Decl.Index) CompileError!Air.Inst.Ref
 /// only triggers analysis for function bodies if `analyze_fn_body` is true. If it's possible for a
 /// decl_ref to end up in runtime code, the function body must be analyzed: `analyzeDeclRef` wraps
 /// this function with `analyze_fn_body` set to true.
-fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: bool) CompileError!Air.Inst.Ref {
+fn analyzeDeclRefInner(sema: *Sema, decl_index: InternPool.DeclIndex, analyze_fn_body: bool) CompileError!Air.Inst.Ref {
     const mod = sema.mod;
     try sema.ensureDeclAnalyzed(decl_index);
 
@@ -31701,7 +31701,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo
     } })));
 }
 
-fn maybeQueueFuncBodyAnalysis(sema: *Sema, decl_index: Decl.Index) !void {
+fn maybeQueueFuncBodyAnalysis(sema: *Sema, decl_index: InternPool.DeclIndex) !void {
     const mod = sema.mod;
     const decl = mod.declPtr(decl_index);
     const tv = try decl.typedValue();
@@ -34861,7 +34861,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp
     var analysis_arena = std.heap.ArenaAllocator.init(gpa);
     defer analysis_arena.deinit();
 
-    var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa);
+    var comptime_mutable_decls = std.ArrayList(InternPool.DeclIndex).init(gpa);
     defer comptime_mutable_decls.deinit();
 
     var sema: Sema = .{
@@ -35683,7 +35683,7 @@ fn semaStructFields(
         },
     };
 
-    var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa);
+    var comptime_mutable_decls = std.ArrayList(InternPool.DeclIndex).init(gpa);
     defer comptime_mutable_decls.deinit();
 
     var sema: Sema = .{
@@ -35949,7 +35949,7 @@ fn semaStructFieldInits(
     const zir_index = struct_type.zir_index;
     const fields_len, const small, var extra_index = structZirInfo(zir, zir_index);
 
-    var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa);
+    var comptime_mutable_decls = std.ArrayList(InternPool.DeclIndex).init(gpa);
     defer comptime_mutable_decls.deinit();
 
     var sema: Sema = .{
@@ -36133,7 +36133,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
 
     const decl = mod.declPtr(decl_index);
 
-    var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa);
+    var comptime_mutable_decls = std.ArrayList(InternPool.DeclIndex).init(gpa);
     defer comptime_mutable_decls.deinit();
 
     var sema: Sema = .{
@@ -36561,7 +36561,7 @@ fn generateUnionTagTypeSimple(
     sema: *Sema,
     block: *Block,
     enum_field_names: []const InternPool.NullTerminatedString,
-    maybe_decl_index: Module.Decl.OptionalIndex,
+    maybe_decl_index: InternPool.OptionalDeclIndex,
 ) !InternPool.Index {
     const mod = sema.mod;
     const ip = &mod.intern_pool;
@@ -36630,7 +36630,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
     return sema.analyzeDeclVal(&block, src, decl_index);
 }
 
-fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Module.Decl.Index {
+fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex {
     const gpa = sema.gpa;
 
     const src = LazySrcLoc.nodeOffset(0);
src/type.zig
@@ -2778,7 +2778,7 @@ pub const Type = struct {
     }
 
     /// Returns null if the type has no namespace.
-    pub fn getNamespaceIndex(ty: Type, mod: *Module) Module.Namespace.OptionalIndex {
+    pub fn getNamespaceIndex(ty: Type, mod: *Module) InternPool.OptionalNamespaceIndex {
         return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
             .opaque_type => |opaque_type| opaque_type.namespace.toOptional(),
             .struct_type => |struct_type| struct_type.namespace,
@@ -3123,11 +3123,11 @@ pub const Type = struct {
         };
     }
 
-    pub fn getOwnerDecl(ty: Type, mod: *Module) Module.Decl.Index {
+    pub fn getOwnerDecl(ty: Type, mod: *Module) InternPool.DeclIndex {
         return ty.getOwnerDeclOrNull(mod) orelse unreachable;
     }
 
-    pub fn getOwnerDeclOrNull(ty: Type, mod: *Module) ?Module.Decl.Index {
+    pub fn getOwnerDeclOrNull(ty: Type, mod: *Module) ?InternPool.DeclIndex {
         return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
             .struct_type => |struct_type| struct_type.decl.unwrap(),
             .union_type => |union_type| union_type.decl,
src/value.zig
@@ -1556,7 +1556,7 @@ pub const Value = struct {
     /// Gets the decl referenced by this pointer.  If the pointer does not point
     /// to a decl, or if it points to some part of a decl (like field_ptr or element_ptr),
     /// this function returns null.
-    pub fn pointerDecl(val: Value, mod: *Module) ?Module.Decl.Index {
+    pub fn pointerDecl(val: Value, mod: *Module) ?InternPool.DeclIndex {
         return switch (mod.intern_pool.indexToKey(val.toIntern())) {
             .variable => |variable| variable.decl,
             .extern_func => |extern_func| extern_func.decl,
src/Zir.zig
@@ -21,9 +21,6 @@ const Ast = std.zig.Ast;
 
 const InternPool = @import("InternPool.zig");
 const Zir = @This();
-const Type = @import("type.zig").Type;
-const Value = @import("value.zig").Value;
-const TypedValue = @import("TypedValue.zig");
 const Module = @import("Module.zig");
 const LazySrcLoc = Module.LazySrcLoc;