WIP fixing the borrowing in HOFs

This commit is contained in:
Folkert 2021-05-19 15:28:20 +02:00
parent 653d745dc5
commit 87b9f866d3
7 changed files with 310 additions and 225 deletions

View file

@ -425,15 +425,74 @@ impl<'a> BorrowInfState<'a> {
debug_assert!(op.is_higher_order());
match op {
ListMap => match self.param_map.get_symbol(arguments[1], *closure_layout) {
Some(ps) => {
if !ps[0].borrow {
ListMap | ListSortWith => {
match self.param_map.get_symbol(arguments[1], *closure_layout) {
Some(function_ps) => {
// own the list if the function wants to own the element
if !function_ps[0].borrow {
self.own_var(arguments[0]);
}
// own the closure environment if the function needs to own it
if let Some(false) = function_ps.get(1).map(|p| p.borrow) {
self.own_var(arguments[2]);
}
}
None => unreachable!(),
}
}
ListMapWithIndex => {
match self.param_map.get_symbol(arguments[1], *closure_layout) {
Some(function_ps) => {
// own the list if the function wants to own the element
if !function_ps[1].borrow {
self.own_var(arguments[0]);
}
// own the closure environment if the function needs to own it
if let Some(false) = function_ps.get(2).map(|p| p.borrow) {
self.own_var(arguments[2]);
}
}
None => unreachable!(),
}
}
ListMap2 => match self.param_map.get_symbol(arguments[2], *closure_layout) {
Some(function_ps) => {
// own the lists if the function wants to own the element
if !function_ps[0].borrow {
self.own_var(arguments[0]);
}
if ps.len() > 1 && !ps[1].borrow {
if !function_ps[1].borrow {
self.own_var(arguments[1]);
}
// own the closure environment if the function needs to own it
if let Some(false) = function_ps.get(2).map(|p| p.borrow) {
self.own_var(arguments[3]);
}
}
None => unreachable!(),
},
ListMap3 => match self.param_map.get_symbol(arguments[3], *closure_layout) {
Some(function_ps) => {
// own the lists if the function wants to own the element
if !function_ps[0].borrow {
self.own_var(arguments[0]);
}
if !function_ps[1].borrow {
self.own_var(arguments[1]);
}
if !function_ps[2].borrow {
self.own_var(arguments[2]);
}
// own the closure environment if the function needs to own it
if let Some(false) = function_ps.get(3).map(|p| p.borrow) {
self.own_var(arguments[4]);
}
}
None => unreachable!(),
},