mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Update unused warnings for inline imports
Now that imports can be limited to smaller scopes than the entire module, unused import warnings need to work like unused def warnings. This commit moves unused import warnings discovery and reporting from load to canonicalization where we can track their usage per scope. This also fixes a longstanding bug where unused exposed names from an import were not reported if they were only used in a qualified manner.
This commit is contained in:
parent
08e6b79dca
commit
7b3317dbb6
18 changed files with 334 additions and 122 deletions
|
@ -2142,44 +2142,6 @@ macro_rules! debug_check_ir {
|
|||
};
|
||||
}
|
||||
|
||||
/// Report modules that are imported, but from which nothing is used
|
||||
fn report_unused_imported_modules(
|
||||
state: &mut State<'_>,
|
||||
module_id: ModuleId,
|
||||
constrained_module: &ConstrainedModule,
|
||||
) {
|
||||
// [modules-revamp] TODO: take expr-level into account
|
||||
let mut unused_imported_modules = constrained_module.imported_modules.clone();
|
||||
let mut unused_imports = constrained_module.module.exposed_imports.clone();
|
||||
|
||||
for symbol in constrained_module.module.referenced_values.iter() {
|
||||
unused_imported_modules.remove(&symbol.module_id());
|
||||
unused_imports.remove(symbol);
|
||||
}
|
||||
|
||||
for symbol in constrained_module.module.referenced_types.iter() {
|
||||
unused_imported_modules.remove(&symbol.module_id());
|
||||
unused_imports.remove(symbol);
|
||||
}
|
||||
|
||||
let existing = match state.module_cache.can_problems.entry(module_id) {
|
||||
Vacant(entry) => entry.insert(std::vec::Vec::new()),
|
||||
Occupied(entry) => entry.into_mut(),
|
||||
};
|
||||
|
||||
for (unused, region) in unused_imported_modules.drain() {
|
||||
if !unused.is_builtin() {
|
||||
existing.push(roc_problem::can::Problem::UnusedModuleImport(
|
||||
unused, region,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
for (unused, region) in unused_imports.drain() {
|
||||
existing.push(roc_problem::can::Problem::UnusedImport(unused, region));
|
||||
}
|
||||
}
|
||||
|
||||
fn extend_module_with_builtin_import(module: &mut ParsedModule, module_id: ModuleId) {
|
||||
module
|
||||
.package_qualified_imported_modules
|
||||
|
@ -2514,8 +2476,6 @@ fn update<'a>(
|
|||
state.module_cache.documentation.insert(module_id, docs);
|
||||
}
|
||||
|
||||
report_unused_imported_modules(&mut state, module_id, &constrained_module);
|
||||
|
||||
state
|
||||
.module_cache
|
||||
.aliases
|
||||
|
@ -5145,7 +5105,6 @@ fn canonicalize_and_constrain<'a>(
|
|||
exposed_imports: module_output.exposed_imports,
|
||||
exposed_symbols: module_output.exposed_symbols,
|
||||
referenced_values: module_output.referenced_values,
|
||||
referenced_types: module_output.referenced_types,
|
||||
aliases,
|
||||
rigid_variables: module_output.rigid_variables,
|
||||
abilities_store: module_output.scope.abilities_store,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue