mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
llvm one element tag store
This commit is contained in:
parent
b6ca5e2fb9
commit
ba69987c1a
3 changed files with 39 additions and 2 deletions
|
@ -316,14 +316,20 @@ pub fn build_expr<'a, 'ctx, 'env>(
|
||||||
BasicValueEnum::StructValue(struct_val.into_struct_value())
|
BasicValueEnum::StructValue(struct_val.into_struct_value())
|
||||||
}
|
}
|
||||||
Tag {
|
Tag {
|
||||||
tag_id, arguments, ..
|
tag_id,
|
||||||
|
arguments,
|
||||||
|
tag_layout,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
|
/*
|
||||||
// put the discriminant in the first slot
|
// put the discriminant in the first slot
|
||||||
let discriminant = (
|
let discriminant = (
|
||||||
Expr::Byte(*tag_id),
|
Expr::Byte(*tag_id),
|
||||||
Layout::Builtin(Builtin::Byte(MutMap::default())),
|
Layout::Builtin(Builtin::Byte(MutMap::default())),
|
||||||
);
|
);
|
||||||
let it = std::iter::once(&discriminant).chain(arguments.iter());
|
let it = std::iter::once(&discriminant).chain(arguments.iter());
|
||||||
|
*/
|
||||||
|
let it = arguments.iter();
|
||||||
|
|
||||||
let ctx = env.context;
|
let ctx = env.context;
|
||||||
let builder = env.builder;
|
let builder = env.builder;
|
||||||
|
|
|
@ -68,7 +68,21 @@ pub fn basic_type_from_layout<'ctx>(
|
||||||
.struct_type(field_types.into_bump_slice(), false)
|
.struct_type(field_types.into_bump_slice(), false)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
}
|
}
|
||||||
Union(_) => {
|
Union(tags) if tags.len() == 1 => {
|
||||||
|
let (_, layouts) = tags.into_iter().next().unwrap();
|
||||||
|
|
||||||
|
// Determine types
|
||||||
|
let mut field_types = Vec::with_capacity_in(layouts.len(), arena);
|
||||||
|
|
||||||
|
for layout in layouts.iter() {
|
||||||
|
field_types.push(basic_type_from_layout(arena, context, layout));
|
||||||
|
}
|
||||||
|
|
||||||
|
context
|
||||||
|
.struct_type(field_types.into_bump_slice(), false)
|
||||||
|
.as_basic_type_enum()
|
||||||
|
}
|
||||||
|
Union(tags) => {
|
||||||
// TODO make this dynamic
|
// TODO make this dynamic
|
||||||
let ptr_size = std::mem::size_of::<i64>();
|
let ptr_size = std::mem::size_of::<i64>();
|
||||||
let union_size = layout.stack_size(ptr_size as u32);
|
let union_size = layout.stack_size(ptr_size as u32);
|
||||||
|
|
|
@ -77,6 +77,7 @@ mod test_gen {
|
||||||
// Populate Procs and Subs, and get the low-level Expr from the canonical Expr
|
// Populate Procs and Subs, and get the low-level Expr from the canonical Expr
|
||||||
let mono_expr = Expr::new(&arena, &mut subs, loc_expr.value, &mut procs, home, &mut ident_ids, POINTER_SIZE);
|
let mono_expr = Expr::new(&arena, &mut subs, loc_expr.value, &mut procs, home, &mut ident_ids, POINTER_SIZE);
|
||||||
|
|
||||||
|
|
||||||
// Put this module's ident_ids back in the interns
|
// Put this module's ident_ids back in the interns
|
||||||
env.interns.all_ident_ids.insert(home, ident_ids);
|
env.interns.all_ident_ids.insert(home, ident_ids);
|
||||||
|
|
||||||
|
@ -691,6 +692,22 @@ mod test_gen {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn one_element_tag() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
x : [ Pair Int ]
|
||||||
|
x = Pair 2
|
||||||
|
|
||||||
|
0x3
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
3,
|
||||||
|
i64
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn gen_when_one_branch() {
|
fn gen_when_one_branch() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue