Boxed helpers

This commit is contained in:
Ayaz Hafiz 2023-07-12 15:55:25 -05:00
parent a8d821bf87
commit 5e9a06e537
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
4 changed files with 30 additions and 79 deletions

View file

@ -0,0 +1,23 @@
use roc_module::symbol::Symbol;
use crate::layout::{InLayout, UnionLayout};
use super::Expr;
pub fn box_<'a>(symbol: &'a Symbol, element_layout: &'a InLayout<'a>) -> Expr<'a> {
Expr::Tag {
tag_layout: UnionLayout::NonNullableUnwrapped(std::slice::from_ref(element_layout)),
tag_id: 0,
arguments: std::slice::from_ref(symbol),
reuse: None,
}
}
pub fn unbox<'a>(symbol: Symbol, element_layout: &'a InLayout<'a>) -> Expr<'a> {
Expr::UnionAtIndex {
structure: symbol,
tag_id: 0,
union_layout: UnionLayout::NonNullableUnwrapped(std::slice::from_ref(element_layout)),
index: 0,
}
}

View file

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