aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-05-28 10:33:59 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:47:56 -0700
commit3064d2aa7b9a8ea836cb70884b0640fe902ecc29 (patch)
treea3e315a06c0912e03ddac6b04cbe23205872bd31 /src/type.zig
parent3b6ca1d35b950d67fff5964f0063dadf01f30e2d (diff)
downloadzig-3064d2aa7b9a8ea836cb70884b0640fe902ecc29.tar.gz
zig-3064d2aa7b9a8ea836cb70884b0640fe902ecc29.zip
behavior: additional llvm fixes
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/type.zig b/src/type.zig
index bc2ce6fc7e..27c7756a68 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -1842,17 +1842,15 @@ pub const Type = struct {
/// See also `isPtrLikeOptional`.
pub fn optionalReprIsPayload(ty: Type, mod: *const Module) bool {
return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
- .opt_type => |child| switch (child.toType().zigTypeTag(mod)) {
- .Pointer => {
- const info = child.toType().ptrInfo(mod);
- return switch (info.size) {
- .C => false,
- else => !info.@"allowzero",
- };
+ .opt_type => |child_type| switch (mod.intern_pool.indexToKey(child_type)) {
+ .ptr_type => |ptr_type| switch (ptr_type.size) {
+ .C => false,
+ .Slice, .Many, .One => !ptr_type.is_allowzero,
},
- .ErrorSet => true,
+ .error_set_type => true,
else => false,
},
+ .ptr_type => |ptr_type| ptr_type.size == .C,
else => false,
};
}
@@ -2570,23 +2568,27 @@ pub const Type = struct {
return null;
},
- .auto, .explicit => switch (enum_type.names.len) {
- 0 => return Value.@"unreachable",
- 1 => {
- if (enum_type.values.len == 0) {
- const only = try mod.intern(.{ .enum_tag = .{
- .ty = ty.toIntern(),
- .int = try mod.intern(.{ .int = .{
- .ty = enum_type.tag_ty,
- .storage = .{ .u64 = 0 },
- } }),
- } });
- return only.toValue();
- } else {
- return enum_type.values[0].toValue();
- }
- },
- else => return null,
+ .auto, .explicit => {
+ if (enum_type.tag_ty.toType().hasRuntimeBits(mod)) return null;
+
+ switch (enum_type.names.len) {
+ 0 => return Value.@"unreachable",
+ 1 => {
+ if (enum_type.values.len == 0) {
+ const only = try mod.intern(.{ .enum_tag = .{
+ .ty = ty.toIntern(),
+ .int = try mod.intern(.{ .int = .{
+ .ty = enum_type.tag_ty,
+ .storage = .{ .u64 = 0 },
+ } }),
+ } });
+ return only.toValue();
+ } else {
+ return enum_type.values[0].toValue();
+ }
+ },
+ else => return null,
+ }
},
},
@@ -2887,7 +2889,7 @@ pub const Type = struct {
}
/// Asserts the type is an enum or a union.
- pub fn intTagType(ty: Type, mod: *Module) !Type {
+ pub fn intTagType(ty: Type, mod: *Module) Type {
return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
.union_type => |union_type| mod.unionPtr(union_type.index).tag_ty.intTagType(mod),
.enum_type => |enum_type| enum_type.tag_ty.toType(),