Merge pull request #2952 from rtfeldman/ability-unused-method-reporting

Ability unused method reporting
This commit is contained in:
Ayaz 2022-04-25 15:53:06 -04:00 committed by GitHub
commit e736adaa24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 72 deletions

View file

@ -203,7 +203,7 @@ pub(crate) fn canonicalize_defs<'a>(
env: &mut Env<'a>, env: &mut Env<'a>,
mut output: Output, mut output: Output,
var_store: &mut VarStore, var_store: &mut VarStore,
original_scope: &Scope, mut scope: Scope,
loc_defs: &'a [&'a Loc<ast::Def<'a>>], loc_defs: &'a [&'a Loc<ast::Def<'a>>],
pattern_type: PatternType, pattern_type: PatternType,
) -> (CanDefs, Scope, Output, MutMap<Symbol, Region>) { ) -> (CanDefs, Scope, Output, MutMap<Symbol, Region>) {
@ -224,30 +224,19 @@ pub(crate) fn canonicalize_defs<'a>(
// This naturally handles recursion too, because a given expr which refers // This naturally handles recursion too, because a given expr which refers
// to itself won't be processed until after its def has been added to scope. // to itself won't be processed until after its def has been added to scope.
// Record both the original and final idents from the scope,
// so we can diff them while detecting unused defs.
let mut scope = original_scope.clone();
let num_defs = loc_defs.len(); let num_defs = loc_defs.len();
let mut pending_type_defs = Vec::with_capacity(num_defs);
let mut type_defs = Vec::with_capacity(num_defs);
let mut value_defs = Vec::with_capacity(num_defs); let mut value_defs = Vec::with_capacity(num_defs);
for loc_def in loc_defs { for loc_def in loc_defs {
match loc_def.value.unroll_def() { match loc_def.value.unroll_def() {
Ok(type_def) => type_defs.push(Loc::at(loc_def.region, type_def)), Ok(type_def) => {
pending_type_defs.push(to_pending_type_def(env, type_def, &mut scope, pattern_type))
}
Err(value_def) => value_defs.push(Loc::at(loc_def.region, value_def)), Err(value_def) => value_defs.push(Loc::at(loc_def.region, value_def)),
} }
} }
// We need to canonicalize all the type defs first.
// Clippy is wrong - we do need the collect, otherwise "env" and "scope" are captured for
// longer than we'd like.
#[allow(clippy::needless_collect)]
let pending_type_defs = type_defs
.into_iter()
.map(|loc_def| to_pending_type_def(env, loc_def.value, &mut scope, pattern_type))
.collect::<Vec<_>>();
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
env.home.register_debug_idents(&env.ident_ids); env.home.register_debug_idents(&env.ident_ids);
} }
@ -452,7 +441,6 @@ pub(crate) fn canonicalize_defs<'a>(
&mut output, &mut output,
var_store, var_store,
&mut scope, &mut scope,
&mut symbols_introduced,
abilities, abilities,
&abilities_in_scope, &abilities_in_scope,
pattern_type, pattern_type,
@ -554,7 +542,6 @@ fn resolve_abilities<'a>(
output: &mut Output, output: &mut Output,
var_store: &mut VarStore, var_store: &mut VarStore,
scope: &mut Scope, scope: &mut Scope,
symbols_introduced: &mut MutMap<Symbol, Region>,
abilities: MutMap<Symbol, (Loc<Symbol>, &[AbilityMember])>, abilities: MutMap<Symbol, (Loc<Symbol>, &[AbilityMember])>,
abilities_in_scope: &[Symbol], abilities_in_scope: &[Symbol],
pattern_type: PatternType, pattern_type: PatternType,
@ -598,8 +585,6 @@ fn resolve_abilities<'a>(
} }
}; };
symbols_introduced.insert(member_sym, name_region);
if pattern_type == PatternType::TopLevelDef { if pattern_type == PatternType::TopLevelDef {
env.top_level_symbols.insert(member_sym); env.top_level_symbols.insert(member_sym);
} }
@ -1402,7 +1387,7 @@ pub fn can_defs_with_return<'a>(
env, env,
Output::default(), Output::default(),
var_store, var_store,
&scope, scope,
loc_defs, loc_defs,
PatternType::DefExpr, PatternType::DefExpr,
); );

View file

@ -289,7 +289,7 @@ pub fn canonicalize_module_defs<'a>(
&mut env, &mut env,
Output::default(), Output::default(),
var_store, var_store,
&scope, scope,
&desugared, &desugared,
PatternType::TopLevelDef, PatternType::TopLevelDef,
); );

View file

@ -9203,16 +9203,6 @@ I need all branches in an `if` to have the same type!
| a has Ability | a has Ability
at the end of the type. at the end of the type.
UNUSED DEFINITION /code/proj/Main.roc
`ab` is not used anywhere in your code.
3 Ability has ab : a -> {} | a has Ability
^^
If you didn't intend on using `ab` then remove it so future readers of
your code don't wonder why it is there.
"# "#
), ),
) )
@ -9289,16 +9279,6 @@ I need all branches in an `if` to have the same type!
If you didn't intend on using `Ability` then remove it so future readers If you didn't intend on using `Ability` then remove it so future readers
of your code don't wonder why it is there. of your code don't wonder why it is there.
UNUSED DEFINITION /code/proj/Main.roc
`ab` is not used anywhere in your code.
3 Ability has ab : {} -> {}
^^
If you didn't intend on using `ab` then remove it so future readers of
your code don't wonder why it is there.
"# "#
), ),
) )
@ -9330,16 +9310,6 @@ I need all branches in an `if` to have the same type!
are a part of. are a part of.
Hint: Did you mean to bind the `Hash` ability instead? Hint: Did you mean to bind the `Hash` ability instead?
UNUSED DEFINITION /code/proj/Main.roc
`hash` is not used anywhere in your code.
4 Hash has hash : a, b -> Num.U64 | a has Eq, b has Hash
^^^^
If you didn't intend on using `hash` then remove it so future readers of
your code don't wonder why it is there.
"# "#
), ),
) )
@ -9371,16 +9341,6 @@ I need all branches in an `if` to have the same type!
looking at specializations! looking at specializations!
Hint: Did you mean to only bind `a` to `Eq`? Hint: Did you mean to only bind `a` to `Eq`?
UNUSED DEFINITION /code/proj/Main.roc
`eq` is not used anywhere in your code.
3 Eq has eq : a, b -> Bool.Bool | a has Eq, b has Eq
^^
If you didn't intend on using `eq` then remove it so future readers of
your code don't wonder why it is there.
"# "#
), ),
) )
@ -9424,16 +9384,6 @@ I need all branches in an `if` to have the same type!
a has Hash a has Hash
Otherwise, the function does not need to be part of the ability! Otherwise, the function does not need to be part of the ability!
UNUSED DEFINITION /code/proj/Main.roc
`hash` is not used anywhere in your code.
3 Hash has hash : (a | a has Hash) -> Num.U64
^^^^
If you didn't intend on using `hash` then remove it so future readers of
your code don't wonder why it is there.
"# "#
), ),
) )