use GetTagId in one more place

This commit is contained in:
Folkert 2021-06-20 21:05:02 +02:00
parent aecb509909
commit 454241a04f
3 changed files with 8 additions and 53 deletions

View file

@ -1554,55 +1554,12 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
}
}
PointerValue(value) => match structure_layout {
Layout::Union(UnionLayout::NullableWrapped { nullable_id, .. })
if *index == 0 =>
{
let ptr = value;
let is_null = env.builder.build_is_null(ptr, "is_null");
let ctx = env.context;
let then_block = ctx.append_basic_block(parent, "then");
let else_block = ctx.append_basic_block(parent, "else");
let cont_block = ctx.append_basic_block(parent, "cont");
let result = builder.build_alloca(ctx.i64_type(), "result");
env.builder
.build_conditional_branch(is_null, then_block, else_block);
{
env.builder.position_at_end(then_block);
let tag_id = ctx.i64_type().const_int(*nullable_id as u64, false);
env.builder.build_store(result, tag_id);
env.builder.build_unconditional_branch(cont_block);
}
{
env.builder.position_at_end(else_block);
let tag_id = extract_tag_discriminant_ptr(env, ptr);
env.builder.build_store(result, tag_id);
env.builder.build_unconditional_branch(cont_block);
}
env.builder.position_at_end(cont_block);
env.builder.build_load(result, "load_result")
Layout::Union(UnionLayout::NullableWrapped { .. }) if *index == 0 => {
panic!("this should not happen any more")
}
Layout::Union(UnionLayout::NullableUnwrapped { nullable_id, .. }) => {
Layout::Union(UnionLayout::NullableUnwrapped { .. }) => {
if *index == 0 {
let is_null = env.builder.build_is_null(value, "is_null");
let ctx = env.context;
let then_value = ctx.i64_type().const_int(*nullable_id as u64, false);
let else_value = ctx.i64_type().const_int(!*nullable_id as u64, false);
env.builder.build_select(
is_null,
then_value,
else_value,
"select_tag_id",
)
panic!("this should not happen any more")
} else {
let struct_type = env
.context

View file

@ -1746,7 +1746,7 @@ fn decide_to_branching<'a>(
// We have learned more about the exact layout of the cond (based on the path)
// but tests are still relative to the original cond symbol
let mut switch = if let Layout::Union(_) = inner_cond_layout {
let mut switch = if let Layout::Union(union_layout) = inner_cond_layout {
let tag_id_symbol = env.unique_symbol();
let temp = Stmt::Switch {
@ -1757,11 +1757,9 @@ fn decide_to_branching<'a>(
ret_layout,
};
let expr = Expr::AccessAtIndex {
index: 0,
field_layouts: &[Layout::TAG_SIZE],
let expr = Expr::GetTagId {
structure: inner_cond_symbol,
wrapped: Wrapped::MultiTagUnion,
union_layout,
};
Stmt::Let(tag_id_symbol, expr, Layout::TAG_SIZE, env.arena.alloc(temp))

View file

@ -3,7 +3,7 @@ procedure Test.0 ():
let Test.10 = 1i64;
let Test.11 = 2i64;
let Test.5 = These Test.12 Test.10 Test.11;
let Test.9 = Index 0 Test.5;
let Test.9 = GetTagId Test.5;
switch Test.9:
case 2:
let Test.2 = Index 1 Test.5;