mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
remove by-pointer calls
This commit is contained in:
parent
45111ec7e6
commit
ae5b0d8cfd
5 changed files with 20 additions and 211 deletions
|
@ -399,14 +399,6 @@ impl<'a> BorrowInfState<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
ByPointer { .. } => {
|
||||
// the return value will be owned
|
||||
self.own_var(z);
|
||||
|
||||
// if the function exects an owned argument (ps), the argument must be owned (args)
|
||||
self.own_args(arguments);
|
||||
}
|
||||
|
||||
LowLevel { op } => {
|
||||
debug_assert!(!op.is_higher_order());
|
||||
|
||||
|
@ -599,42 +591,27 @@ impl<'a> BorrowInfState<'a> {
|
|||
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
fn preserve_tail_call(&mut self, x: Symbol, v: &Expr<'a>, b: &Stmt<'a>) {
|
||||
match (v, b) {
|
||||
(
|
||||
Expr::Call(crate::ir::Call {
|
||||
call_type:
|
||||
crate::ir::CallType::ByName {
|
||||
name: g,
|
||||
full_layout,
|
||||
..
|
||||
},
|
||||
arguments: ys,
|
||||
..
|
||||
}),
|
||||
Stmt::Ret(z),
|
||||
)
|
||||
| (
|
||||
Expr::Call(crate::ir::Call {
|
||||
call_type:
|
||||
crate::ir::CallType::ByPointer {
|
||||
name: g,
|
||||
full_layout,
|
||||
..
|
||||
},
|
||||
arguments: ys,
|
||||
..
|
||||
}),
|
||||
Stmt::Ret(z),
|
||||
) => {
|
||||
if self.current_proc == *g && x == *z {
|
||||
// anonymous functions (for which the ps may not be known)
|
||||
// can never be tail-recursive, so this is fine
|
||||
if let Some(ps) = self.param_map.get_symbol(*g, *full_layout) {
|
||||
self.own_params_using_args(ys, ps)
|
||||
}
|
||||
if let (
|
||||
Expr::Call(crate::ir::Call {
|
||||
call_type:
|
||||
crate::ir::CallType::ByName {
|
||||
name: g,
|
||||
full_layout,
|
||||
..
|
||||
},
|
||||
arguments: ys,
|
||||
..
|
||||
}),
|
||||
Stmt::Ret(z),
|
||||
) = (v, b)
|
||||
{
|
||||
if self.current_proc == *g && x == *z {
|
||||
// anonymous functions (for which the ps may not be known)
|
||||
// can never be tail-recursive, so this is fine
|
||||
if let Some(ps) = self.param_map.get_symbol(*g, *full_layout) {
|
||||
self.own_params_using_args(ys, ps)
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -700,18 +700,6 @@ impl<'a> Context<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ByPointer { .. } => {
|
||||
let v = Expr::Call(crate::ir::Call {
|
||||
call_type,
|
||||
arguments,
|
||||
});
|
||||
|
||||
self.add_inc_before_consume_all(
|
||||
arguments,
|
||||
self.arena.alloc(Stmt::Let(z, v, l, b)),
|
||||
b_live_vars,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -993,9 +981,6 @@ impl<'a> Context<'a> {
|
|||
),
|
||||
}
|
||||
}
|
||||
CallType::ByPointer { .. } => {
|
||||
self.add_inc_before_consume_all(call.arguments, cont, &invoke_live_vars)
|
||||
}
|
||||
};
|
||||
|
||||
(stmt, invoke_live_vars)
|
||||
|
|
|
@ -1038,15 +1038,6 @@ impl<'a> Call<'a> {
|
|||
|
||||
alloc.text("CallByName ").append(alloc.intersperse(it, " "))
|
||||
}
|
||||
CallType::ByPointer { name, .. } => {
|
||||
let it = std::iter::once(name)
|
||||
.chain(arguments.iter().copied())
|
||||
.map(|s| symbol_to_doc(alloc, s));
|
||||
|
||||
alloc
|
||||
.text("CallByPointer ")
|
||||
.append(alloc.intersperse(it, " "))
|
||||
}
|
||||
LowLevel { op: lowlevel } => {
|
||||
let it = arguments.iter().map(|s| symbol_to_doc(alloc, *s));
|
||||
|
||||
|
@ -1083,13 +1074,6 @@ pub enum CallType<'a> {
|
|||
ret_layout: Layout<'a>,
|
||||
arg_layouts: &'a [Layout<'a>],
|
||||
},
|
||||
ByPointer {
|
||||
name: Symbol,
|
||||
|
||||
full_layout: Layout<'a>,
|
||||
ret_layout: Layout<'a>,
|
||||
arg_layouts: &'a [Layout<'a>],
|
||||
},
|
||||
Foreign {
|
||||
foreign_symbol: ForeignSymbol,
|
||||
ret_layout: Layout<'a>,
|
||||
|
@ -4102,20 +4086,7 @@ pub fn with_hole<'a>(
|
|||
hole,
|
||||
);
|
||||
} else {
|
||||
result = Stmt::Let(
|
||||
assigned,
|
||||
Expr::Call(self::Call {
|
||||
call_type: CallType::ByPointer {
|
||||
name: function_symbol,
|
||||
full_layout,
|
||||
ret_layout,
|
||||
arg_layouts,
|
||||
},
|
||||
arguments: arg_symbols,
|
||||
}),
|
||||
ret_layout,
|
||||
hole,
|
||||
);
|
||||
unreachable!("calling a non-closure layout")
|
||||
}
|
||||
}
|
||||
NotASymbol => {
|
||||
|
@ -5335,17 +5306,6 @@ fn substitute_in_call<'a>(
|
|||
ret_layout: *ret_layout,
|
||||
full_layout: *full_layout,
|
||||
}),
|
||||
CallType::ByPointer {
|
||||
name,
|
||||
arg_layouts,
|
||||
ret_layout,
|
||||
full_layout,
|
||||
} => substitute(subs, *name).map(|new| CallType::ByPointer {
|
||||
name: new,
|
||||
arg_layouts,
|
||||
ret_layout: *ret_layout,
|
||||
full_layout: *full_layout,
|
||||
}),
|
||||
CallType::Foreign { .. } => None,
|
||||
CallType::LowLevel { .. } => None,
|
||||
CallType::HigherOrderLowLevel { .. } => None,
|
||||
|
@ -6050,10 +6010,6 @@ fn can_throw_exception(call: &Call) -> bool {
|
|||
| Symbol::NUM_ABS
|
||||
| Symbol::NUM_NEG
|
||||
),
|
||||
CallType::ByPointer { .. } => {
|
||||
// we don't know what we're calling; it might throw, so better be safe than sorry
|
||||
true
|
||||
}
|
||||
|
||||
CallType::Foreign { .. } => {
|
||||
// calling foreign functions is very unsafe
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue