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

@ -5783,7 +5783,7 @@ pub fn with_hole<'a>(
_ => unreachable!("invalid layout for a box expression"),
};
let expr = boxed::expr_box(arena.alloc(x), element_layout);
let expr = boxed::box_(arena.alloc(x), element_layout);
Stmt::Let(assigned, expr, layout, hole)
}
@ -5791,7 +5791,7 @@ pub fn with_hole<'a>(
debug_assert_eq!(arg_symbols.len(), 1);
let x = arg_symbols[0];
let expr = boxed::expr_unbox(x, arena.alloc(layout));
let expr = boxed::unbox(x, arena.alloc(layout));
Stmt::Let(assigned, expr, layout, hole)
}
@ -10284,7 +10284,7 @@ where
let field_get_stmt = Stmt::Let(result, field_get_expr, *field, ret_stmt);
let unbox_expr = boxed::expr_unbox(argument, arena.alloc(interned_unboxed_struct_layout));
let unbox_expr = boxed::unbox(argument, arena.alloc(interned_unboxed_struct_layout));
let unbox_stmt = Stmt::Let(
unboxed,
@ -10386,7 +10386,7 @@ where
let field_get_stmt = Stmt::Let(result, field_get_expr, *field, ret_stmt);
let unbox_expr = boxed::expr_unbox(argument, arena.alloc(interned));
let unbox_expr = boxed::unbox(argument, arena.alloc(interned));
let unbox_stmt = Stmt::Let(unboxed, unbox_expr, interned, arena.alloc(field_get_stmt));
let proc = Proc {

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),
);