Unused warnings#3819
Conversation
|
Looks like there's a lot of diff churn due to automatic formatting. |
|
Yeah apparently I didn't manage to fork off latest or I spent long enough doing so that things have moved on, I'll do some rebasing. In the meantime, the changes in Linter however are all new - I didn't couple it to the existing pass there |
c325257 to
40c1dd7
Compare
|
OK, I did do some funky reformat for some reason. This should now be rebased, unfortunately I can't run tests even on master locally since updating to latest. |
|
You need to delete .test_modules |
|
Thanks, got it passing now. Some reason had to update the golden test for 1 file I didn't touch |
| let n (ValueRef _ ident) = Just ident | ||
| n _ = Nothing |
There was a problem hiding this comment.
This is getValueRef in AST.Declarations
| getDeclIdent :: Declaration -> Maybe Ident | ||
| getDeclIdent (ValueDeclaration vd) = Just (valdeclIdent vd) | ||
| getDeclIdent (ExternDeclaration _ ident _) = Just ident | ||
| getDeclIdent (TypeInstanceDeclaration _ _ _ ident _ _ _ _) = Just ident | ||
| getDeclIdent BindingGroupDeclaration{} = internalError "lint: binding groups should not be desugared yet." | ||
| getDeclIdent _ = Nothing |
There was a problem hiding this comment.
This is getIdentName <=< declName.
There was a problem hiding this comment.
This is copied from earlier in the same file actually, oops!
|
|
||
| goDecl _ = mempty | ||
|
|
||
| go :: SourceSpan -> Expr -> (S.Set Ident, MultipleErrors) |
There was a problem hiding this comment.
If everythingWithContextOnValues let you get a hold of PositionedValue, could this be implemented in terms of that traversal? Much of this traversal looks like it's reimplementing that, but the only difference is the context is a source span, which you can't get with the current implementation. I don't think it would break anything to expose that.
There was a problem hiding this comment.
No, the main issue with everythingWithContextOnValues is that at the point of binders, we don't want to do something on the binder and the expression under its scope separately and combine them, we want to take the result on the scoped expression then look at that together with the binder. I guess it would likely be possible to bake more into the context and do all the logic in the combine, but that seems rather contorted, really this is another traversal for capture-aware operations.
(Aside, I originally followed the logic for the type-level version of the same, which inverts to go top-down with the set of so far unused variables - now that was a bunch of make-work...)
|
Just wanted to say I really appreciate you picking this up. I'm sure this will have a hugely positive effect on the codebase I work on (although I guess I won't be able to give it a try until we've released 0.14 and updated at work). |
|
I think this looks good. Have you tried running it against https://github.com/JordanMartinez/purescript-hail-mary? I would like to get an idea of the number of warnings to expect from this overall. You can use |
|
@natefaubion I actually just deleted that repo. When I said there were 381 warnings using my Since I'm no Bash-fu person, I found that this code made it possible to install all packages in that set: The current number of warnings is now 377, but not all of them are the "the inferred kind for X is Y. Consider adding a kind signature" warnings. |
|
I think there are some missing cases, particularly around record puns. When running against the package set, I get warnings for things like |
|
This is missing a case for |
|
I did see the (earlier) comment nate, just not got around to running against that compatible package set - I don't think I was aware of it before |
|
@nwolverson I made a change to fix this, but I'm not going to presume by pushing to this branch. From that above and then to generate a table: Or to filter specific modules: |
5d49d96 to
eb0498b
Compare
|
I've updated a bunch of cases here, there were quite a few issues
Looking at that package set now, I'm only finding genuine unused issues - including a surprising number of declarations that are not used or exported :) Improvements that could be made
btw @JordanMartinez I have a different spago version apparently but I used this |
bf6cf59 to
c5e9f7f
Compare
|
Rebased on master and fixed golden tests |
|
Updated to avoid warning on variables with |
|
Just curious, what sort of situation is that useful in? We tend to prefix our foreign imports with |
|
@garyb the change I just pushed only makes that distinction for locally bound identifiers, rather than top level declarations, I believe, so should not affect the foreign import case. For those top-level decls I don't really see any possible reason to distinguish - why would you want to define a function or import a foreign and not use it, I can only imagine it is dead or intended to be used in future, and a warning is appropriate. The situation tends to be when pattern matching on multiple arguments, it's often clearer to see what is being ignored rather than seeing The leading underscore is a convention in a number of languages/compilers/linters - e.g. Erlang, Haskell (GHC), Rust, TypeScript, Ruby (Rubocop) |
|
Thanks for the explanation! |
|
Just looking through my open prs - the build failure on this is a timeout - I expect only worth kicking it when looking to merge this. |
* Declarations that are used but not exported * Variables bound in let/lambda bindings, case patterns, etc which are unused
664d85d to
1873aaf
Compare
| (S.Set Ident, MultipleErrors) -> | ||
| (S.Set Ident, MultipleErrors) -> | ||
| (S.Set Ident, MultipleErrors) | ||
| combine (a, b) (c, d) = (S.union a c, b <> d) |
There was a problem hiding this comment.
I think this is just <>? Or did you avoid that deliberately for readability?
There was a problem hiding this comment.
I imagine this is like this because of the other version in this file which is (S.intersection a c, b <> d) - I think this code originally worked the other way around so the instance wasn't right. I don't think infix combine is readable - I'll change it
|
|
||
| go _ (PositionedValue ss' _ v1) = go ss' v1 | ||
|
|
||
| go _ _ = (mempty, mempty) |
There was a problem hiding this comment.
I'd quite like to avoid catch-all patterns here, as I think it will be quite easy to forget to update this function if we do add new cases to Expr in the future. Would you mind matching every constructor here?
|
Looks great! I have a few (very minor) comments and then I would be happy to merge this. |
Co-authored-by: Harry Garrood <harry@garrood.me>
|
I'm going to push a commit updating the changelog and then merge this. Thanks! |
|
FYI, these two error docs currently lead to 404 |
We move to the latest version of everything. We're addressing both errors and warnings in this change (because we'd like to treat warnings like errors anyway). For the most part this is straight-forward find/replace change. We did have to do something about the static checks though. What we did was dump them all into an array and export that single value. Since there doesn't seem to be any way to define a value at the top-level that is otherwise unused without it also producing a warning, we're kind of pigeon-holed into this sort of solution. The only other option is to remove the static checks, but they've caught way more issues than is reasonable for the amount of code they are so that feels like a major step backwards. It would've been ideal to prefix them with an `_` (like you can do in other situations), but that's not how things work. For more information, see this discussion: purescript/purescript#3819 (comment).
Addresses some parts of #1670, specifically unused let/where bound values, binders, un-exported value declarations.
There are some warnings-tests but I've yet to throw this at a decent-sized codebase to see how much it picks up.
Will need update to CONTRIBUTORS before merging.