Repository navigation
Replace the Mathlib dependency with a vendored, checked subset - #8713
Closed
cjen1-msft wants to merge 2 commits into
Closed
cjen1-msft wants to merge 2 commits into
cjen1-msft wants to merge 2 commits into
Conversation
cjen1-msft
force-pushed
the
cjen1-msft-jubilant-doodle
branch
2 times, most recently
from
November 9, 2026 17:45
44b8fa2 to
dc93c69
Compare
lean/mathlib-subset vendors the Mathlib and Batteries declarations that the Lean packages use, from the same module paths as upstream Mathlib v4.35.0. lean/mathlib-subset-check compares the vendored declarations with upstream, and a new path-filtered Lean Mathlib Subset workflow runs it when the subset, the checker, the toolchain or the workflow change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The packages now require lean/mathlib-subset instead of Mathlib, so CI and local setup no longer clone Mathlib or fetch its build cache. The proofs adopt the Mathlib-free rewrites from #8702 where they reduce what must be vendored. The kv and disaster-recovery packages drop the Batteries runLinter lint driver, which needed full Batteries; Lean's built-in linters still run. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
cjen1-msft
force-pushed
the
cjen1-msft-jubilant-doodle
branch
from
November 9, 2026 17:53
dc93c69 to
b78572f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Lean packages now depend on a small subset of Mathlib, vendored in
lean/mathlib-subset, instead of on Mathlib itself; a new CI workflow checks that subset against upstream Mathlib.This is an alternative to #8702, which removes Mathlib by replacing the parts CCF uses with hand-written
CCF.*modules.It reuses #8702's proof rewrites, which cut what the proofs need from Mathlib to a few definitions, so it gets most of the same CI savings: no Mathlib clone or
lake exe cache getin any package or replay job, and a much smaller import closure forlake checkto re-check.The difference is what replaces Mathlib:
Finset,Stream'.Seq,Function.update, order lemmasCCF.Finset,CCF.Seq,CCF.Function,CCF.Order(565 lines)CCF.Finsetis a different representationlean/mathlib-subset-checkcompares the vendored declarations with Mathlibv4.35.0CCF.FinsetandCCF.SeqlemmadeclarationstheoremMathlib.Tactic.Lemmais vendored)runLinterlint driverCCFversion and the lemmas it needsLean Mathlib Subsetworkflow, which runs only when the subset, the checker, the toolchain or the workflow changesThe checker requires each vendored declaration to have the same module, kind, universe parameters and type as upstream, the same value for definitions with proofs erased, and the same reducibility, instance priority and structure shape.
Theorems must have the upstream statement but may be proved differently, and only
propext,Quot.soundandClassical.choiceare allowed as axioms.Metaprograms (such as notation and tactics) must match upstream in everything but their value, since they only affect elaboration and the terms they produce are checked.
Internal declarations, such as auxiliary proofs and matchers, need not exist upstream, but a definition that refers to one only matches if upstream refers to an identically named, matching declaration.
lean/mathlib-subset/README.mdexplains how to add a declaration and how to move to a new Mathlib version.Discontinuities
lean/mathlib-subsetkeeps upstream copyright headers and formatting, soscripts/lean-format-checks.shskips it, and it carries Mathlib's Apache 2.0LICENSE. The checker package is format-checked as usual.TODOline was dropped from a module docstring inMathlib/Tactic/SetNotationForOrder.lean, to satisfyscripts/todo-checks.sh. Docstrings are not compared.runLinteris removed from kv and disaster-recovery because it needs all of Batteries.lake lintstill runs Lean's builtin linters, but the Batteries and Mathlib environment linters no longer run.lean-mathlib-subset.yml, with apathsfilter, likevendor-verification.yml. It is therefore not part of theLean models and proofsgate, and cannot be a required check without blocking pull requests that do not trigger it. It does not cache Mathlib (about 7 GB), since it rarely runs.DisasterRecovery/Proofs/Deadlock.lean, added on main by lean: Prove deadlock freedom for consistency and recovery #8716, usedaesop, which only came via Mathlib; it now uses coregrind.Testing
The
Lean Mathlib Subsetworkflow passes on this PR in 89s (subsetlake build --wfail4s,lake exe cache get47s, check 8s); all 533 vendored declarations that are not internal match upstream. Locally, the check fails ifabbrev PartialOrder.liftbecomes adef, or ifFinset.card's type is changed to mentionLean(which would otherwise be taken for a metaprogram).actionlintreports nothing forlean-mathlib-subset.ymlandlean.ymlbeyond the custom runner labels it does not know.The
Leanworkflow passes on this PR (run 42668962868), as does a local replay of every package job's commands (lake check,check-imports, formatting,lake lint, replay fixtures) and the three replay jobs.CI job times, one run each, so indicative only (main: run 42611960081; Remove the Mathlib dependency from the Lean packages #8702: run 42501320257, attempt 2; this PR: run 42668962868):
The
Build, kernel and axiom checkstep (lake check), as build and export plus kernel and axiom check:Neither CI run of this PR hit the
.lake/packagescache, which now holds only leanfmt: the first because this PR changes each package'slake-manifest.json, and the second, with the same keys, because the repository's Actions cache (about 30 GB in 50 entries) had evicted the first run's entries within 90 minutes. The jobs other than common, which skips formatting, therefore built leanfmt in the formatting step, taking 22 to 27s against 3 to 9s in the Remove the Mathlib dependency from the Lean packages #8702 run, which hit its cache; main's disaster-recovery job also missed its cache. The rest of the difference from Remove the Mathlib dependency from the Lean packages #8702 is inlake check, 1 to 12s per check, from building the vendored subset and re-checking it in the kernel. This run also includes the deadlock proofs added to consistency and disaster-recovery on main since Remove the Mathlib dependency from the Lean packages #8702's run. The replay jobs' build steps take 11, 7 and 4s against 5, 6 and 4s in Remove the Mathlib dependency from the Lean packages #8702; the KV replay job also spent 12s inInstall Leanand 8s stopping containers, against 0 and 2s in Remove the Mathlib dependency from the Lean packages #8702's run and 0 and 1s in this PR's previous run.Reviewed with sol-loop: 2 rounds with gpt-6.1-sol. Sol verdict: approved