mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
and remove everything because it has no effect
This commit is contained in:
parent
1b1a7b0385
commit
cee1a787c9
2 changed files with 0 additions and 127 deletions
|
@ -1,7 +1,6 @@
|
||||||
use crate::annotation::canonicalize_annotation;
|
use crate::annotation::canonicalize_annotation;
|
||||||
use crate::annotation::IntroducedVariables;
|
use crate::annotation::IntroducedVariables;
|
||||||
use crate::env::Env;
|
use crate::env::Env;
|
||||||
use crate::expr::references_from;
|
|
||||||
use crate::expr::ClosureData;
|
use crate::expr::ClosureData;
|
||||||
use crate::expr::Expr::{self, *};
|
use crate::expr::Expr::{self, *};
|
||||||
use crate::expr::{canonicalize_expr, local_successors, Output, Recursive};
|
use crate::expr::{canonicalize_expr, local_successors, Output, Recursive};
|
||||||
|
@ -12,7 +11,6 @@ use crate::scope::Scope;
|
||||||
use roc_collections::all::{default_hasher, ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap};
|
use roc_collections::all::{default_hasher, ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap};
|
||||||
use roc_error_macros::todo_abilities;
|
use roc_error_macros::todo_abilities;
|
||||||
use roc_module::ident::Lowercase;
|
use roc_module::ident::Lowercase;
|
||||||
use roc_module::symbol::ModuleId;
|
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_parse::ast;
|
use roc_parse::ast;
|
||||||
use roc_parse::ast::TypeHeader;
|
use roc_parse::ast::TypeHeader;
|
||||||
|
@ -423,33 +421,6 @@ pub fn canonicalize_defs<'a>(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_used_defs(
|
|
||||||
home: ModuleId,
|
|
||||||
value_lookups: &ImSet<Symbol>,
|
|
||||||
calls: &ImSet<Symbol>,
|
|
||||||
refs_by_def: &MutMap<Symbol, (Region, References)>,
|
|
||||||
closures: &MutMap<Symbol, References>,
|
|
||||||
) -> 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.
|
|
||||||
let locals = value_lookups
|
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.filter(|symbol| symbol.module_id() == home);
|
|
||||||
let calls = calls.iter().copied();
|
|
||||||
|
|
||||||
references_from(locals, calls, refs_by_def, closures)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn sort_can_defs(
|
pub fn sort_can_defs(
|
||||||
env: &mut Env<'_>,
|
env: &mut Env<'_>,
|
||||||
|
@ -466,18 +437,6 @@ pub fn sort_can_defs(
|
||||||
output.aliases.insert(symbol, alias);
|
output.aliases.insert(symbol, alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
let initial = output.references.clone();
|
|
||||||
|
|
||||||
let b = initial.union(find_used_defs(
|
|
||||||
env.home,
|
|
||||||
&output.references.value_lookups,
|
|
||||||
&output.references.calls,
|
|
||||||
&refs_by_symbol,
|
|
||||||
&env.closures,
|
|
||||||
));
|
|
||||||
|
|
||||||
output.references = b;
|
|
||||||
|
|
||||||
let mut defined_symbols: Vec<Symbol> = Vec::new();
|
let mut defined_symbols: Vec<Symbol> = Vec::new();
|
||||||
let mut defined_symbols_set: ImSet<Symbol> = ImSet::default();
|
let mut defined_symbols_set: ImSet<Symbol> = ImSet::default();
|
||||||
|
|
||||||
|
|
|
@ -1147,92 +1147,6 @@ fn call_successors(call_symbol: Symbol, closures: &MutMap<Symbol, References>) -
|
||||||
answer
|
answer
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
enum ReferencesFrom {
|
|
||||||
Local(Symbol),
|
|
||||||
Call(Symbol),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn references_from<'a, T>(
|
|
||||||
locals: impl IntoIterator<Item = Symbol>,
|
|
||||||
calls: impl IntoIterator<Item = Symbol>,
|
|
||||||
refs_by_def: &'a MutMap<Symbol, (T, References)>,
|
|
||||||
closures: &'a MutMap<Symbol, References>,
|
|
||||||
) -> References
|
|
||||||
where
|
|
||||||
T: Debug,
|
|
||||||
{
|
|
||||||
let mut stack = Vec::new();
|
|
||||||
|
|
||||||
stack.extend(locals.into_iter().map(ReferencesFrom::Local));
|
|
||||||
stack.extend(calls.into_iter().map(ReferencesFrom::Call));
|
|
||||||
|
|
||||||
references_from_help(stack, refs_by_def, closures)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn references_from_help<'a, T>(
|
|
||||||
mut stack: Vec<ReferencesFrom>,
|
|
||||||
refs_by_def: &'a MutMap<Symbol, (T, References)>,
|
|
||||||
closures: &'a MutMap<Symbol, References>,
|
|
||||||
) -> References
|
|
||||||
where
|
|
||||||
T: Debug,
|
|
||||||
{
|
|
||||||
let mut visited = Vec::new();
|
|
||||||
let mut result = References::default();
|
|
||||||
|
|
||||||
while let Some(job) = stack.pop() {
|
|
||||||
match job {
|
|
||||||
ReferencesFrom::Local(defined_symbol) => {
|
|
||||||
if let Some((_, refs)) = refs_by_def.get(&defined_symbol) {
|
|
||||||
if visited.contains(&defined_symbol) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
visited.push(defined_symbol);
|
|
||||||
|
|
||||||
for local in refs.value_lookups.iter() {
|
|
||||||
stack.push(ReferencesFrom::Local(*local));
|
|
||||||
|
|
||||||
result.value_lookups.insert(*local);
|
|
||||||
}
|
|
||||||
|
|
||||||
for call in refs.calls.iter() {
|
|
||||||
stack.push(ReferencesFrom::Call(*call));
|
|
||||||
|
|
||||||
result.calls.insert(*call);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ReferencesFrom::Call(call_symbol) => {
|
|
||||||
if let Some(references) = closures.get(&call_symbol) {
|
|
||||||
if visited.contains(&call_symbol) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
visited.push(call_symbol);
|
|
||||||
|
|
||||||
result = result.union(references.clone());
|
|
||||||
|
|
||||||
for closed_over_local in references.value_lookups.iter() {
|
|
||||||
stack.push(ReferencesFrom::Local(*closed_over_local));
|
|
||||||
|
|
||||||
result.value_lookups.insert(*closed_over_local);
|
|
||||||
}
|
|
||||||
|
|
||||||
for call in references.calls.iter() {
|
|
||||||
stack.push(ReferencesFrom::Call(*call));
|
|
||||||
|
|
||||||
result.calls.insert(*call);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CanonicalizeRecordProblem {
|
enum CanonicalizeRecordProblem {
|
||||||
InvalidOptionalValue {
|
InvalidOptionalValue {
|
||||||
field_name: Lowercase,
|
field_name: Lowercase,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue