authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-03-25 19:02:21+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-03-26 13:48:06+00:00
logc6f3e9d79cf849623e6c4f25e02e17cdfab07b7c
tree0efc0142dd23a67509015113b9e1a3aaa2d6c15a
parent341857e5cd4fd4453cf9c7d1a6679feb66710d84
signaturelock-open Commit is signed but in an unrecognized format.

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`.

23 files changed, 120 insertions(+), 123 deletions(-)

src/InternPool.zig-4
......@@ -6581,7 +6581,6 @@ pub fn getFuncInstance(ip: *InternPool, gpa: Allocator, arg: GetFuncInstanceKey)
65816581 generic_owner,
65826582 func_index,
65836583 func_extra_index,
6584 func_ty,
65856584 arg.alignment,
65866585 arg.section,
65876586 );
......@@ -6711,7 +6710,6 @@ pub fn getFuncInstanceIes(
67116710 generic_owner,
67126711 func_index,
67136712 func_extra_index,
6714 func_ty,
67156713 arg.alignment,
67166714 arg.section,
67176715 );
......@@ -6723,7 +6721,6 @@ fn finishFuncInstance(
67236721 generic_owner: Index,
67246722 func_index: Index,
67256723 func_extra_index: u32,
6726 func_ty: Index,
67276724 alignment: Alignment,
67286725 section: OptionalNullTerminatedString,
67296726) Allocator.Error!Index {
......@@ -6735,7 +6732,6 @@ fn finishFuncInstance(
67356732 .src_line = fn_owner_decl.src_line,
67366733 .has_tv = true,
67376734 .owns_tv = true,
6738 .ty = @import("type.zig").Type.fromInterned(func_ty),
67396735 .val = @import("Value.zig").fromInterned(func_index),
67406736 .alignment = alignment,
67416737 .@"linksection" = section,
src/Module.zig+25-26
......@@ -330,9 +330,6 @@ const ValueArena = struct {
330330
331331pub const Decl = struct {
332332 name: InternPool.NullTerminatedString,
333 /// The most recent Type of the Decl after a successful semantic analysis.
334 /// Populated when `has_tv`.
335 ty: Type,
336333 /// The most recent Value of the Decl after a successful semantic analysis.
337334 /// Populated when `has_tv`.
338335 val: Value,
......@@ -487,20 +484,28 @@ pub const Decl = struct {
487484 zcu.namespacePtr(decl.src_namespace).fullyQualifiedName(zcu, decl.name);
488485 }
489486
490 pub fn typedValue(decl: Decl) error{AnalysisFail}!TypedValue {
487 pub fn typeOf(decl: Decl, zcu: *const Zcu) Type {
488 assert(decl.has_tv);
489 return Type.fromInterned(zcu.intern_pool.typeOf(decl.val.toIntern()));
490 }
491
492 pub fn typedValue(decl: Decl, zcu: *const Zcu) error{AnalysisFail}!TypedValue {
491493 if (!decl.has_tv) return error.AnalysisFail;
492 return TypedValue{ .ty = decl.ty, .val = decl.val };
494 return .{
495 .ty = decl.typeOf(zcu),
496 .val = decl.val,
497 };
493498 }
494499
495500 pub fn internValue(decl: *Decl, zcu: *Zcu) Allocator.Error!InternPool.Index {
496501 assert(decl.has_tv);
497 const ip_index = try decl.val.intern(decl.ty, zcu);
502 const ip_index = try decl.val.intern(decl.typeOf(zcu), zcu);
498503 decl.val = Value.fromInterned(ip_index);
499504 return ip_index;
500505 }
501506
502507 pub fn isFunction(decl: Decl, zcu: *const Zcu) !bool {
503 const tv = try decl.typedValue();
508 const tv = try decl.typedValue(zcu);
504509 return tv.ty.zigTypeTag(zcu) == .Fn;
505510 }
506511
......@@ -590,7 +595,7 @@ pub const Decl = struct {
590595 @tagName(decl.analysis),
591596 });
592597 if (decl.has_tv) {
593 std.debug.print(" ty={} val={}", .{ decl.ty, decl.val });
598 std.debug.print(" val={}", .{decl.val});
594599 }
595600 std.debug.print("\n", .{});
596601 }
......@@ -615,7 +620,7 @@ pub const Decl = struct {
615620 pub fn getAlignment(decl: Decl, zcu: *Zcu) Alignment {
616621 assert(decl.has_tv);
617622 if (decl.alignment != .none) return decl.alignment;
618 return decl.ty.abiAlignment(zcu);
623 return decl.typeOf(zcu).abiAlignment(zcu);
619624 }
620625
621626 /// Upgrade a `LazySrcLoc` to a `SrcLoc` based on the `Decl` provided.
......@@ -3525,7 +3530,6 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {
35253530 new_decl.src_line = 0;
35263531 new_decl.is_pub = true;
35273532 new_decl.is_exported = false;
3528 new_decl.ty = Type.type;
35293533 new_decl.alignment = .none;
35303534 new_decl.@"linksection" = .none;
35313535 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 {
35943598
35953599 const old_has_tv = decl.has_tv;
35963600 // The following values are ignored if `!old_has_tv`
3597 const old_ty = decl.ty;
3601 const old_ty = decl.typeOf(mod);
35983602 const old_val = decl.val;
35993603 const old_align = decl.alignment;
36003604 const old_linksection = decl.@"linksection";
......@@ -3716,7 +3720,6 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
37163720 return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)});
37173721 }
37183722
3719 decl.ty = Type.fromInterned(InternPool.Index.type_type);
37203723 decl.val = ty.toValue();
37213724 decl.alignment = .none;
37223725 decl.@"linksection" = .none;
......@@ -3760,7 +3763,6 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
37603763 },
37613764 }
37623765
3763 decl.ty = decl_tv.ty;
37643766 decl.val = Value.fromInterned((try decl_tv.val.intern(decl_tv.ty, mod)));
37653767 // Function linksection, align, and addrspace were already set by Sema
37663768 if (!is_func) {
......@@ -3806,10 +3808,10 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
38063808 decl.analysis = .complete;
38073809
38083810 const result: SemaDeclResult = if (old_has_tv) .{
3809 .invalidate_decl_val = !decl.ty.eql(old_ty, mod) or
3810 !decl.val.eql(old_val, decl.ty, mod) or
3811 .invalidate_decl_val = !decl_tv.ty.eql(old_ty, mod) or
3812 !decl.val.eql(old_val, decl_tv.ty, mod) or
38113813 is_inline != old_is_inline,
3812 .invalidate_decl_ref = !decl.ty.eql(old_ty, mod) or
3814 .invalidate_decl_ref = !decl_tv.ty.eql(old_ty, mod) or
38133815 decl.alignment != old_align or
38143816 decl.@"linksection" != old_linksection or
38153817 decl.@"addrspace" != old_addrspace or
......@@ -3819,11 +3821,11 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
38193821 .invalidate_decl_ref = true,
38203822 };
38213823
3822 const has_runtime_bits = queue_linker_work and (is_func or try sema.typeHasRuntimeBits(decl.ty));
3824 const has_runtime_bits = queue_linker_work and (is_func or try sema.typeHasRuntimeBits(decl_tv.ty));
38233825 if (has_runtime_bits) {
38243826 // Needed for codegen_decl which will call updateDecl and then the
38253827 // codegen backend wants full access to the Decl Type.
3826 try sema.resolveTypeFully(decl.ty);
3828 try sema.resolveTypeFully(decl_tv.ty);
38273829
38283830 try mod.comp.work_queue.writeItem(.{ .codegen_decl = decl_index });
38293831
......@@ -3850,7 +3852,7 @@ fn semaAnonOwnerDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult {
38503852
38513853 log.debug("semaAnonOwnerDecl '{d}'", .{@intFromEnum(decl_index)});
38523854
3853 switch (decl.ty.zigTypeTag(zcu)) {
3855 switch (decl.typeOf(zcu).zigTypeTag(zcu)) {
38543856 .Fn => @panic("TODO: update fn instance"),
38553857 .Type => {},
38563858 else => unreachable,
......@@ -4479,7 +4481,7 @@ pub fn finalizeAnonDecl(mod: *Module, decl_index: Decl.Index) Allocator.Error!vo
44794481 // if the Decl is referenced by an instruction or another constant. Otherwise,
44804482 // the Decl will be garbage collected by the `codegen_decl` task instead of sent
44814483 // to the linker.
4482 if (mod.declPtr(decl_index).ty.isFnOrHasRuntimeBits(mod)) {
4484 if (mod.declPtr(decl_index).typeOf(mod).isFnOrHasRuntimeBits(mod)) {
44834485 try mod.comp.anon_work_queue.writeItem(.{ .codegen_decl = decl_index });
44844486 }
44854487}
......@@ -4563,7 +4565,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
45634565 // the runtime-known parameters only, not to be confused with the
45644566 // generic_owner function type, which potentially has more parameters,
45654567 // including comptime parameters.
4566 const fn_ty = decl.ty;
4568 const fn_ty = decl.typeOf(mod);
45674569 const fn_ty_info = mod.typeToFunc(fn_ty).?;
45684570
45694571 var sema: Sema = .{
......@@ -4812,7 +4814,6 @@ pub fn allocateNewDecl(
48124814 .src_line = undefined,
48134815 .has_tv = false,
48144816 .owns_tv = false,
4815 .ty = undefined,
48164817 .val = undefined,
48174818 .alignment = undefined,
48184819 .@"linksection" = .none,
......@@ -4889,7 +4890,6 @@ pub fn initNewAnonDecl(
48894890
48904891 new_decl.name = name;
48914892 new_decl.src_line = src_line;
4892 new_decl.ty = typed_value.ty;
48934893 new_decl.val = typed_value.val;
48944894 new_decl.alignment = .none;
48954895 new_decl.@"linksection" = .none;
......@@ -5419,7 +5419,7 @@ pub fn populateTestFunctions(
54195419 try mod.ensureDeclAnalyzed(decl_index);
54205420 }
54215421 const decl = mod.declPtr(decl_index);
5422 const test_fn_ty = decl.ty.slicePtrFieldType(mod).childType(mod);
5422 const test_fn_ty = decl.typeOf(mod).slicePtrFieldType(mod).childType(mod);
54235423
54245424 const array_decl_index = d: {
54255425 // Add mod.test_functions to an array decl then make the test_functions
......@@ -5463,7 +5463,7 @@ pub fn populateTestFunctions(
54635463 // func
54645464 try mod.intern(.{ .ptr = .{
54655465 .ty = try mod.intern(.{ .ptr_type = .{
5466 .child = test_decl.ty.toIntern(),
5466 .child = test_decl.typeOf(mod).toIntern(),
54675467 .flags = .{
54685468 .is_const = true,
54695469 },
......@@ -5515,7 +5515,6 @@ pub fn populateTestFunctions(
55155515
55165516 // Since we are replacing the Decl's value we must perform cleanup on the
55175517 // previous value.
5518 decl.ty = new_ty;
55195518 decl.val = new_val;
55205519 decl.has_tv = true;
55215520 }
src/Sema.zig+16-17
......@@ -6425,16 +6425,17 @@ pub fn analyzeExport(
64256425
64266426 try mod.ensureDeclAnalyzed(exported_decl_index);
64276427 const exported_decl = mod.declPtr(exported_decl_index);
6428 const export_ty = exported_decl.typeOf(mod);
64286429
6429 if (!try sema.validateExternType(exported_decl.ty, .other)) {
6430 if (!try sema.validateExternType(export_ty, .other)) {
64306431 const msg = msg: {
6431 const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{exported_decl.ty.fmt(mod)});
6432 const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{export_ty.fmt(mod)});
64326433 errdefer msg.destroy(gpa);
64336434
64346435 const src_decl = mod.declPtr(block.src_decl);
6435 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), exported_decl.ty, .other);
6436 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), export_ty, .other);
64366437
6437 try sema.addDeclaredHereNote(msg, exported_decl.ty);
6438 try sema.addDeclaredHereNote(msg, export_ty);
64386439 break :msg msg;
64396440 };
64406441 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -6503,7 +6504,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
65036504 }
65046505
65056506 const fn_owner_decl = mod.funcOwnerDeclPtr(sema.func_index);
6506 switch (fn_owner_decl.ty.fnCallingConvention(mod)) {
6507 switch (fn_owner_decl.typeOf(mod).fnCallingConvention(mod)) {
65076508 .Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}),
65086509 .Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}),
65096510 else => if (block.inlining != null) {
......@@ -7692,7 +7693,7 @@ fn analyzeCall(
76927693 // comptime memory is mutated.
76937694 const memoized_arg_values = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len);
76947695
7695 const owner_info = mod.typeToFunc(fn_owner_decl.ty).?;
7696 const owner_info = mod.typeToFunc(fn_owner_decl.typeOf(mod)).?;
76967697 const new_param_types = try sema.arena.alloc(InternPool.Index, owner_info.param_types.len);
76977698 var new_fn_info: InternPool.GetFuncTypeKey = .{
76987699 .param_types = new_param_types,
......@@ -7960,9 +7961,9 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ
79607961 });
79617962 }
79627963 const func_decl = mod.funcOwnerDeclPtr(sema.owner_func_index);
7963 if (!func_ty.eql(func_decl.ty, mod)) {
7964 if (!func_ty.eql(func_decl.typeOf(mod), mod)) {
79647965 return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{}' does not match type of calling function '{}'", .{
7965 func_ty.fmt(mod), func_decl.ty.fmt(mod),
7966 func_ty.fmt(mod), func_decl.typeOf(mod).fmt(mod),
79667967 });
79677968 }
79687969 _ = try block.addUnOp(.ret, result);
......@@ -26641,7 +26642,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block) !void {
2664126642 // decl_index may be an alias; we must find the decl that actually
2664226643 // owns the function.
2664326644 try sema.ensureDeclAnalyzed(decl_index);
26644 const tv = try mod.declPtr(decl_index).typedValue();
26645 const tv = try mod.declPtr(decl_index).typedValue(mod);
2664526646 try sema.declareDependency(.{ .decl_val = decl_index });
2664626647 assert(tv.ty.zigTypeTag(mod) == .Fn);
2664726648 assert(try sema.fnHasRuntimeBits(tv.ty));
......@@ -31374,16 +31375,16 @@ fn beginComptimePtrLoad(
3137431375 .ptr => |ptr| switch (ptr.addr) {
3137531376 .decl => |decl_index| blk: {
3137631377 const decl = mod.declPtr(decl_index);
31377 const decl_tv = try decl.typedValue();
31378 const decl_tv = try decl.typedValue(mod);
3137831379 try sema.declareDependency(.{ .decl_val = decl_index });
3137931380 if (decl.val.getVariable(mod) != null) return error.RuntimeLoad;
3138031381
31381 const layout_defined = decl.ty.hasWellDefinedLayout(mod);
31382 const layout_defined = decl.typeOf(mod).hasWellDefinedLayout(mod);
3138231383 break :blk ComptimePtrLoadKit{
3138331384 .parent = if (layout_defined) .{ .tv = decl_tv, .byte_offset = 0 } else null,
3138431385 .pointee = decl_tv,
3138531386 .is_mutable = false,
31386 .ty_without_well_defined_layout = if (!layout_defined) decl.ty else null,
31387 .ty_without_well_defined_layout = if (!layout_defined) decl.typeOf(mod) else null,
3138731388 };
3138831389 },
3138931390 .comptime_alloc => |alloc_index| kit: {
......@@ -32668,7 +32669,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: InternPool.DeclIndex, analyze_fn
3266832669 const mod = sema.mod;
3266932670 try sema.ensureDeclAnalyzed(decl_index);
3267032671
32671 const decl_tv = try mod.declPtr(decl_index).typedValue();
32672 const decl_tv = try mod.declPtr(decl_index).typedValue(mod);
3267232673 const owner_decl = mod.declPtr(switch (mod.intern_pool.indexToKey(decl_tv.val.toIntern())) {
3267332674 .variable => |variable| variable.decl,
3267432675 .extern_func => |extern_func| extern_func.decl,
......@@ -32697,7 +32698,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: InternPool.DeclIndex, analyze_fn
3269732698fn maybeQueueFuncBodyAnalysis(sema: *Sema, decl_index: InternPool.DeclIndex) !void {
3269832699 const mod = sema.mod;
3269932700 const decl = mod.declPtr(decl_index);
32700 const tv = try decl.typedValue();
32701 const tv = try decl.typedValue(mod);
3270132702 if (tv.ty.zigTypeTag(mod) != .Fn) return;
3270232703 if (!try sema.fnHasRuntimeBits(tv.ty)) return;
3270332704 const func_index = tv.val.toIntern();
......@@ -36611,7 +36612,7 @@ fn resolveInferredErrorSet(
3661136612 // inferred error sets, each call gets an adhoc InferredErrorSet object, which
3661236613 // has no corresponding function body.
3661336614 const ies_func_owner_decl = mod.declPtr(func.owner_decl);
36614 const ies_func_info = mod.typeToFunc(ies_func_owner_decl.ty).?;
36615 const ies_func_info = mod.typeToFunc(ies_func_owner_decl.typeOf(mod)).?;
3661536616 // if ies declared by a inline function with generic return type, the return_type should be generic_poison,
3661636617 // because inline function does not create a new declaration, and the ies has been filled with analyzeCall,
3661736618 // so here we can simply skip this case.
......@@ -37629,7 +37630,6 @@ fn generateUnionTagTypeNumbered(
3762937630 .tag_mode = .explicit,
3763037631 });
3763137632
37632 new_decl.ty = Type.type;
3763337633 new_decl.val = Value.fromInterned(enum_ty);
3763437634
3763537635 try mod.finalizeAnonDecl(new_decl_index);
......@@ -37675,7 +37675,6 @@ fn generateUnionTagTypeSimple(
3767537675
3767637676 const new_decl = mod.declPtr(new_decl_index);
3767737677 new_decl.owns_tv = true;
37678 new_decl.ty = Type.type;
3767937678 new_decl.val = Value.fromInterned(enum_ty);
3768037679
3768137680 try mod.finalizeAnonDecl(new_decl_index);
src/TypedValue.zig+1-1
......@@ -315,7 +315,7 @@ pub fn print(
315315 const decl = mod.declPtr(decl_index);
316316 if (level == 0) return writer.print("(decl '{}')", .{decl.name.fmt(ip)});
317317 return print(.{
318 .ty = decl.ty,
318 .ty = decl.typeOf(mod),
319319 .val = decl.val,
320320 }, writer, level - 1, mod);
321321 },
src/Value.zig+1-1
......@@ -1585,7 +1585,7 @@ pub fn sliceLen(val: Value, mod: *Module) u64 {
15851585 const ip = &mod.intern_pool;
15861586 return switch (ip.indexToKey(val.toIntern())) {
15871587 .ptr => |ptr| switch (ip.indexToKey(switch (ptr.addr) {
1588 .decl => |decl| mod.declPtr(decl).ty.toIntern(),
1588 .decl => |decl| mod.declPtr(decl).typeOf(mod).toIntern(),
15891589 .comptime_alloc => @panic("TODO"),
15901590 .anon_decl => |anon_decl| ip.typeOf(anon_decl.val),
15911591 .comptime_field => |comptime_field| ip.typeOf(comptime_field),
src/arch/aarch64/CodeGen.zig+1-1
......@@ -342,7 +342,7 @@ pub fn generate(
342342 const func = zcu.funcInfo(func_index);
343343 const fn_owner_decl = zcu.declPtr(func.owner_decl);
344344 assert(fn_owner_decl.has_tv);
345 const fn_type = fn_owner_decl.ty;
345 const fn_type = fn_owner_decl.typeOf(zcu);
346346 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
347347 const target = &namespace.file_scope.mod.resolved_target.result;
348348
src/arch/arm/CodeGen.zig+1-1
......@@ -349,7 +349,7 @@ pub fn generate(
349349 const func = zcu.funcInfo(func_index);
350350 const fn_owner_decl = zcu.declPtr(func.owner_decl);
351351 assert(fn_owner_decl.has_tv);
352 const fn_type = fn_owner_decl.ty;
352 const fn_type = fn_owner_decl.typeOf(zcu);
353353 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
354354 const target = &namespace.file_scope.mod.resolved_target.result;
355355
src/arch/riscv64/CodeGen.zig+1-1
......@@ -230,7 +230,7 @@ pub fn generate(
230230 const func = zcu.funcInfo(func_index);
231231 const fn_owner_decl = zcu.declPtr(func.owner_decl);
232232 assert(fn_owner_decl.has_tv);
233 const fn_type = fn_owner_decl.ty;
233 const fn_type = fn_owner_decl.typeOf(zcu);
234234 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
235235 const target = &namespace.file_scope.mod.resolved_target.result;
236236
src/arch/sparc64/CodeGen.zig+1-1
......@@ -273,7 +273,7 @@ pub fn generate(
273273 const func = zcu.funcInfo(func_index);
274274 const fn_owner_decl = zcu.declPtr(func.owner_decl);
275275 assert(fn_owner_decl.has_tv);
276 const fn_type = fn_owner_decl.ty;
276 const fn_type = fn_owner_decl.typeOf(zcu);
277277 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
278278 const target = &namespace.file_scope.mod.resolved_target.result;
279279
src/arch/wasm/CodeGen.zig+11-10
......@@ -1243,12 +1243,12 @@ pub fn generate(
12431243fn genFunc(func: *CodeGen) InnerError!void {
12441244 const mod = func.bin_file.base.comp.module.?;
12451245 const ip = &mod.intern_pool;
1246 const fn_info = mod.typeToFunc(func.decl.ty).?;
1246 const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?;
12471247 var func_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types.get(ip), Type.fromInterned(fn_info.return_type), mod);
12481248 defer func_type.deinit(func.gpa);
12491249 _ = try func.bin_file.storeDeclType(func.decl_index, func_type);
12501250
1251 var cc_result = try func.resolveCallingConventionValues(func.decl.ty);
1251 var cc_result = try func.resolveCallingConventionValues(func.decl.typeOf(mod));
12521252 defer cc_result.deinit(func.gpa);
12531253
12541254 func.args = cc_result.args;
......@@ -2087,7 +2087,7 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20872087 const mod = func.bin_file.base.comp.module.?;
20882088 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
20892089 const operand = try func.resolveInst(un_op);
2090 const fn_info = mod.typeToFunc(func.decl.ty).?;
2090 const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?;
20912091 const ret_ty = Type.fromInterned(fn_info.return_type);
20922092
20932093 // 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 {
21352135 break :result try func.allocStack(Type.usize); // create pointer to void
21362136 }
21372137
2138 const fn_info = mod.typeToFunc(func.decl.ty).?;
2138 const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?;
21392139 if (firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), mod)) {
21402140 break :result func.return_value;
21412141 }
......@@ -2152,7 +2152,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21522152 const operand = try func.resolveInst(un_op);
21532153 const ret_ty = func.typeOf(un_op).childType(mod);
21542154
2155 const fn_info = mod.typeToFunc(func.decl.ty).?;
2155 const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?;
21562156 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
21572157 if (ret_ty.isError(mod)) {
21582158 try func.addImm32(0);
......@@ -2193,7 +2193,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
21932193 break :blk function.owner_decl;
21942194 } else if (func_val.getExternFunc(mod)) |extern_func| {
21952195 const ext_decl = mod.declPtr(extern_func.decl);
2196 const ext_info = mod.typeToFunc(ext_decl.ty).?;
2196 const ext_info = mod.typeToFunc(ext_decl.typeOf(mod)).?;
21972197 var func_type = try genFunctype(func.gpa, ext_info.cc, ext_info.param_types.get(ip), Type.fromInterned(ext_info.return_type), mod);
21982198 defer func_type.deinit(func.gpa);
21992199 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 {
25302530 const mod = func.bin_file.base.comp.module.?;
25312531 const arg_index = func.arg_index;
25322532 const arg = func.args[arg_index];
2533 const cc = mod.typeToFunc(func.decl.ty).?.cc;
2533 const cc = mod.typeToFunc(func.decl.typeOf(mod)).?.cc;
25342534 const arg_ty = func.typeOfIndex(inst);
25352535 if (cc == .C) {
25362536 const arg_classes = abi.classifyType(arg_ty, mod);
......@@ -3122,7 +3122,7 @@ fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: InternPool.Dec
31223122 const mod = func.bin_file.base.comp.module.?;
31233123 const decl = mod.declPtr(decl_index);
31243124 try mod.markDeclAlive(decl);
3125 const ptr_ty = try mod.singleMutPtrType(decl.ty);
3125 const ptr_ty = try mod.singleMutPtrType(decl.typeOf(mod));
31263126 return func.lowerDeclRefValue(.{ .ty = ptr_ty, .val = ptr_val }, decl_index, offset);
31273127}
31283128
......@@ -3173,7 +3173,8 @@ fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: InternPool.Decl
31733173 return func.lowerDeclRefValue(tv, func_val.decl, offset);
31743174 }
31753175 }
3176 if (decl.ty.zigTypeTag(mod) != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime(mod)) {
3176 const decl_ty = decl.typeOf(mod);
3177 if (decl_ty.zigTypeTag(mod) != .Fn and !decl_ty.hasRuntimeBitsIgnoreComptime(mod)) {
31773178 return WValue{ .imm32 = 0xaaaaaaaa };
31783179 }
31793180
......@@ -3182,7 +3183,7 @@ fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: InternPool.Decl
31823183 const atom = func.bin_file.getAtom(atom_index);
31833184
31843185 const target_sym_index = @intFromEnum(atom.sym_index);
3185 if (decl.ty.zigTypeTag(mod) == .Fn) {
3186 if (decl_ty.zigTypeTag(mod) == .Fn) {
31863187 return WValue{ .function_index = target_sym_index };
31873188 } else if (offset == 0) {
31883189 return WValue{ .memory = target_sym_index };
src/arch/x86_64/CodeGen.zig+1-1
......@@ -808,7 +808,7 @@ pub fn generate(
808808 const func = zcu.funcInfo(func_index);
809809 const fn_owner_decl = zcu.declPtr(func.owner_decl);
810810 assert(fn_owner_decl.has_tv);
811 const fn_type = fn_owner_decl.ty;
811 const fn_type = fn_owner_decl.typeOf(zcu);
812812 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
813813 const mod = namespace.file_scope.mod;
814814
src/codegen.zig+3-3
......@@ -829,8 +829,8 @@ fn lowerDeclRef(
829829 const target = namespace.file_scope.mod.resolved_target.result;
830830
831831 const ptr_width = target.ptrBitWidth();
832 const is_fn_body = decl.ty.zigTypeTag(zcu) == .Fn;
833 if (!is_fn_body and !decl.ty.hasRuntimeBits(zcu)) {
832 const is_fn_body = decl.typeOf(zcu).zigTypeTag(zcu) == .Fn;
833 if (!is_fn_body and !decl.typeOf(zcu).hasRuntimeBits(zcu)) {
834834 try code.appendNTimes(0xaa, @divExact(ptr_width, 8));
835835 return Result.ok;
836836 }
......@@ -932,7 +932,7 @@ fn genDeclRef(
932932 };
933933 const decl = zcu.declPtr(decl_index);
934934
935 if (!decl.ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
935 if (!decl.typeOf(zcu).isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
936936 const imm: u64 = switch (ptr_bytes) {
937937 1 => 0xaa,
938938 2 => 0xaaaa,
src/codegen/c.zig+14-13
......@@ -657,7 +657,7 @@ pub const DeclGen = struct {
657657 assert(decl.has_tv);
658658
659659 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
660 if (ty.isPtrAtRuntime(mod) and !decl.ty.isFnOrHasRuntimeBits(mod)) {
660 if (ty.isPtrAtRuntime(mod) and !decl.typeOf(mod).isFnOrHasRuntimeBits(mod)) {
661661 return dg.writeCValue(writer, .{ .undef = ty });
662662 }
663663
......@@ -673,7 +673,7 @@ pub const DeclGen = struct {
673673 // them). The analysis until now should ensure that the C function
674674 // pointers are compatible. If they are not, then there is a bug
675675 // somewhere and we should let the C compiler tell us about it.
676 const need_typecast = if (ty.castPtrToFn(mod)) |_| false else !ty.childType(mod).eql(decl.ty, mod);
676 const need_typecast = if (ty.castPtrToFn(mod)) |_| false else !ty.childType(mod).eql(decl.typeOf(mod), mod);
677677 if (need_typecast) {
678678 try writer.writeAll("((");
679679 try dg.renderType(writer, ty);
......@@ -1588,9 +1588,10 @@ pub const DeclGen = struct {
15881588 const ip = &mod.intern_pool;
15891589
15901590 const fn_decl = mod.declPtr(fn_decl_index);
1591 const fn_cty_idx = try dg.typeToIndex(fn_decl.ty, kind);
1591 const fn_ty = fn_decl.typeOf(mod);
1592 const fn_cty_idx = try dg.typeToIndex(fn_ty, kind);
15921593
1593 const fn_info = mod.typeToFunc(fn_decl.ty).?;
1594 const fn_info = mod.typeToFunc(fn_ty).?;
15941595 if (fn_info.cc == .Naked) {
15951596 switch (kind) {
15961597 .forward => try w.writeAll("zig_naked_decl "),
......@@ -1971,7 +1972,7 @@ pub const DeclGen = struct {
19711972 ) !void {
19721973 const decl = dg.module.declPtr(decl_index);
19731974 const fwd = dg.fwdDeclWriter();
1974 const is_global = variable.is_extern or dg.declIsGlobal(.{ .ty = decl.ty, .val = decl.val });
1975 const is_global = variable.is_extern or dg.declIsGlobal(.{ .ty = decl.typeOf(dg.module), .val = decl.val });
19751976 try fwd.writeAll(if (is_global) "zig_extern " else "static ");
19761977 const maybe_exports = dg.module.decl_exports.get(decl_index);
19771978 const export_weak_linkage = if (maybe_exports) |exports|
......@@ -1982,7 +1983,7 @@ pub const DeclGen = struct {
19821983 if (variable.is_threadlocal) try fwd.writeAll("zig_threadlocal ");
19831984 try dg.renderTypeAndName(
19841985 fwd,
1985 decl.ty,
1986 decl.typeOf(dg.module),
19861987 .{ .decl = decl_index },
19871988 CQualifiers.init(.{ .@"const" = variable.is_const }),
19881989 decl.alignment,
......@@ -2656,7 +2657,7 @@ fn genExports(o: *Object) !void {
26562657 .anon, .flush => return,
26572658 };
26582659 const decl = mod.declPtr(decl_index);
2659 const tv: TypedValue = .{ .ty = decl.ty, .val = Value.fromInterned((try decl.internValue(mod))) };
2660 const tv: TypedValue = .{ .ty = decl.typeOf(mod), .val = Value.fromInterned((try decl.internValue(mod))) };
26602661 const fwd = o.dg.fwdDeclWriter();
26612662
26622663 const exports = mod.decl_exports.get(decl_index) orelse return;
......@@ -2687,7 +2688,7 @@ fn genExports(o: *Object) !void {
26872688 const export_name = ip.stringToSlice(@"export".opts.name);
26882689 try o.dg.renderTypeAndName(
26892690 fwd,
2690 decl.ty,
2691 decl.typeOf(mod),
26912692 .{ .identifier = export_name },
26922693 CQualifiers.init(.{ .@"const" = is_variable_const }),
26932694 decl.alignment,
......@@ -2769,7 +2770,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
27692770 },
27702771 .never_tail, .never_inline => |fn_decl_index| {
27712772 const fn_decl = mod.declPtr(fn_decl_index);
2772 const fn_cty = try o.dg.typeToCType(fn_decl.ty, .complete);
2773 const fn_cty = try o.dg.typeToCType(fn_decl.typeOf(mod), .complete);
27732774 const fn_info = fn_cty.cast(CType.Payload.Function).?.data;
27742775
27752776 const fwd_decl_writer = o.dg.fwdDeclWriter();
......@@ -2806,7 +2807,7 @@ pub fn genFunc(f: *Function) !void {
28062807 const decl_index = o.dg.pass.decl;
28072808 const decl = mod.declPtr(decl_index);
28082809 const tv: TypedValue = .{
2809 .ty = decl.ty,
2810 .ty = decl.typeOf(mod),
28102811 .val = decl.val,
28112812 };
28122813
......@@ -2893,7 +2894,7 @@ pub fn genDecl(o: *Object) !void {
28932894 const mod = o.dg.module;
28942895 const decl_index = o.dg.pass.decl;
28952896 const decl = mod.declPtr(decl_index);
2896 const tv: TypedValue = .{ .ty = decl.ty, .val = Value.fromInterned((try decl.internValue(mod))) };
2897 const tv: TypedValue = .{ .ty = decl.typeOf(mod), .val = Value.fromInterned((try decl.internValue(mod))) };
28972898
28982899 if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return;
28992900 if (tv.val.getExternFunc(mod)) |_| {
......@@ -2979,7 +2980,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {
29792980 const decl_index = dg.pass.decl;
29802981 const decl = mod.declPtr(decl_index);
29812982 const tv: TypedValue = .{
2982 .ty = decl.ty,
2983 .ty = decl.typeOf(mod),
29832984 .val = decl.val,
29842985 };
29852986 const writer = dg.fwdDeclWriter();
......@@ -7392,7 +7393,7 @@ fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue {
73927393 const inst_ty = f.typeOfIndex(inst);
73937394 const decl_index = f.object.dg.pass.decl;
73947395 const decl = mod.declPtr(decl_index);
7395 const fn_cty = try f.typeToCType(decl.ty, .complete);
7396 const fn_cty = try f.typeToCType(decl.typeOf(mod), .complete);
73967397 const param_len = fn_cty.castTag(.varargs_function).?.data.param_types.len;
73977398
73987399 const writer = f.object.writer();
src/codegen/llvm.zig+14-13
......@@ -1384,7 +1384,7 @@ pub const Object = struct {
13841384 const decl = zcu.declPtr(decl_index);
13851385 const namespace = zcu.namespacePtr(decl.src_namespace);
13861386 const owner_mod = namespace.file_scope.mod;
1387 const fn_info = zcu.typeToFunc(decl.ty).?;
1387 const fn_info = zcu.typeToFunc(decl.typeOf(zcu)).?;
13881388 const target = zcu.getTarget();
13891389 const ip = &zcu.intern_pool;
13901390
......@@ -1659,7 +1659,7 @@ pub const Object = struct {
16591659 const line_number = decl.src_line + 1;
16601660 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and
16611661 !zcu.decl_exports.contains(decl_index);
1662 const debug_decl_type = try o.lowerDebugType(decl.ty);
1662 const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu));
16631663
16641664 const subprogram = try o.builder.debugSubprogram(
16651665 file,
......@@ -2881,7 +2881,7 @@ pub const Object = struct {
28812881 const decl = zcu.declPtr(decl_index);
28822882 const namespace = zcu.namespacePtr(decl.src_namespace);
28832883 const owner_mod = namespace.file_scope.mod;
2884 const zig_fn_type = decl.ty;
2884 const zig_fn_type = decl.typeOf(zcu);
28852885 const gop = try o.decl_map.getOrPut(gpa, decl_index);
28862886 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function;
28872887
......@@ -3112,7 +3112,7 @@ pub const Object = struct {
31123112 try o.builder.strtabString(mod.intern_pool.stringToSlice(
31133113 if (is_extern) decl.name else try decl.fullyQualifiedName(mod),
31143114 )),
3115 try o.lowerType(decl.ty),
3115 try o.lowerType(decl.typeOf(mod)),
31163116 toLlvmGlobalAddressSpace(decl.@"addrspace", mod.getTarget()),
31173117 );
31183118 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
......@@ -4263,7 +4263,7 @@ pub const Object = struct {
42634263 const mod = o.module;
42644264 const decl = mod.declPtr(decl_index);
42654265 try mod.markDeclAlive(decl);
4266 const ptr_ty = try mod.singleMutPtrType(decl.ty);
4266 const ptr_ty = try mod.singleMutPtrType(decl.typeOf(mod));
42674267 return o.lowerDeclRefValue(ptr_ty, decl_index);
42684268 }
42694269
......@@ -4450,9 +4450,10 @@ pub const Object = struct {
44504450 }
44514451 }
44524452
4453 const is_fn_body = decl.ty.zigTypeTag(mod) == .Fn;
4454 if ((!is_fn_body and !decl.ty.hasRuntimeBits(mod)) or
4455 (is_fn_body and mod.typeToFunc(decl.ty).?.is_generic)) return o.lowerPtrToVoid(ty);
4453 const decl_ty = decl.typeOf(mod);
4454 const is_fn_body = decl_ty.zigTypeTag(mod) == .Fn;
4455 if ((!is_fn_body and !decl_ty.hasRuntimeBits(mod)) or
4456 (is_fn_body and mod.typeToFunc(decl_ty).?.is_generic)) return o.lowerPtrToVoid(ty);
44564457
44574458 try mod.markDeclAlive(decl);
44584459
......@@ -4740,7 +4741,7 @@ pub const DeclGen = struct {
47404741 debug_file, // File
47414742 debug_file, // Scope
47424743 line_number,
4743 try o.lowerDebugType(decl.ty),
4744 try o.lowerDebugType(decl.typeOf(zcu)),
47444745 variable_index,
47454746 .{ .local = is_internal_linkage },
47464747 );
......@@ -5530,7 +5531,7 @@ pub const FuncGen = struct {
55305531 const mod = o.module;
55315532 const msg_decl_index = mod.panic_messages[@intFromEnum(panic_id)].unwrap().?;
55325533 const msg_decl = mod.declPtr(msg_decl_index);
5533 const msg_len = msg_decl.ty.childType(mod).arrayLen(mod);
5534 const msg_len = msg_decl.typeOf(mod).childType(mod).arrayLen(mod);
55345535 const msg_ptr = try o.lowerValue(try msg_decl.internValue(mod));
55355536 const null_opt_addr_global = try fg.resolveNullOptUsize();
55365537 const target = mod.getTarget();
......@@ -5544,7 +5545,7 @@ pub const FuncGen = struct {
55445545 // )
55455546 const panic_func = mod.funcInfo(mod.panic_func_index);
55465547 const panic_decl = mod.declPtr(panic_func.owner_decl);
5547 const fn_info = mod.typeToFunc(panic_decl.ty).?;
5548 const fn_info = mod.typeToFunc(panic_decl.typeOf(mod)).?;
55485549 const panic_global = try o.resolveLlvmFunction(panic_func.owner_decl);
55495550 _ = try fg.wip.call(
55505551 .normal,
......@@ -5612,7 +5613,7 @@ pub const FuncGen = struct {
56125613 _ = try self.wip.retVoid();
56135614 return .none;
56145615 }
5615 const fn_info = mod.typeToFunc(self.dg.decl.ty).?;
5616 const fn_info = mod.typeToFunc(self.dg.decl.typeOf(mod)).?;
56165617 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
56175618 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
56185619 // Functions with an empty error set are emitted with an error code
......@@ -5674,7 +5675,7 @@ pub const FuncGen = struct {
56745675 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
56755676 const ptr_ty = self.typeOf(un_op);
56765677 const ret_ty = ptr_ty.childType(mod);
5677 const fn_info = mod.typeToFunc(self.dg.decl.ty).?;
5678 const fn_info = mod.typeToFunc(self.dg.decl.typeOf(mod)).?;
56785679 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
56795680 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
56805681 // Functions with an empty error set are emitted with an error code
src/codegen/spirv.zig+10-10
......@@ -1221,7 +1221,7 @@ const DeclGen = struct {
12211221 else => {},
12221222 }
12231223
1224 if (!decl.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) {
1224 if (!decl.typeOf(mod).isFnOrHasRuntimeBitsIgnoreComptime(mod)) {
12251225 // Pointer to nothing - return undefined.
12261226 return self.spv.constUndef(ty_ref);
12271227 }
......@@ -1237,7 +1237,7 @@ const DeclGen = struct {
12371237 const final_storage_class = self.spvStorageClass(decl.@"addrspace");
12381238 try self.addFunctionDep(spv_decl_index, final_storage_class);
12391239
1240 const decl_ptr_ty_ref = try self.ptrType(decl.ty, final_storage_class);
1240 const decl_ptr_ty_ref = try self.ptrType(decl.typeOf(mod), final_storage_class);
12411241
12421242 const ptr_id = switch (final_storage_class) {
12431243 .Generic => try self.castToGeneric(self.typeId(decl_ptr_ty_ref), decl_id),
......@@ -2044,11 +2044,11 @@ const DeclGen = struct {
20442044
20452045 switch (self.spv.declPtr(spv_decl_index).kind) {
20462046 .func => {
2047 assert(decl.ty.zigTypeTag(mod) == .Fn);
2048 const fn_info = mod.typeToFunc(decl.ty).?;
2047 assert(decl.typeOf(mod).zigTypeTag(mod) == .Fn);
2048 const fn_info = mod.typeToFunc(decl.typeOf(mod)).?;
20492049 const return_ty_ref = try self.resolveFnReturnType(Type.fromInterned(fn_info.return_type));
20502050
2051 const prototype_ty_ref = try self.resolveType(decl.ty, .direct);
2051 const prototype_ty_ref = try self.resolveType(decl.typeOf(mod), .direct);
20522052 try self.func.prologue.emit(self.spv.gpa, .OpFunction, .{
20532053 .id_result_type = self.typeId(return_ty_ref),
20542054 .id_result = result_id,
......@@ -2121,7 +2121,7 @@ const DeclGen = struct {
21212121 const final_storage_class = self.spvStorageClass(decl.@"addrspace");
21222122 assert(final_storage_class != .Generic); // These should be instance globals
21232123
2124 const ptr_ty_ref = try self.ptrType(decl.ty, final_storage_class);
2124 const ptr_ty_ref = try self.ptrType(decl.typeOf(mod), final_storage_class);
21252125
21262126 try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpVariable, .{
21272127 .id_result_type = self.typeId(ptr_ty_ref),
......@@ -2144,7 +2144,7 @@ const DeclGen = struct {
21442144
21452145 try self.spv.declareDeclDeps(spv_decl_index, &.{});
21462146
2147 const ptr_ty_ref = try self.ptrType(decl.ty, .Function);
2147 const ptr_ty_ref = try self.ptrType(decl.typeOf(mod), .Function);
21482148
21492149 if (maybe_init_val) |init_val| {
21502150 // TODO: Combine with resolveAnonDecl?
......@@ -2168,7 +2168,7 @@ const DeclGen = struct {
21682168 });
21692169 self.current_block_label = root_block_id;
21702170
2171 const val_id = try self.constant(decl.ty, init_val, .indirect);
2171 const val_id = try self.constant(decl.typeOf(mod), init_val, .indirect);
21722172 try self.func.body.emit(self.spv.gpa, .OpStore, .{
21732173 .pointer = result_id,
21742174 .object = val_id,
......@@ -4785,7 +4785,7 @@ const DeclGen = struct {
47854785 const mod = self.module;
47864786 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
47874787 const decl = mod.declPtr(self.decl_index);
4788 const fn_info = mod.typeToFunc(decl.ty).?;
4788 const fn_info = mod.typeToFunc(decl.typeOf(mod)).?;
47894789 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
47904790 // Functions with an empty error set are emitted with an error code
47914791 // return type and return zero so they can be function pointers coerced
......@@ -4810,7 +4810,7 @@ const DeclGen = struct {
48104810
48114811 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
48124812 const decl = mod.declPtr(self.decl_index);
4813 const fn_info = mod.typeToFunc(decl.ty).?;
4813 const fn_info = mod.typeToFunc(decl.typeOf(mod)).?;
48144814 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
48154815 // Functions with an empty error set are emitted with an error code
48164816 // return type and return zero so they can be function pointers coerced
src/link/C.zig+1-1
......@@ -209,7 +209,7 @@ pub fn updateFunc(
209209 .module = module,
210210 .error_msg = null,
211211 .pass = .{ .decl = decl_index },
212 .is_naked_fn = decl.ty.fnCallingConvention(module) == .Naked,
212 .is_naked_fn = decl.typeOf(module).fnCallingConvention(module) == .Naked,
213213 .fwd_decl = fwd_decl.toManaged(gpa),
214214 .ctypes = ctypes.*,
215215 .anon_decl_deps = self.anon_decls,
src/link/Coff.zig+3-3
......@@ -1272,7 +1272,7 @@ pub fn updateDecl(
12721272
12731273 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
12741274 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
1275 .ty = decl.ty,
1275 .ty = decl.typeOf(mod),
12761276 .val = decl_val,
12771277 }, &code_buffer, .none, .{
12781278 .parent_atom_index = atom.getSymbolIndex().?,
......@@ -1399,8 +1399,8 @@ pub fn getOrCreateAtomForDecl(self: *Coff, decl_index: InternPool.DeclIndex) !At
13991399
14001400fn getDeclOutputSection(self: *Coff, decl_index: InternPool.DeclIndex) u16 {
14011401 const decl = self.base.comp.module.?.declPtr(decl_index);
1402 const ty = decl.ty;
14031402 const mod = self.base.comp.module.?;
1403 const ty = decl.typeOf(mod);
14041404 const zig_ty = ty.zigTypeTag(mod);
14051405 const val = decl.val;
14061406 const index: u16 = blk: {
......@@ -1535,7 +1535,7 @@ pub fn updateExports(
15351535 .x86 => std.builtin.CallingConvention.Stdcall,
15361536 else => std.builtin.CallingConvention.C,
15371537 };
1538 const decl_cc = exported_decl.ty.fnCallingConvention(mod);
1538 const decl_cc = exported_decl.typeOf(mod).fnCallingConvention(mod);
15391539 if (decl_cc == .C and ip.stringEqlSlice(exp.opts.name, "main") and
15401540 comp.config.link_libc)
15411541 {
src/link/Dwarf.zig+3-3
......@@ -1109,7 +1109,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde
11091109
11101110 assert(decl.has_tv);
11111111
1112 switch (decl.ty.zigTypeTag(mod)) {
1112 switch (decl.typeOf(mod).zigTypeTag(mod)) {
11131113 .Fn => {
11141114 _ = try self.getOrCreateAtomForDecl(.src_fn, decl_index);
11151115
......@@ -1162,7 +1162,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde
11621162 try dbg_info_buffer.ensureUnusedCapacity(1 + ptr_width_bytes + 4 + 4 +
11631163 (decl_name_slice.len + 1) + (decl_linkage_name_slice.len + 1));
11641164
1165 const fn_ret_type = decl.ty.fnReturnType(mod);
1165 const fn_ret_type = decl.typeOf(mod).fnReturnType(mod);
11661166 const fn_ret_has_bits = fn_ret_type.hasRuntimeBits(mod);
11671167 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(
11681168 @as(AbbrevCode, if (fn_ret_has_bits) .subprogram else .subprogram_retvoid),
......@@ -1215,7 +1215,7 @@ pub fn commitDeclState(
12151215 var dbg_info_buffer = &decl_state.dbg_info;
12161216
12171217 assert(decl.has_tv);
1218 switch (decl.ty.zigTypeTag(zcu)) {
1218 switch (decl.typeOf(zcu).zigTypeTag(zcu)) {
12191219 .Fn => {
12201220 try decl_state.setInlineFunc(decl.val.toIntern());
12211221
src/link/Elf/ZigObject.zig+3-3
......@@ -846,7 +846,7 @@ fn getDeclShdrIndex(
846846 _ = self;
847847 const mod = elf_file.base.comp.module.?;
848848 const any_non_single_threaded = elf_file.base.comp.config.any_non_single_threaded;
849 const shdr_index = switch (decl.ty.zigTypeTag(mod)) {
849 const shdr_index = switch (decl.typeOf(mod).zigTypeTag(mod)) {
850850 .Fn => elf_file.zig_text_section_index.?,
851851 else => blk: {
852852 if (decl.getOwnedVariable(mod)) |variable| {
......@@ -1158,7 +1158,7 @@ pub fn updateDecl(
11581158 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
11591159 const res = if (decl_state) |*ds|
11601160 try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{
1161 .ty = decl.ty,
1161 .ty = decl.typeOf(mod),
11621162 .val = decl_val,
11631163 }, &code_buffer, .{
11641164 .dwarf = ds,
......@@ -1167,7 +1167,7 @@ pub fn updateDecl(
11671167 })
11681168 else
11691169 try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{
1170 .ty = decl.ty,
1170 .ty = decl.typeOf(mod),
11711171 .val = decl_val,
11721172 }, &code_buffer, .none, .{
11731173 .parent_atom_index = sym_index,
src/link/MachO/ZigObject.zig+2-2
......@@ -740,7 +740,7 @@ pub fn updateDecl(
740740 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
741741 const res =
742742 try codegen.generateSymbol(&macho_file.base, decl.srcLoc(mod), .{
743 .ty = decl.ty,
743 .ty = decl.typeOf(mod),
744744 .val = decl_val,
745745 }, &code_buffer, dio, .{
746746 .parent_atom_index = sym_index,
......@@ -1021,7 +1021,7 @@ fn getDeclOutputSection(
10211021 _ = self;
10221022 const mod = macho_file.base.comp.module.?;
10231023 const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded;
1024 const sect_id: u8 = switch (decl.ty.zigTypeTag(mod)) {
1024 const sect_id: u8 = switch (decl.typeOf(mod).zigTypeTag(mod)) {
10251025 .Fn => macho_file.zig_text_sect_index.?,
10261026 else => blk: {
10271027 if (decl.getOwnedVariable(mod)) |variable| {
src/link/Plan9.zig+3-3
......@@ -177,7 +177,7 @@ pub const Atom = struct {
177177 return if (self.code_ptr) |p| p[0..self.other.code_len] else blk: {
178178 const decl_index = self.other.decl_index;
179179 const decl = mod.declPtr(decl_index);
180 if (decl.ty.zigTypeTag(mod) == .Fn) {
180 if (decl.typeOf(mod).zigTypeTag(mod) == .Fn) {
181181 const table = plan9.fn_decl_table.get(decl.getFileScope(mod)).?.functions;
182182 const output = table.get(decl_index).?;
183183 break :blk output.code;
......@@ -540,7 +540,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
540540 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
541541 // TODO we need the symbol index for symbol in the table of locals for the containing atom
542542 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
543 .ty = decl.ty,
543 .ty = decl.typeOf(mod),
544544 .val = decl_val,
545545 }, &code_buffer, .{ .none = {} }, .{
546546 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),
......@@ -566,7 +566,7 @@ fn updateFinish(self: *Plan9, decl_index: InternPool.DeclIndex) !void {
566566 const gpa = self.base.comp.gpa;
567567 const mod = self.base.comp.module.?;
568568 const decl = mod.declPtr(decl_index);
569 const is_fn = (decl.ty.zigTypeTag(mod) == .Fn);
569 const is_fn = (decl.typeOf(mod).zigTypeTag(mod) == .Fn);
570570 const sym_t: aout.Sym.Type = if (is_fn) .t else .d;
571571
572572 const atom = self.getAtomPtr(self.decls.get(decl_index).?.index);
src/link/SpirV.zig+1-1
......@@ -163,7 +163,7 @@ pub fn updateExports(
163163 if (decl.val.isFuncBody(mod)) {
164164 const target = mod.getTarget();
165165 const spv_decl_index = try self.object.resolveDecl(mod, decl_index);
166 const execution_model = switch (decl.ty.fnCallingConvention(mod)) {
166 const execution_model = switch (decl.typeOf(mod).fnCallingConvention(mod)) {
167167 .Vertex => spec.ExecutionModel.Vertex,
168168 .Fragment => spec.ExecutionModel.Fragment,
169169 .Kernel => spec.ExecutionModel.Kernel,
src/link/Wasm/ZigObject.zig+4-4
......@@ -270,7 +270,7 @@ pub fn updateDecl(
270270 const res = try codegen.generateSymbol(
271271 &wasm_file.base,
272272 decl.srcLoc(mod),
273 .{ .ty = decl.ty, .val = val },
273 .{ .ty = decl.typeOf(mod), .val = val },
274274 &code_writer,
275275 .none,
276276 .{ .parent_atom_index = @intFromEnum(atom.sym_index) },
......@@ -346,7 +346,7 @@ fn finishUpdateDecl(
346346 try atom.code.appendSlice(gpa, code);
347347 atom.size = @intCast(code.len);
348348
349 switch (decl.ty.zigTypeTag(mod)) {
349 switch (decl.typeOf(mod).zigTypeTag(mod)) {
350350 .Fn => {
351351 sym.index = try zig_object.appendFunction(gpa, .{ .type_index = zig_object.atom_types.get(atom_index).? });
352352 sym.tag = .function;
......@@ -764,7 +764,7 @@ pub fn getDeclVAddr(
764764 const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;
765765 const atom = wasm_file.getAtomPtr(atom_index);
766766 const is_wasm32 = target.cpu.arch == .wasm32;
767 if (decl.ty.zigTypeTag(mod) == .Fn) {
767 if (decl.typeOf(mod).zigTypeTag(mod) == .Fn) {
768768 std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations
769769 try atom.relocs.append(gpa, .{
770770 .index = target_symbol_index,
......@@ -964,7 +964,7 @@ pub fn freeDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_index: InternPool
964964 if (sym.isGlobal()) {
965965 std.debug.assert(zig_object.global_syms.remove(atom.sym_index));
966966 }
967 switch (decl.ty.zigTypeTag(mod)) {
967 switch (decl.typeOf(mod).zigTypeTag(mod)) {
968968 .Fn => {
969969 zig_object.functions_free_list.append(gpa, sym.index) catch {};
970970 std.debug.assert(zig_object.atom_types.remove(atom_index));