Skip to content

[Merged by Bors] - chore: demote public imports that need no downstream imports - #43918

Closed
kim-em wants to merge 16 commits into
leanprover-community:masterfrom
kim-em:claude/public-import-demote
Closed

kim-em wants to merge 16 commits into
leanprover-community:masterfrom
kim-em:claude/public-import-demote

Conversation

@kim-em

@kim-em kim-em commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

This PR replaces public import with import in those cases where no additional downstream imports are then needed (and the changes doesn't otherwise cause an error).

This is a small step towards a fully shake of public imports, essentially doing the "costless" piece. This is a semantic change, as there is no guarantee that downstream users of Mathlib will not need to adjust their imports.

Nevertheless, I think this is worth doing!

🤖 Prepared with Claude Code

@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

PR summary 2567e5d3dc

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

No declarations were harmed in the making of this PR! 🐙

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 2567e5d).

  • +0 new declarations
  • −0 removed declarations

No declaration differences.


No changes to strong technical debt.
No changes to weak technical debt.

Current commit 2567e5d3dc
Reference commit b63f6e8a68

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 relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@kim-em

kim-em commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Sep 18, 2026 •

Copy link
Copy Markdown

Benchmark results for a9c2924 against 4541bc6 are in. There are significant results. @kim-em

  • 🟥 build//instructions: +87.8G (+0.06%)

Large changes (2✅, 3🟥)

  • 🟥 build/module/Mathlib.Algebra.Category.ModuleCat.Sheaf.Generators//instructions: +5.6G (+39.10%)
  • 🟥 build/module/Mathlib.Algebra.Category.ModuleCat.Sheaf.LocallyFree//instructions: +15.7G (+134.33%)
  • 🟥 build/module/Mathlib.Algebra.Category.ModuleCat.Sheaf.Quasicoherent//instructions: +251.6G (+249.66%)
  • ✅ build/module/Mathlib.RingTheory.DedekindDomain.Different//instructions: -47.9G (-26.81%)
  • ✅ build/module/Mathlib.RingTheory.DedekindDomain.LinearDisjoint//instructions: -15.8G (-17.06%)

Medium changes (8✅, 3🟥)

  • 🟥 build/module/Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafification//instructions: +6.3G (+18.73%)
  • 🟥 build/module/Mathlib.Algebra.Category.ModuleCat.Sheaf.Free//instructions: +3.6G (+17.89%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Mathlib.AlgebraicGeometry.Modules.Tilde//instructions: +22.2G (+6.86%)
  • ✅ build/module/Mathlib.Analysis.Normed.Field.WithAbs//instructions: -2.7G (-9.42%)
  • ✅ build/module/Mathlib.Geometry.Manifold.VectorBundle.CovariantDerivative.LeviCivita//instructions: -4.3G (-5.96%)
  • ✅ build/module/Mathlib.Geometry.Manifold.VectorBundle.CovariantDerivative.Metric//instructions: -4.3G (-15.30%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Geometry.Manifold.VectorBundle.CovariantDerivative.Torsion//instructions: -1.2G (-5.58%)
  • ✅ build/module/Mathlib.NumberTheory.ModularForms.Cusps//instructions: -1.9G (-5.75%)
  • ✅ build/module/Mathlib.NumberTheory.RamificationInertia.Unramified//instructions: -2.3G (-15.16%)
  • ✅ build/module/Mathlib.RingTheory.DedekindDomain.Factorization//instructions: -4.7G (-7.22%)
  • ✅ build/module/Mathlib.RingTheory.Localization.AtPrime.Extension//instructions: -2.3G (-11.53%)

Small changes (22✅, 9🟥)

  • ✅ build/lakeprof/longest rebuild path//instructions: -210.4G (-5.22%)
  • 🟥 build/module/Mathlib.Algebra.BrauerGroup.Defs//instructions: +227.8M (+3.88%)
  • 🟥 build/module/Mathlib.Algebra.Category.ModuleCat.Sheaf.Abelian//instructions: +484.0M (+10.44%)
  • ✅ build/module/Mathlib.Algebra.Homology.ModelCategory.Injective//instructions: -646.9M (-4.17%)
  • ✅ build/module/Mathlib.Algebra.Module.Torsion.PrimaryComponent//instructions: -609.0M (-1.77%)
  • ✅ build/module/Mathlib.Algebra.Order.Rearrangement//instructions: -926.8M (-4.42%)
  • 🟥 build/module/Mathlib.AlgebraicTopology.SimplicialSet.Subcomplex//instructions: +1.3G (+6.95%)
  • ✅ build/module/Mathlib.Analysis.FunctionalSpaces.SobolevInequality//instructions: -1.6G (-2.47%)
  • ✅ build/module/Mathlib.Analysis.InnerProductSpace.Coalgebra//instructions: -1.4G (-3.61%)
  • ✅ build/module/Mathlib.Analysis.Meromorphic.Complex//instructions: -117.2M (-2.14%)
  • 🟥 build/module/Mathlib.Analysis.Meromorphic.Order//instructions: +635.4M (+0.90%)
  • 🟥 build/module/Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Basic//instructions: +755.3M (+3.75%)
  • 🟥 build/module/Mathlib.Analysis.SpecialFunctions.OrdinaryHypergeometric//instructions: +527.2M (+2.87%)
  • 🟥 build/module/Mathlib.CategoryTheory.Sites.Point.Conservative//instructions: +628.5M (+5.26%)
  • ✅ build/module/Mathlib.Combinatorics.SimpleGraph.Tutte//instructions: -616.1M (-2.45%)
  • ✅ build/module/Mathlib.Data.Matrix.Invertible//instructions: -37.6M (-1.37%)
  • ✅ build/module/Mathlib.Geometry.Euclidean.Angle.Bisector//instructions: -849.0M (-1.64%)
  • 🟥 build/module/Mathlib.GroupTheory.Presentation//instructions: +327.5M (+6.63%)
  • ✅ build/module/Mathlib.LinearAlgebra.JordanChevalley//instructions: -483.0M (-3.48%)
  • ✅ build/module/Mathlib.MeasureTheory.Measure.CharacteristicFunction//instructions: -130.2M (-2.85%)
  • and 11 more

…d warnings-as-errors

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@mathlib-merge-conflicts mathlib-merge-conflicts 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 Sep 18, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

kim-em and others added 2 commits September 21, 2026 01:24
…t-demote-v2

# Conflicts:
#	Mathlib/Dynamics/BirkhoffSum/NormedSpace.lean
…tive

Demoting this import reorders the module load order so that
`Sites.Sheafification` is loaded before `Sites.ConcreteSheafification`,
which flips the tie-break between `instHasWeakSheafifyOfHasSheafify` and
`sheafToPresheaf_isRightAdjoint`. Downstream, every stuck
`HasWeakSheafify (J.over X) AddCommGrpCat` search then explores the
`sheafToPresheaf_isRightAdjoint` preconditions before failing, making
`ModuleCat.Sheaf.Quasicoherent` and its dependents about 3x slower.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kim-em

kim-em commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Sep 21, 2026 •

Copy link
Copy Markdown

Benchmark results for 265c9fc against 4541bc6 are in. There are significant results. @kim-em

  • ✅ build//instructions: -166.6G (-0.12%)

Large changes (2✅)

  • ✅ build/module/Mathlib.RingTheory.DedekindDomain.Different//instructions: -48.1G (-26.91%)
  • ✅ build/module/Mathlib.RingTheory.DedekindDomain.LinearDisjoint//instructions: -15.7G (-17.01%)

Medium changes (9✅)

  • ✅ build/module/Mathlib.Analysis.Normed.Algebra.TrivSqZeroExt//instructions: -1.3G (-3.81%)
  • ✅ build/module/Mathlib.Analysis.Normed.Field.WithAbs//instructions: -2.7G (-9.39%)
  • ✅ build/module/Mathlib.Geometry.Manifold.VectorBundle.CovariantDerivative.LeviCivita//instructions: -4.3G (-5.97%)
  • ✅ build/module/Mathlib.Geometry.Manifold.VectorBundle.CovariantDerivative.Metric//instructions: -4.3G (-15.42%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Geometry.Manifold.VectorBundle.CovariantDerivative.Torsion//instructions: -1.2G (-5.58%)
  • ✅ build/module/Mathlib.NumberTheory.ModularForms.Cusps//instructions: -1.9G (-5.74%)
  • ✅ build/module/Mathlib.NumberTheory.RamificationInertia.Unramified//instructions: -2.4G (-15.30%)
  • ✅ build/module/Mathlib.RingTheory.DedekindDomain.Factorization//instructions: -4.7G (-7.12%)
  • ✅ build/module/Mathlib.RingTheory.Localization.AtPrime.Extension//instructions: -2.3G (-11.49%)

