[Merged by Bors] - feat(Linter): port unused Decidable* instance hypothesis linter#31142
[Merged by Bors] - feat(Linter): port unused Decidable* instance hypothesis linter#31142thorimur wants to merge 56 commits intoleanprover-community:masterfrom
Decidable* instance hypothesis linter#31142Conversation
PR summary b3cf7a02d3Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
6bdaa74 to
91aeeb9
Compare
1bdccd2 to
aece211
Compare
aece211 to
83f39b6
Compare
|
Quick question @kim-em : I realized the EDIT: discussed it a bit with @grunweg; we agree it's sensible to have the option declaration itself as public API accessible to other metaprograms; still curious what you think. |
|
I know from the discussion on Zulip that you did some extensive benchmarking, so maybe my suggestion is not really needed. However, I expect that most lemmas in mathlib should not even be eligible for this linter, since there is neither an active This check simply requires accessing the currently available Would it make sense to implement them? Or are there already early exits in the linter that take something like this into account? |
No no, this is certainly very welcome! :) I haven't yet focused on performance optimizations in the infotree (or earlier!) part of the linter, but I certainly plan to in subsequent PRs, especially since this linter architecture will also handle Fintype, Encodable, etc. instances. I think that an early exit of the kind you mention is a good idea! I'm trying to think of cases where it would early-exit when it shouldn't, but can't. I'd like to test this thoroughly to be sure there are no false negatives, so I will try it in that subsequent performance-oriented PR. :) (Note: there are also some minor performance improvements we could make to the infotree search itself; |
Co-authored-by: damiano <adomani@gmail.com>
Co-authored-by: damiano <adomani@gmail.com>
Co-authored-by: damiano <adomani@gmail.com>
|
Okay, I think all comments are resolved (or promised to be resolved in future versions! 😁), and I think making the option declaration |
|
bors r+ |
…1142) This PR ports the `decidableClassical` linter from mathlib3 which detects `Decidable*` instances in the type of a theorem that are unused in the remainder of the type, and can therefore be replaced with `classical` in the proof. Prior art: #10235, by @urkud. This is an open pull request from over a year ago that has slowed down, but fulfills a similar purpose. There is a major difference: #10235 contributes an `env_linter` that does not run interactively, while the current PR is a syntax linter that runs while editing. In this PR, we lint only user-written theorems (including `theorem`s, `lemma`s, and `instance`s of `Prop` classes) by looking for elaborated declarations in the infotree. This opens us up to better logging and try-this suggestions. (While this PR is written with future expansion in mind, these tasks require developing the meta API a bit further and are left to subsequent PRs.) The infrastructure here is generic to unused instances in the remainder of a type, and can easily be used to write the other `FinType`, `Encodable`, etc. linters. We rename the linter from `decidableClassical` to `unusedDecidableInType` with the intention of naming all future related linters according to the same pattern. This PR does *not* turn the linter on; it is off by default. Turning the linter on is performed in #31747. Discussed in part on Zulip [here](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Unused.20Decidable.20Instances.20linter/with/558333633). In recognition of the work on #10235, and its influence on this PR: Co-authored-by: Yury Kudryashov urkud@urkud.name Co-authored-by: thorimur <thomasmurrills@gmail.com>
|
Pull request successfully merged into master. Build succeeded: |
Decidable* instance hypothesis linterDecidable* instance hypothesis linter
This PR turns on the `unusedDecidableInType` syntax linter (#31142) after fixing the remaining violations in #31831, #31934, and #32153. This also imports the linter into Mathlib.Init and adds the linter to the Mathlib standard set. Given that classicality is embedded in Lean, this is probably the behavior downstream repos who use the mathlib standard set want; if they are specifically constructive repos, the linter can always be turned off in the lakefile. We exempt the entirety of [Mathlib/Data/Fintype/Quotient.lean](https://github.com/leanprover-community/mathlib4/pull/31747/files#diff-9591d2f3828bee189ea954bc33586ce451536bf00792362f7cdca4f5a8551207), [Mathlib/Order/Heyting/Regular.lean](https://github.com/leanprover-community/mathlib4/pull/31747/files#diff-af85d99e5d2f5561fe837f662f179c58f1ebe2a4ed0432a15260199883850c50), [Mathlib/Logic/Encodable/Basic.lean](https://github.com/leanprover-community/mathlib4/pull/31747/files#diff-db01c9a2d4726fe7ca0e6eb18a7cd485b5a9c6b26ba422dfbe501dcebef3cf77) and a declaration in [Mathlib/Computability/Halting.lean](https://github.com/leanprover-community/mathlib4/pull/31747/files#diff-d47323ee8b4b2321052b4be93715f8b2f3f840f76ec441d8bf75c834b8665b32) since constructivity is desired there. We also exempt `dec_em'`, which is a variant of `Decidable.em` but with the disjuncts reversed. Many prior violations have already been fixed through the use of #10235, hence the small number of violations picked up by the syntax linter. Co-authored-by: thorimur <thomasmurrills@gmail.com> Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
This PR ports the
decidableClassicallinter from mathlib3 which detectsDecidable*instances in the type of a theorem that are unused in the remainder of the type, and can therefore be replaced withclassicalin the proof.Prior art: #10235, by @urkud. This is an open pull request from over a year ago that has slowed down, but fulfills a similar purpose. There is a major difference: #10235 contributes an
env_linterthat does not run interactively, while the current PR is a syntax linter that runs while editing.In this PR, we lint only user-written theorems (including
theorems,lemmas, andinstances ofPropclasses) by looking for elaborated declarations in the infotree. This opens us up to better logging and try-this suggestions. (While this PR is written with future expansion in mind, these tasks require developing the meta API a bit further and are left to subsequent PRs.)The infrastructure here is generic to unused instances in the remainder of a type, and can easily be used to write the other
FinType,Encodable, etc. linters.We rename the linter from
decidableClassicaltounusedDecidableInTypewith the intention of naming all future related linters according to the same pattern.This PR does not turn the linter on; it is off by default. Turning the linter on is performed in #31747.
Discussed in part on Zulip here.
In recognition of the work on #10235, and its influence on this PR:
Co-authored-by: Yury Kudryashov urkud@urkud.name