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.
This commit is contained in:
Andrew Kelley
2023-05-12 16:22:37 -07:00
parent d89807efbb
commit 88dbd62bcb
19 changed files with 771 additions and 674 deletions

View File

@@ -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()) {