Small changes (18✅, 5🟥)

  • ✅ build/lakeprof/longest rebuild path//instructions: -199.7G (-4.95%)
  • ✅ build/module/Mathlib.Algebra.Homology.ModelCategory.Injective//instructions: -688.4M (-4.44%)
  • ✅ build/module/Mathlib.Algebra.Module.Torsion.PrimaryComponent//instructions: -616.1M (-1.79%)
  • ✅ build/module/Mathlib.Algebra.Order.Rearrangement//instructions: -910.8M (-4.34%)
  • ✅ build/module/Mathlib.Analysis.FunctionalSpaces.SobolevInequality//instructions: -1.6G (-2.49%)
  • ✅ build/module/Mathlib.Analysis.InnerProductSpace.Coalgebra//instructions: -1.3G (-3.56%)
  • 🟥 build/module/Mathlib.Analysis.Meromorphic.Order//instructions: +692.6M (+0.98%)
  • 🟥 build/module/Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Basic//instructions: +763.5M (+3.79%)
  • ✅ build/module/Mathlib.Analysis.SpecialFunctions.Integrals.Log//instructions: -752.0M (-7.99%)
  • 🟥 build/module/Mathlib.Analysis.SpecialFunctions.OrdinaryHypergeometric//instructions: +617.2M (+3.36%)
  • ✅ build/module/Mathlib.Combinatorics.SimpleGraph.Tutte//instructions: -643.7M (-2.56%)
  • 🟥 build/module/Mathlib.GroupTheory.IsPerfect//instructions: +295.0M (+4.59%)
  • 🟥 build/module/Mathlib.GroupTheory.SpecificGroups.VirtuallyCyclic//instructions: +266.3M (+4.23%)
  • ✅ build/module/Mathlib.LinearAlgebra.JordanChevalley//instructions: -511.1M (-3.68%)
  • ✅ build/module/Mathlib.MeasureTheory.Measure.CharacteristicFunction//instructions: -109.7M (-2.40%)
  • ✅ build/module/Mathlib.MeasureTheory.VectorMeasure.Integral//instructions: -4.3G (-2.98%)
  • ✅ build/module/Mathlib.NumberTheory.NumberField.ExistsRamified//instructions: -322.4M (-2.00%)
  • ✅ build/module/Mathlib.NumberTheory.NumberField.Ideal.KummerDedekind//instructions: -574.9M (-2.72%)
  • ✅ build/module/Mathlib.Probability.Decision.Risk.Basic//instructions: -541.2M (-3.76%)
  • ✅ build/module/Mathlib.Probability.Distributions.Gaussian.HasGaussianLaw.Independence//instructions: -732.0M (-1.09%)
  • and 2 more
  • and 1 hidden

@github-actions github-actions 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 Sep 21, 2026
@kim-em
kim-em marked this pull request as ready for review September 21, 2026 02:36
Comment thread Mathlib/Algebra/Algebra/Hom/Rat.lean Outdated

public import Mathlib.Algebra.Algebra.Equiv
public import Mathlib.Algebra.Algebra.Hom
import Mathlib.Algebra.Algebra.Hom

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.

This seems like a weird change to me, aren't the public definitions in this file using AlgHom?

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.

Indeed, because we haven't been running shake regularly in Mathlib, in fact many imports are simply redundant and can be dropped. I'm uncertain whether it is better to do that as part of this PR, as a preliminary PR, or not to do it at all.

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 think I'll just delete those imports which are touched here, but can be deleted.

kim-em and others added 3 commits September 21, 2026 11:23
…t-demote

# Conflicts:
#	Mathlib/LinearAlgebra/TensorProduct/Basis.lean
#	Mathlib/Tactic/DeprecateTo.lean
Every import demoted by this PR whose module is already in the public
closure of the file's remaining public imports is removed outright: such
a private import is a no-op for the file and for everything downstream.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Restore the 27 deleted imports that were only reachable through
`public meta import` chains (meta imports do not make declarations
visible to non-meta code), and make `Lean.LocalContext` a public import
of `Mathlib.Lean.LocalContext` again since its public definitions
mention `LocalContext`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions 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 Sep 21, 2026
# Conflicts:
#	Mathlib/Analysis/Analytic/Order.lean
#	Mathlib/RingTheory/Adjoin/Polynomial/Bivariate.lean
@github-actions github-actions 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 Sep 22, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@mathlib-merge-conflicts mathlib-merge-conflicts 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 Sep 22, 2026
@github-actions github-actions 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 Sep 23, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts 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 Sep 23, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

