mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
use GetTagId in one more place
This commit is contained in:
parent
aecb509909
commit
454241a04f
3 changed files with 8 additions and 53 deletions
|
@ -1554,55 +1554,12 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PointerValue(value) => match structure_layout {
|
PointerValue(value) => match structure_layout {
|
||||||
Layout::Union(UnionLayout::NullableWrapped { nullable_id, .. })
|
Layout::Union(UnionLayout::NullableWrapped { .. }) if *index == 0 => {
|
||||||
if *index == 0 =>
|
panic!("this should not happen any more")
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
Layout::Union(UnionLayout::NullableUnwrapped { .. }) => {
|
||||||
{
|
|
||||||
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::NullableUnwrapped { nullable_id, .. }) => {
|
|
||||||
if *index == 0 {
|
if *index == 0 {
|
||||||
let is_null = env.builder.build_is_null(value, "is_null");
|
panic!("this should not happen any more")
|
||||||
|
|
||||||
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",
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
let struct_type = env
|
let struct_type = env
|
||||||
.context
|
.context
|
||||||
|
|
|
@ -1746,7 +1746,7 @@ fn decide_to_branching<'a>(
|
||||||
|
|
||||||
// We have learned more about the exact layout of the cond (based on the path)
|
// 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
|
// 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 tag_id_symbol = env.unique_symbol();
|
||||||
|
|
||||||
let temp = Stmt::Switch {
|
let temp = Stmt::Switch {
|
||||||
|
@ -1757,11 +1757,9 @@ fn decide_to_branching<'a>(
|
||||||
ret_layout,
|
ret_layout,
|
||||||
};
|
};
|
||||||
|
|
||||||
let expr = Expr::AccessAtIndex {
|
let expr = Expr::GetTagId {
|
||||||
index: 0,
|
|
||||||
field_layouts: &[Layout::TAG_SIZE],
|
|
||||||
structure: inner_cond_symbol,
|
structure: inner_cond_symbol,
|
||||||
wrapped: Wrapped::MultiTagUnion,
|
union_layout,
|
||||||
};
|
};
|
||||||
|
|
||||||
Stmt::Let(tag_id_symbol, expr, Layout::TAG_SIZE, env.arena.alloc(temp))
|
Stmt::Let(tag_id_symbol, expr, Layout::TAG_SIZE, env.arena.alloc(temp))
|
||||||
|
|
|
@ -3,7 +3,7 @@ procedure Test.0 ():
|
||||||
let Test.10 = 1i64;
|
let Test.10 = 1i64;
|
||||||
let Test.11 = 2i64;
|
let Test.11 = 2i64;
|
||||||
let Test.5 = These Test.12 Test.10 Test.11;
|
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:
|
switch Test.9:
|
||||||
case 2:
|
case 2:
|
||||||
let Test.2 = Index 1 Test.5;
|
let Test.2 = Index 1 Test.5;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue