aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-03-26 21:11:18 -0700
committerGitHub <noreply@github.com>2024-03-26 21:11:18 -0700
commit5140f2726ae6e09381d9d44a72626dfe319f068b (patch)
treeb2163e1439be4858c8e11b7d210ab91e262ab761 /src/codegen
parent341857e5cd4fd4453cf9c7d1a6679feb66710d84 (diff)
parent513254956525f8f970e972f6973ab4df0b19d06a (diff)
downloadzig-5140f2726ae6e09381d9d44a72626dfe319f068b.tar.gz
zig-5140f2726ae6e09381d9d44a72626dfe319f068b.zip
Merge pull request #19437 from mlugg/value-cleanups
Follow-up to #19414
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig81
-rw-r--r--src/codegen/llvm.zig67
-rw-r--r--src/codegen/spirv.zig23
3 files changed, 75 insertions, 96 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 9b856de111..7ae5c87ee5 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -9,7 +9,6 @@ const Module = @import("../Module.zig");
const Compilation = @import("../Compilation.zig");
const Value = @import("../Value.zig");
const Type = @import("../type.zig").Type;
-const TypedValue = @import("../TypedValue.zig");
const C = link.File.C;
const Decl = Module.Decl;
const trace = @import("../tracy.zig").trace;
@@ -657,7 +656,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 +672,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 +1587,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 "),
@@ -1876,9 +1876,9 @@ pub const DeclGen = struct {
try renderTypeSuffix(dg.pass, store.*, mod, w, cty_idx, .suffix, .{});
}
- fn declIsGlobal(dg: *DeclGen, tv: TypedValue) bool {
+ fn declIsGlobal(dg: *DeclGen, val: Value) bool {
const mod = dg.module;
- return switch (mod.intern_pool.indexToKey(tv.val.ip_index)) {
+ return switch (mod.intern_pool.indexToKey(val.ip_index)) {
.variable => |variable| mod.decl_exports.contains(variable.decl),
.extern_func => true,
.func => |func| mod.decl_exports.contains(func.owner_decl),
@@ -1971,7 +1971,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(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 +1982,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,
@@ -2009,7 +2009,6 @@ pub const DeclGen = struct {
fn renderDeclName(dg: *DeclGen, writer: anytype, decl_index: InternPool.DeclIndex, export_index: u32) !void {
const mod = dg.module;
const decl = mod.declPtr(decl_index);
- try mod.markDeclAlive(decl);
if (mod.decl_exports.get(decl_index)) |exports| {
try writer.print("{ }", .{
@@ -2656,13 +2655,12 @@ 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 fwd = o.dg.fwdDeclWriter();
const exports = mod.decl_exports.get(decl_index) orelse return;
if (exports.items.len < 2) return;
- const is_variable_const = switch (ip.indexToKey(tv.val.toIntern())) {
+ const is_variable_const = switch (ip.indexToKey(decl.val.toIntern())) {
.func => return for (exports.items[1..], 1..) |@"export", i| {
try fwd.writeAll("zig_extern ");
if (@"export".opts.linkage == .weak) try fwd.writeAll("zig_weak_linkage_fn ");
@@ -2687,7 +2685,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 +2767,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();
@@ -2805,15 +2803,11 @@ pub fn genFunc(f: *Function) !void {
const gpa = o.dg.gpa;
const decl_index = o.dg.pass.decl;
const decl = mod.declPtr(decl_index);
- const tv: TypedValue = .{
- .ty = decl.ty,
- .val = decl.val,
- };
o.code_header = std.ArrayList(u8).init(gpa);
defer o.code_header.deinit();
- const is_global = o.dg.declIsGlobal(tv);
+ const is_global = o.dg.declIsGlobal(decl.val);
const fwd_decl_writer = o.dg.fwdDeclWriter();
try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
@@ -2893,22 +2887,23 @@ 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 decl_val = decl.val;
+ const decl_ty = decl_val.typeOf(mod);
- if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return;
- if (tv.val.getExternFunc(mod)) |_| {
+ if (!decl_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return;
+ if (decl_val.getExternFunc(mod)) |_| {
const fwd_decl_writer = o.dg.fwdDeclWriter();
try fwd_decl_writer.writeAll("zig_extern ");
try o.dg.renderFunctionSignature(fwd_decl_writer, decl_index, .forward, .{ .export_index = 0 });
try fwd_decl_writer.writeAll(";\n");
try genExports(o);
- } else if (tv.val.getVariable(mod)) |variable| {
+ } else if (decl_val.getVariable(mod)) |variable| {
try o.dg.renderFwdDecl(decl_index, variable, .final);
try genExports(o);
if (variable.is_extern) return;
- const is_global = variable.is_extern or o.dg.declIsGlobal(tv);
+ const is_global = variable.is_extern or o.dg.declIsGlobal(decl_val);
const w = o.writer();
if (!is_global) try w.writeAll("static ");
if (variable.is_weak_linkage) try w.writeAll("zig_weak_linkage ");
@@ -2916,22 +2911,22 @@ pub fn genDecl(o: *Object) !void {
if (mod.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |s|
try w.print("zig_linksection(\"{s}\", ", .{s});
const decl_c_value = .{ .decl = decl_index };
- try o.dg.renderTypeAndName(w, tv.ty, decl_c_value, .{}, decl.alignment, .complete);
+ try o.dg.renderTypeAndName(w, decl_ty, decl_c_value, .{}, decl.alignment, .complete);
if (decl.@"linksection" != .none) try w.writeAll(", read, write)");
try w.writeAll(" = ");
- try o.dg.renderValue(w, tv.ty, Value.fromInterned(variable.init), .StaticInitializer);
+ try o.dg.renderValue(w, decl_ty, Value.fromInterned(variable.init), .StaticInitializer);
try w.writeByte(';');
try o.indent_writer.insertNewline();
} else {
const is_global = o.dg.module.decl_exports.contains(decl_index);
const decl_c_value = .{ .decl = decl_index };
- try genDeclValue(o, tv, is_global, decl_c_value, decl.alignment, decl.@"linksection");
+ try genDeclValue(o, decl_val, is_global, decl_c_value, decl.alignment, decl.@"linksection");
}
}
pub fn genDeclValue(
o: *Object,
- tv: TypedValue,
+ val: Value,
is_global: bool,
decl_c_value: CValue,
alignment: Alignment,
@@ -2940,8 +2935,10 @@ pub fn genDeclValue(
const mod = o.dg.module;
const fwd_decl_writer = o.dg.fwdDeclWriter();
+ const ty = val.typeOf(mod);
+
try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
- try o.dg.renderTypeAndName(fwd_decl_writer, tv.ty, decl_c_value, Const, alignment, .complete);
+ try o.dg.renderTypeAndName(fwd_decl_writer, ty, decl_c_value, Const, alignment, .complete);
switch (o.dg.pass) {
.decl => |decl_index| {
if (mod.decl_exports.get(decl_index)) |exports| {
@@ -2964,10 +2961,10 @@ pub fn genDeclValue(
if (mod.intern_pool.stringToSliceUnwrap(link_section)) |s|
try w.print("zig_linksection(\"{s}\", ", .{s});
- try o.dg.renderTypeAndName(w, tv.ty, decl_c_value, Const, alignment, .complete);
+ try o.dg.renderTypeAndName(w, ty, decl_c_value, Const, alignment, .complete);
if (link_section != .none) try w.writeAll(", read)");
try w.writeAll(" = ");
- try o.dg.renderValue(w, tv.ty, tv.val, .StaticInitializer);
+ try o.dg.renderValue(w, ty, val, .StaticInitializer);
try w.writeAll(";\n");
}
@@ -2978,14 +2975,10 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {
const mod = dg.module;
const decl_index = dg.pass.decl;
const decl = mod.declPtr(decl_index);
- const tv: TypedValue = .{
- .ty = decl.ty,
- .val = decl.val,
- };
const writer = dg.fwdDeclWriter();
- switch (tv.ty.zigTypeTag(mod)) {
- .Fn => if (dg.declIsGlobal(tv)) {
+ switch (decl.val.typeOf(mod).zigTypeTag(mod)) {
+ .Fn => if (dg.declIsGlobal(decl.val)) {
try writer.writeAll("zig_extern ");
try dg.renderFunctionSignature(writer, dg.pass.decl, .complete, .{ .export_index = 0 });
try dg.fwd_decl.appendSlice(";\n");
@@ -5304,25 +5297,25 @@ fn airIsNull(
const err_int_ty = try mod.errorIntType();
const rhs = if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod))
- TypedValue{ .ty = Type.bool, .val = Value.true }
+ Value.true
else if (optional_ty.isPtrLikeOptional(mod))
// operand is a regular pointer, test `operand !=/== NULL`
- TypedValue{ .ty = optional_ty, .val = try mod.getCoerced(Value.null, optional_ty) }
+ try mod.getCoerced(Value.null, optional_ty)
else if (payload_ty.zigTypeTag(mod) == .ErrorSet)
- TypedValue{ .ty = err_int_ty, .val = try mod.intValue(err_int_ty, 0) }
+ try mod.intValue(err_int_ty, 0)
else if (payload_ty.isSlice(mod) and optional_ty.optionalReprIsPayload(mod)) rhs: {
try writer.writeAll(".ptr");
const slice_ptr_ty = payload_ty.slicePtrFieldType(mod);
const opt_slice_ptr_ty = try mod.optionalType(slice_ptr_ty.toIntern());
- break :rhs TypedValue{ .ty = opt_slice_ptr_ty, .val = try mod.nullValue(opt_slice_ptr_ty) };
+ break :rhs try mod.nullValue(opt_slice_ptr_ty);
} else rhs: {
try writer.writeAll(".is_null");
- break :rhs TypedValue{ .ty = Type.bool, .val = Value.true };
+ break :rhs Value.true;
};
try writer.writeByte(' ');
try writer.writeAll(operator);
try writer.writeByte(' ');
- try f.object.dg.renderValue(writer, rhs.ty, rhs.val, .Other);
+ try f.object.dg.renderValue(writer, rhs.typeOf(mod), rhs, .Other);
try writer.writeAll(";\n");
return local;
}
@@ -7392,7 +7385,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..8ddacbe11c 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -18,7 +18,6 @@ const Module = @import("../Module.zig");
const Zcu = Module;
const InternPool = @import("../InternPool.zig");
const Package = @import("../Package.zig");
-const TypedValue = @import("../TypedValue.zig");
const Air = @import("../Air.zig");
const Liveness = @import("../Liveness.zig");
const Value = @import("../Value.zig");
@@ -1384,7 +1383,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 +1658,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,
@@ -1762,7 +1761,7 @@ pub const Object = struct {
const decl_name = decl_name: {
const decl_name = mod.intern_pool.stringToSlice(decl.name);
- if (mod.getTarget().isWasm() and try decl.isFunction(mod)) {
+ if (mod.getTarget().isWasm() and decl.val.typeOf(mod).zigTypeTag(mod) == .Fn) {
if (mod.intern_pool.stringToSliceUnwrap(decl.getOwnedExternFunc(mod).?.lib_name)) |lib_name| {
if (!std.mem.eql(u8, lib_name, "c")) {
break :decl_name try self.builder.strtabStringFmt("{s}|{s}", .{ decl_name, lib_name });
@@ -2881,7 +2880,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 +3111,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;
@@ -3722,15 +3721,11 @@ pub const Object = struct {
=> unreachable, // non-runtime values
.extern_func => |extern_func| {
const fn_decl_index = extern_func.decl;
- const fn_decl = mod.declPtr(fn_decl_index);
- try mod.markDeclAlive(fn_decl);
const function_index = try o.resolveLlvmFunction(fn_decl_index);
return function_index.ptrConst(&o.builder).global.toConst();
},
.func => |func| {
const fn_decl_index = func.owner_decl;
- const fn_decl = mod.declPtr(fn_decl_index);
- try mod.markDeclAlive(fn_decl);
const function_index = try o.resolveLlvmFunction(fn_decl_index);
return function_index.ptrConst(&o.builder).global.toConst();
},
@@ -4262,8 +4257,7 @@ pub const Object = struct {
fn lowerParentPtrDecl(o: *Object, decl_index: InternPool.DeclIndex) Allocator.Error!Builder.Constant {
const mod = o.module;
const decl = mod.declPtr(decl_index);
- try mod.markDeclAlive(decl);
- 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,11 +4444,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);
-
- try mod.markDeclAlive(decl);
+ 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);
const llvm_global = if (is_fn_body)
(try o.resolveLlvmFunction(decl_index)).ptrConst(&o.builder).global
@@ -4740,7 +4733,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 },
);
@@ -4829,19 +4822,17 @@ pub const FuncGen = struct {
const o = self.dg.object;
const mod = o.module;
- const llvm_val = try self.resolveValue(.{
- .ty = self.typeOf(inst),
- .val = (try self.air.value(inst, mod)).?,
- });
+ const llvm_val = try self.resolveValue((try self.air.value(inst, mod)).?);
gop.value_ptr.* = llvm_val.toValue();
return llvm_val.toValue();
}
- fn resolveValue(self: *FuncGen, tv: TypedValue) Error!Builder.Constant {
+ fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant {
const o = self.dg.object;
const mod = o.module;
- const llvm_val = try o.lowerValue(tv.val.toIntern());
- if (!isByRef(tv.ty, mod)) return llvm_val;
+ const ty = val.typeOf(mod);
+ const llvm_val = try o.lowerValue(val.toIntern());
+ if (!isByRef(ty, mod)) return llvm_val;
// We have an LLVM value but we need to create a global constant and
// set the value as its initializer, and then return a pointer to the global.
@@ -4855,7 +4846,7 @@ pub const FuncGen = struct {
variable_index.setLinkage(.private, &o.builder);
variable_index.setMutability(.constant, &o.builder);
variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
- variable_index.setAlignment(tv.ty.abiAlignment(mod).toLlvm(), &o.builder);
+ variable_index.setAlignment(ty.abiAlignment(mod).toLlvm(), &o.builder);
return o.builder.convConst(
.unneeded,
variable_index.toConst(&o.builder),
@@ -4867,11 +4858,10 @@ pub const FuncGen = struct {
const o = self.dg.object;
const mod = o.module;
if (o.null_opt_usize == .no_init) {
- const ty = try mod.intern(.{ .opt_type = .usize_type });
- o.null_opt_usize = try self.resolveValue(.{
- .ty = Type.fromInterned(ty),
- .val = Value.fromInterned((try mod.intern(.{ .opt = .{ .ty = ty, .val = .none } }))),
- });
+ o.null_opt_usize = try self.resolveValue(Value.fromInterned(try mod.intern(.{ .opt = .{
+ .ty = try mod.intern(.{ .opt_type = .usize_type }),
+ .val = .none,
+ } })));
}
return o.null_opt_usize;
}
@@ -5530,8 +5520,8 @@ 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_ptr = try o.lowerValue(try msg_decl.internValue(mod));
+ const msg_len = msg_decl.typeOf(mod).childType(mod).arrayLen(mod);
+ const msg_ptr = try o.lowerValue(msg_decl.val.toIntern());
const null_opt_addr_global = try fg.resolveNullOptUsize();
const target = mod.getTarget();
const llvm_usize = try o.lowerType(Type.usize);
@@ -5544,7 +5534,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 +5602,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 +5664,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
@@ -10067,10 +10057,7 @@ pub const FuncGen = struct {
const elem_ptr = try self.wip.gep(.inbounds, llvm_result_ty, alloca_inst, &.{
usize_zero, try o.builder.intValue(llvm_usize, array_info.len),
}, "");
- const llvm_elem = try self.resolveValue(.{
- .ty = array_info.elem_type,
- .val = sent_val,
- });
+ const llvm_elem = try self.resolveValue(sent_val);
try self.store(elem_ptr, elem_ptr_ty, llvm_elem.toValue(), .none);
}
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig
index 10bbe2204d..6b13f2623a 100644
--- a/src/codegen/spirv.zig
+++ b/src/codegen/spirv.zig
@@ -255,7 +255,6 @@ pub const Object = struct {
pub fn resolveDecl(self: *Object, mod: *Module, decl_index: InternPool.DeclIndex) !SpvModule.Decl.Index {
const decl = mod.declPtr(decl_index);
assert(decl.has_tv); // TODO: Do we need to handle a situation where this is false?
- try mod.markDeclAlive(decl);
const entry = try self.decl_link.getOrPut(self.gpa, decl_index);
if (!entry.found_existing) {
@@ -861,7 +860,7 @@ const DeclGen = struct {
const val = arg_val;
- log.debug("constant: ty = {}, val = {}", .{ ty.fmt(mod), val.fmtValue(ty, mod) });
+ log.debug("constant: ty = {}, val = {}", .{ ty.fmt(mod), val.fmtValue(mod) });
if (val.isUndefDeep(mod)) {
return self.spv.constUndef(result_ty_ref);
}
@@ -1221,7 +1220,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 +1236,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 +2043,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 +2120,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 +2143,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 +2167,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 +4784,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 +4809,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