mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
use GetTagId
This commit is contained in:
parent
bc8bd95b3d
commit
0de501554a
2 changed files with 28 additions and 42 deletions
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue