diff --git a/crates/compiler/gen_llvm/src/llvm/build.rs b/crates/compiler/gen_llvm/src/llvm/build.rs index 569276e83a..2160feba5c 100644 --- a/crates/compiler/gen_llvm/src/llvm/build.rs +++ b/crates/compiler/gen_llvm/src/llvm/build.rs @@ -1134,7 +1134,14 @@ pub(crate) fn build_exp_expr<'a, 'ctx>( let callee = scope.load_symbol(callee).into_pointer_value(); 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 { symbol, diff --git a/crates/compiler/gen_llvm/src/llvm/erased.rs b/crates/compiler/gen_llvm/src/llvm/erased.rs index af3ad47b92..1f3eea1c40 100644 --- a/crates/compiler/gen_llvm/src/llvm/erased.rs +++ b/crates/compiler/gen_llvm/src/llvm/erased.rs @@ -1,8 +1,9 @@ use inkwell::{ - types::StructType, + types::{PointerType, StructType}, values::{PointerValue, StructValue}, AddressSpace, }; +use roc_mono::ir::ErasedField; use super::build::Env; @@ -64,3 +65,28 @@ pub fn build<'a, 'ctx>( 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 +}