Skip to content

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

Closed
adomani wants to merge 55 commits intomasterfrom
adomani/useless_tactic
Closed

[Merged by Bors] - feat: unused tactic linter#11308
adomani wants to merge 55 commits intomasterfrom
adomani/useless_tactic

Conversation

@adomani
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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!

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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
```
@github-actions github-actions bot removed the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Jun 26, 2024
@ghost ghost 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
@ghost ghost 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
Copy Markdown
Contributor

@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
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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.

@github-actions
Copy link
Copy Markdown

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

1 similar comment
@github-actions
Copy link
Copy Markdown

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

@github-actions github-actions bot added maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. labels Jun 29, 2024
@kim-em
Copy link
Copy Markdown
Contributor

kim-em commented Jun 30, 2024

bors d+

@mathlib-bors
Copy link
Copy Markdown
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.

@github-actions github-actions bot added delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). and removed awaiting-review labels Jun 30, 2024
@adomani
Copy link
Copy Markdown
Contributor 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
Copy Markdown
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 This pull request has been delegated to the PR author (or occasionally another non-maintainer). maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. t-meta Tactics, attributes or user commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants