mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
from_layout
This commit is contained in:
parent
b28b32cdc4
commit
c2e14864ab
1 changed files with 11 additions and 15 deletions
|
@ -21,12 +21,16 @@ pub enum Ownership {
|
||||||
Borrowed,
|
Borrowed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Ownership {
|
||||||
/// For reference-counted types (lists, (big) strings, recursive tags), owning a value
|
/// For reference-counted types (lists, (big) strings, recursive tags), owning a value
|
||||||
/// means incrementing its reference count. Hence, we prefer borrowing for these types
|
/// means incrementing its reference count. Hence, we prefer borrowing for these types
|
||||||
fn should_borrow_layout(layout: &Layout) -> bool {
|
fn from_layout(layout: &Layout) -> Self {
|
||||||
layout.is_refcounted()
|
match layout.is_refcounted() {
|
||||||
|
true => Ownership::Borrowed,
|
||||||
|
false => Ownership::Owned,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn infer_borrow<'a>(
|
pub fn infer_borrow<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
procs: &MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
procs: &MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||||
|
@ -226,11 +230,7 @@ impl<'a> ParamMap<'a> {
|
||||||
fn init_borrow_params(arena: &'a Bump, ps: &'a [Param<'a>]) -> &'a [Param<'a>] {
|
fn init_borrow_params(arena: &'a Bump, ps: &'a [Param<'a>]) -> &'a [Param<'a>] {
|
||||||
Vec::from_iter_in(
|
Vec::from_iter_in(
|
||||||
ps.iter().map(|p| Param {
|
ps.iter().map(|p| Param {
|
||||||
ownership: if p.layout.is_refcounted() {
|
ownership: Ownership::from_layout(&p.layout),
|
||||||
Ownership::Borrowed
|
|
||||||
} else {
|
|
||||||
Ownership::Owned
|
|
||||||
},
|
|
||||||
layout: p.layout,
|
layout: p.layout,
|
||||||
symbol: p.symbol,
|
symbol: p.symbol,
|
||||||
}),
|
}),
|
||||||
|
@ -242,11 +242,7 @@ impl<'a> ParamMap<'a> {
|
||||||
fn init_borrow_args(arena: &'a Bump, ps: &'a [(Layout<'a>, Symbol)]) -> &'a [Param<'a>] {
|
fn init_borrow_args(arena: &'a Bump, ps: &'a [(Layout<'a>, Symbol)]) -> &'a [Param<'a>] {
|
||||||
Vec::from_iter_in(
|
Vec::from_iter_in(
|
||||||
ps.iter().map(|(layout, symbol)| Param {
|
ps.iter().map(|(layout, symbol)| Param {
|
||||||
ownership: if should_borrow_layout(layout) {
|
ownership: Ownership::from_layout(layout),
|
||||||
Ownership::Borrowed
|
|
||||||
} else {
|
|
||||||
Ownership::Owned
|
|
||||||
},
|
|
||||||
layout: *layout,
|
layout: *layout,
|
||||||
symbol: *symbol,
|
symbol: *symbol,
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue