Repository navigation
fix: mathlib4 breakage from importGraph#193 — #import_diff reserved the all token - #270
Merged
Merged
Conversation
… the `all` token
importGraph#193 ("feat: modulize and revamp `#import_diff`") gave the command a
module-system-aware syntax that mentions `Lean.Parser.Module.import`, and a
`syntax` declaration registers every token the parsers it mentions can read.
That put `all` into the token table — before, core's
`Lean.Parser.Module.all := leading_parser "all"` only ever reached the builtin
table used for the module header — and `ImportGraph.Tools` is in
`Mathlib.Init`'s closure, so `all` became a reserved keyword in every Mathlib
module, where it is an ordinary identifier: `protected theorem all` in
`Mathlib/Algebra/Group/Commute/Defs.lean`, `let all ← walkDir ml`,
`def mkRecNames (all : List Name)` and three more sites stopped parsing, taking
`repl`'s test phase with them.
`ImportGraph.importStx` is a local copy of the import parser that reads `all`
with `nonReservedSymbol`, whose `ParserInfo` registers no token, and the three
`#import_diff` syntax declarations use it. The syntax kind is still
``Lean.Parser.Module.import``, so the quotations in the same file and in
`ImportGraph/Imports/Pretty.lean` match unchanged, and
`#import_diff … import all M` keeps working; `withAntiquot (mkAntiquot …)` is
what `leading_parser` would have added and is needed by the
`` `(diffCurrentItem| +$imp) `` quotations. `public` and `meta` are still
registered, exactly as before — both were already reserved keywords, which is
why only `all` broke.
Two tests at the end of `ImportGraphTest/ImportDiff/Test.lean`: a `def` with an
`all` binder, which does not parse without the fix, and an
`#import_diff … import all`, whose branch had no test before.
Verified: `import-graph` `lake build` + `lake test` (189 jobs) green; `mathlib4`
`lake build Mathlib Archive Counterexamples Wanted cache --wfail` (18641 jobs,
a full recompile — the change invalidates all of Mathlib's artifact cache),
`lake test --iofail` (19205 jobs) and `lake lint` all green; `repl` `lake build`
+ `lake test` green, including the `test/Mathlib` suite that CI failed in.
Co-Authored-By: Claude Opus 5 <[email protected]>
thorimur
approved these changes
Nov 20, 2026
thorimur
left a comment
Contributor
There was a problem hiding this comment.
Wow, that's quite surprising to me—sorrry about this, and thanks for the fix! This adaptation looks good to me.
Contributor
|
I've also opened a PR to change this in core, since I figure this public parser should be freely usable downstream without requiring this sort of workaround: leanprover/lean4#16650 |
Rob23oba
pushed a commit
that referenced
this pull request
Nov 21, 2026
…Do.Context.controlInfoCache` (#271) Run [44844350878](https://github.com/leanprover/downstream-lean4/actions/runs/44844350878) on `nightly-2026-11-20`. This fixes the run's **new** breakage, `batteries` (critical), which took `aesop`, `mathlib4` and `cslib` down with it as skips. The rest of the red set is carried by PRs that are already open — `reference-manual` by #268, and `mathlib4` + `repl` by #270 (approved) — so **this PR's own CI stays red on `reference-manual`** until those merge. ## `batteries` — `Do.Context` gained a field, and `#do` builds one by hand [lean4#16557](leanprover/lean4#16557) ("perf: memoize the control information of `do` sequences", @sgraf812, in `nightly-2026-11-20`) added a field with no default to `Lean.Elab.Do.Context`: ```lean /-- The `ControlInfo` of the `doSeq` nodes of this `do` block inferred so far. -/ controlInfoCache : ControlInfoCache ``` The `downstream: update repo batteries` merge at the head of this run then brought in [batteries#1962](leanprover-community/batteries#1962) ("feat: `#do` command", @Rob23oba), whose `elabDoCommandCore` assembles a `Do.Context` itself rather than going through `Do.mkContext`. That file was written against batteries `main`, which still pins `v4.37.0-rc1`, so on the nightly it fails: ``` error: Batteries/Tactic/DoCommand.lean:213:15: Fields missing: `controlInfoCache` ``` `Batteries.Tactic.DoCommand` is reachable from the `Batteries` root module, so this is a critical-repo build failure, and `aesop`, `mathlib4` and `cslib` were all skipped behind it. ### The fix One field, a fresh cache, exactly what core's own `Do.mkContext` writes: ```lean controlInfoCache := ← ControlInfoCache.new ``` A `ControlInfoCache` memoizes the inferred `ControlInfo` of the `doSeq` nodes *within one `do` block*; `#do` elaborates one `doSeq` per invocation, so there is nothing to carry across calls and no reason to park a cache in `DoCommandExtensionState` next to the local context and the `mut` variables. Upstream batteries cannot see this yet: `nightly-testing` is on `nightly-2026-11-20` and carries the same unadapted file (byte-identical), and there is no batteries PR open that mentions `controlInfoCache` or lean4#16557 — so the same fix is wanted there. ### Verified * `batteries`: `lake build --wfail` (531 jobs), `lake test` (including the new `BatteriesTest.do_command`) and `lake lint`. * `aesop`: `lake build --wfail` and `lake test`, the two phases CI skipped (no lint driver). * `mathlib4`: `lake build Mathlib Archive Counterexamples Wanted cache --wfail` (18647 jobs), `lake test --iofail` (19211 jobs) and `lake lint`, with #270's `import-graph` fix applied locally, since `mathlib4` does not parse without it. `repl` was not rebuilt: it is noncritical, and the sites it failed at are #270's. `cslib` is left to `mathlib-nightly-testing` as before. <!-- downstream-watch: unattended --> Co-authored-by: downstream-lean4[bot] <downstream-lean4[bot]@users.noreply.github.com>
Contributor
Author
Build report for chore: one last docs update...Turned green:
Stayed red
Stayed green
|
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.
Run 44826859647 on
nightly-2026-11-20. This fixes the run's new breakage —mathlib4(critical) andrepl.reference-manualhas been red since run 44720445467 and is carried by the open #268, so this PR's own CI stays red onreference-manualuntil that one merges.cslibwas only skipped behindmathlib4here; its own break is Mathlib-caused and left to its bump bot.import-graph—#import_diff's syntax reserved theallkeywordimportGraph#193 (@thorimur) gave
#import_diffa module-system-aware syntax that mentionsLean.Parser.Module.import:A
syntaxdeclaration registers every token the parsers it mentions can read, andLean.Parser.Module.importcan readall— core hasdef «all» := leading_parser (withAnonymousAntiquot := false) "all"inLean/Parser/Module/Syntax.lean. Until now that token only ever reached the builtin table used for the module header.ImportGraph.Toolsis inMathlib.Init's closure, soallbecame a reserved keyword in every Mathlib module, where it is an ordinary identifier:all as
unexpected token 'all'; expected …, plus the cascades behind them (Unknown identifier mkRecNames,elaboration function for commandCompile_inductive% has not been implemented).repl's test phase fails at the same sites, since it compiles Mathlib. Reducible without any of this tree:The fix
ImportGraph.Lean.Parser.Module.import'is a local copy ofLean.Parser.Module.importthat readsallwithnonReservedSymbolinstead of core's reserved atom, and the three#import_diffsyntax declarations use it.nonReservedSymbolInforegisters no token, so nothing is reserved downstream; it matches the identifieralland pushes the same atom, so#import_diff … import all Mkeeps working. The syntax kind is stillLean.Parser.Module.import, so the`(Parser.Module.import| …)quotations in the same file and inImportGraph/Imports/Pretty.leanmatch unchanged, andwithAntiquot (mkAntiquot "import" …)is whatleading_parserwould have added — the`(diffCurrentItem| +$imp)quotations need it.publicandmetaare still registered by this syntax, exactly as before: both were already reserved keywords, which is why onlyallbroke.Two tests at the end of
ImportGraphTest/ImportDiff/Test.lean: adefwith anallbinder, which does not parse without the fix, and an#import_diff … import all, whose table shows theimport allrow andir loaded +1— that branch had no test before.The proper home for this is upstream
import-graph; the same trap waits for any tool that reuses core's module-header parsers from a command, so a core-sidenonReservedSymbolforModule.allmay be the better long-term answer.Verified
import-graph:lake build(148 jobs) andlake test(189 jobs, includingImportGraphTest.ImportDiff.Test).mathlib4:lake build Mathlib Archive Counterexamples Wanted cache --wfail(18641 jobs — a full recompile, since the change invalidates all of Mathlib's artifact cache; the six modules that failed in CI were reallyBuilt),lake test --iofail(19205 jobs) andlake lint.repl:lake buildandlake test, including thetest/Mathlibsuite that CI failed in.Nothing else was adapted:
reference-manualis #268's, andcslibis left tomathlib-nightly-testing.