From c6f3e9d79cf849623e6c4f25e02e17cdfab07b7c Mon Sep 17 00:00:00 2001 From: mlugg Date: Mon, 25 Mar 2024 19:02:21 +0000 Subject: [PATCH] Zcu.Decl: remove `ty` field `Decl` can no longer store un-interned values, so this field is now unnecessary. The type can instead be fetched with the new `typeOf` helper method, which just gets the type of the Decl's `Value`. --- src/InternPool.zig | 4 --- src/Module.zig | 51 ++++++++++++++++++------------------ src/Sema.zig | 33 +++++++++++------------ src/TypedValue.zig | 2 +- src/Value.zig | 2 +- src/arch/aarch64/CodeGen.zig | 2 +- src/arch/arm/CodeGen.zig | 2 +- src/arch/riscv64/CodeGen.zig | 2 +- src/arch/sparc64/CodeGen.zig | 2 +- src/arch/wasm/CodeGen.zig | 21 ++++++++------- src/arch/x86_64/CodeGen.zig | 2 +- src/codegen.zig | 6 ++--- src/codegen/c.zig | 27 ++++++++++--------- src/codegen/llvm.zig | 27 ++++++++++--------- src/codegen/spirv.zig | 20 +++++++------- src/link/C.zig | 2 +- src/link/Coff.zig | 6 ++--- src/link/Dwarf.zig | 6 ++--- src/link/Elf/ZigObject.zig | 6 ++--- src/link/MachO/ZigObject.zig | 4 +-- src/link/Plan9.zig | 6 ++--- src/link/SpirV.zig | 2 +- src/link/Wasm/ZigObject.zig | 8 +++--- 23 files changed, 120 insertions(+), 123 deletions(-) diff --git a/src/InternPool.zig b/src/InternPool.zig index daec1f5c0d..e4132e577e 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -6581,7 +6581,6 @@ pub fn getFuncInstance(ip: *InternPool, gpa: Allocator, arg: GetFuncInstanceKey) generic_owner, func_index, func_extra_index, - func_ty, arg.alignment, arg.section, ); @@ -6711,7 +6710,6 @@ pub fn getFuncInstanceIes( generic_owner, func_index, func_extra_index, - func_ty, arg.alignment, arg.section, ); @@ -6723,7 +6721,6 @@ fn finishFuncInstance( generic_owner: Index, func_index: Index, func_extra_index: u32, - func_ty: Index, alignment: Alignment, section: OptionalNullTerminatedString, ) Allocator.Error!Index { @@ -6735,7 +6732,6 @@ fn finishFuncInstance( .src_line = fn_owner_decl.src_line, .has_tv = true, .owns_tv = true, - .ty = @import("type.zig").Type.fromInterned(func_ty), .val = @import("Value.zig").fromInterned(func_index), .alignment = alignment, .@"linksection" = section, diff --git a/src/Module.zig b/src/Module.zig index 7d91ceb7d1..9cbb2cc89a 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -330,9 +330,6 @@ const ValueArena = struct { pub const Decl = struct { name: InternPool.NullTerminatedString, - /// The most recent Type of the Decl after a successful semantic analysis. - /// Populated when `has_tv`. - ty: Type, /// The most recent Value of the Decl after a successful semantic analysis. /// Populated when `has_tv`. val: Value, @@ -487,20 +484,28 @@ pub const Decl = struct { zcu.namespacePtr(decl.src_namespace).fullyQualifiedName(zcu, decl.name); } - pub fn typedValue(decl: Decl) error{AnalysisFail}!TypedValue { + pub fn typeOf(decl: Decl, zcu: *const Zcu) Type { + assert(decl.has_tv); + return Type.fromInterned(zcu.intern_pool.typeOf(decl.val.toIntern())); + } + + pub fn typedValue(decl: Decl, zcu: *const Zcu) error{AnalysisFail}!TypedValue { if (!decl.has_tv) return error.AnalysisFail; - return TypedValue{ .ty = decl.ty, .val = decl.val }; + return .{ + .ty = decl.typeOf(zcu), + .val = decl.val, + }; } pub fn internValue(decl: *Decl, zcu: *Zcu) Allocator.Error!InternPool.Index { assert(decl.has_tv); - const ip_index = try decl.val.intern(decl.ty, zcu); + const ip_index = try decl.val.intern(decl.typeOf(zcu), zcu); decl.val = Value.fromInterned(ip_index); return ip_index; } pub fn isFunction(decl: Decl, zcu: *const Zcu) !bool { - const tv = try decl.typedValue(); + const tv = try decl.typedValue(zcu); return tv.ty.zigTypeTag(zcu) == .Fn; } @@ -590,7 +595,7 @@ pub const Decl = struct { @tagName(decl.analysis), }); if (decl.has_tv) { - std.debug.print(" ty={} val={}", .{ decl.ty, decl.val }); + std.debug.print(" val={}", .{decl.val}); } std.debug.print("\n", .{}); } @@ -615,7 +620,7 @@ pub const Decl = struct { pub fn getAlignment(decl: Decl, zcu: *Zcu) Alignment { assert(decl.has_tv); if (decl.alignment != .none) return decl.alignment; - return decl.ty.abiAlignment(zcu); + return decl.typeOf(zcu).abiAlignment(zcu); } /// Upgrade a `LazySrcLoc` to a `SrcLoc` based on the `Decl` provided. @@ -3525,7 +3530,6 @@ fn semaFile(mod: *Module, file: *File) SemaError!void { new_decl.src_line = 0; new_decl.is_pub = true; new_decl.is_exported = false; - new_decl.ty = Type.type; new_decl.alignment = .none; new_decl.@"linksection" = .none; new_decl.alive = true; // This Decl corresponds to a File and is therefore always alive. @@ -3594,7 +3598,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { const old_has_tv = decl.has_tv; // The following values are ignored if `!old_has_tv` - const old_ty = decl.ty; + const old_ty = decl.typeOf(mod); const old_val = decl.val; const old_align = decl.alignment; const old_linksection = decl.@"linksection"; @@ -3716,7 +3720,6 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)}); } - decl.ty = Type.fromInterned(InternPool.Index.type_type); decl.val = ty.toValue(); decl.alignment = .none; decl.@"linksection" = .none; @@ -3760,7 +3763,6 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { }, } - decl.ty = decl_tv.ty; decl.val = Value.fromInterned((try decl_tv.val.intern(decl_tv.ty, mod))); // Function linksection, align, and addrspace were already set by Sema if (!is_func) { @@ -3806,10 +3808,10 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { decl.analysis = .complete; const result: SemaDeclResult = if (old_has_tv) .{ - .invalidate_decl_val = !decl.ty.eql(old_ty, mod) or - !decl.val.eql(old_val, decl.ty, mod) or + .invalidate_decl_val = !decl_tv.ty.eql(old_ty, mod) or + !decl.val.eql(old_val, decl_tv.ty, mod) or is_inline != old_is_inline, - .invalidate_decl_ref = !decl.ty.eql(old_ty, mod) or + .invalidate_decl_ref = !decl_tv.ty.eql(old_ty, mod) or decl.alignment != old_align or decl.@"linksection" != old_linksection or decl.@"addrspace" != old_addrspace or @@ -3819,11 +3821,11 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { .invalidate_decl_ref = true, }; - const has_runtime_bits = queue_linker_work and (is_func or try sema.typeHasRuntimeBits(decl.ty)); + const has_runtime_bits = queue_linker_work and (is_func or try sema.typeHasRuntimeBits(decl_tv.ty)); if (has_runtime_bits) { // Needed for codegen_decl which will call updateDecl and then the // codegen backend wants full access to the Decl Type. - try sema.resolveTypeFully(decl.ty); + try sema.resolveTypeFully(decl_tv.ty); try mod.comp.work_queue.writeItem(.{ .codegen_decl = decl_index }); @@ -3850,7 +3852,7 @@ fn semaAnonOwnerDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult { log.debug("semaAnonOwnerDecl '{d}'", .{@intFromEnum(decl_index)}); - switch (decl.ty.zigTypeTag(zcu)) { + switch (decl.typeOf(zcu).zigTypeTag(zcu)) { .Fn => @panic("TODO: update fn instance"), .Type => {}, else => unreachable, @@ -4479,7 +4481,7 @@ pub fn finalizeAnonDecl(mod: *Module, decl_index: Decl.Index) Allocator.Error!vo // if the Decl is referenced by an instruction or another constant. Otherwise, // the Decl will be garbage collected by the `codegen_decl` task instead of sent // to the linker. - if (mod.declPtr(decl_index).ty.isFnOrHasRuntimeBits(mod)) { + if (mod.declPtr(decl_index).typeOf(mod).isFnOrHasRuntimeBits(mod)) { try mod.comp.anon_work_queue.writeItem(.{ .codegen_decl = decl_index }); } } @@ -4563,7 +4565,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato // the runtime-known parameters only, not to be confused with the // generic_owner function type, which potentially has more parameters, // including comptime parameters. - const fn_ty = decl.ty; + const fn_ty = decl.typeOf(mod); const fn_ty_info = mod.typeToFunc(fn_ty).?; var sema: Sema = .{ @@ -4812,7 +4814,6 @@ pub fn allocateNewDecl( .src_line = undefined, .has_tv = false, .owns_tv = false, - .ty = undefined, .val = undefined, .alignment = undefined, .@"linksection" = .none, @@ -4889,7 +4890,6 @@ pub fn initNewAnonDecl( new_decl.name = name; new_decl.src_line = src_line; - new_decl.ty = typed_value.ty; new_decl.val = typed_value.val; new_decl.alignment = .none; new_decl.@"linksection" = .none; @@ -5419,7 +5419,7 @@ pub fn populateTestFunctions( try mod.ensureDeclAnalyzed(decl_index); } const decl = mod.declPtr(decl_index); - const test_fn_ty = decl.ty.slicePtrFieldType(mod).childType(mod); + const test_fn_ty = decl.typeOf(mod).slicePtrFieldType(mod).childType(mod); const array_decl_index = d: { // Add mod.test_functions to an array decl then make the test_functions @@ -5463,7 +5463,7 @@ pub fn populateTestFunctions( // func try mod.intern(.{ .ptr = .{ .ty = try mod.intern(.{ .ptr_type = .{ - .child = test_decl.ty.toIntern(), + .child = test_decl.typeOf(mod).toIntern(), .flags = .{ .is_const = true, }, @@ -5515,7 +5515,6 @@ pub fn populateTestFunctions( // Since we are replacing the Decl's value we must perform cleanup on the // previous value. - decl.ty = new_ty; decl.val = new_val; decl.has_tv = true; } diff --git a/src/Sema.zig b/src/Sema.zig index a14a0a0e08..826988ee34 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -6425,16 +6425,17 @@ pub fn analyzeExport( try mod.ensureDeclAnalyzed(exported_decl_index); const exported_decl = mod.declPtr(exported_decl_index); + const export_ty = exported_decl.typeOf(mod); - if (!try sema.validateExternType(exported_decl.ty, .other)) { + if (!try sema.validateExternType(export_ty, .other)) { const msg = msg: { - const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{exported_decl.ty.fmt(mod)}); + const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{export_ty.fmt(mod)}); errdefer msg.destroy(gpa); const src_decl = mod.declPtr(block.src_decl); - try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), exported_decl.ty, .other); + try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), export_ty, .other); - try sema.addDeclaredHereNote(msg, exported_decl.ty); + try sema.addDeclaredHereNote(msg, export_ty); break :msg msg; }; return sema.failWithOwnedErrorMsg(block, msg); @@ -6503,7 +6504,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst } const fn_owner_decl = mod.funcOwnerDeclPtr(sema.func_index); - switch (fn_owner_decl.ty.fnCallingConvention(mod)) { + switch (fn_owner_decl.typeOf(mod).fnCallingConvention(mod)) { .Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}), .Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}), else => if (block.inlining != null) { @@ -7692,7 +7693,7 @@ fn analyzeCall( // comptime memory is mutated. const memoized_arg_values = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); - const owner_info = mod.typeToFunc(fn_owner_decl.ty).?; + const owner_info = mod.typeToFunc(fn_owner_decl.typeOf(mod)).?; const new_param_types = try sema.arena.alloc(InternPool.Index, owner_info.param_types.len); var new_fn_info: InternPool.GetFuncTypeKey = .{ .param_types = new_param_types, @@ -7960,9 +7961,9 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ }); } const func_decl = mod.funcOwnerDeclPtr(sema.owner_func_index); - if (!func_ty.eql(func_decl.ty, mod)) { + if (!func_ty.eql(func_decl.typeOf(mod), mod)) { return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{}' does not match type of calling function '{}'", .{ - func_ty.fmt(mod), func_decl.ty.fmt(mod), + func_ty.fmt(mod), func_decl.typeOf(mod).fmt(mod), }); } _ = try block.addUnOp(.ret, result); @@ -26641,7 +26642,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block) !void { // decl_index may be an alias; we must find the decl that actually // owns the function. try sema.ensureDeclAnalyzed(decl_index); - const tv = try mod.declPtr(decl_index).typedValue(); + const tv = try mod.declPtr(decl_index).typedValue(mod); try sema.declareDependency(.{ .decl_val = decl_index }); assert(tv.ty.zigTypeTag(mod) == .Fn); assert(try sema.fnHasRuntimeBits(tv.ty)); @@ -31374,16 +31375,16 @@ fn beginComptimePtrLoad( .ptr => |ptr| switch (ptr.addr) { .decl => |decl_index| blk: { const decl = mod.declPtr(decl_index); - const decl_tv = try decl.typedValue(); + const decl_tv = try decl.typedValue(mod); try sema.declareDependency(.{ .decl_val = decl_index }); if (decl.val.getVariable(mod) != null) return error.RuntimeLoad; - const layout_defined = decl.ty.hasWellDefinedLayout(mod); + const layout_defined = decl.typeOf(mod).hasWellDefinedLayout(mod); break :blk ComptimePtrLoadKit{ .parent = if (layout_defined) .{ .tv = decl_tv, .byte_offset = 0 } else null, .pointee = decl_tv, .is_mutable = false, - .ty_without_well_defined_layout = if (!layout_defined) decl.ty else null, + .ty_without_well_defined_layout = if (!layout_defined) decl.typeOf(mod) else null, }; }, .comptime_alloc => |alloc_index| kit: { @@ -32668,7 +32669,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: InternPool.DeclIndex, analyze_fn const mod = sema.mod; try sema.ensureDeclAnalyzed(decl_index); - const decl_tv = try mod.declPtr(decl_index).typedValue(); + const decl_tv = try mod.declPtr(decl_index).typedValue(mod); const owner_decl = mod.declPtr(switch (mod.intern_pool.indexToKey(decl_tv.val.toIntern())) { .variable => |variable| variable.decl, .extern_func => |extern_func| extern_func.decl, @@ -32697,7 +32698,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: InternPool.DeclIndex, analyze_fn fn maybeQueueFuncBodyAnalysis(sema: *Sema, decl_index: InternPool.DeclIndex) !void { const mod = sema.mod; const decl = mod.declPtr(decl_index); - const tv = try decl.typedValue(); + const tv = try decl.typedValue(mod); if (tv.ty.zigTypeTag(mod) != .Fn) return; if (!try sema.fnHasRuntimeBits(tv.ty)) return; const func_index = tv.val.toIntern(); @@ -36611,7 +36612,7 @@ fn resolveInferredErrorSet( // inferred error sets, each call gets an adhoc InferredErrorSet object, which // has no corresponding function body. const ies_func_owner_decl = mod.declPtr(func.owner_decl); - const ies_func_info = mod.typeToFunc(ies_func_owner_decl.ty).?; + const ies_func_info = mod.typeToFunc(ies_func_owner_decl.typeOf(mod)).?; // if ies declared by a inline function with generic return type, the return_type should be generic_poison, // because inline function does not create a new declaration, and the ies has been filled with analyzeCall, // so here we can simply skip this case. @@ -37629,7 +37630,6 @@ fn generateUnionTagTypeNumbered( .tag_mode = .explicit, }); - new_decl.ty = Type.type; new_decl.val = Value.fromInterned(enum_ty); try mod.finalizeAnonDecl(new_decl_index); @@ -37675,7 +37675,6 @@ fn generateUnionTagTypeSimple( const new_decl = mod.declPtr(new_decl_index); new_decl.owns_tv = true; - new_decl.ty = Type.type; new_decl.val = Value.fromInterned(enum_ty); try mod.finalizeAnonDecl(new_decl_index); diff --git a/src/TypedValue.zig b/src/TypedValue.zig index a502ed306c..5d9c062417 100644 --- a/src/TypedValue.zig +++ b/src/TypedValue.zig @@ -315,7 +315,7 @@ pub fn print( const decl = mod.declPtr(decl_index); if (level == 0) return writer.print("(decl '{}')", .{decl.name.fmt(ip)}); return print(.{ - .ty = decl.ty, + .ty = decl.typeOf(mod), .val = decl.val, }, writer, level - 1, mod); }, diff --git a/src/Value.zig b/src/Value.zig index 3707c33d46..c220f6d0d9 100644 --- a/src/Value.zig +++ b/src/Value.zig @@ -1585,7 +1585,7 @@ pub fn sliceLen(val: Value, mod: *Module) u64 { const ip = &mod.intern_pool; return switch (ip.indexToKey(val.toIntern())) { .ptr => |ptr| switch (ip.indexToKey(switch (ptr.addr) { - .decl => |decl| mod.declPtr(decl).ty.toIntern(), + .decl => |decl| mod.declPtr(decl).typeOf(mod).toIntern(), .comptime_alloc => @panic("TODO"), .anon_decl => |anon_decl| ip.typeOf(anon_decl.val), .comptime_field => |comptime_field| ip.typeOf(comptime_field), diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 59a9fb31aa..9926f3ef7b 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -342,7 +342,7 @@ pub fn generate( const func = zcu.funcInfo(func_index); const fn_owner_decl = zcu.declPtr(func.owner_decl); assert(fn_owner_decl.has_tv); - const fn_type = fn_owner_decl.ty; + const fn_type = fn_owner_decl.typeOf(zcu); const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); const target = &namespace.file_scope.mod.resolved_target.result; diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 43ffd11097..ab1b41a25e 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -349,7 +349,7 @@ pub fn generate( const func = zcu.funcInfo(func_index); const fn_owner_decl = zcu.declPtr(func.owner_decl); assert(fn_owner_decl.has_tv); - const fn_type = fn_owner_decl.ty; + const fn_type = fn_owner_decl.typeOf(zcu); const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); const target = &namespace.file_scope.mod.resolved_target.result; diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index 9e4870222d..e7a872d616 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -230,7 +230,7 @@ pub fn generate( const func = zcu.funcInfo(func_index); const fn_owner_decl = zcu.declPtr(func.owner_decl); assert(fn_owner_decl.has_tv); - const fn_type = fn_owner_decl.ty; + const fn_type = fn_owner_decl.typeOf(zcu); const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); const target = &namespace.file_scope.mod.resolved_target.result; diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index b6b3f30879..d3417fd6de 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -273,7 +273,7 @@ pub fn generate( const func = zcu.funcInfo(func_index); const fn_owner_decl = zcu.declPtr(func.owner_decl); assert(fn_owner_decl.has_tv); - const fn_type = fn_owner_decl.ty; + const fn_type = fn_owner_decl.typeOf(zcu); const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); const target = &namespace.file_scope.mod.resolved_target.result; diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 6d12382d8b..e90a68bea5 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -1243,12 +1243,12 @@ pub fn generate( fn genFunc(func: *CodeGen) InnerError!void { const mod = func.bin_file.base.comp.module.?; const ip = &mod.intern_pool; - const fn_info = mod.typeToFunc(func.decl.ty).?; + const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?; var func_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types.get(ip), Type.fromInterned(fn_info.return_type), mod); defer func_type.deinit(func.gpa); _ = try func.bin_file.storeDeclType(func.decl_index, func_type); - var cc_result = try func.resolveCallingConventionValues(func.decl.ty); + var cc_result = try func.resolveCallingConventionValues(func.decl.typeOf(mod)); defer cc_result.deinit(func.gpa); func.args = cc_result.args; @@ -2087,7 +2087,7 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { const mod = func.bin_file.base.comp.module.?; const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op; const operand = try func.resolveInst(un_op); - const fn_info = mod.typeToFunc(func.decl.ty).?; + const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?; const ret_ty = Type.fromInterned(fn_info.return_type); // result must be stored in the stack and we return a pointer @@ -2135,7 +2135,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { break :result try func.allocStack(Type.usize); // create pointer to void } - const fn_info = mod.typeToFunc(func.decl.ty).?; + const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?; if (firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), mod)) { break :result func.return_value; } @@ -2152,7 +2152,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { const operand = try func.resolveInst(un_op); const ret_ty = func.typeOf(un_op).childType(mod); - const fn_info = mod.typeToFunc(func.decl.ty).?; + const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?; if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) { if (ret_ty.isError(mod)) { try func.addImm32(0); @@ -2193,7 +2193,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif break :blk function.owner_decl; } else if (func_val.getExternFunc(mod)) |extern_func| { const ext_decl = mod.declPtr(extern_func.decl); - const ext_info = mod.typeToFunc(ext_decl.ty).?; + const ext_info = mod.typeToFunc(ext_decl.typeOf(mod)).?; var func_type = try genFunctype(func.gpa, ext_info.cc, ext_info.param_types.get(ip), Type.fromInterned(ext_info.return_type), mod); defer func_type.deinit(func.gpa); const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_func.decl); @@ -2530,7 +2530,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { const mod = func.bin_file.base.comp.module.?; const arg_index = func.arg_index; const arg = func.args[arg_index]; - const cc = mod.typeToFunc(func.decl.ty).?.cc; + const cc = mod.typeToFunc(func.decl.typeOf(mod)).?.cc; const arg_ty = func.typeOfIndex(inst); if (cc == .C) { const arg_classes = abi.classifyType(arg_ty, mod); @@ -3122,7 +3122,7 @@ fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: InternPool.Dec const mod = func.bin_file.base.comp.module.?; const decl = mod.declPtr(decl_index); try mod.markDeclAlive(decl); - const ptr_ty = try mod.singleMutPtrType(decl.ty); + const ptr_ty = try mod.singleMutPtrType(decl.typeOf(mod)); return func.lowerDeclRefValue(.{ .ty = ptr_ty, .val = ptr_val }, decl_index, offset); } @@ -3173,7 +3173,8 @@ fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: InternPool.Decl return func.lowerDeclRefValue(tv, func_val.decl, offset); } } - if (decl.ty.zigTypeTag(mod) != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime(mod)) { + const decl_ty = decl.typeOf(mod); + if (decl_ty.zigTypeTag(mod) != .Fn and !decl_ty.hasRuntimeBitsIgnoreComptime(mod)) { return WValue{ .imm32 = 0xaaaaaaaa }; } @@ -3182,7 +3183,7 @@ fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: InternPool.Decl const atom = func.bin_file.getAtom(atom_index); const target_sym_index = @intFromEnum(atom.sym_index); - if (decl.ty.zigTypeTag(mod) == .Fn) { + if (decl_ty.zigTypeTag(mod) == .Fn) { return WValue{ .function_index = target_sym_index }; } else if (offset == 0) { return WValue{ .memory = target_sym_index }; diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 7db294a37b..273358a6d2 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -808,7 +808,7 @@ pub fn generate( const func = zcu.funcInfo(func_index); const fn_owner_decl = zcu.declPtr(func.owner_decl); assert(fn_owner_decl.has_tv); - const fn_type = fn_owner_decl.ty; + const fn_type = fn_owner_decl.typeOf(zcu); const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); const mod = namespace.file_scope.mod; diff --git a/src/codegen.zig b/src/codegen.zig index 6015270739..5bc0d1a81f 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -829,8 +829,8 @@ fn lowerDeclRef( const target = namespace.file_scope.mod.resolved_target.result; const ptr_width = target.ptrBitWidth(); - const is_fn_body = decl.ty.zigTypeTag(zcu) == .Fn; - if (!is_fn_body and !decl.ty.hasRuntimeBits(zcu)) { + const is_fn_body = decl.typeOf(zcu).zigTypeTag(zcu) == .Fn; + if (!is_fn_body and !decl.typeOf(zcu).hasRuntimeBits(zcu)) { try code.appendNTimes(0xaa, @divExact(ptr_width, 8)); return Result.ok; } @@ -932,7 +932,7 @@ fn genDeclRef( }; const decl = zcu.declPtr(decl_index); - if (!decl.ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) { + if (!decl.typeOf(zcu).isFnOrHasRuntimeBitsIgnoreComptime(zcu)) { const imm: u64 = switch (ptr_bytes) { 1 => 0xaa, 2 => 0xaaaa, diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 9b856de111..32ad38cd4d 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -657,7 +657,7 @@ pub const DeclGen = struct { assert(decl.has_tv); // Render an undefined pointer if we have a pointer to a zero-bit or comptime type. - if (ty.isPtrAtRuntime(mod) and !decl.ty.isFnOrHasRuntimeBits(mod)) { + if (ty.isPtrAtRuntime(mod) and !decl.typeOf(mod).isFnOrHasRuntimeBits(mod)) { return dg.writeCValue(writer, .{ .undef = ty }); } @@ -673,7 +673,7 @@ pub const DeclGen = struct { // them). The analysis until now should ensure that the C function // pointers are compatible. If they are not, then there is a bug // somewhere and we should let the C compiler tell us about it. - const need_typecast = if (ty.castPtrToFn(mod)) |_| false else !ty.childType(mod).eql(decl.ty, mod); + const need_typecast = if (ty.castPtrToFn(mod)) |_| false else !ty.childType(mod).eql(decl.typeOf(mod), mod); if (need_typecast) { try writer.writeAll("(("); try dg.renderType(writer, ty); @@ -1588,9 +1588,10 @@ pub const DeclGen = struct { const ip = &mod.intern_pool; const fn_decl = mod.declPtr(fn_decl_index); - const fn_cty_idx = try dg.typeToIndex(fn_decl.ty, kind); + const fn_ty = fn_decl.typeOf(mod); + const fn_cty_idx = try dg.typeToIndex(fn_ty, kind); - const fn_info = mod.typeToFunc(fn_decl.ty).?; + const fn_info = mod.typeToFunc(fn_ty).?; if (fn_info.cc == .Naked) { switch (kind) { .forward => try w.writeAll("zig_naked_decl "), @@ -1971,7 +1972,7 @@ pub const DeclGen = struct { ) !void { const decl = dg.module.declPtr(decl_index); const fwd = dg.fwdDeclWriter(); - const is_global = variable.is_extern or dg.declIsGlobal(.{ .ty = decl.ty, .val = decl.val }); + const is_global = variable.is_extern or dg.declIsGlobal(.{ .ty = decl.typeOf(dg.module), .val = decl.val }); try fwd.writeAll(if (is_global) "zig_extern " else "static "); const maybe_exports = dg.module.decl_exports.get(decl_index); const export_weak_linkage = if (maybe_exports) |exports| @@ -1982,7 +1983,7 @@ pub const DeclGen = struct { if (variable.is_threadlocal) try fwd.writeAll("zig_threadlocal "); try dg.renderTypeAndName( fwd, - decl.ty, + decl.typeOf(dg.module), .{ .decl = decl_index }, CQualifiers.init(.{ .@"const" = variable.is_const }), decl.alignment, @@ -2656,7 +2657,7 @@ fn genExports(o: *Object) !void { .anon, .flush => return, }; const decl = mod.declPtr(decl_index); - const tv: TypedValue = .{ .ty = decl.ty, .val = Value.fromInterned((try decl.internValue(mod))) }; + const tv: TypedValue = .{ .ty = decl.typeOf(mod), .val = Value.fromInterned((try decl.internValue(mod))) }; const fwd = o.dg.fwdDeclWriter(); const exports = mod.decl_exports.get(decl_index) orelse return; @@ -2687,7 +2688,7 @@ fn genExports(o: *Object) !void { const export_name = ip.stringToSlice(@"export".opts.name); try o.dg.renderTypeAndName( fwd, - decl.ty, + decl.typeOf(mod), .{ .identifier = export_name }, CQualifiers.init(.{ .@"const" = is_variable_const }), decl.alignment, @@ -2769,7 +2770,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void { }, .never_tail, .never_inline => |fn_decl_index| { const fn_decl = mod.declPtr(fn_decl_index); - const fn_cty = try o.dg.typeToCType(fn_decl.ty, .complete); + const fn_cty = try o.dg.typeToCType(fn_decl.typeOf(mod), .complete); const fn_info = fn_cty.cast(CType.Payload.Function).?.data; const fwd_decl_writer = o.dg.fwdDeclWriter(); @@ -2806,7 +2807,7 @@ pub fn genFunc(f: *Function) !void { const decl_index = o.dg.pass.decl; const decl = mod.declPtr(decl_index); const tv: TypedValue = .{ - .ty = decl.ty, + .ty = decl.typeOf(mod), .val = decl.val, }; @@ -2893,7 +2894,7 @@ pub fn genDecl(o: *Object) !void { const mod = o.dg.module; const decl_index = o.dg.pass.decl; const decl = mod.declPtr(decl_index); - const tv: TypedValue = .{ .ty = decl.ty, .val = Value.fromInterned((try decl.internValue(mod))) }; + const tv: TypedValue = .{ .ty = decl.typeOf(mod), .val = Value.fromInterned((try decl.internValue(mod))) }; if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return; if (tv.val.getExternFunc(mod)) |_| { @@ -2979,7 +2980,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void { const decl_index = dg.pass.decl; const decl = mod.declPtr(decl_index); const tv: TypedValue = .{ - .ty = decl.ty, + .ty = decl.typeOf(mod), .val = decl.val, }; const writer = dg.fwdDeclWriter(); @@ -7392,7 +7393,7 @@ fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue { const inst_ty = f.typeOfIndex(inst); const decl_index = f.object.dg.pass.decl; const decl = mod.declPtr(decl_index); - const fn_cty = try f.typeToCType(decl.ty, .complete); + const fn_cty = try f.typeToCType(decl.typeOf(mod), .complete); const param_len = fn_cty.castTag(.varargs_function).?.data.param_types.len; const writer = f.object.writer(); diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 7c198a7733..cef6a9f7f3 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1384,7 +1384,7 @@ pub const Object = struct { const decl = zcu.declPtr(decl_index); const namespace = zcu.namespacePtr(decl.src_namespace); const owner_mod = namespace.file_scope.mod; - const fn_info = zcu.typeToFunc(decl.ty).?; + const fn_info = zcu.typeToFunc(decl.typeOf(zcu)).?; const target = zcu.getTarget(); const ip = &zcu.intern_pool; @@ -1659,7 +1659,7 @@ pub const Object = struct { const line_number = decl.src_line + 1; const is_internal_linkage = decl.val.getExternFunc(zcu) == null and !zcu.decl_exports.contains(decl_index); - const debug_decl_type = try o.lowerDebugType(decl.ty); + const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu)); const subprogram = try o.builder.debugSubprogram( file, @@ -2881,7 +2881,7 @@ pub const Object = struct { const decl = zcu.declPtr(decl_index); const namespace = zcu.namespacePtr(decl.src_namespace); const owner_mod = namespace.file_scope.mod; - const zig_fn_type = decl.ty; + const zig_fn_type = decl.typeOf(zcu); const gop = try o.decl_map.getOrPut(gpa, decl_index); if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function; @@ -3112,7 +3112,7 @@ pub const Object = struct { try o.builder.strtabString(mod.intern_pool.stringToSlice( if (is_extern) decl.name else try decl.fullyQualifiedName(mod), )), - try o.lowerType(decl.ty), + try o.lowerType(decl.typeOf(mod)), toLlvmGlobalAddressSpace(decl.@"addrspace", mod.getTarget()), ); gop.value_ptr.* = variable_index.ptrConst(&o.builder).global; @@ -4263,7 +4263,7 @@ pub const Object = struct { const mod = o.module; const decl = mod.declPtr(decl_index); try mod.markDeclAlive(decl); - const ptr_ty = try mod.singleMutPtrType(decl.ty); + const ptr_ty = try mod.singleMutPtrType(decl.typeOf(mod)); return o.lowerDeclRefValue(ptr_ty, decl_index); } @@ -4450,9 +4450,10 @@ pub const Object = struct { } } - const is_fn_body = decl.ty.zigTypeTag(mod) == .Fn; - if ((!is_fn_body and !decl.ty.hasRuntimeBits(mod)) or - (is_fn_body and mod.typeToFunc(decl.ty).?.is_generic)) return o.lowerPtrToVoid(ty); + const decl_ty = decl.typeOf(mod); + const is_fn_body = decl_ty.zigTypeTag(mod) == .Fn; + if ((!is_fn_body and !decl_ty.hasRuntimeBits(mod)) or + (is_fn_body and mod.typeToFunc(decl_ty).?.is_generic)) return o.lowerPtrToVoid(ty); try mod.markDeclAlive(decl); @@ -4740,7 +4741,7 @@ pub const DeclGen = struct { debug_file, // File debug_file, // Scope line_number, - try o.lowerDebugType(decl.ty), + try o.lowerDebugType(decl.typeOf(zcu)), variable_index, .{ .local = is_internal_linkage }, ); @@ -5530,7 +5531,7 @@ pub const FuncGen = struct { const mod = o.module; const msg_decl_index = mod.panic_messages[@intFromEnum(panic_id)].unwrap().?; const msg_decl = mod.declPtr(msg_decl_index); - const msg_len = msg_decl.ty.childType(mod).arrayLen(mod); + const msg_len = msg_decl.typeOf(mod).childType(mod).arrayLen(mod); const msg_ptr = try o.lowerValue(try msg_decl.internValue(mod)); const null_opt_addr_global = try fg.resolveNullOptUsize(); const target = mod.getTarget(); @@ -5544,7 +5545,7 @@ pub const FuncGen = struct { // ) const panic_func = mod.funcInfo(mod.panic_func_index); const panic_decl = mod.declPtr(panic_func.owner_decl); - const fn_info = mod.typeToFunc(panic_decl.ty).?; + const fn_info = mod.typeToFunc(panic_decl.typeOf(mod)).?; const panic_global = try o.resolveLlvmFunction(panic_func.owner_decl); _ = try fg.wip.call( .normal, @@ -5612,7 +5613,7 @@ pub const FuncGen = struct { _ = try self.wip.retVoid(); return .none; } - const fn_info = mod.typeToFunc(self.dg.decl.ty).?; + const fn_info = mod.typeToFunc(self.dg.decl.typeOf(mod)).?; if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) { if (Type.fromInterned(fn_info.return_type).isError(mod)) { // Functions with an empty error set are emitted with an error code @@ -5674,7 +5675,7 @@ pub const FuncGen = struct { const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; const ptr_ty = self.typeOf(un_op); const ret_ty = ptr_ty.childType(mod); - const fn_info = mod.typeToFunc(self.dg.decl.ty).?; + const fn_info = mod.typeToFunc(self.dg.decl.typeOf(mod)).?; if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) { if (Type.fromInterned(fn_info.return_type).isError(mod)) { // Functions with an empty error set are emitted with an error code diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index 10bbe2204d..17b44806e2 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -1221,7 +1221,7 @@ const DeclGen = struct { else => {}, } - if (!decl.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) { + if (!decl.typeOf(mod).isFnOrHasRuntimeBitsIgnoreComptime(mod)) { // Pointer to nothing - return undefined. return self.spv.constUndef(ty_ref); } @@ -1237,7 +1237,7 @@ const DeclGen = struct { const final_storage_class = self.spvStorageClass(decl.@"addrspace"); try self.addFunctionDep(spv_decl_index, final_storage_class); - const decl_ptr_ty_ref = try self.ptrType(decl.ty, final_storage_class); + const decl_ptr_ty_ref = try self.ptrType(decl.typeOf(mod), final_storage_class); const ptr_id = switch (final_storage_class) { .Generic => try self.castToGeneric(self.typeId(decl_ptr_ty_ref), decl_id), @@ -2044,11 +2044,11 @@ const DeclGen = struct { switch (self.spv.declPtr(spv_decl_index).kind) { .func => { - assert(decl.ty.zigTypeTag(mod) == .Fn); - const fn_info = mod.typeToFunc(decl.ty).?; + assert(decl.typeOf(mod).zigTypeTag(mod) == .Fn); + const fn_info = mod.typeToFunc(decl.typeOf(mod)).?; const return_ty_ref = try self.resolveFnReturnType(Type.fromInterned(fn_info.return_type)); - const prototype_ty_ref = try self.resolveType(decl.ty, .direct); + const prototype_ty_ref = try self.resolveType(decl.typeOf(mod), .direct); try self.func.prologue.emit(self.spv.gpa, .OpFunction, .{ .id_result_type = self.typeId(return_ty_ref), .id_result = result_id, @@ -2121,7 +2121,7 @@ const DeclGen = struct { const final_storage_class = self.spvStorageClass(decl.@"addrspace"); assert(final_storage_class != .Generic); // These should be instance globals - const ptr_ty_ref = try self.ptrType(decl.ty, final_storage_class); + const ptr_ty_ref = try self.ptrType(decl.typeOf(mod), final_storage_class); try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpVariable, .{ .id_result_type = self.typeId(ptr_ty_ref), @@ -2144,7 +2144,7 @@ const DeclGen = struct { try self.spv.declareDeclDeps(spv_decl_index, &.{}); - const ptr_ty_ref = try self.ptrType(decl.ty, .Function); + const ptr_ty_ref = try self.ptrType(decl.typeOf(mod), .Function); if (maybe_init_val) |init_val| { // TODO: Combine with resolveAnonDecl? @@ -2168,7 +2168,7 @@ const DeclGen = struct { }); self.current_block_label = root_block_id; - const val_id = try self.constant(decl.ty, init_val, .indirect); + const val_id = try self.constant(decl.typeOf(mod), init_val, .indirect); try self.func.body.emit(self.spv.gpa, .OpStore, .{ .pointer = result_id, .object = val_id, @@ -4785,7 +4785,7 @@ const DeclGen = struct { const mod = self.module; if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) { const decl = mod.declPtr(self.decl_index); - const fn_info = mod.typeToFunc(decl.ty).?; + const fn_info = mod.typeToFunc(decl.typeOf(mod)).?; if (Type.fromInterned(fn_info.return_type).isError(mod)) { // Functions with an empty error set are emitted with an error code // return type and return zero so they can be function pointers coerced @@ -4810,7 +4810,7 @@ const DeclGen = struct { if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) { const decl = mod.declPtr(self.decl_index); - const fn_info = mod.typeToFunc(decl.ty).?; + const fn_info = mod.typeToFunc(decl.typeOf(mod)).?; if (Type.fromInterned(fn_info.return_type).isError(mod)) { // Functions with an empty error set are emitted with an error code // return type and return zero so they can be function pointers coerced diff --git a/src/link/C.zig b/src/link/C.zig index 59ebed800b..1bfe55c70a 100644 --- a/src/link/C.zig +++ b/src/link/C.zig @@ -209,7 +209,7 @@ pub fn updateFunc( .module = module, .error_msg = null, .pass = .{ .decl = decl_index }, - .is_naked_fn = decl.ty.fnCallingConvention(module) == .Naked, + .is_naked_fn = decl.typeOf(module).fnCallingConvention(module) == .Naked, .fwd_decl = fwd_decl.toManaged(gpa), .ctypes = ctypes.*, .anon_decl_deps = self.anon_decls, diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 206cf7348c..01fa6cac67 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -1272,7 +1272,7 @@ pub fn updateDecl( const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ - .ty = decl.ty, + .ty = decl.typeOf(mod), .val = decl_val, }, &code_buffer, .none, .{ .parent_atom_index = atom.getSymbolIndex().?, @@ -1399,8 +1399,8 @@ pub fn getOrCreateAtomForDecl(self: *Coff, decl_index: InternPool.DeclIndex) !At fn getDeclOutputSection(self: *Coff, decl_index: InternPool.DeclIndex) u16 { const decl = self.base.comp.module.?.declPtr(decl_index); - const ty = decl.ty; const mod = self.base.comp.module.?; + const ty = decl.typeOf(mod); const zig_ty = ty.zigTypeTag(mod); const val = decl.val; const index: u16 = blk: { @@ -1535,7 +1535,7 @@ pub fn updateExports( .x86 => std.builtin.CallingConvention.Stdcall, else => std.builtin.CallingConvention.C, }; - const decl_cc = exported_decl.ty.fnCallingConvention(mod); + const decl_cc = exported_decl.typeOf(mod).fnCallingConvention(mod); if (decl_cc == .C and ip.stringEqlSlice(exp.opts.name, "main") and comp.config.link_libc) { diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 26eb536c08..e2d4669156 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -1109,7 +1109,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde assert(decl.has_tv); - switch (decl.ty.zigTypeTag(mod)) { + switch (decl.typeOf(mod).zigTypeTag(mod)) { .Fn => { _ = try self.getOrCreateAtomForDecl(.src_fn, decl_index); @@ -1162,7 +1162,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde try dbg_info_buffer.ensureUnusedCapacity(1 + ptr_width_bytes + 4 + 4 + (decl_name_slice.len + 1) + (decl_linkage_name_slice.len + 1)); - const fn_ret_type = decl.ty.fnReturnType(mod); + const fn_ret_type = decl.typeOf(mod).fnReturnType(mod); const fn_ret_has_bits = fn_ret_type.hasRuntimeBits(mod); dbg_info_buffer.appendAssumeCapacity(@intFromEnum( @as(AbbrevCode, if (fn_ret_has_bits) .subprogram else .subprogram_retvoid), @@ -1215,7 +1215,7 @@ pub fn commitDeclState( var dbg_info_buffer = &decl_state.dbg_info; assert(decl.has_tv); - switch (decl.ty.zigTypeTag(zcu)) { + switch (decl.typeOf(zcu).zigTypeTag(zcu)) { .Fn => { try decl_state.setInlineFunc(decl.val.toIntern()); diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index 4c86bb3a89..3bf6f1246c 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -846,7 +846,7 @@ fn getDeclShdrIndex( _ = self; const mod = elf_file.base.comp.module.?; const any_non_single_threaded = elf_file.base.comp.config.any_non_single_threaded; - const shdr_index = switch (decl.ty.zigTypeTag(mod)) { + const shdr_index = switch (decl.typeOf(mod).zigTypeTag(mod)) { .Fn => elf_file.zig_text_section_index.?, else => blk: { if (decl.getOwnedVariable(mod)) |variable| { @@ -1158,7 +1158,7 @@ pub fn updateDecl( const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; const res = if (decl_state) |*ds| try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{ - .ty = decl.ty, + .ty = decl.typeOf(mod), .val = decl_val, }, &code_buffer, .{ .dwarf = ds, @@ -1167,7 +1167,7 @@ pub fn updateDecl( }) else try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{ - .ty = decl.ty, + .ty = decl.typeOf(mod), .val = decl_val, }, &code_buffer, .none, .{ .parent_atom_index = sym_index, diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index bfd02fbd78..42f186d961 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -740,7 +740,7 @@ pub fn updateDecl( const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none; const res = try codegen.generateSymbol(&macho_file.base, decl.srcLoc(mod), .{ - .ty = decl.ty, + .ty = decl.typeOf(mod), .val = decl_val, }, &code_buffer, dio, .{ .parent_atom_index = sym_index, @@ -1021,7 +1021,7 @@ fn getDeclOutputSection( _ = self; const mod = macho_file.base.comp.module.?; const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded; - const sect_id: u8 = switch (decl.ty.zigTypeTag(mod)) { + const sect_id: u8 = switch (decl.typeOf(mod).zigTypeTag(mod)) { .Fn => macho_file.zig_text_sect_index.?, else => blk: { if (decl.getOwnedVariable(mod)) |variable| { diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig index e14fc18a55..d092351c47 100644 --- a/src/link/Plan9.zig +++ b/src/link/Plan9.zig @@ -177,7 +177,7 @@ pub const Atom = struct { return if (self.code_ptr) |p| p[0..self.other.code_len] else blk: { const decl_index = self.other.decl_index; const decl = mod.declPtr(decl_index); - if (decl.ty.zigTypeTag(mod) == .Fn) { + if (decl.typeOf(mod).zigTypeTag(mod) == .Fn) { const table = plan9.fn_decl_table.get(decl.getFileScope(mod)).?.functions; const output = table.get(decl_index).?; break :blk output.code; @@ -540,7 +540,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex) const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; // TODO we need the symbol index for symbol in the table of locals for the containing atom const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ - .ty = decl.ty, + .ty = decl.typeOf(mod), .val = decl_val, }, &code_buffer, .{ .none = {} }, .{ .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)), @@ -566,7 +566,7 @@ fn updateFinish(self: *Plan9, decl_index: InternPool.DeclIndex) !void { const gpa = self.base.comp.gpa; const mod = self.base.comp.module.?; const decl = mod.declPtr(decl_index); - const is_fn = (decl.ty.zigTypeTag(mod) == .Fn); + const is_fn = (decl.typeOf(mod).zigTypeTag(mod) == .Fn); const sym_t: aout.Sym.Type = if (is_fn) .t else .d; const atom = self.getAtomPtr(self.decls.get(decl_index).?.index); diff --git a/src/link/SpirV.zig b/src/link/SpirV.zig index 27172c3fd3..dc25ac5105 100644 --- a/src/link/SpirV.zig +++ b/src/link/SpirV.zig @@ -163,7 +163,7 @@ pub fn updateExports( if (decl.val.isFuncBody(mod)) { const target = mod.getTarget(); const spv_decl_index = try self.object.resolveDecl(mod, decl_index); - const execution_model = switch (decl.ty.fnCallingConvention(mod)) { + const execution_model = switch (decl.typeOf(mod).fnCallingConvention(mod)) { .Vertex => spec.ExecutionModel.Vertex, .Fragment => spec.ExecutionModel.Fragment, .Kernel => spec.ExecutionModel.Kernel, diff --git a/src/link/Wasm/ZigObject.zig b/src/link/Wasm/ZigObject.zig index 30aab49cb1..293c088c66 100644 --- a/src/link/Wasm/ZigObject.zig +++ b/src/link/Wasm/ZigObject.zig @@ -270,7 +270,7 @@ pub fn updateDecl( const res = try codegen.generateSymbol( &wasm_file.base, decl.srcLoc(mod), - .{ .ty = decl.ty, .val = val }, + .{ .ty = decl.typeOf(mod), .val = val }, &code_writer, .none, .{ .parent_atom_index = @intFromEnum(atom.sym_index) }, @@ -346,7 +346,7 @@ fn finishUpdateDecl( try atom.code.appendSlice(gpa, code); atom.size = @intCast(code.len); - switch (decl.ty.zigTypeTag(mod)) { + switch (decl.typeOf(mod).zigTypeTag(mod)) { .Fn => { sym.index = try zig_object.appendFunction(gpa, .{ .type_index = zig_object.atom_types.get(atom_index).? }); sym.tag = .function; @@ -764,7 +764,7 @@ pub fn getDeclVAddr( const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?; const atom = wasm_file.getAtomPtr(atom_index); const is_wasm32 = target.cpu.arch == .wasm32; - if (decl.ty.zigTypeTag(mod) == .Fn) { + if (decl.typeOf(mod).zigTypeTag(mod) == .Fn) { std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations try atom.relocs.append(gpa, .{ .index = target_symbol_index, @@ -964,7 +964,7 @@ pub fn freeDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_index: InternPool if (sym.isGlobal()) { std.debug.assert(zig_object.global_syms.remove(atom.sym_index)); } - switch (decl.ty.zigTypeTag(mod)) { + switch (decl.typeOf(mod).zigTypeTag(mod)) { .Fn => { zig_object.functions_free_list.append(gpa, sym.index) catch {}; std.debug.assert(zig_object.atom_types.remove(atom_index));