Build erased load in llvm

This commit is contained in:
Ayaz Hafiz 2023-07-06 15:50:54 -05:00
parent fcb907b0c9
commit f37cc48e88
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
2 changed files with 35 additions and 2 deletions

View File

@ -1134,7 +1134,14 @@ pub(crate) fn build_exp_expr<'a, 'ctx>(
let callee = scope.load_symbol(callee).into_pointer_value(); let callee = scope.load_symbol(callee).into_pointer_value();
erased::build(env, value, callee).into() erased::build(env, value, callee).into()
} }
ErasedLoad { .. } => todo_lambda_erasure!(), ErasedLoad { symbol, field } => {
let value = scope.load_symbol(symbol).into_struct_value();
let wanted_llvm_type =
basic_type_from_layout(env, layout_interner, layout_interner.get_repr(layout))
.into_pointer_type();
erased::load(env, value, *field, wanted_llvm_type).into()
}
Reset { Reset {
symbol, symbol,

View File

@ -1,8 +1,9 @@
use inkwell::{ use inkwell::{
types::StructType, types::{PointerType, StructType},
values::{PointerValue, StructValue}, values::{PointerValue, StructValue},
AddressSpace, AddressSpace,
}; };
use roc_mono::ir::ErasedField;
use super::build::Env; use super::build::Env;
@ -64,3 +65,28 @@ pub fn build<'a, 'ctx>(
struct_value.into_struct_value() struct_value.into_struct_value()
} }
pub fn load<'ctx>(
env: &Env<'_, 'ctx, '_>,
erasure: StructValue<'ctx>,
field: ErasedField,
as_type: PointerType<'ctx>,
) -> PointerValue<'ctx> {
let index = match field {
ErasedField::Value => 0,
ErasedField::Callee => 1,
};
let value = env
.builder
.build_extract_value(erasure, index, "extract_value")
.unwrap()
.into_pointer_value();
let value = env
.builder
.build_bitcast(value, as_type, "bitcast_to_type")
.into_pointer_value();
value
}