Added traits and updated remaining borrowed

This commit is contained in:
J.Teeuwissen 2023-01-05 12:02:20 +01:00
parent 09f9df1f40
commit 1f10d0cb92
No known key found for this signature in database
GPG key ID: DB5F7A1ED8D478AD
3 changed files with 32 additions and 25 deletions

View file

@ -399,12 +399,12 @@ impl<'a> BorrowInfState<'a> {
fn update_param_map_help(&mut self, ps: &[Param<'a>]) -> &'a [Param<'a>] {
let mut new_ps = Vec::with_capacity_in(ps.len(), self.arena);
new_ps.extend(ps.iter().map(|p| {
if !p.borrow {
if p.ownership == Ownership::Owned {
*p
} else if self.is_owned(p.symbol) {
self.modified = true;
let mut p = *p;
p.borrow = false;
p.ownership = Ownership::Owned;
p
} else {
@ -425,11 +425,11 @@ impl<'a> BorrowInfState<'a> {
let ps = &mut param_map.declarations[index..][..length];
for p in ps.iter_mut() {
if !p.borrow {
if p.ownership == Ownership::Owned {
// do nothing
} else if self.is_owned(p.symbol) {
self.modified = true;
p.borrow = false;
p.ownership = Ownership::Owned;
} else {
// do nothing
}
@ -449,7 +449,7 @@ impl<'a> BorrowInfState<'a> {
debug_assert_eq!(xs.len(), ps.len());
for (x, p) in xs.iter().zip(ps.iter()) {
if !p.borrow {
if p.ownership == Ownership::Owned {
self.own_var(*x);
}
}
@ -577,44 +577,44 @@ impl<'a> BorrowInfState<'a> {
match op {
ListMap { xs } => {
// own the list if the function wants to own the element
if !function_ps[0].borrow {
if function_ps[0].ownership == Ownership::Owned {
self.own_var(*xs);
}
}
ListMap2 { xs, ys } => {
// own the lists if the function wants to own the element
if !function_ps[0].borrow {
if function_ps[0].ownership == Ownership::Owned {
self.own_var(*xs);
}
if !function_ps[1].borrow {
if function_ps[1].ownership == Ownership::Owned {
self.own_var(*ys);
}
}
ListMap3 { xs, ys, zs } => {
// own the lists if the function wants to own the element
if !function_ps[0].borrow {
if function_ps[0].ownership == Ownership::Owned {
self.own_var(*xs);
}
if !function_ps[1].borrow {
if function_ps[1].ownership == Ownership::Owned {
self.own_var(*ys);
}
if !function_ps[2].borrow {
if function_ps[2].ownership == Ownership::Owned {
self.own_var(*zs);
}
}
ListMap4 { xs, ys, zs, ws } => {
// own the lists if the function wants to own the element
if !function_ps[0].borrow {
if function_ps[0].ownership == Ownership::Owned {
self.own_var(*xs);
}
if !function_ps[1].borrow {
if function_ps[1].ownership == Ownership::Owned {
self.own_var(*ys);
}
if !function_ps[2].borrow {
if function_ps[2].ownership == Ownership::Owned {
self.own_var(*zs);
}
if !function_ps[3].borrow {
if function_ps[3].ownership == Ownership::Owned {
self.own_var(*ws);
}
}
@ -626,7 +626,10 @@ impl<'a> BorrowInfState<'a> {
// own the closure environment if the function needs to own it
let function_env_position = op.function_arity();
if let Some(false) = function_ps.get(function_env_position).map(|p| p.borrow) {
if let Some(false) = function_ps
.get(function_env_position)
.map(|p| p.ownership == Ownership::Borrowed)
{
self.own_var(passed_function.captured_environment);
}
}

View file

@ -61,13 +61,13 @@ impl DataFunction {
use DataFunction::*;
let data_borrowed = !vars[&lowlevel_argument].consume;
let function_borrows = passed_function_argument.borrow;
let function_ownership = passed_function_argument.ownership;
match (data_borrowed, function_borrows) {
(BORROWED, BORROWED) => DataBorrowedFunctionBorrows,
(BORROWED, OWNED) => DataBorrowedFunctionOwns,
(OWNED, BORROWED) => DataOwnedFunctionBorrows,
(OWNED, OWNED) => DataOwnedFunctionOwns,
match (data_borrowed, function_ownership) {
(BORROWED, Ownership::Borrowed) => DataBorrowedFunctionBorrows,
(BORROWED, Ownership::Owned) => DataBorrowedFunctionOwns,
(OWNED, Ownership::Borrowed) => DataOwnedFunctionBorrows,
(OWNED, Ownership::Owned) => DataOwnedFunctionOwns,
}
}
}
@ -998,7 +998,10 @@ impl<'a, 'i> Context<'a, 'i> {
for p in ps.iter() {
let info = VarInfo {
reference: p.layout.contains_refcounted(self.layout_interner),
consume: !p.borrow,
consume: match p.ownership {
Ownership::Owned => true,
Ownership::Borrowed => false,
},
persistent: false,
reset: false,
};
@ -1020,7 +1023,7 @@ impl<'a, 'i> Context<'a, 'i> {
b_live_vars: &LiveVarSet,
) -> &'a Stmt<'a> {
for p in ps.iter() {
if !p.borrow
if p.ownership == Ownership::Owned
&& p.layout.contains_refcounted(self.layout_interner)
&& !b_live_vars.contains(&p.symbol)
{
@ -1340,7 +1343,7 @@ fn create_holl_call<'a>(
arguments: &'a [Symbol],
) -> Expr<'a> {
let call = crate::ir::Call {
call_type: if let Some(OWNED) = param.map(|p| p.borrow) {
call_type: if let Some(Ownership::Owned) = param.map(|p| p.ownership) {
let mut passed_function = holl.passed_function;
passed_function.owns_captured_environment = true;

View file

@ -1523,6 +1523,7 @@ impl<'a, 'i> Env<'a, 'i> {
#[derive(Clone, Debug, PartialEq, Copy, Eq, Hash)]
pub struct JoinPointId(pub Symbol);
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Ownership {
Owned,
Borrowed,