diff --git a/crates/compiler/gen_llvm/src/llvm/convert.rs b/crates/compiler/gen_llvm/src/llvm/convert.rs index 265b18f968..ec57c5f359 100644 --- a/crates/compiler/gen_llvm/src/llvm/convert.rs +++ b/crates/compiler/gen_llvm/src/llvm/convert.rs @@ -1,5 +1,5 @@ use crate::llvm::build::{BuilderExt, Env}; -use crate::llvm::struct_::RocStructType; +use bumpalo::collections::Vec as AVec; use inkwell::context::Context; use inkwell::types::{BasicType, BasicTypeEnum, FloatType, IntType, StructType}; use inkwell::values::StructValue; @@ -22,7 +22,7 @@ pub fn basic_type_from_layout<'a, 'ctx, 'env>( match layout_interner.get_repr(layout) { Struct(sorted_fields, ..) => { - RocStructType::build(env, layout_interner, sorted_fields).into() + basic_type_from_record(env, layout_interner, sorted_fields).into() } LambdaSet(lambda_set) => { basic_type_from_layout(env, layout_interner, lambda_set.runtime_representation()) @@ -43,6 +43,23 @@ pub fn basic_type_from_layout<'a, 'ctx, 'env>( } } +fn basic_type_from_record<'a, 'ctx>( + env: &Env<'a, 'ctx, '_>, + layout_interner: &mut STLayoutInterner<'a>, + fields: &[InLayout<'_>], +) -> StructType<'ctx> { + let mut field_types = AVec::with_capacity_in(fields.len(), env.arena); + + for field_layout in fields.iter() { + let typ = basic_type_from_layout(env, layout_interner, *field_layout); + + field_types.push(typ); + } + + env.context + .struct_type(field_types.into_bump_slice(), false) +} + pub fn struct_type_from_union_layout<'a, 'ctx>( env: &Env<'a, 'ctx, '_>, layout_interner: &mut STLayoutInterner<'a>, @@ -82,7 +99,7 @@ pub fn struct_type_from_union_layout<'a, 'ctx>( } } -pub fn basic_type_from_union_layout<'a, 'ctx>( +fn basic_type_from_union_layout<'a, 'ctx>( env: &Env<'a, 'ctx, '_>, layout_interner: &mut STLayoutInterner<'a>, union_layout: &UnionLayout<'_>, diff --git a/crates/compiler/gen_llvm/src/llvm/struct_.rs b/crates/compiler/gen_llvm/src/llvm/struct_.rs index ef4833c09f..dbf852f0ff 100644 --- a/crates/compiler/gen_llvm/src/llvm/struct_.rs +++ b/crates/compiler/gen_llvm/src/llvm/struct_.rs @@ -2,7 +2,7 @@ use bumpalo::collections::Vec as AVec; use inkwell::{ - types::{BasicType, BasicTypeEnum, StructType}, + types::StructType, values::{BasicValue, BasicValueEnum, PointerValue, StructValue}, }; use roc_module::symbol::Symbol; @@ -16,51 +16,6 @@ use super::{ scope::Scope, }; -pub(crate) enum RocStructType<'ctx> { - /// The roc struct should be passed by rvalue. - ByValue(StructType<'ctx>), -} - -impl<'ctx> Into> for RocStructType<'ctx> { - fn into(self) -> BasicTypeEnum<'ctx> { - self.as_basic_type_enum() - } -} - -impl<'ctx> RocStructType<'ctx> { - pub fn build<'a>( - env: &Env<'a, 'ctx, '_>, - layout_interner: &mut STLayoutInterner<'a>, - fields: &[InLayout<'_>], - ) -> Self { - let struct_type = basic_type_from_record(env, layout_interner, fields); - RocStructType::ByValue(struct_type) - } - - pub fn as_basic_type_enum(&self) -> BasicTypeEnum<'ctx> { - match self { - RocStructType::ByValue(struct_type) => struct_type.as_basic_type_enum(), - } - } -} - -fn basic_type_from_record<'a, 'ctx>( - env: &Env<'a, 'ctx, '_>, - layout_interner: &mut STLayoutInterner<'a>, - fields: &[InLayout<'_>], -) -> StructType<'ctx> { - let mut field_types = AVec::with_capacity_in(fields.len(), env.arena); - - for field_layout in fields.iter() { - let typ = basic_type_from_layout(env, layout_interner, *field_layout); - - field_types.push(typ); - } - - env.context - .struct_type(field_types.into_bump_slice(), false) -} - #[derive(Debug)] pub(crate) enum RocStruct<'ctx> { /// The roc struct should be passed by rvalue.