Repository navigation
Conversation
|
!bench |
Welcome new contributor!Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests. We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the If you haven't already done so, please come to Zulip and join the Lean community. |
|
Benchmark results for 41b22a9 against 11aadab are in. There are significant results. @Vilin97
Large changes (1✅)
Medium changes (2🟥)
Small changes (534✅, 67🟥)
|
PR summary aba48159f1Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
41b22a9 to
23c6e98
Compare
public imports private where nothing downstream needs thempublic imports private where nothing downstream needs them
|
!bench |
|
Benchmark results for 23c6e98 against 11aadab are in. There are significant results. @Vilin97
Large changes (1✅)
Medium changes (2🟥)
Small changes (493✅, 71🟥)
|
…ds them Each `public import A` in a file `B` becomes `import A` when `B`'s public interface (statements, types, exposed bodies) does not need `A`, and no module downstream of `B` relies on getting `A` through `B`. No imports are added elsewhere. Co-Authored-By: Claude Opus 5.5 <[email protected]>
23c6e98 to
aba4815
Compare
|
bors merge |
…ds them (#46228) This PR turns 639 `public import A` lines into plain `import A`. No imports are added anywhere else. ### The idea, in plain words In a `module` file `B`: * `public import A` means: `B` uses `A`, **and** every file that imports `B` also gets `A`. * `import A` means: `B` uses `A`, but keeps it to itself. We switch `public import A` to `import A` in `B` when both of these hold: 1. `B` does not need `A` in anything it exports: theorem statements, the types of definitions, and the bodies of exposed definitions only use things `B` can see without `A`. Typically `A` is only used inside proofs. 2. No file that imports `B` (directly or indirectly) relies on getting `A` through `B`: every such file that uses something from `A` already imports it some other way. Because of (2), nothing else has to change: this PR only edits the import lines of the files whose imports become private. ### Example `Mathlib/Data/Fin/Basic.lean` had `public import Mathlib.Data.Int.DivMod`, but it only uses the `Int.emod` lemmas inside proofs, and every file downstream of `Fin.Basic` that uses `Int.DivMod` already reaches it another way. So it becomes `import Mathlib.Data.Int.DivMod`, and about 6,500 modules that import `Fin.Basic` no longer load `Int.DivMod` through it. ### How the candidates were chosen This is the same idea as #43918 (which found such imports by trial builds). Here the candidates come from the compiled `.olean` files, using the analysis `lake shake` already does (which modules each declaration's statement and proof depend on, split into public and private uses), with one addition: proofs nested inside exposed definitions count as public, since Lean elaborates them in the public scope. Since making one import private can make another one costly, the candidates are accepted one at a time, each re-checked against those already accepted. Skipped on purpose: * `module -- shake: keep-all` files and deprecated-module shims, whose job is to re-export; * imports marked `shake: keep` (except the ones only needed for `example`s); * imports that would hide, downstream, a module that registers options, aesop rule sets, simp attributes or `positivity` extensions; * files using `backward.privateInPublic`; * a handful of imports whose demotion broke `deriving` or `@[simps!]` in a full build. Overall, the total number of modules loaded across all Mathlib files (the sum of the import closures) goes down by about 1%, and 7,194 of 8,726 modules load fewer files. ### Other changes * `Mathlib/Combinatorics/SimpleGraph/Extremal/Turan.lean`: `grw [Nat.mod_le]` now closes its goal, so the `exact` after it is removed. As with #43918, this is a semantic change for downstream projects: something that used to arrive through `B` may now need an explicit import. Checked with `lake build Mathlib Archive Counterexamples` and `lake test`. Benchmark (`!bench`, against `master`): `build//instructions` **−95.4G (−0.09%)**. The largest single change is `Mathlib.Condensed.Discrete.Colimit` (−31%); there are two small (about +1G, low-significance) per-module regressions. For comparison, #43918 measured −0.12%. This is the first of a stack of three PRs, ordered from most to least conservative. ### Use of AI This PR was prepared with Claude Code (Claude Opus). It wrote the analysis tooling (a small Lean program built on `lake shake`'s dependency computation, plus Python scripts that pick the imports and edit the headers), ran the builds that found and removed the bad candidates, and drafted this description. All edits to `Mathlib/` are produced mechanically by those scripts. The hand fix listed above is the only non-header change. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
Pull request successfully merged into master. Build succeeded: |
public imports private where nothing downstream needs thempublic imports private where nothing downstream needs them
…ds them (leanprover-community#46228) This PR turns 639 `public import A` lines into plain `import A`. No imports are added anywhere else. ### The idea, in plain words In a `module` file `B`: * `public import A` means: `B` uses `A`, **and** every file that imports `B` also gets `A`. * `import A` means: `B` uses `A`, but keeps it to itself. We switch `public import A` to `import A` in `B` when both of these hold: 1. `B` does not need `A` in anything it exports: theorem statements, the types of definitions, and the bodies of exposed definitions only use things `B` can see without `A`. Typically `A` is only used inside proofs. 2. No file that imports `B` (directly or indirectly) relies on getting `A` through `B`: every such file that uses something from `A` already imports it some other way. Because of (2), nothing else has to change: this PR only edits the import lines of the files whose imports become private. ### Example `Mathlib/Data/Fin/Basic.lean` had `public import Mathlib.Data.Int.DivMod`, but it only uses the `Int.emod` lemmas inside proofs, and every file downstream of `Fin.Basic` that uses `Int.DivMod` already reaches it another way. So it becomes `import Mathlib.Data.Int.DivMod`, and about 6,500 modules that import `Fin.Basic` no longer load `Int.DivMod` through it. ### How the candidates were chosen This is the same idea as leanprover-community#43918 (which found such imports by trial builds). Here the candidates come from the compiled `.olean` files, using the analysis `lake shake` already does (which modules each declaration's statement and proof depend on, split into public and private uses), with one addition: proofs nested inside exposed definitions count as public, since Lean elaborates them in the public scope. Since making one import private can make another one costly, the candidates are accepted one at a time, each re-checked against those already accepted. Skipped on purpose: * `module -- shake: keep-all` files and deprecated-module shims, whose job is to re-export; * imports marked `shake: keep` (except the ones only needed for `example`s); * imports that would hide, downstream, a module that registers options, aesop rule sets, simp attributes or `positivity` extensions; * files using `backward.privateInPublic`; * a handful of imports whose demotion broke `deriving` or `@[simps!]` in a full build. Overall, the total number of modules loaded across all Mathlib files (the sum of the import closures) goes down by about 1%, and 7,194 of 8,726 modules load fewer files. ### Other changes * `Mathlib/Combinatorics/SimpleGraph/Extremal/Turan.lean`: `grw [Nat.mod_le]` now closes its goal, so the `exact` after it is removed. As with leanprover-community#43918, this is a semantic change for downstream projects: something that used to arrive through `B` may now need an explicit import. Checked with `lake build Mathlib Archive Counterexamples` and `lake test`. Benchmark (`!bench`, against `master`): `build//instructions` **−95.4G (−0.09%)**. The largest single change is `Mathlib.Condensed.Discrete.Colimit` (−31%); there are two small (about +1G, low-significance) per-module regressions. For comparison, leanprover-community#43918 measured −0.12%. This is the first of a stack of three PRs, ordered from most to least conservative. ### Use of AI This PR was prepared with Claude Code (Claude Opus). It wrote the analysis tooling (a small Lean program built on `lake shake`'s dependency computation, plus Python scripts that pick the imports and edit the headers), ran the builds that found and removed the bad candidates, and drafted this description. All edits to `Mathlib/` are produced mechanically by those scripts. The hand fix listed above is the only non-header change. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This PR turns 639
public import Alines into plainimport A. No imports are added anywhere else.The idea, in plain words
In a
modulefileB:public import Ameans:BusesA, and every file that importsBalso getsA.import Ameans:BusesA, but keeps it to itself.We switch
public import Atoimport AinBwhen both of these hold:Bdoes not needAin anything it exports: theorem statements, the types of definitions, and the bodies of exposed definitions only use thingsBcan see withoutA. TypicallyAis only used inside proofs.B(directly or indirectly) relies on gettingAthroughB: every such file that uses something fromAalready imports it some other way.Because of (2), nothing else has to change: this PR only edits the import lines of the files whose imports become private.
Example
Mathlib/Data/Fin/Basic.leanhadpublic import Mathlib.Data.Int.DivMod, but it only uses theInt.emodlemmas inside proofs, and every file downstream ofFin.Basicthat usesInt.DivModalready reaches it another way. So it becomesimport Mathlib.Data.Int.DivMod, and about 6,500 modules that importFin.Basicno longer loadInt.DivModthrough it.How the candidates were chosen
This is the same idea as #43918 (which found such imports by trial builds). Here the candidates come from the compiled
.oleanfiles, using the analysislake shakealready does (which modules each declaration's statement and proof depend on, split into public and private uses), with one addition: proofs nested inside exposed definitions count as public, since Lean elaborates them in the public scope. Since making one import private can make another one costly, the candidates are accepted one at a time, each re-checked against those already accepted.Skipped on purpose:
module -- shake: keep-allfiles and deprecated-module shims, whose job is to re-export;shake: keep(except the ones only needed forexamples);positivityextensions;backward.privateInPublic;derivingor@[simps!]in a full build.Overall, the total number of modules loaded across all Mathlib files (the sum of the import closures) goes down by about 1%, and 7,194 of 8,726 modules load fewer files.
Other changes
Mathlib/Combinatorics/SimpleGraph/Extremal/Turan.lean:grw [Nat.mod_le]now closes its goal, so theexactafter it is removed.As with #43918, this is a semantic change for downstream projects: something that used to arrive through
Bmay now need an explicit import.Checked with
lake build Mathlib Archive Counterexamplesandlake test.Benchmark (
!bench, againstmaster):build//instructions−95.4G (−0.09%). The largest single change isMathlib.Condensed.Discrete.Colimit(−31%); there are two small (about +1G, low-significance) per-module regressions. For comparison, #43918 measured −0.12%.This is the first of a stack of three PRs, ordered from most to least conservative.
Use of AI
This PR was prepared with Claude Code (Claude Opus). It wrote the analysis tooling (a small Lean program built on
lake shake's dependency computation, plus Python scripts that pick the imports and edit the headers), ran the builds that found and removed the bad candidates, and drafted this description. All edits toMathlib/are produced mechanically by those scripts. The hand fix listed above is the only non-header change.🤖 Generated with Claude Code