mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
make call_successors safe
For recursive functions, it could enter an infinite recursion.
This commit is contained in:
parent
f265651ee6
commit
429ba6ed06
1 changed files with 15 additions and 8 deletions
|
@ -707,17 +707,24 @@ fn call_successors<'a>(
|
|||
call_symbol: Symbol,
|
||||
closures: &'a MutMap<Symbol, References>,
|
||||
) -> ImSet<Symbol> {
|
||||
// TODO (this comment should be moved to a GH issue) this may cause an infinite loop if 2 definitions reference each other; may need to track visited definitions!
|
||||
match closures.get(&call_symbol) {
|
||||
Some(references) => {
|
||||
let mut answer = local_successors(&references, closures);
|
||||
let mut answer = im_rc::hashset::HashSet::default();
|
||||
let mut seen = MutSet::default();
|
||||
let mut queue = vec![call_symbol];
|
||||
|
||||
answer.insert(call_symbol.clone());
|
||||
|
||||
answer
|
||||
while let Some(symbol) = queue.pop() {
|
||||
if seen.contains(&symbol) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(references) = closures.get(&symbol) {
|
||||
answer.extend(references.lookups.iter().copied());
|
||||
queue.extend(references.calls.iter().copied());
|
||||
|
||||
seen.insert(symbol);
|
||||
}
|
||||
None => ImSet::default(),
|
||||
}
|
||||
|
||||
answer
|
||||
}
|
||||
|
||||
pub fn references_from_local<'a, T>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue