Inline RocStructType back in

This commit is contained in:
Ayaz Hafiz 2023-06-13 13:51:46 -05:00
parent 7b1dc7eff0
commit c09a33f9f4
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 21 additions and 49 deletions

View file

@ -1,5 +1,5 @@
use crate::llvm::build::{BuilderExt, Env}; use crate::llvm::build::{BuilderExt, Env};
use crate::llvm::struct_::RocStructType; use bumpalo::collections::Vec as AVec;
use inkwell::context::Context; use inkwell::context::Context;
use inkwell::types::{BasicType, BasicTypeEnum, FloatType, IntType, StructType}; use inkwell::types::{BasicType, BasicTypeEnum, FloatType, IntType, StructType};
use inkwell::values::StructValue; use inkwell::values::StructValue;
@ -22,7 +22,7 @@ pub fn basic_type_from_layout<'a, 'ctx, 'env>(
match layout_interner.get_repr(layout) { match layout_interner.get_repr(layout) {
Struct(sorted_fields, ..) => { Struct(sorted_fields, ..) => {
RocStructType::build(env, layout_interner, sorted_fields).into() basic_type_from_record(env, layout_interner, sorted_fields).into()
} }
LambdaSet(lambda_set) => { LambdaSet(lambda_set) => {
basic_type_from_layout(env, layout_interner, lambda_set.runtime_representation()) 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>( pub fn struct_type_from_union_layout<'a, 'ctx>(
env: &Env<'a, 'ctx, '_>, env: &Env<'a, 'ctx, '_>,
layout_interner: &mut STLayoutInterner<'a>, 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, '_>, env: &Env<'a, 'ctx, '_>,
layout_interner: &mut STLayoutInterner<'a>, layout_interner: &mut STLayoutInterner<'a>,
union_layout: &UnionLayout<'_>, union_layout: &UnionLayout<'_>,

View file

@ -2,7 +2,7 @@
use bumpalo::collections::Vec as AVec; use bumpalo::collections::Vec as AVec;
use inkwell::{ use inkwell::{
types::{BasicType, BasicTypeEnum, StructType}, types::StructType,
values::{BasicValue, BasicValueEnum, PointerValue, StructValue}, values::{BasicValue, BasicValueEnum, PointerValue, StructValue},
}; };
use roc_module::symbol::Symbol; use roc_module::symbol::Symbol;
@ -16,51 +16,6 @@ use super::{
scope::Scope, scope::Scope,
}; };
pub(crate) enum RocStructType<'ctx> {
/// The roc struct should be passed by rvalue.
ByValue(StructType<'ctx>),
}
impl<'ctx> Into<BasicTypeEnum<'ctx>> 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)] #[derive(Debug)]
pub(crate) enum RocStruct<'ctx> { pub(crate) enum RocStruct<'ctx> {
/// The roc struct should be passed by rvalue. /// The roc struct should be passed by rvalue.