mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
use a NonNullableUnwrapped union for Box
This commit is contained in:
parent
b7e7059b36
commit
a9813aeae7
2 changed files with 35 additions and 3 deletions
|
@ -2118,6 +2118,24 @@ impl<'a> Expr<'a> {
|
|||
arguments: std::slice::from_ref(symbol),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn expr_box(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(crate) fn expr_unbox(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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Stmt<'a> {
|
||||
|
@ -5614,13 +5632,22 @@ pub fn with_hole<'a>(
|
|||
debug_assert_eq!(arg_symbols.len(), 1);
|
||||
let x = arg_symbols[0];
|
||||
|
||||
Stmt::Let(assigned, Expr::ExprBox { symbol: x }, layout, hole)
|
||||
let element_layout = match layout_cache.interner.get_repr(layout) {
|
||||
LayoutRepr::Union(UnionLayout::NonNullableUnwrapped([l])) => l,
|
||||
_ => unreachable!("invalid layout for a box expression"),
|
||||
};
|
||||
|
||||
let expr = Expr::expr_box(arena.alloc(x), element_layout);
|
||||
|
||||
Stmt::Let(assigned, expr, layout, hole)
|
||||
}
|
||||
UnboxExpr => {
|
||||
debug_assert_eq!(arg_symbols.len(), 1);
|
||||
let x = arg_symbols[0];
|
||||
|
||||
Stmt::Let(assigned, Expr::ExprUnbox { symbol: x }, layout, hole)
|
||||
let expr = Expr::expr_unbox(x, arena.alloc(layout));
|
||||
|
||||
Stmt::Let(assigned, expr, layout, hole)
|
||||
}
|
||||
_ => {
|
||||
let call = self::Call {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue