use GetTagId

This commit is contained in:
Folkert 2021-06-20 20:49:36 +02:00
parent bc8bd95b3d
commit 0de501554a
2 changed files with 28 additions and 42 deletions

View file

@ -1660,8 +1660,7 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
builder.build_load(tag_id_pointer.into_pointer_value(), "load_tag_id")
}
UnionLayout::Recursive(_) => {
let pointer = builder.build_alloca(argument.get_type(), "get_type");
builder.build_store(pointer, argument);
let pointer = argument.into_pointer_value();
let tag_id_pointer = builder.build_bitcast(
pointer,
env.context.i64_type().ptr_type(AddressSpace::Generic),

View file

@ -1161,39 +1161,23 @@ fn test_to_equality<'a>(
Layout<'a>,
Option<ConstructorKnown<'a>>,
) {
let (rhs_symbol, mut stores, _layout) =
let (rhs_symbol, mut stores, test_layout) =
path_to_expr_help(env, cond_symbol, &path, *cond_layout);
match test {
Test::IsCtor {
tag_id,
union,
arguments,
..
} => {
Test::IsCtor { tag_id, union, .. } => {
let path_symbol = rhs_symbol;
// the IsCtor check should never be generated for tag unions of size 1
// (e.g. record pattern guard matches)
debug_assert!(union.alternatives.len() > 1);
match test_layout {
Layout::Union(union_layout) => {
let lhs = Expr::Literal(Literal::Int(tag_id as i128));
let mut field_layouts =
bumpalo::collections::Vec::with_capacity_in(arguments.len(), env.arena);
// add the tag discriminant
field_layouts.push(Layout::Builtin(Builtin::Int64));
for (_, layout) in arguments {
field_layouts.push(layout);
}
let field_layouts = field_layouts.into_bump_slice();
let rhs = Expr::AccessAtIndex {
index: 0,
field_layouts,
let rhs = Expr::GetTagId {
structure: path_symbol,
wrapped: Wrapped::MultiTagUnion,
union_layout,
};
let lhs_symbol = env.unique_symbol();
@ -1214,6 +1198,9 @@ fn test_to_equality<'a>(
}),
)
}
_ => unreachable!("{:?}", (cond_layout, union)),
}
}
Test::IsInt(test_int) => {
// TODO don't downcast i128 here
debug_assert!(test_int <= i64::MAX as i128);