Repository navigation
Conversation
|
!bench |
PR summary 0579efd528Import changes exceeding 2%
|
| Files | Import difference |
|---|---|
| ../mathlib-ci/scripts/pr_summary/import_trans_difference.sh all | |
| There are 8514 files with changed transitive imports taking up over 372064 characters: this is too many to display! | |
You can run this locally from your mathlib4 directory: |
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
Declarations diff (regex)
+ _root_.Lean.ConstantVal.logOnUnusedInstancesInTypeWhere
+ declTypeLinter
- _root_.Lean.Syntax.logUnusedInstancesInTheoremsWhere
You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>
## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.
Declarations diff (Lean)
✅ Lean-aware diff — post-build, computed from the Lean environment (commit
0579efd).
- +5 new declarations
- −0 removed declarations
+Mathlib.Linter.OverlappingInstances.linter.overlappingInstances
+Mathlib.Linter.OverlappingInstances.overlappingInstances
+Mathlib.Linter.UnusedInstancesInType.unusedDecidableInType
+Mathlib.Linter.UnusedInstancesInType.unusedFintypeInType
+Mathlib.Linter.declTypeLinterNo changes to strong technical debt.
No changes to weak technical debt.
Current commit 0579efd528
Reference commit 87fc9444ea
This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
- The
relativevalue is the weighted sum of the differences with weight given by the inverse of the current value of the statistic. - The
absolutevalue is therelativevalue divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).
|
Benchmark results for 30ddd61 against 87fc944 are in. There are significant results. @JovanGerb
Large changes (1✅)
Small changes (58✅)
|
| import all Mathlib.Tactic.Linter.UnusedInstancesInType | ||
| import all Mathlib.Tactic.Linter.OverlappingInstances |
There was a problem hiding this comment.
Is there a reason we don't want to/can't simply make the relevant declarations public? Does it hurt performance or something? (If so we should document it :) )
There was a problem hiding this comment.
We can! Either that or using import all works. Would you prefer to make them public?
There was a problem hiding this comment.
On the one hand, I don't want to have to deprecate them if we change the type signature, but on the other, I'd like to banish all import alls. XD
How about this: we make the necessary final definitions public, and we put them in the Mathlib.Linter.UnusedInstancesInType.Lean.ConstantVal namespace, since these are specifically the "constantval versions". (Then we can use dot notation thanks to DNRO.)
Similarly let's also take the _root_ off of declarations in that file and rely instead on DNRO, since iirc those declarations are touched as well :)
| {importFintypeOfFiniteNote?.getD m!""}" | ||
|
|
||
| initialize addLinter unusedFintypeInType | ||
| def unusedFintypeInType (thm : ConstantVal) (bodyRef : Syntax) : CoreM Unit := do |
There was a problem hiding this comment.
I pushed a commit that passes the bodyRef and does the same logging-on-type approximation we did in the overlapping instances linter. If we're changing the type signature, I feel we may as well :)
I also added two small tests for it.
Fun fact, this builds the source files if you downgrade the batteries import to non-public, but causes an interpreter error 😁
There was a problem hiding this comment.
Ah right, I guess the module system still has some rough edges around meta code.
| -/ | ||
| @[nolint unusedArguments] -- TODO: we plan to use `_cmd` in future | ||
| def _root_.Lean.Syntax.logUnusedInstancesInTheoremsWhere (_cmd : Syntax) | ||
| def logUnusedInstancesInTheorem (thm : ConstantVal) |
There was a problem hiding this comment.
Actually, what about
| def logUnusedInstancesInTheorem (thm : ConstantVal) | |
| def Lean.ConstantVal.logUnusedInstancesInTypeWhere (thm : ConstantVal) |
(and dot notation below)?
There was a problem hiding this comment.
I would say it is a bit redundant to set up dot notation here. It doesn't save us any characters at the use site. (And this function could just as naturally take a ConstantInfo or TheoremInfo)
There was a problem hiding this comment.
My thinking is mostly that it makes the Where more readable and also tells us what this is "acting on": thm.logUnusedInstancesInTypeWhere filter. Also aligns it with onUnusedInstancesWhere.
(More broadly, is the purpose of dot notation to save characters? I thought it was mostly for conceptual organization.)
There was a problem hiding this comment.
I'm not a fan of using "where" in the name like this (I don't really know what it is supposed to mean).
I don't think the purpose of dot notation is to describe the type: you can just look at the type directly for that. I do think the purpose is to save characters. E.g. for Array.push, without dot notation it would need to be called e.g. arrayPush which is longer.
So I really do think this definition should just live in a UnusedInstancesInType (or similar) namespace.
There was a problem hiding this comment.
"Where" means that it's subject to the provided condition, as in "log on all unused instances in the type where the instances are a variant of Decidable", for example. (Kind of like a more natural-language P in e.g. eraseP, I guess.)
Hmm, I disagree re: the purpose of dot notation. I think it's a readability and API exposure affordance inspired ultimately by the notion of methods in OOP, right? Meant primarily to connote that this is somehow the object whose data we are acting on (whether to modify it or extract something from it). I generally read x.foo a b as something like "act on x using foo according to a and b". (And also for discoverability, both so that a. lets you find Array.push via autocomplete even when the namespace is not open, though that's not really relevant in this case.)
There was a problem hiding this comment.
No, just to be clear, my reasoning for the public constant being in the namespace is totally disjoint from my dot notation preferences in general (and is not "for" dot notation at all).
For these particular public definitions I anticipate some churn in the future, and "putting them in the namespace of one of the arguments" seems like as good a means as any to allow us to deprecate it in the future if/when the type changes. (So that we don't change the type of a public facing decl, which would be a breaking change. I mean, in principle. Probably no one is going to call this in practice even if it's public. XD) But any other means of making the name more specific and therefore deprecatable when the type changed would do just as well.
There was a problem hiding this comment.
Anyways, I wouldn't really count this definition as public, in the sense that it is "morally" private. That was my idea behind making it actually private in the first place.
(I was wondering more generally if maybe all meta definitions that are part of the implementation of a specific tactic/linter should be made private, because they are never meant to be used anywhere else. This is just annoying when the implementation itself spans multiple files, like here.)
There was a problem hiding this comment.
Sure, I agree. I just seek to prevent hypothetical frustrating experiences from occurring! 😁 If you're very against it I won't force it.
There was a problem hiding this comment.
(Also, yes, I agree managing the API surface is good for meta code just as it is for other code! :) )
There was a problem hiding this comment.
I weakly support Thomas' suggestion to rename (I think his suggestion is a better name but also it is a nearly-private declaration so it is not worth dropping this PR over it).
Co-authored-by: Thomas R. Murrills <[email protected]>
|
I think this is nearly ready: can you please update the docstrings to match the new type signatures? Also, let's call that private function maintainer delegate |
|
🚀 Pull request has been placed on the maintainer queue by thorimur. |
| for (bodyRef, ctx, info) in t.getDeclBodyInfos do | ||
| if overlap then | ||
| overlappingInstances bodyRef ctx info | ||
| if let some declName := ctx.parentDecl? then |
There was a problem hiding this comment.
Do we want to do a micro-optimization by checking for decidable || fintype before the later checks? (I suppose in Mathlib this isn't going to make an impact either way since both linters are going to be enabled throughout.)
There was a problem hiding this comment.
I don't think that findTheoremConstVal? and Command.liftCoreM are sufficiently slow that we need to do this optimization. (And to be honest I can't really imagine a scenario where you would want only one of these two linters)
Vierkantor
left a comment
There was a problem hiding this comment.
LGTM otherwise!
bors d+
| -/ | ||
| @[nolint unusedArguments] -- TODO: we plan to use `_cmd` in future | ||
| def _root_.Lean.Syntax.logUnusedInstancesInTheoremsWhere (_cmd : Syntax) | ||
| def logUnusedInstancesInTheorem (thm : ConstantVal) |
There was a problem hiding this comment.
I weakly support Thomas' suggestion to rename (I think his suggestion is a better name but also it is a nearly-private declaration so it is not worth dropping this PR over it).
|
✌️ JovanGerb can now approve this pull request until 2026-10-19 11:41 UTC (in 2 weeks). To approve and merge, reply with
|
|
@thorimur, which docstrings did you want me to update? |
b36bdda to
148ab14
Compare
|
|
|
bors r+ |
This PR bundles the three instance linters we have into a single linter for performance. The new linter lives in `Mathlib.Tactic.Linter.DeclType`, because it can accommodate any linter that acts on declaration types. Note: we could implement some kind of extensible framework for declaration type linters. But that could make the performance worse again. It would probably be more trouble than it's worth. This is in preparation for adding another instance linter: the concrete instance linter. After this PR, it should be possible to implement this with minimal performance cost. Co-authored-by: thorimur <[email protected]>
|
Pull request successfully merged into master. Build succeeded: |
Most conflicts come from master's regrouping of public and private imports (#44512, #44513): resolved by taking master's import layout and reapplying this PR's meta/removal changes line by line. - Mathlib/Init.lean: keep master's new `Batteries.Tactic.Alias` import and `Linter.DeclType` (which bundles the instance linters, #44436), the latter as a `public meta import`. - Mathlib/Data/Ineq.lean: drop the duplicate `ToFormat` instance as master did (#44383); the parsing functions stay moved to `Mathlib.Tactic.Ineq`. - Control/Monad/{Basic,Cont}, Lean/Expr/Basic, FieldSimp, Linarith/Lemmas, LinearCombination/Lemmas: re-add this PR's new imports (`Batteries.Data.Except`, `Lean.ProjFns`, `Lean.Structure`, `Mathlib.Tactic.Ineq`) in master's public import group. - Mathlib/Tactic/Push.lean: drop the `public import Lean.Elab.ConfigEval` that git's auto-merge reintroduced. - Mathlib/Tactic/Echelon/Core.lean: master added `public import Qq` to this `public meta section` file; make it `public meta import Qq`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This PR bundles the three instance linters we have into a single linter for performance. The new linter lives in
Mathlib.Tactic.Linter.DeclType, because it can accommodate any linter that acts on declaration types.Note: we could implement some kind of extensible framework for declaration type linters. But that could make the performance worse again. It would probably be more trouble than it's worth.
This is in preparation for adding another instance linter: the concrete instance linter. After this PR, it should be possible to implement this with minimal performance cost.