kim-em and others added 2 commits September 25, 2026 19:58
…t-demote

# Conflicts:
#	Mathlib/Algebra/Order/AbsoluteValue/Basic.lean
#	Mathlib/Algebra/Order/GroupWithZero/Unbundled/Basic.lean
#	Mathlib/Algebra/Order/GroupWithZero/Unbundled/Defs.lean
#	Mathlib/Algebra/Order/GroupWithZero/Unbundled/OrderIso.lean
#	Mathlib/AlgebraicGeometry/RationalMap.lean
#	Mathlib/Analysis/Normed/Operator/FredholmAlternative.lean
#	Mathlib/Analysis/Normed/Order/Hom/Basic.lean
#	Mathlib/Analysis/NormedSpace/FunctionSeries.lean
#	Mathlib/Analysis/NormedSpace/OperatorNorm/Completeness.lean
#	Mathlib/Analysis/NormedSpace/OperatorNorm/NNNorm.lean
#	Mathlib/Analysis/NormedSpace/OperatorNorm/Prod.lean
#	Mathlib/Analysis/NormedSpace/RCLike.lean
#	Mathlib/Analysis/NormedSpace/Real.lean
#	Mathlib/Analysis/Seminorm.lean
#	Mathlib/Condensed/CartesianClosed.lean
#	Mathlib/Condensed/Light/CartesianClosed.lean
#	Mathlib/Data/Finite/Card.lean
#	Mathlib/Data/Fintype/Units.lean
#	Mathlib/Data/Matrix/Action.lean
#	Mathlib/Data/Matrix/Bilinear.lean
#	Mathlib/Data/Matrix/DualNumber.lean
#	Mathlib/Data/Matrix/Invertible.lean
#	Mathlib/Data/NNRat/Order.lean
#	Mathlib/Data/Nat/Cast/Synonym.lean
#	Mathlib/Data/Nat/Lattice.lean
#	Mathlib/Data/Rat/Cardinal.lean
#	Mathlib/Data/Rat/NatSqrt/Real.lean
#	Mathlib/Data/Real/Archimedean.lean
#	Mathlib/Data/Real/CompleteField.lean
#	Mathlib/Data/Real/Hom.lean
#	Mathlib/Data/Real/StarOrdered.lean
#	Mathlib/Geometry/Manifold/VectorBundle/SmoothSection.lean
#	Mathlib/LinearAlgebra/ConvexSpace.lean
#	Mathlib/LinearAlgebra/ConvexSpace/AffineSpace.lean
#	Mathlib/MeasureTheory/Measure/CharacteristicFunction.lean
#	Mathlib/MeasureTheory/Measure/MeasureSpace.lean
#	Mathlib/NumberTheory/NumberField/FinitePlaces.lean
#	Mathlib/NumberTheory/RamificationInertia/Valuation.lean
#	Mathlib/Order/Bounded.lean
#	Mathlib/Order/Synonym.lean
#	Mathlib/RingTheory/Regular/Depth.lean
#	Mathlib/RingTheory/UniqueFactorizationDomain/Localization.lean
#	Mathlib/SetTheory/Cardinal/Cofinality.lean
#	Mathlib/Topology/Algebra/Module/WeakDual.lean
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions 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 Sep 25, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts 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 Sep 25, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

…t-demote

