diff --git a/compiler/gen/src/llvm/build.rs b/compiler/gen/src/llvm/build.rs index 6ff2a8a417..f9bfb9bafc 100644 --- a/compiler/gen/src/llvm/build.rs +++ b/compiler/gen/src/llvm/build.rs @@ -316,14 +316,20 @@ pub fn build_expr<'a, 'ctx, 'env>( BasicValueEnum::StructValue(struct_val.into_struct_value()) } Tag { - tag_id, arguments, .. + tag_id, + arguments, + tag_layout, + .. } => { + /* // put the discriminant in the first slot let discriminant = ( Expr::Byte(*tag_id), Layout::Builtin(Builtin::Byte(MutMap::default())), ); let it = std::iter::once(&discriminant).chain(arguments.iter()); + */ + let it = arguments.iter(); let ctx = env.context; let builder = env.builder; diff --git a/compiler/gen/src/llvm/convert.rs b/compiler/gen/src/llvm/convert.rs index e03224ca55..ecd14decd8 100644 --- a/compiler/gen/src/llvm/convert.rs +++ b/compiler/gen/src/llvm/convert.rs @@ -68,7 +68,21 @@ pub fn basic_type_from_layout<'ctx>( .struct_type(field_types.into_bump_slice(), false) .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 let ptr_size = std::mem::size_of::(); let union_size = layout.stack_size(ptr_size as u32); diff --git a/compiler/gen/tests/test_gen.rs b/compiler/gen/tests/test_gen.rs index 0387f15b76..a42712c710 100644 --- a/compiler/gen/tests/test_gen.rs +++ b/compiler/gen/tests/test_gen.rs @@ -77,6 +77,7 @@ mod test_gen { // 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); + // Put this module's ident_ids back in the interns 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] fn gen_when_one_branch() { assert_evals_to!(