mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Inline RocStructType back in
This commit is contained in:
parent
7b1dc7eff0
commit
c09a33f9f4
2 changed files with 21 additions and 49 deletions
|
@ -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<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)]
|
||||
pub(crate) enum RocStruct<'ctx> {
|
||||
/// The roc struct should be passed by rvalue.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue