mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
cleanup
This commit is contained in:
parent
80a1ca698f
commit
3e53f0a14d
5 changed files with 33 additions and 33 deletions
|
@ -141,8 +141,7 @@ fn build_has_tag_id_help<'a, 'ctx, 'env>(
|
|||
|
||||
let actual_tag_id = {
|
||||
let tag_id_i64 =
|
||||
crate::llvm::build::get_tag_id(env, function_value, &union_layout, tag_value)
|
||||
.into_int_value();
|
||||
crate::llvm::build::get_tag_id(env, function_value, &union_layout, tag_value);
|
||||
|
||||
env.builder
|
||||
.build_int_cast(tag_id_i64, env.context.i16_type(), "to_i16")
|
||||
|
|
|
@ -1156,7 +1156,7 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
// cast the argument bytes into the desired shape for this tag
|
||||
let (argument, _structure_layout) = load_symbol_and_layout(scope, structure);
|
||||
|
||||
get_tag_id(env, parent, union_layout, argument)
|
||||
get_tag_id(env, parent, &union_layout, argument).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1584,20 +1584,18 @@ pub fn get_tag_id<'a, 'ctx, 'env>(
|
|||
parent: FunctionValue<'ctx>,
|
||||
union_layout: &UnionLayout<'a>,
|
||||
argument: BasicValueEnum<'ctx>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
) -> IntValue<'ctx> {
|
||||
let builder = env.builder;
|
||||
match union_layout {
|
||||
UnionLayout::NonRecursive(_) => {
|
||||
let tag = argument.into_struct_value();
|
||||
|
||||
builder
|
||||
.build_extract_value(tag, TAG_ID_INDEX, "get_tag_id")
|
||||
.unwrap()
|
||||
extract_tag_discriminant_non_recursive(env, tag)
|
||||
}
|
||||
UnionLayout::Recursive(_) => {
|
||||
extract_tag_discriminant_ptr2(env, argument.into_pointer_value()).into()
|
||||
extract_tag_discriminant_ptr(env, argument.into_pointer_value())
|
||||
}
|
||||
UnionLayout::NonNullableUnwrapped(_) => env.context.i64_type().const_zero().into(),
|
||||
UnionLayout::NonNullableUnwrapped(_) => env.context.i64_type().const_zero(),
|
||||
UnionLayout::NullableWrapped { nullable_id, .. } => {
|
||||
let argument_ptr = argument.into_pointer_value();
|
||||
let is_null = env.builder.build_is_null(argument_ptr, "is_null");
|
||||
|
@ -1621,14 +1619,16 @@ pub fn get_tag_id<'a, 'ctx, 'env>(
|
|||
|
||||
{
|
||||
env.builder.position_at_end(else_block);
|
||||
let tag_id = extract_tag_discriminant_ptr2(env, argument_ptr);
|
||||
let tag_id = extract_tag_discriminant_ptr(env, argument_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")
|
||||
env.builder
|
||||
.build_load(result, "load_result")
|
||||
.into_int_value()
|
||||
}
|
||||
UnionLayout::NullableUnwrapped { nullable_id, .. } => {
|
||||
let argument_ptr = argument.into_pointer_value();
|
||||
|
@ -1641,6 +1641,7 @@ pub fn get_tag_id<'a, 'ctx, 'env>(
|
|||
|
||||
env.builder
|
||||
.build_select(is_null, then_value, else_value, "select_tag_id")
|
||||
.into_int_value()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2545,16 +2546,7 @@ pub fn complex_bitcast<'ctx>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn extract_tag_discriminant<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
parent: FunctionValue<'ctx>,
|
||||
union_layout: UnionLayout<'a>,
|
||||
cond_value: BasicValueEnum<'ctx>,
|
||||
) -> IntValue<'ctx> {
|
||||
get_tag_id(env, parent, &union_layout, cond_value).into_int_value()
|
||||
}
|
||||
|
||||
fn extract_tag_discriminant_ptr2<'a, 'ctx, 'env>(
|
||||
fn extract_tag_discriminant_ptr<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
from_value: PointerValue<'ctx>,
|
||||
) -> IntValue<'ctx> {
|
||||
|
@ -2568,6 +2560,16 @@ fn extract_tag_discriminant_ptr2<'a, 'ctx, 'env>(
|
|||
.into_int_value()
|
||||
}
|
||||
|
||||
fn extract_tag_discriminant_non_recursive<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
tag: StructValue<'ctx>,
|
||||
) -> IntValue<'ctx> {
|
||||
env.builder
|
||||
.build_extract_value(tag, TAG_ID_INDEX, "get_tag_id")
|
||||
.unwrap()
|
||||
.into_int_value()
|
||||
}
|
||||
|
||||
struct SwitchArgsIr<'a, 'ctx> {
|
||||
pub cond_symbol: Symbol,
|
||||
pub cond_layout: Layout<'a>,
|
||||
|
@ -2647,7 +2649,7 @@ fn build_switch_ir<'a, 'ctx, 'env>(
|
|||
Layout::Union(variant) => {
|
||||
cond_layout = Layout::Builtin(Builtin::Int64);
|
||||
|
||||
extract_tag_discriminant(env, parent, variant, cond_value)
|
||||
get_tag_id(env, parent, &variant, cond_value)
|
||||
}
|
||||
Layout::Builtin(_) => cond_value.into_int_value(),
|
||||
other => todo!("Build switch value from layout: {:?}", other),
|
||||
|
|
|
@ -406,7 +406,7 @@ fn hash_tag<'a, 'ctx, 'env>(
|
|||
env.builder.position_at_end(entry_block);
|
||||
match union_layout {
|
||||
NonRecursive(tags) => {
|
||||
let tag_id = get_tag_id(env, parent, union_layout, tag).into_int_value();
|
||||
let tag_id = get_tag_id(env, parent, union_layout, tag);
|
||||
|
||||
let mut cases = Vec::with_capacity_in(tags.len(), env.arena);
|
||||
|
||||
|
@ -448,7 +448,7 @@ fn hash_tag<'a, 'ctx, 'env>(
|
|||
env.builder.build_switch(tag_id, default, &cases);
|
||||
}
|
||||
Recursive(tags) => {
|
||||
let tag_id = get_tag_id(env, parent, union_layout, tag).into_int_value();
|
||||
let tag_id = get_tag_id(env, parent, union_layout, tag);
|
||||
|
||||
let mut cases = Vec::with_capacity_in(tags.len(), env.arena);
|
||||
|
||||
|
@ -551,7 +551,7 @@ fn hash_tag<'a, 'ctx, 'env>(
|
|||
|
||||
env.builder.position_at_end(hash_other_block);
|
||||
|
||||
let tag_id = get_tag_id(env, parent, union_layout, tag.into()).into_int_value();
|
||||
let tag_id = get_tag_id(env, parent, union_layout, tag.into());
|
||||
|
||||
let default = cases.pop().unwrap().1;
|
||||
|
||||
|
|
|
@ -846,8 +846,8 @@ fn build_tag_eq_help<'a, 'ctx, 'env>(
|
|||
|
||||
match union_layout {
|
||||
NonRecursive(tags) => {
|
||||
let id1 = get_tag_id(env, parent, union_layout, tag1).into_int_value();
|
||||
let id2 = get_tag_id(env, parent, union_layout, tag2).into_int_value();
|
||||
let id1 = get_tag_id(env, parent, union_layout, tag1);
|
||||
let id2 = get_tag_id(env, parent, union_layout, tag2);
|
||||
|
||||
let compare_tag_fields = ctx.append_basic_block(parent, "compare_tag_fields");
|
||||
|
||||
|
@ -925,8 +925,8 @@ fn build_tag_eq_help<'a, 'ctx, 'env>(
|
|||
|
||||
env.builder.position_at_end(compare_tag_ids);
|
||||
|
||||
let id1 = get_tag_id(env, parent, union_layout, tag1).into_int_value();
|
||||
let id2 = get_tag_id(env, parent, union_layout, tag2).into_int_value();
|
||||
let id1 = get_tag_id(env, parent, union_layout, tag1);
|
||||
let id2 = get_tag_id(env, parent, union_layout, tag2);
|
||||
|
||||
let compare_tag_fields = ctx.append_basic_block(parent, "compare_tag_fields");
|
||||
|
||||
|
@ -1076,8 +1076,8 @@ fn build_tag_eq_help<'a, 'ctx, 'env>(
|
|||
|
||||
env.builder.position_at_end(compare_other);
|
||||
|
||||
let id1 = get_tag_id(env, parent, union_layout, tag1).into_int_value();
|
||||
let id2 = get_tag_id(env, parent, union_layout, tag2).into_int_value();
|
||||
let id1 = get_tag_id(env, parent, union_layout, tag1);
|
||||
let id2 = get_tag_id(env, parent, union_layout, tag2);
|
||||
|
||||
let compare_tag_fields = ctx.append_basic_block(parent, "compare_tag_fields");
|
||||
|
||||
|
|
|
@ -1520,8 +1520,7 @@ fn build_rec_union_recursive_decrement<'a, 'ctx, 'env>(
|
|||
env.builder.build_unconditional_branch(only_branch);
|
||||
} else {
|
||||
// read the tag_id
|
||||
let current_tag_id =
|
||||
get_tag_id(env, parent, &union_layout, value_ptr.into()).into_int_value();
|
||||
let current_tag_id = get_tag_id(env, parent, &union_layout, value_ptr.into());
|
||||
|
||||
let merge_block = env.context.append_basic_block(parent, "decrement_merge");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue