mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
use Ptr instead of Boxed in the code-gen-help
This commit is contained in:
parent
cde3615ec2
commit
3b18494ddd
4 changed files with 83 additions and 80 deletions
|
@ -302,14 +302,14 @@ 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_direct_no_semantic(LayoutRepr::Boxed(arg));
|
||||
let ptr_arg = layout_interner.insert_direct_no_semantic(LayoutRepr::Ptr(arg));
|
||||
|
||||
match ctx.op {
|
||||
Dec | DecRef(_) => (LAYOUT_UNIT, self.arena.alloc([arg])),
|
||||
Reset | ResetRef => (layout, self.arena.alloc([layout])),
|
||||
Inc => (LAYOUT_UNIT, self.arena.alloc([arg, self.layout_isize])),
|
||||
IndirectDec => (LAYOUT_UNIT, arena.alloc([box_arg])),
|
||||
IndirectInc => (LAYOUT_UNIT, arena.alloc([box_arg, self.layout_isize])),
|
||||
IndirectDec => (LAYOUT_UNIT, arena.alloc([ptr_arg])),
|
||||
IndirectInc => (LAYOUT_UNIT, arena.alloc([ptr_arg, self.layout_isize])),
|
||||
Eq => (LAYOUT_BOOL, self.arena.alloc([arg, arg])),
|
||||
}
|
||||
};
|
||||
|
@ -431,15 +431,15 @@ impl<'a> CodeGenHelp<'a> {
|
|||
}
|
||||
Dec | DecRef(_) | Reset | ResetRef => self.arena.alloc([roc_value]),
|
||||
IndirectInc => {
|
||||
let box_layout =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(layout));
|
||||
let ptr_layout =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Ptr(layout));
|
||||
let inc_amount = (self.layout_isize, ARG_2);
|
||||
self.arena.alloc([(box_layout, ARG_1), inc_amount])
|
||||
self.arena.alloc([(ptr_layout, ARG_1), inc_amount])
|
||||
}
|
||||
IndirectDec => {
|
||||
let box_layout =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(layout));
|
||||
self.arena.alloc([(box_layout, ARG_1)])
|
||||
let ptr_layout =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Ptr(layout));
|
||||
self.arena.alloc([(ptr_layout, ARG_1)])
|
||||
}
|
||||
Eq => self.arena.alloc([roc_value, (layout, ARG_2)]),
|
||||
}
|
||||
|
@ -486,21 +486,19 @@ impl<'a> CodeGenHelp<'a> {
|
|||
niche: Niche::NONE,
|
||||
},
|
||||
HelperOp::IndirectInc => {
|
||||
let box_layout =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(layout));
|
||||
let ptr_layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Ptr(layout));
|
||||
|
||||
ProcLayout {
|
||||
arguments: self.arena.alloc([box_layout, self.layout_isize]),
|
||||
arguments: self.arena.alloc([ptr_layout, self.layout_isize]),
|
||||
result: LAYOUT_UNIT,
|
||||
niche: Niche::NONE,
|
||||
}
|
||||
}
|
||||
HelperOp::IndirectDec => {
|
||||
let box_layout =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(layout));
|
||||
let ptr_layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Ptr(layout));
|
||||
|
||||
ProcLayout {
|
||||
arguments: self.arena.alloc([box_layout]),
|
||||
arguments: self.arena.alloc([ptr_layout]),
|
||||
result: LAYOUT_UNIT,
|
||||
niche: Niche::NONE,
|
||||
}
|
||||
|
@ -674,20 +672,20 @@ impl<'a> CallerProc<'a> {
|
|||
op: HelperOp::Eq,
|
||||
};
|
||||
|
||||
let box_capture_layout = if let Some(capture_layout) = capture_layout {
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(capture_layout))
|
||||
let ptr_capture_layout = if let Some(capture_layout) = capture_layout {
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Ptr(capture_layout))
|
||||
} else {
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(Layout::UNIT))
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Ptr(Layout::UNIT))
|
||||
};
|
||||
|
||||
let box_argument_layout = layout_interner
|
||||
.insert_direct_no_semantic(LayoutRepr::Boxed(passed_function.argument_layouts[0]));
|
||||
let ptr_argument_layout = layout_interner
|
||||
.insert_direct_no_semantic(LayoutRepr::Ptr(passed_function.argument_layouts[0]));
|
||||
|
||||
let box_return_layout = layout_interner
|
||||
.insert_direct_no_semantic(LayoutRepr::Boxed(passed_function.return_layout));
|
||||
let ptr_return_layout = layout_interner
|
||||
.insert_direct_no_semantic(LayoutRepr::Ptr(passed_function.return_layout));
|
||||
|
||||
let proc_layout = ProcLayout {
|
||||
arguments: arena.alloc([box_capture_layout, box_argument_layout, box_return_layout]),
|
||||
arguments: arena.alloc([ptr_capture_layout, ptr_argument_layout, ptr_return_layout]),
|
||||
result: Layout::UNIT,
|
||||
niche: Niche::NONE,
|
||||
};
|
||||
|
@ -697,16 +695,11 @@ impl<'a> CallerProc<'a> {
|
|||
|
||||
ctx.new_linker_data.push((proc_symbol, proc_layout));
|
||||
|
||||
let unbox_capture = Expr::ExprUnbox {
|
||||
symbol: Symbol::ARG_1,
|
||||
};
|
||||
let load_capture = Expr::ptr_load(arena.alloc(Symbol::ARG_1));
|
||||
let load_argument = Expr::ptr_load(arena.alloc(Symbol::ARG_2));
|
||||
|
||||
let unbox_argument = Expr::ExprUnbox {
|
||||
symbol: Symbol::ARG_2,
|
||||
};
|
||||
|
||||
let unboxed_capture = Self::create_symbol(home, ident_ids, "unboxed_capture");
|
||||
let unboxed_argument = Self::create_symbol(home, ident_ids, "unboxed_argument");
|
||||
let loaded_capture = Self::create_symbol(home, ident_ids, "loaded_capture");
|
||||
let loaded_argument = Self::create_symbol(home, ident_ids, "loaded_argument");
|
||||
let call_result = Self::create_symbol(home, ident_ids, "call_result");
|
||||
let unit_symbol = Self::create_symbol(home, ident_ids, "unit_symbol");
|
||||
let ignored = Self::create_symbol(home, ident_ids, "ignored");
|
||||
|
@ -719,9 +712,9 @@ impl<'a> CallerProc<'a> {
|
|||
specialization_id: passed_function.specialization_id,
|
||||
},
|
||||
arguments: if capture_layout.is_some() {
|
||||
arena.alloc([unboxed_argument, unboxed_capture])
|
||||
arena.alloc([loaded_argument, loaded_capture])
|
||||
} else {
|
||||
arena.alloc([unboxed_argument])
|
||||
arena.alloc([loaded_argument])
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -734,8 +727,8 @@ impl<'a> CallerProc<'a> {
|
|||
});
|
||||
|
||||
let mut body = Stmt::Let(
|
||||
unboxed_argument,
|
||||
unbox_argument,
|
||||
loaded_argument,
|
||||
load_argument,
|
||||
passed_function.argument_layouts[0],
|
||||
arena.alloc(Stmt::Let(
|
||||
call_result,
|
||||
|
@ -744,7 +737,7 @@ impl<'a> CallerProc<'a> {
|
|||
arena.alloc(Stmt::Let(
|
||||
ignored,
|
||||
ptr_write,
|
||||
box_return_layout,
|
||||
ptr_return_layout,
|
||||
arena.alloc(Stmt::Let(
|
||||
unit_symbol,
|
||||
Expr::Struct(&[]),
|
||||
|
@ -757,8 +750,8 @@ impl<'a> CallerProc<'a> {
|
|||
|
||||
if let Some(capture_layout) = capture_layout {
|
||||
body = Stmt::Let(
|
||||
unboxed_capture,
|
||||
unbox_capture,
|
||||
loaded_capture,
|
||||
load_capture,
|
||||
capture_layout,
|
||||
arena.alloc(body),
|
||||
);
|
||||
|
@ -766,9 +759,9 @@ impl<'a> CallerProc<'a> {
|
|||
|
||||
let args: &'a [(InLayout<'a>, Symbol)] = {
|
||||
arena.alloc([
|
||||
(box_capture_layout, ARG_1),
|
||||
(box_argument_layout, ARG_2),
|
||||
(box_return_layout, ARG_3),
|
||||
(ptr_capture_layout, ARG_1),
|
||||
(ptr_argument_layout, ARG_2),
|
||||
(ptr_return_layout, ARG_3),
|
||||
])
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue