mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Support captures between mutually recursive closures
This commit is contained in:
parent
4b55416ca1
commit
6bcd682dde
3 changed files with 77 additions and 2 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue