aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorkcbanner <kcbanner@gmail.com>2023-09-23 13:03:03 -0400
committerkcbanner <kcbanner@gmail.com>2023-09-23 13:05:04 -0400
commitf2a24b48e1221a8954ddf16e9070e1470ee13e8d (patch)
tree65443a1d67bb03be28927643462f92568fedbbc0 /src/Module.zig
parent2fddd767ba20374e7677003c101e60f470c3804c (diff)
downloadzig-f2a24b48e1221a8954ddf16e9070e1470ee13e8d.tar.gz
zig-f2a24b48e1221a8954ddf16e9070e1470ee13e8d.zip
sema: rework the comptime representation of comptime unions
When the tag is not known, it's set to `.none`. In this case, the value is either an array of bytes (for extern unions) or an integer (for packed unions).
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig31
1 files changed, 2 insertions, 29 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 09e136cde8..349a7d4ba5 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -5823,7 +5823,7 @@ pub fn markReferencedDeclsAlive(mod: *Module, val: Value) Allocator.Error!void {
.aggregate => |aggregate| for (aggregate.storage.values()) |elem|
try mod.markReferencedDeclsAlive(elem.toValue()),
.un => |un| {
- try mod.markReferencedDeclsAlive(un.tag.toValue());
+ if (un.tag != .none) try mod.markReferencedDeclsAlive(un.tag.toValue());
try mod.markReferencedDeclsAlive(un.val.toValue());
},
else => {},
@@ -6607,7 +6607,7 @@ pub fn unionFieldNormalAlignment(mod: *Module, u: InternPool.UnionType, field_in
pub fn unionTagFieldIndex(mod: *Module, u: InternPool.UnionType, enum_tag: Value) ?u32 {
const ip = &mod.intern_pool;
- if (enum_tag.toIntern() == .undef) return null;
+ if (enum_tag.toIntern() == .none) return null;
assert(ip.typeOf(enum_tag.toIntern()) == u.enum_tag_ty);
const enum_type = ip.indexToKey(u.enum_tag_ty).enum_type;
return enum_type.tagValueIndex(ip, enum_tag.toIntern());
@@ -6673,30 +6673,3 @@ pub fn structPackedFieldBitOffset(
}
unreachable; // index out of bounds
}
-
-pub fn unionLargestField(mod: *Module, u: InternPool.UnionType) struct {
- ty: Type,
- index: u32,
- size: u64,
-} {
- const fields = u.field_types.get(&mod.intern_pool);
- assert(fields.len != 0);
- var largest_field_ty: Type = undefined;
- var largest_field_size: u64 = 0;
- var largest_field_index: u32 = 0;
- for (fields, 0..) |union_field, i| {
- const field_ty = union_field.toType();
- const size: u32 = @intCast(field_ty.abiSize(mod));
- if (size > largest_field_size) {
- largest_field_ty = field_ty;
- largest_field_size = size;
- largest_field_index = @intCast(i);
- }
- }
-
- return .{
- .ty = largest_field_ty,
- .index = largest_field_index,
- .size = largest_field_size,
- };
-}