From f2a24b48e1221a8954ddf16e9070e1470ee13e8d Mon Sep 17 00:00:00 2001 From: kcbanner Date: Sat, 23 Sep 2023 13:03:03 -0400 Subject: 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). --- src/InternPool.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/InternPool.zig') diff --git a/src/InternPool.zig b/src/InternPool.zig index 79d4127787..7c8702a716 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -1105,7 +1105,10 @@ pub const Key = union(enum) { pub const Union = extern struct { /// This is the union type; not the field type. ty: Index, - /// Indicates the active field. + /// Indicates the active field. This could be `none`, which indicates the tag is not known. `none` is only a valid value for extern and packed unions. + /// In those cases, the type of `val` is: + /// extern: a u8 array of the same byte length as the union + /// packed: an unsigned integer with the same bit size as the union tag: Index, /// The value of the active field. val: Index, @@ -5130,7 +5133,6 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { .un => |un| { assert(un.ty != .none); - assert(un.tag != .none); assert(un.val != .none); ip.items.appendAssumeCapacity(.{ .tag = .union_value, -- cgit v1.2.3