# Conflicts:
#	Mathlib/Analysis/CStarAlgebra/Module/Synonym.lean
#	Mathlib/Analysis/Fourier/Notation.lean
#	Mathlib/Analysis/InnerProductSpace/LinearPMap.lean
#	Mathlib/Analysis/Normed/Operator/ContinuousLinearMap.lean
#	Mathlib/Analysis/Normed/Operator/LinearIsometry.lean
#	Mathlib/Data/Fin/Init.lean
#	Mathlib/NumberTheory/Padics/PadicNumbers.lean
#	Mathlib/RepresentationTheory/Continuous/Basic.lean
#	Mathlib/RingTheory/Ideal/Operations.lean
#	Mathlib/Topology/Algebra/ContinuousAffineEquiv.lean
#	Mathlib/Topology/Algebra/Module/Alternating/Basic.lean
#	Mathlib/Topology/Algebra/Module/IsWeak.lean
#	Mathlib/Topology/Algebra/Module/LinearPMap.lean
#	Mathlib/Topology/Algebra/Module/Multilinear/Topology.lean
#	Mathlib/Topology/Algebra/Module/Spaces/UniformConvergenceCLM.lean
#	Mathlib/Topology/Algebra/Valued/ValuedField.lean
#	Mathlib/Topology/Instances/ENNReal/Lemmas.lean
@github-actions github-actions 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 Sep 28, 2026
@j-loreaux

Copy link
Copy Markdown
Contributor

bors merge

@mathlib-bors mathlib-bors Bot added the ready-to-merge This PR has been sent to bors. label Sep 28, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Sep 28, 2026
This PR replaces `public import` with `import` in those cases where no additional downstream imports are then needed (and the changes doesn't otherwise cause an error).

This is a small step towards a fully `shake` of public imports, essentially doing the "costless" piece. This is a semantic change, as there is no guarantee that downstream users of Mathlib will not need to adjust their imports.

Nevertheless, I think this is worth doing!

🤖 Prepared with Claude Code
@mathlib-bors mathlib-bors Bot added the bors-staging This PR is currently being built by bors on the staging branch. label Sep 28, 2026
@mathlib-bors

mathlib-bors Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

@mathlib-bors mathlib-bors Bot changed the title chore: demote public imports that need no downstream imports [Merged by Bors] - chore: demote public imports that need no downstream imports Sep 28, 2026
@mathlib-bors mathlib-bors Bot closed this Sep 28, 2026
ZRTMRH added a commit to ZRTMRH/mathlib4 that referenced this pull request Oct 12, 2026
leanprover-community#43918 made the import of `Mathlib.Analysis.Convex.SpecificFunctions.Deriv` in
`Trigonometric/Bounds.lean` private, so `hasDerivAt_pow`, `strictMonoOn_of_deriv_pos` and
`strictAntiOn_of_deriv_neg` are no longer available transitively.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SnirBroshi added a commit to SnirBroshi/mathlib4 that referenced this pull request Oct 26, 2026
Whysoserioushah added a commit to rmhi/mathlib4 that referenced this pull request Nov 20, 2026
…inflation

Conflict in Mathlib/Topology/Algebra/Group/Quotient.lean resolved by keeping master's demoted imports (leanprover-community#43918) and adding the public import of Mathlib.Topology.Algebra.ContinuousMonoidHom needed by QuotientTopGroup.mk.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mathlib-bors Bot pushed a commit that referenced this pull request Nov 21, 2026
…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)
TJHeeringa pushed a commit to TJHeeringa/mathlib4 that referenced this pull request Dec 2, 2026
…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)
ocfnash added a commit to ocfnash/mathlib4 that referenced this pull request Dec 2, 2026
- Regenerate `VecNotation.lean` as a pure move from `master`'s `Notation.lean`, restoring
  upstream changes that had been reverted (leanprover-community#44933, leanprover-community#43918, leanprover-community#44513, leanprover-community#43408, leanprover-community#42318); in
  particular `cons_transpose`, `head_transpose` and `tail_transpose` are no longer simp.
- Fix the `!![...]` delaborator for literals with more than 32 entries, whose list literals
  contain `let`s and are too deep to delaborate as `#[...]`: delaborate entries one at a
  time. Move `listLitElems?` to `Notation/Basic.lean` and reuse it in the tactic parser.
  Add a 6x6 delaborator test.
- Remove `@[simp]` from `transposeArray_size` and `submatrixArray_size` (simpNF).
- Drop `@[expose]` from `Notation.lean` and `Notation/Basic.lean`.
- Add the new modules to `Mathlib.lean`.
- Nits: avoid shadowing in `List.tendsto_getD`, split tactic one-liners, merge `simp` calls
  in `CanonicalEmbedding/Basic.lean`, simplify the `Modular.lean` literal products, and
  replace `simp? says` with `simp` in `MathlibTest/matrix.lean`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bors-staging This PR is currently being built by bors on the staging branch. ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants