aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-05-03 18:11:07 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:40:04 -0700
commit836d8a1f64cb811641e621799429c54f222717eb (patch)
treebbcdd77b43cf4fa0bdd97abcfbe2457b57d9ae46 /src/codegen
parentbcd4bb8afbea84d86fd8758b581b141e7086b16b (diff)
downloadzig-836d8a1f64cb811641e621799429c54f222717eb.tar.gz
zig-836d8a1f64cb811641e621799429c54f222717eb.zip
stage2: move most simple types to InternPool
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig16
-rw-r--r--src/codegen/llvm.zig38
-rw-r--r--src/codegen/spirv.zig6
3 files changed, 30 insertions, 30 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index f4daa56a6d..2e5e45d54c 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -1508,7 +1508,7 @@ pub const DeclGen = struct {
}
if (fn_decl.val.castTag(.function)) |func_payload|
if (func_payload.data.is_cold) try w.writeAll("zig_cold ");
- if (fn_info.return_type.tag() == .noreturn) try w.writeAll("zig_noreturn ");
+ if (fn_info.return_type.ip_index == .noreturn_type) try w.writeAll("zig_noreturn ");
const trailing = try renderTypePrefix(
dg.decl_index,
@@ -3783,7 +3783,7 @@ fn airNot(f: *Function, inst: Air.Inst.Index) !CValue {
const ty_op = f.air.instructions.items(.data)[inst].ty_op;
const operand_ty = f.typeOf(ty_op.operand);
const scalar_ty = operand_ty.scalarType(mod);
- if (scalar_ty.tag() != .bool) return try airUnBuiltinCall(f, inst, "not", .bits);
+ if (scalar_ty.ip_index != .bool_type) return try airUnBuiltinCall(f, inst, "not", .bits);
const op = try f.resolveInst(ty_op.operand);
try reap(f, inst, &.{ty_op.operand});
@@ -4292,7 +4292,7 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {
const writer = f.object.writer();
const inst_ty = f.typeOfIndex(inst);
- const result = if (inst_ty.tag() != .void and !f.liveness.isUnused(inst))
+ const result = if (inst_ty.ip_index != .void_type and !f.liveness.isUnused(inst))
try f.allocLocal(inst, inst_ty)
else
.none;
@@ -4354,7 +4354,7 @@ fn lowerTry(
const payload_ty = err_union_ty.errorUnionPayload();
const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(mod);
- if (!err_union_ty.errorUnionSet().errorSetIsEmpty()) {
+ if (!err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
try writer.writeAll("if (");
if (!payload_has_bits) {
if (is_ptr)
@@ -5549,7 +5549,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
if (!payload_ty.hasRuntimeBits(mod)) {
try f.writeCValue(writer, operand, .Other);
} else {
- if (!error_ty.errorSetIsEmpty())
+ if (!error_ty.errorSetIsEmpty(mod))
if (operand_is_ptr)
try f.writeCValueDerefMember(writer, operand, .{ .identifier = "error" })
else
@@ -5768,7 +5768,7 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const
try f.writeCValue(writer, local, .Other);
try writer.writeAll(" = ");
- if (!error_ty.errorSetIsEmpty())
+ if (!error_ty.errorSetIsEmpty(mod))
if (payload_ty.hasRuntimeBits(mod))
if (is_ptr)
try f.writeCValueDerefMember(writer, operand, .{ .identifier = "error" })
@@ -6032,7 +6032,7 @@ fn airCmpBuiltinCall(
try writer.writeByte(')');
if (!ref_ret) try writer.print(" {s} {}", .{
compareOperatorC(operator),
- try f.fmtIntLiteral(Type.initTag(.i32), Value.zero),
+ try f.fmtIntLiteral(Type.i32, Value.zero),
});
try writer.writeAll(";\n");
try v.end(f, inst, writer);
@@ -7749,7 +7749,7 @@ const LowerFnRetTyBuffer = struct {
payload: Type.Payload.AnonStruct,
};
fn lowerFnRetTy(ret_ty: Type, buffer: *LowerFnRetTyBuffer, mod: *const Module) Type {
- if (ret_ty.zigTypeTag(mod) == .NoReturn) return Type.initTag(.noreturn);
+ if (ret_ty.zigTypeTag(mod) == .NoReturn) return Type.noreturn;
if (lowersToArray(ret_ty, mod)) {
buffer.names = [1][]const u8{"array"};
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index ce78b06f2e..232cd9d42f 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -1730,7 +1730,7 @@ pub const Object = struct {
return ptr_di_ty;
},
.Opaque => {
- if (ty.tag() == .anyopaque) {
+ if (ty.ip_index == .anyopaque_type) {
const di_ty = dib.createBasicType("anyopaque", 0, DW.ATE.signed);
gop.value_ptr.* = AnnotatedDITypePtr.initFull(di_ty);
return di_ty;
@@ -2847,25 +2847,23 @@ pub const DeclGen = struct {
const llvm_addrspace = toLlvmAddressSpace(ptr_info.@"addrspace", target);
return dg.context.pointerType(llvm_addrspace);
},
- .Opaque => switch (t.tag()) {
- .@"opaque" => {
- const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = dg.module });
- if (gop.found_existing) return gop.value_ptr.*;
+ .Opaque => {
+ if (t.ip_index == .anyopaque_type) return dg.context.intType(8);
- // The Type memory is ephemeral; since we want to store a longer-lived
- // reference, we need to copy it here.
- gop.key_ptr.* = try t.copy(dg.object.type_map_arena.allocator());
+ const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = dg.module });
+ if (gop.found_existing) return gop.value_ptr.*;
- const opaque_obj = t.castTag(.@"opaque").?.data;
- const name = try opaque_obj.getFullyQualifiedName(dg.module);
- defer gpa.free(name);
+ // The Type memory is ephemeral; since we want to store a longer-lived
+ // reference, we need to copy it here.
+ gop.key_ptr.* = try t.copy(dg.object.type_map_arena.allocator());
- const llvm_struct_ty = dg.context.structCreateNamed(name);
- gop.value_ptr.* = llvm_struct_ty; // must be done before any recursive calls
- return llvm_struct_ty;
- },
- .anyopaque => return dg.context.intType(8),
- else => unreachable,
+ const opaque_obj = t.castTag(.@"opaque").?.data;
+ const name = try opaque_obj.getFullyQualifiedName(dg.module);
+ defer gpa.free(name);
+
+ const llvm_struct_ty = dg.context.structCreateNamed(name);
+ gop.value_ptr.* = llvm_struct_ty; // must be done before any recursive calls
+ return llvm_struct_ty;
},
.Array => {
const elem_ty = t.childType();
@@ -5531,7 +5529,7 @@ pub const FuncGen = struct {
const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(mod);
const err_union_llvm_ty = try fg.dg.lowerType(err_union_ty);
- if (!err_union_ty.errorUnionSet().errorSetIsEmpty()) {
+ if (!err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
const is_err = err: {
const err_set_ty = try fg.dg.lowerType(Type.anyerror);
const zero = err_set_ty.constNull();
@@ -6715,7 +6713,7 @@ pub const FuncGen = struct {
const err_set_ty = try self.dg.lowerType(Type.anyerror);
const zero = err_set_ty.constNull();
- if (err_union_ty.errorUnionSet().errorSetIsEmpty()) {
+ if (err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
const llvm_i1 = self.context.intType(1);
switch (op) {
.EQ => return llvm_i1.constInt(1, .False), // 0 == 0
@@ -6864,7 +6862,7 @@ pub const FuncGen = struct {
const operand = try self.resolveInst(ty_op.operand);
const operand_ty = self.typeOf(ty_op.operand);
const err_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
- if (err_union_ty.errorUnionSet().errorSetIsEmpty()) {
+ if (err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
const err_llvm_ty = try self.dg.lowerType(Type.anyerror);
if (operand_is_ptr) {
return operand;
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig
index 90c2d93458..3a5f5d6f6a 100644
--- a/src/codegen/spirv.zig
+++ b/src/codegen/spirv.zig
@@ -2849,6 +2849,7 @@ pub const DeclGen = struct {
}
fn airTry(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
+ const mod = self.module;
const pl_op = self.air.instructions.items(.data)[inst].pl_op;
const err_union_id = try self.resolve(pl_op.operand);
const extra = self.air.extraData(Air.Try, pl_op.payload);
@@ -2862,7 +2863,7 @@ pub const DeclGen = struct {
const eu_layout = self.errorUnionLayout(payload_ty);
- if (!err_union_ty.errorUnionSet().errorSetIsEmpty()) {
+ if (!err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
const err_id = if (eu_layout.payload_has_bits)
try self.extractField(Type.anyerror, err_union_id, eu_layout.errorFieldIndex())
else
@@ -2910,12 +2911,13 @@ pub const DeclGen = struct {
fn airErrUnionErr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
if (self.liveness.isUnused(inst)) return null;
+ const mod = self.module;
const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const operand_id = try self.resolve(ty_op.operand);
const err_union_ty = self.typeOf(ty_op.operand);
const err_ty_ref = try self.resolveType(Type.anyerror, .direct);
- if (err_union_ty.errorUnionSet().errorSetIsEmpty()) {
+ if (err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
// No error possible, so just return undefined.
return try self.spv.constUndef(err_ty_ref);
}