mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Inline RocStructType back in
This commit is contained in:
parent
7b1dc7eff0
commit
c09a33f9f4
2 changed files with 21 additions and 49 deletions
|
@ -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<'_>,
|
||||
|
|
|
@ -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