diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-05-12 16:22:37 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-06-10 20:46:17 -0700 |
| commit | 88dbd62bcbac24c09791a7838d2f08c2f540967a (patch) | |
| tree | 9935a67bb6644fc448513eb728a1f22a587a89fb /src/codegen.zig | |
| parent | d89807efbb1bd5af0a92544298fc08ad6ba2d255 (diff) | |
| download | zig-88dbd62bcbac24c09791a7838d2f08c2f540967a.tar.gz zig-88dbd62bcbac24c09791a7838d2f08c2f540967a.zip | |
stage2: move enum tag values into the InternPool
I'm seeing a new assertion trip: the call to `enumTagFieldIndex` in the
implementation of `@Type` is attempting to query the field index of an
union's enum tag, but the type of the enum tag value provided is not the
same as the union's tag type. Most likely this is a problem with type
coercion, since values are now typed.
Another problem is that I added some hacks in std.builtin because I
didn't see any convenient way to access them from Sema. That should
definitely be cleaned up before merging this branch.
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 148a69016a..90b6bfccf2 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -196,7 +196,7 @@ pub fn generateSymbol( typed_value.val.fmtValue(typed_value.ty, mod), }); - if (typed_value.val.isUndefDeep()) { + if (typed_value.val.isUndefDeep(mod)) { const abi_size = math.cast(usize, typed_value.ty.abiSize(mod)) orelse return error.Overflow; try code.appendNTimes(0xaa, abi_size); return Result.ok; @@ -1168,7 +1168,7 @@ pub fn genTypedValue( typed_value.val.fmtValue(typed_value.ty, mod), }); - if (typed_value.val.isUndef()) + if (typed_value.val.isUndef(mod)) return GenResult.mcv(.undef); const target = bin_file.options.target; @@ -1229,24 +1229,12 @@ pub fn genTypedValue( } }, .Enum => { - if (typed_value.val.castTag(.enum_field_index)) |field_index| { - const enum_type = mod.intern_pool.indexToKey(typed_value.ty.ip_index).enum_type; - if (enum_type.values.len != 0) { - const tag_val = enum_type.values[field_index.data]; - return genTypedValue(bin_file, src_loc, .{ - .ty = enum_type.tag_ty.toType(), - .val = tag_val.toValue(), - }, owner_decl_index); - } else { - return GenResult.mcv(.{ .immediate = field_index.data }); - } - } else { - const int_tag_ty = try typed_value.ty.intTagType(mod); - return genTypedValue(bin_file, src_loc, .{ - .ty = int_tag_ty, - .val = typed_value.val, - }, owner_decl_index); - } + const enum_tag = mod.intern_pool.indexToKey(typed_value.val.ip_index).enum_tag; + const int_tag_ty = mod.intern_pool.typeOf(enum_tag.int); + return genTypedValue(bin_file, src_loc, .{ + .ty = int_tag_ty.toType(), + .val = enum_tag.int.toValue(), + }, owner_decl_index); }, .ErrorSet => { switch (typed_value.val.tag()) { |
