moved Ownership to borrow

This commit is contained in:
J.Teeuwissen 2023-01-09 18:15:34 +01:00
parent a11d94aee2
commit b28b32cdc4
No known key found for this signature in database
GPG key ID: DB5F7A1ED8D478AD
8 changed files with 23 additions and 19 deletions

View file

@ -2,8 +2,7 @@ use std::collections::HashMap;
use std::hash::Hash;
use crate::ir::{
Expr, HigherOrderLowLevel, JoinPointId, Ownership, Param, PassedFunction, Proc, ProcLayout,
Stmt,
Expr, HigherOrderLowLevel, JoinPointId, Param, PassedFunction, Proc, ProcLayout, Stmt,
};
use crate::layout::Layout;
use bumpalo::collections::Vec;
@ -16,6 +15,12 @@ use roc_module::symbol::Symbol;
pub(crate) const OWNED: bool = false;
pub(crate) const BORROWED: bool = true;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Ownership {
Owned,
Borrowed,
}
/// For reference-counted types (lists, (big) strings, recursive tags), owning a value
/// means incrementing its reference count. Hence, we prefer borrowing for these types
fn should_borrow_layout(layout: &Layout) -> bool {
@ -107,7 +112,7 @@ pub struct ParamOffset(usize);
impl From<ParamOffset> for usize {
fn from(id: ParamOffset) -> Self {
id.0 as usize
id.0
}
}
@ -421,7 +426,7 @@ impl<'a> BorrowInfState<'a> {
start: ParamOffset,
length: usize,
) {
let index: usize = start.into();
let ParamOffset(index) = start;
let ps = &mut param_map.declarations[index..][..length];
for p in ps.iter_mut() {