Support captures between mutually recursive closures

This commit is contained in:
Ayaz Hafiz 2022-08-10 14:53:18 -07:00
parent 4b55416ca1
commit 6bcd682dde
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 77 additions and 2 deletions

View file

@ -829,11 +829,34 @@ fn fix_values_captured_in_closure_defs(
);
}
// TODO mutually recursive functions should both capture the union of both their capture sets
for def in defs.iter_mut() {
fix_values_captured_in_closure_def(def, no_capture_symbols, closure_captures);
}
// Mutually recursive functions should both capture the union of all their capture sets
//
// Really unfortunate we make a lot of clones here, can this be done more efficiently?
let mut total_capture_set = Vec::default();
for def in defs.iter_mut() {
match &def.loc_expr.value {
Expr::Closure(ClosureData {
captured_symbols, ..
}) => total_capture_set.extend(captured_symbols.iter().copied()),
_ => {}
}
}
total_capture_set.sort_by_key(|(sym, _)| *sym);
total_capture_set.dedup_by_key(|(sym, _)| *sym);
for def in defs.iter_mut() {
match &mut def.loc_expr.value {
Expr::Closure(ClosureData {
captured_symbols, ..
}) => {
*captured_symbols = total_capture_set.clone();
}
_ => {}
}
}
}
fn fix_values_captured_in_closure_pattern(