mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
cleanup
This commit is contained in:
parent
cc9873eb6d
commit
a170f461e0
2 changed files with 2 additions and 146 deletions
|
@ -427,51 +427,6 @@ pub fn canonicalize_defs<'a>(
|
|||
)
|
||||
}
|
||||
|
||||
fn crawl_for_references(
|
||||
home: ModuleId,
|
||||
input_references: References,
|
||||
refs_by_def: &MutMap<Symbol, (Region, References)>,
|
||||
closures: &MutMap<Symbol, References>,
|
||||
) -> References {
|
||||
// Determine the full set of references by traversing the graph.
|
||||
let mut visited_symbols = MutSet::default();
|
||||
let returned_lookups = ImSet::clone(&input_references.value_lookups);
|
||||
|
||||
let mut output_references = input_references;
|
||||
|
||||
// Start with the return expression's referenced locals. They're the only ones that count!
|
||||
//
|
||||
// If I have two defs which reference each other, but neither of them is referenced
|
||||
// in the return expression, I don't want either of them (or their references) to end up
|
||||
// in the final output.references. They were unused, and so were their references!
|
||||
//
|
||||
// The reason we need a graph here is so we don't overlook transitive dependencies.
|
||||
// For example, if I have `a = b + 1` and the def returns `a + 1`, then the
|
||||
// def as a whole references both `a` *and* `b`, even though it doesn't
|
||||
// directly mention `b` - because `a` depends on `b`. If we didn't traverse a graph here,
|
||||
// we'd erroneously give a warning that `b` was unused since it wasn't directly referenced.
|
||||
for symbol in returned_lookups.into_iter() {
|
||||
// We only care about local symbols in this analysis.
|
||||
if symbol.module_id() == home {
|
||||
// Traverse the graph and look up *all* the references for this local symbol.
|
||||
let refs = references_from_local(symbol, &mut visited_symbols, refs_by_def, closures);
|
||||
|
||||
output_references = output_references.union(refs);
|
||||
}
|
||||
}
|
||||
|
||||
for symbol in ImSet::clone(&output_references.calls).into_iter() {
|
||||
// Traverse the graph and look up *all* the references for this call.
|
||||
// Reuse the same visited_symbols as before; if we already visited it,
|
||||
// we won't learn anything new from visiting it again!
|
||||
let refs = references_from_call(symbol, &mut visited_symbols, refs_by_def, closures);
|
||||
|
||||
output_references = output_references.union(refs);
|
||||
}
|
||||
|
||||
output_references
|
||||
}
|
||||
|
||||
fn find_used_defs(
|
||||
home: ModuleId,
|
||||
value_lookups: &ImSet<Symbol>,
|
||||
|
@ -535,10 +490,8 @@ pub fn sort_can_defs(
|
|||
}
|
||||
|
||||
let initial = output.references.clone();
|
||||
let initial1 = output.references.clone();
|
||||
let initial2 = output.references.clone();
|
||||
|
||||
let b = initial2.union(find_used_defs(
|
||||
let b = initial.union(find_used_defs(
|
||||
env.home,
|
||||
&output.references.value_lookups,
|
||||
&output.references.calls,
|
||||
|
@ -546,16 +499,7 @@ pub fn sort_can_defs(
|
|||
&env.closures,
|
||||
));
|
||||
|
||||
let a = output.references.union(crawl_for_references(
|
||||
env.home,
|
||||
initial,
|
||||
&refs_by_symbol,
|
||||
&env.closures,
|
||||
));
|
||||
|
||||
assert!(a == b);
|
||||
|
||||
output.references = a;
|
||||
output.references = b;
|
||||
|
||||
let mut defined_symbols: Vec<Symbol> = Vec::new();
|
||||
let mut defined_symbols_set: ImSet<Symbol> = ImSet::default();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue