Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat: unused tactic linter #11308

Closed
wants to merge 55 commits into from

Conversation

adomani
Copy link
Collaborator

@adomani adomani commented Mar 12, 2024

The unusedTactic linter emits a warning if a tactic does nothing.

Previous PRs (see below) removed all the "unused tactics" that the linter flagged.

Here is an overview of this PR:

  • the linter is defined in Mathlib/Tactic/Linter/UnusedTactic.lean;
  • the file Mathlib/GroupTheory/Perm/Cycle/Concrete.lean contains the "only" set_option to opt out of the linter, since it defines notation that uses decide that the notation itself does not use;
  • 17 test files that have surgically opted out of the linter;
  • noise to import the new file, place it low in the import hierarchy and update noshake.

PRs removing some unused tactics:

Zulip thread


Open in Gitpod

@adomani adomani added awaiting-review t-meta Tactics, attributes or user commands labels Mar 12, 2024
Copy link
Member

@alexjbest alexjbest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow super cool!

Mathlib/CategoryTheory/Limits/Shapes/Terminal.lean Outdated Show resolved Hide resolved
Mathlib/Data/Finset/Lattice.lean Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message looks quite suboptimal. Could the tactic offer a Try this: <tactic call without the useless tactic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, It probably could, although the cure is typically to simply remove the underlined code.

I'll try it, though and see how the formatting goes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried a bit and I find it tricky: I do not know how to consistently remove the "unused" syntax. I could make it work when you have a very basic sequence of tactics, but as soon as there are combinators or any non-trivial nesting, I fail to produce well-formed syntax robustly.

@grunweg
Copy link
Collaborator

grunweg commented Mar 12, 2024

Just FWIW, when I read the PR title "pointless linter", at first I thought (apart from the pun, which I like!) it was about missing focusing dots... If/when this is running in CI, being clearly about pointless tactics will really help. (You mostly already do this.)

@adomani
Copy link
Collaborator Author

adomani commented Mar 12, 2024

Just FWIW, when I read the PR title "pointless linter", at first I thought (apart from the pun, which I like!) it was about missing focusing dots... If/when this is running in CI, being clearly about pointless tactics will really help. (You mostly already do this.)

You are right: maybe calling it a more sober "unused tactic linter" might be better. I'll leave it as is while I clean up the "useless" tactics and will maybe have a poll later on.

EDIT: I've done just that now. The linter is now called the "unused tactic linter".

@YaelDillies
Copy link
Collaborator

As said on the other PR, I'm not sure what the point of eradicating "purposely pointless" tactics like skip or done is

@adomani
Copy link
Collaborator Author

adomani commented Mar 12, 2024

As said on the other PR, I'm not sure what the point of eradicating "purposely pointless" tactics like skip or done is

I have not yet found a way to nolint skips that appear in a <;> [...] block and for the moment I am leaving those as they are, unless there is something that looks like an improvement. The remaining skips seem completely superfluous, maybe introduced by Mathport, I am not sure.

With respect to done, I am happy to nolint it: I already have nolinted ; for the same reason. However, it seems to me that done is a good way to internally verify that a tactic is finished doing what it should do, but seems to almost never appear in "visible" code.

@adomani adomani changed the title feat: a pointless linter feat: unused tactic linter Mar 13, 2024
mathlib-bors bot pushed a commit that referenced this pull request Mar 13, 2024
The removal of some pointless tactics flagged by #11308.
mathlib-bors bot pushed a commit that referenced this pull request Mar 13, 2024
I removed some of the tactics that were not used and are hopefully uncontroversial arising from the linter at #11308.

As the commit messages should convey, the removed tactics are, essentially,
```
push_cast
norm_cast
congr
norm_num
dsimp
funext
intro
infer_instance
```
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jun 26, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jun 26, 2024
Copy link
Collaborator

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty straighforward now.

maintainer merge

end

/-- Gets the value of the `linter.unusedTactic` option. -/
def getLinterHash (o : Options) : Bool := Linter.getLinterValue linter.unusedTactic o
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def getLinterHash (o : Options) : Bool := Linter.getLinterValue linter.unusedTactic o
def getLinterHash (o : Options) : Bool := linter.unusedTactic.getLinterValue o

no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the reviews, Yaël!

I tried this suggestion, but it does not work: the type of linter.unusedTactic is Lean.Option Bool. The Linter itself is the following declaration, unusedTacticLinter.

Copy link

🚀 Pull request has been placed on the maintainer queue by YaelDillies.

1 similar comment
Copy link

🚀 Pull request has been placed on the maintainer queue by YaelDillies.

@kim-em
Copy link
Contributor

kim-em commented Jun 30, 2024

bors d+

@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Jun 30, 2024

✌️ adomani can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@adomani
Copy link
Collaborator Author

adomani commented Jun 30, 2024

Two more unused tactics had snuck in since the last time I merged master!

Thanks for the reviews!

bors r+

mathlib-bors bot pushed a commit that referenced this pull request Jun 30, 2024
The `unusedTactic` linter emits a warning if a tactic does nothing.

Previous PRs (see below) removed all the "unused tactics" that the linter flagged.

Here is an overview of this PR:
* the linter is defined in `Mathlib/Tactic/Linter/UnusedTactic.lean`;
* the file `Mathlib/GroupTheory/Perm/Cycle/Concrete.lean` contains the "only" `set_option` to opt out of the linter, since it defines notation that uses `decide` that the notation itself does not use;
* 17 test files that have surgically opted out of the linter;
* noise to import the new file, place it low in the import hierarchy and update `noshake`.


PRs removing some unused tactics:
* #11333
* #11351
* #11365
* #11379

[Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/pointless.20tactic.20linter)
@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Jun 30, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title feat: unused tactic linter [Merged by Bors] - feat: unused tactic linter Jun 30, 2024
@mathlib-bors mathlib-bors bot closed this Jun 30, 2024
@mathlib-bors mathlib-bors bot deleted the adomani/useless_tactic branch June 30, 2024 05:01
dagurtomas pushed a commit that referenced this pull request Jul 2, 2024
The `unusedTactic` linter emits a warning if a tactic does nothing.

Previous PRs (see below) removed all the "unused tactics" that the linter flagged.

Here is an overview of this PR:
* the linter is defined in `Mathlib/Tactic/Linter/UnusedTactic.lean`;
* the file `Mathlib/GroupTheory/Perm/Cycle/Concrete.lean` contains the "only" `set_option` to opt out of the linter, since it defines notation that uses `decide` that the notation itself does not use;
* 17 test files that have surgically opted out of the linter;
* noise to import the new file, place it low in the import hierarchy and update `noshake`.


PRs removing some unused tactics:
* #11333
* #11351
* #11365
* #11379

[Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/pointless.20tactic.20linter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
delegated maintainer-merge t-meta Tactics, attributes or user commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants