mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
parent
5a0562c7f1
commit
96584cb98a
1 changed files with 39 additions and 42 deletions
|
@ -399,7 +399,7 @@ pub fn sort_can_defs(
|
|||
) -> (Result<Vec<Declaration>, RuntimeError>, Output) {
|
||||
let CanDefs {
|
||||
refs_by_symbol,
|
||||
mut can_defs_by_symbol,
|
||||
can_defs_by_symbol,
|
||||
aliases,
|
||||
} = defs;
|
||||
|
||||
|
@ -583,7 +583,7 @@ pub fn sort_can_defs(
|
|||
&group,
|
||||
&env.closures,
|
||||
&mut all_successors_with_self,
|
||||
&mut can_defs_by_symbol,
|
||||
&can_defs_by_symbol,
|
||||
&mut declarations,
|
||||
);
|
||||
}
|
||||
|
@ -717,7 +717,7 @@ pub fn sort_can_defs(
|
|||
group,
|
||||
&env.closures,
|
||||
&mut all_successors_with_self,
|
||||
&mut can_defs_by_symbol,
|
||||
&can_defs_by_symbol,
|
||||
&mut declarations,
|
||||
);
|
||||
}
|
||||
|
@ -739,7 +739,7 @@ fn group_to_declaration(
|
|||
group: &[Symbol],
|
||||
closures: &MutMap<Symbol, References>,
|
||||
successors: &mut dyn FnMut(&Symbol) -> ImSet<Symbol>,
|
||||
can_defs_by_symbol: &mut MutMap<Symbol, Def>,
|
||||
can_defs_by_symbol: &MutMap<Symbol, Def>,
|
||||
declarations: &mut Vec<Declaration>,
|
||||
) {
|
||||
use Declaration::*;
|
||||
|
@ -765,54 +765,51 @@ fn group_to_declaration(
|
|||
if cycle.len() == 1 {
|
||||
let symbol = &cycle[0];
|
||||
|
||||
match can_defs_by_symbol.remove(symbol) {
|
||||
Some(mut new_def) => {
|
||||
// Determine recursivity of closures that are not tail-recursive
|
||||
if let Closure(ClosureData {
|
||||
recursive: recursive @ Recursive::NotRecursive,
|
||||
..
|
||||
}) = &mut new_def.loc_expr.value
|
||||
{
|
||||
*recursive = closure_recursivity(*symbol, closures);
|
||||
}
|
||||
if let Some(can_def) = can_defs_by_symbol.get(symbol) {
|
||||
let mut new_def = can_def.clone();
|
||||
|
||||
let is_recursive = successors(symbol).contains(symbol);
|
||||
|
||||
if !seen_pattern_regions.contains(&new_def.loc_pattern.region) {
|
||||
seen_pattern_regions.insert(new_def.loc_pattern.region);
|
||||
|
||||
if is_recursive {
|
||||
declarations.push(DeclareRec(vec![new_def]));
|
||||
} else {
|
||||
declarations.push(Declare(new_def));
|
||||
}
|
||||
}
|
||||
// Determine recursivity of closures that are not tail-recursive
|
||||
if let Closure(ClosureData {
|
||||
recursive: recursive @ Recursive::NotRecursive,
|
||||
..
|
||||
}) = &mut new_def.loc_expr.value
|
||||
{
|
||||
*recursive = closure_recursivity(*symbol, closures);
|
||||
}
|
||||
|
||||
let is_recursive = successors(symbol).contains(symbol);
|
||||
|
||||
if !seen_pattern_regions.contains(&new_def.loc_pattern.region) {
|
||||
if is_recursive {
|
||||
declarations.push(DeclareRec(vec![new_def.clone()]));
|
||||
} else {
|
||||
declarations.push(Declare(new_def.clone()));
|
||||
}
|
||||
seen_pattern_regions.insert(new_def.loc_pattern.region);
|
||||
}
|
||||
None => roc_error_macros::internal_error!("def not available {:?}", symbol),
|
||||
}
|
||||
} else {
|
||||
let mut can_defs = Vec::new();
|
||||
|
||||
// Topological sort gives us the reverse of the sorting we want!
|
||||
for symbol in cycle.into_iter().rev() {
|
||||
match can_defs_by_symbol.remove(&symbol) {
|
||||
Some(mut new_def) => {
|
||||
// Determine recursivity of closures that are not tail-recursive
|
||||
if let Closure(ClosureData {
|
||||
recursive: recursive @ Recursive::NotRecursive,
|
||||
..
|
||||
}) = &mut new_def.loc_expr.value
|
||||
{
|
||||
*recursive = closure_recursivity(symbol, closures);
|
||||
}
|
||||
if let Some(can_def) = can_defs_by_symbol.get(&symbol) {
|
||||
let mut new_def = can_def.clone();
|
||||
|
||||
seen_pattern_regions.insert(new_def.loc_pattern.region);
|
||||
|
||||
if !seen_pattern_regions.contains(&new_def.loc_pattern.region) {
|
||||
can_defs.push(new_def);
|
||||
}
|
||||
// Determine recursivity of closures that are not tail-recursive
|
||||
if let Closure(ClosureData {
|
||||
recursive: recursive @ Recursive::NotRecursive,
|
||||
..
|
||||
}) = &mut new_def.loc_expr.value
|
||||
{
|
||||
*recursive = closure_recursivity(symbol, closures);
|
||||
}
|
||||
None => roc_error_macros::internal_error!("def not available {:?}", symbol),
|
||||
|
||||
if !seen_pattern_regions.contains(&new_def.loc_pattern.region) {
|
||||
can_defs.push(new_def.clone());
|
||||
}
|
||||
|
||||
seen_pattern_regions.insert(new_def.loc_pattern.region);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue