Fixed erased with nullable unwrapped union

This commit is contained in:
Ayaz Hafiz 2023-07-12 16:01:44 -05:00
parent 5e9a06e537
commit 937e042c8f
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
4 changed files with 105 additions and 10 deletions

View file

@ -21,3 +21,21 @@ pub fn unbox<'a>(symbol: Symbol, element_layout: &'a InLayout<'a>) -> Expr<'a> {
index: 0,
}
}
pub fn box_nullable<'a>(symbol: &'a Symbol, element_layout: &'a InLayout<'a>) -> Expr<'a> {
Expr::Tag {
tag_layout: UnionLayout::boxed_erased_value(element_layout),
tag_id: 0,
arguments: std::slice::from_ref(symbol),
reuse: None,
}
}
pub fn unbox_nullable<'a>(symbol: Symbol, element_layout: &'a InLayout<'a>) -> Expr<'a> {
Expr::UnionAtIndex {
structure: symbol,
tag_id: 0,
union_layout: UnionLayout::boxed_erased_value(element_layout),
index: 0,
}
}

View file

@ -8,9 +8,8 @@ use crate::{
};
use super::{
boxed::{self, unbox},
with_hole, BranchInfo, Call, CallType, CapturedSymbols, Env, ErasedField, Expr, JoinPointId,
Param, Procs, Stmt, UpdateModeId,
boxed, with_hole, BranchInfo, Call, CallType, CapturedSymbols, Env, ErasedField, Expr,
JoinPointId, Param, Procs, Stmt, UpdateModeId,
};
fn index_erased_function<'a>(
@ -351,7 +350,7 @@ pub fn build_erased_function<'a>(
let result = Stmt::Let(
value.unwrap(),
boxed::box_(env.arena.alloc(stack_captures), stack_captures_layout),
boxed::box_nullable(env.arena.alloc(stack_captures), stack_captures_layout),
boxed_captures_layout,
env.arena.alloc(result),
);
@ -485,7 +484,7 @@ pub fn unpack_closure_data<'a>(
hole = Stmt::Let(
stack_captures,
unbox(heap_captures, stack_captures_layout),
boxed::unbox_nullable(heap_captures, stack_captures_layout),
*stack_captures_layout,
env.arena.alloc(hole),
);