Add a Newtype variant to LayoutWrapper

This commit is contained in:
Ayaz Hafiz 2023-05-11 12:12:00 -05:00
parent dd94d6ba16
commit 5274dbcd00
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
22 changed files with 348 additions and 265 deletions

View file

@ -434,7 +434,8 @@ fn eq_tag_union_help<'a>(
if is_non_recursive {
compare_ptr_or_value
} else {
let union_layout = layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
let union_layout =
layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
let loop_params_iter = operands.iter().map(|arg| Param {
symbol: *arg,
ownership: Ownership::Borrowed,
@ -657,7 +658,7 @@ fn eq_list<'a>(
let arena = root.arena;
// A "Box" layout (heap pointer to a single list element)
let box_layout = layout_interner.insert_no_semantic(LayoutRepr::Boxed(elem_layout));
let box_layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(elem_layout));
// Compare lengths
@ -703,7 +704,7 @@ fn eq_list<'a>(
let size = root.create_symbol(ident_ids, "size");
let size_expr = Expr::Literal(Literal::Int(
(layout_interner
.get(elem_layout)
.get_repr(elem_layout)
.stack_size(layout_interner, root.target_info) as i128)
.to_ne_bytes(),
));

View file

@ -10,8 +10,8 @@ use crate::ir::{
Proc, ProcLayout, SelfRecursive, Stmt, UpdateModeId,
};
use crate::layout::{
Builtin, InLayout, LambdaName, Layout, LayoutInterner, LayoutRepr, Niche, STLayoutInterner,
UnionLayout,
Builtin, InLayout, LambdaName, Layout, LayoutInterner, LayoutRepr, LayoutWrapper, Niche,
STLayoutInterner, UnionLayout,
};
mod equality;
@ -290,7 +290,7 @@ impl<'a> CodeGenHelp<'a> {
LayoutRepr::RecursivePointer(_)
) {
let union_layout = ctx.recursive_union.unwrap();
layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout))
layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout))
} else {
called_layout
};
@ -301,7 +301,7 @@ impl<'a> CodeGenHelp<'a> {
let (ret_layout, arg_layouts): (InLayout<'a>, &'a [InLayout<'a>]) = {
let arg = self.replace_rec_ptr(ctx, layout_interner, layout);
let box_arg = layout_interner.insert_no_semantic(LayoutRepr::Boxed(arg));
let box_arg = layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(arg));
match ctx.op {
Dec | DecRef(_) => (LAYOUT_UNIT, self.arena.alloc([arg])),
@ -430,12 +430,14 @@ impl<'a> CodeGenHelp<'a> {
}
Dec | DecRef(_) | Reset | ResetRef => self.arena.alloc([roc_value]),
IndirectInc => {
let box_layout = layout_interner.insert_no_semantic(LayoutRepr::Boxed(layout));
let box_layout =
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(layout));
let inc_amount = (self.layout_isize, ARG_2);
self.arena.alloc([(box_layout, ARG_1), inc_amount])
}
IndirectDec => {
let box_layout = layout_interner.insert_no_semantic(LayoutRepr::Boxed(layout));
let box_layout =
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(layout));
self.arena.alloc([(box_layout, ARG_1)])
}
Eq => self.arena.alloc([roc_value, (layout, ARG_2)]),
@ -483,7 +485,8 @@ impl<'a> CodeGenHelp<'a> {
niche: Niche::NONE,
},
HelperOp::IndirectInc => {
let box_layout = layout_interner.insert_no_semantic(LayoutRepr::Boxed(layout));
let box_layout =
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(layout));
ProcLayout {
arguments: self.arena.alloc([box_layout, self.layout_isize]),
@ -492,7 +495,8 @@ impl<'a> CodeGenHelp<'a> {
}
}
HelperOp::IndirectDec => {
let box_layout = layout_interner.insert_no_semantic(LayoutRepr::Boxed(layout));
let box_layout =
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(layout));
ProcLayout {
arguments: self.arena.alloc([box_layout]),
@ -581,7 +585,7 @@ impl<'a> CodeGenHelp<'a> {
LayoutRepr::RecursivePointer(_) => LayoutRepr::Union(ctx.recursive_union.unwrap()),
};
layout_interner.insert(Layout::new(repr, semantic))
layout_interner.insert(Layout::new(LayoutWrapper::Direct(repr), semantic))
}
fn union_tail_recursion_fields(
@ -665,16 +669,16 @@ impl<'a> CallerProc<'a> {
};
let box_capture_layout = if let Some(capture_layout) = capture_layout {
layout_interner.insert_no_semantic(LayoutRepr::Boxed(capture_layout))
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(capture_layout))
} else {
layout_interner.insert_no_semantic(LayoutRepr::Boxed(Layout::UNIT))
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(Layout::UNIT))
};
let box_argument_layout = layout_interner
.insert_no_semantic(LayoutRepr::Boxed(passed_function.argument_layouts[0]));
.insert_direct_no_semantic(LayoutRepr::Boxed(passed_function.argument_layouts[0]));
let box_return_layout =
layout_interner.insert_no_semantic(LayoutRepr::Boxed(passed_function.return_layout));
let box_return_layout = layout_interner
.insert_direct_no_semantic(LayoutRepr::Boxed(passed_function.return_layout));
let proc_layout = ProcLayout {
arguments: arena.alloc([box_capture_layout, box_argument_layout, box_return_layout]),

View file

@ -309,7 +309,8 @@ pub fn refcount_reset_proc_body<'a>(
// Whenever we recurse into a child layout we will want to Decrement
ctx.op = HelperOp::Dec;
ctx.recursive_union = Some(union_layout);
let recursion_ptr = layout_interner.insert_no_semantic(LayoutRepr::RecursivePointer(layout));
let recursion_ptr =
layout_interner.insert_direct_no_semantic(LayoutRepr::RecursivePointer(layout));
// Reset structure is unique. Decrement its children and return a pointer to the allocation.
let then_stmt = {
@ -491,7 +492,8 @@ pub fn refcount_resetref_proc_body<'a>(
// Whenever we recurse into a child layout we will want to Decrement
ctx.op = HelperOp::Dec;
ctx.recursive_union = Some(union_layout);
let recursion_ptr = layout_interner.insert_no_semantic(LayoutRepr::RecursivePointer(layout));
let recursion_ptr =
layout_interner.insert_direct_no_semantic(LayoutRepr::RecursivePointer(layout));
// Reset structure is unique. Return a pointer to the allocation.
let then_stmt = Stmt::Ret(addr);
@ -979,7 +981,7 @@ fn refcount_list<'a>(
let arena = root.arena;
// A "Box" layout (heap pointer to a single list element)
let box_layout = layout_interner.insert_no_semantic(LayoutRepr::Boxed(elem_layout));
let box_layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(elem_layout));
//
// Check if the list is empty
@ -1106,7 +1108,7 @@ fn refcount_list<'a>(
let is_relevant_op = ctx.op.is_dec() || ctx.op.is_inc();
let modify_elems_and_list =
if is_relevant_op && layout_interner.get(elem_layout).is_refcounted() {
if is_relevant_op && layout_interner.get_repr(elem_layout).is_refcounted() {
refcount_list_elems(
root,
ident_ids,
@ -1742,7 +1744,7 @@ fn refcount_union_tailrec<'a>(
let tailrec_loop = JoinPointId(root.create_symbol(ident_ids, "tailrec_loop"));
let current = root.create_symbol(ident_ids, "current");
let next_ptr = root.create_symbol(ident_ids, "next_ptr");
let layout = layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
let layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
let tag_id_layout = union_layout.tag_id_layout();
@ -1887,7 +1889,7 @@ fn refcount_union_tailrec<'a>(
let jump_with_null_ptr = Stmt::Let(
null_pointer,
Expr::NullPointer,
layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout)),
layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout)),
root.arena.alloc(Stmt::Jump(
jp_modify_union,
root.arena.alloc([null_pointer]),
@ -1931,7 +1933,7 @@ fn refcount_union_tailrec<'a>(
));
let loop_init = Stmt::Jump(tailrec_loop, root.arena.alloc([initial_structure]));
let union_layout = layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
let union_layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
let loop_param = Param {
symbol: current,
ownership: Ownership::Borrowed,