mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
replace borrowed boolean with ownership enum
This commit is contained in:
parent
6bdab37541
commit
6c95bc1fb9
9 changed files with 48 additions and 29 deletions
|
@ -1012,11 +1012,11 @@ impl<
|
|||
param_storage.reserve(params.len());
|
||||
for Param {
|
||||
symbol,
|
||||
borrow,
|
||||
ownership,
|
||||
layout,
|
||||
} in params
|
||||
{
|
||||
if *borrow {
|
||||
if *ownership == Ownership::Borrowed {
|
||||
// These probably need to be passed by pointer/reference?
|
||||
// Otherwise, we probably need to copy back to the param at the end of the joinpoint.
|
||||
todo!("joinpoints with borrowed parameters");
|
||||
|
|
|
@ -220,7 +220,11 @@ impl<'a> ParamMap<'a> {
|
|||
fn init_borrow_params(arena: &'a Bump, ps: &'a [Param<'a>]) -> &'a [Param<'a>] {
|
||||
Vec::from_iter_in(
|
||||
ps.iter().map(|p| Param {
|
||||
borrow: p.layout.is_refcounted(),
|
||||
ownership: if p.layout.is_refcounted() {
|
||||
Ownership::Borrowed
|
||||
} else {
|
||||
Ownership::Owned
|
||||
},
|
||||
layout: p.layout,
|
||||
symbol: p.symbol,
|
||||
}),
|
||||
|
@ -232,7 +236,11 @@ impl<'a> ParamMap<'a> {
|
|||
fn init_borrow_args(arena: &'a Bump, ps: &'a [(Layout<'a>, Symbol)]) -> &'a [Param<'a>] {
|
||||
Vec::from_iter_in(
|
||||
ps.iter().map(|(layout, symbol)| Param {
|
||||
borrow: should_borrow_layout(layout),
|
||||
ownership: if should_borrow_layout(layout) {
|
||||
Ownership::Borrowed
|
||||
} else {
|
||||
Ownership::Owned
|
||||
},
|
||||
layout: *layout,
|
||||
symbol: *symbol,
|
||||
}),
|
||||
|
@ -247,7 +255,7 @@ impl<'a> ParamMap<'a> {
|
|||
) -> &'a [Param<'a>] {
|
||||
Vec::from_iter_in(
|
||||
ps.iter().map(|(layout, symbol)| Param {
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
layout: *layout,
|
||||
symbol: *symbol,
|
||||
}),
|
||||
|
|
|
@ -417,7 +417,7 @@ fn eq_tag_union_help<'a>(
|
|||
} else {
|
||||
let loop_params_iter = operands.iter().map(|arg| Param {
|
||||
symbol: *arg,
|
||||
borrow: true,
|
||||
ownership: Ownership::Borrowed,
|
||||
layout: Layout::Union(union_layout),
|
||||
});
|
||||
|
||||
|
@ -717,13 +717,13 @@ fn eq_list<'a>(
|
|||
|
||||
let param_addr1 = Param {
|
||||
symbol: addr1,
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
layout: layout_isize,
|
||||
};
|
||||
|
||||
let param_addr2 = Param {
|
||||
symbol: addr2,
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
layout: layout_isize,
|
||||
};
|
||||
|
||||
|
|
|
@ -943,7 +943,7 @@ fn refcount_list_elems<'a>(
|
|||
|
||||
let param_addr = Param {
|
||||
symbol: addr,
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
layout: layout_isize,
|
||||
};
|
||||
|
||||
|
@ -1601,7 +1601,7 @@ fn refcount_union_tailrec<'a>(
|
|||
|
||||
let jp_param = Param {
|
||||
symbol: next_ptr,
|
||||
borrow: true,
|
||||
ownership: Ownership::Borrowed,
|
||||
layout,
|
||||
};
|
||||
|
||||
|
@ -1621,7 +1621,7 @@ fn refcount_union_tailrec<'a>(
|
|||
let loop_init = Stmt::Jump(tailrec_loop, root.arena.alloc([initial_structure]));
|
||||
let loop_param = Param {
|
||||
symbol: current,
|
||||
borrow: true,
|
||||
ownership: Ownership::Borrowed,
|
||||
layout: Layout::Union(union_layout),
|
||||
};
|
||||
|
||||
|
|
|
@ -346,7 +346,7 @@ impl<'a, 'r> Ctx<'a, 'r> {
|
|||
for Param {
|
||||
symbol,
|
||||
layout,
|
||||
borrow: _,
|
||||
ownership: _,
|
||||
} in parameters
|
||||
{
|
||||
ctx.insert(*symbol, *layout);
|
||||
|
@ -368,7 +368,7 @@ impl<'a, 'r> Ctx<'a, 'r> {
|
|||
for (arg, param) in symbols.iter().zip(parameters.iter()) {
|
||||
let Param {
|
||||
symbol: _,
|
||||
borrow: _,
|
||||
ownership: _,
|
||||
layout,
|
||||
} = param;
|
||||
self.check_sym_layout(*arg, *layout, UseKind::JumpArg);
|
||||
|
|
|
@ -1905,7 +1905,7 @@ fn decide_to_branching<'a>(
|
|||
let param = Param {
|
||||
symbol: test_symbol,
|
||||
layout: Layout::Builtin(Builtin::Bool),
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
};
|
||||
|
||||
let join = Stmt::Join {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::borrow::{ParamMap, BORROWED, OWNED};
|
||||
use crate::ir::{
|
||||
CallType, Expr, HigherOrderLowLevel, JoinPointId, ModifyRc, Param, Proc, ProcLayout, Stmt,
|
||||
UpdateModeIds,
|
||||
CallType, Expr, HigherOrderLowLevel, JoinPointId, ModifyRc, Ownership, Param, Proc, ProcLayout,
|
||||
Stmt, UpdateModeIds,
|
||||
};
|
||||
use crate::layout::{Layout, STLayoutInterner};
|
||||
use bumpalo::collections::Vec;
|
||||
|
@ -296,13 +296,16 @@ where
|
|||
{
|
||||
ys.iter()
|
||||
.enumerate()
|
||||
.any(|(i, y)| x == *y && !consume_param_pred(i))
|
||||
.any(|(i, y)| x == *y && consume_param_pred(i))
|
||||
}
|
||||
|
||||
fn is_borrow_param(x: Symbol, ys: &[Symbol], ps: &[Param]) -> bool {
|
||||
// default to owned arguments
|
||||
let is_owned = |i: usize| match ps.get(i) {
|
||||
Some(param) => !param.borrow,
|
||||
Some(param) => match param.ownership {
|
||||
Ownership::Owned => true,
|
||||
Ownership::Borrowed => false,
|
||||
},
|
||||
None => unreachable!("or?"),
|
||||
};
|
||||
is_borrow_param_help(x, ys, is_owned)
|
||||
|
@ -473,7 +476,10 @@ impl<'a, 'i> Context<'a, 'i> {
|
|||
) -> &'a Stmt<'a> {
|
||||
// default to owned arguments
|
||||
let pred = |i: usize| match ps.get(i) {
|
||||
Some(param) => !param.borrow,
|
||||
Some(param) => match param.ownership {
|
||||
Ownership::Owned => true,
|
||||
Ownership::Borrowed => false,
|
||||
},
|
||||
None => unreachable!("or?"),
|
||||
};
|
||||
self.add_inc_before_help(xs, pred, b, live_vars_after)
|
||||
|
@ -1519,7 +1525,7 @@ fn visit_proc<'a, 'i>(
|
|||
None => Vec::from_iter_in(
|
||||
proc.args.iter().cloned().map(|(layout, symbol)| Param {
|
||||
symbol,
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
layout,
|
||||
}),
|
||||
arena,
|
||||
|
|
|
@ -1523,17 +1523,22 @@ impl<'a, 'i> Env<'a, 'i> {
|
|||
#[derive(Clone, Debug, PartialEq, Copy, Eq, Hash)]
|
||||
pub struct JoinPointId(pub Symbol);
|
||||
|
||||
pub enum Ownership {
|
||||
Owned,
|
||||
Borrowed,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Param<'a> {
|
||||
pub symbol: Symbol,
|
||||
pub borrow: bool,
|
||||
pub ownership: Ownership,
|
||||
pub layout: Layout<'a>,
|
||||
}
|
||||
|
||||
impl<'a> Param<'a> {
|
||||
pub const EMPTY: Self = Param {
|
||||
symbol: Symbol::EMPTY_PARAM,
|
||||
borrow: false,
|
||||
ownership: Owned,
|
||||
layout: Layout::UNIT,
|
||||
};
|
||||
}
|
||||
|
@ -4544,7 +4549,7 @@ pub fn with_hole<'a>(
|
|||
let param = Param {
|
||||
symbol: assigned,
|
||||
layout,
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
};
|
||||
|
||||
Stmt::Join {
|
||||
|
@ -4609,7 +4614,7 @@ pub fn with_hole<'a>(
|
|||
let param = Param {
|
||||
symbol: assigned,
|
||||
layout,
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
};
|
||||
|
||||
Stmt::Join {
|
||||
|
@ -10400,7 +10405,7 @@ where
|
|||
let param = Param {
|
||||
symbol: assigned,
|
||||
layout: return_layout,
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
};
|
||||
|
||||
Stmt::Join {
|
||||
|
@ -10624,7 +10629,7 @@ fn union_lambda_set_to_switch<'a>(
|
|||
let param = Param {
|
||||
symbol: assigned,
|
||||
layout: *return_layout,
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
};
|
||||
|
||||
Stmt::Join {
|
||||
|
@ -10775,7 +10780,7 @@ fn enum_lambda_set_to_switch<'a>(
|
|||
let param = Param {
|
||||
symbol: assigned,
|
||||
layout: *return_layout,
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
};
|
||||
|
||||
Stmt::Join {
|
||||
|
@ -10878,7 +10883,7 @@ where
|
|||
let param = Param {
|
||||
symbol: assigned,
|
||||
layout: return_layout,
|
||||
borrow: false,
|
||||
ownership: Ownership::Owned,
|
||||
};
|
||||
|
||||
Stmt::Join {
|
||||
|
|
|
@ -46,7 +46,7 @@ pub fn make_tail_recursive<'a>(
|
|||
args.iter().map(|(layout, symbol, _)| Param {
|
||||
symbol: *symbol,
|
||||
layout: *layout,
|
||||
borrow: true,
|
||||
ownership: Ownership::Borrowed,
|
||||
}),
|
||||
arena,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue