Skip to content

fix: mathlib4 breakage from importGraph#193 — #import_diff reserved the all token - #270

Merged
thorimur merged 5 commits into
masterfrom
push-ruunyyxztrvv
Nov 23, 2026
Merged

thorimur merged 5 commits into
masterfrom
push-ruunyyxztrvv

Conversation

@downstream-lean4

@downstream-lean4 downstream-lean4 Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Run 44826859647 on nightly-2026-11-20. This fixes the run's new breakage — mathlib4 (critical) and repl. reference-manual has been red since run 44720445467 and is carried by the open #268, so this PR's own CI stays red on reference-manual until that one merges. cslib was only skipped behind mathlib4 here; its own break is Mathlib-caused and left to its bump bot.

import-graph — #import_diff's syntax reserved the all keyword

importGraph#193 (@thorimur) gave #import_diff a module-system-aware syntax that mentions Lean.Parser.Module.import:

syntax diffAbsolute :=
  (&"from" ppLine sepByIndentSemicolon(Parser.Module.import))?
  &"to" ppLine sepByIndentSemicolon(Parser.Module.import)

A syntax declaration registers every token the parsers it mentions can read, and Lean.Parser.Module.import can read all — core has def «all» := leading_parser (withAnonymousAntiquot := false) "all" in Lean/Parser/Module/Syntax.lean. Until now that token only ever reached the builtin table used for the module header. ImportGraph.Tools is in Mathlib.Init's closure, so all became a reserved keyword in every Mathlib module, where it is an ordinary identifier:

Mathlib/Algebra/Group/Commute/Defs.lean:105:17   -- protected theorem all
Mathlib/Util/GetAllModules.lean:43:9             -- let all ← walkDir ml
Mathlib/Util/CompileInductive.lean:44:16         -- def mkRecNames (all : List Name)
Mathlib/Data/Bool/AllAny.lean:27:31              -- (all l fun a => p a)
Mathlib/Tactic/Widget/SelectPanelUtils.lean:91:7 -- let all := …
Mathlib/Tactic/ClickSuggestions/SectionState.lean:102:9

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:

import Lean
open Lean Parser
syntax myDiff := Module.import
syntax (name := myCmd) "#my_diff " myDiff : command
def f (all : Nat) := all   -- unexpected token 'all'; expected '_' or identifier

The fix

ImportGraph.Lean.Parser.Module.import' is a local copy of Lean.Parser.Module.import that reads all with nonReservedSymbol instead of core's reserved atom, and the three #import_diff syntax declarations use it. nonReservedSymbolInfo registers no token, so nothing is reserved downstream; it matches the identifier all and pushes the same atom, so #import_diff … import all M keeps working. The syntax kind is still Lean.Parser.Module.import, so the `(Parser.Module.import| …) quotations in the same file and in ImportGraph/Imports/Pretty.lean match unchanged, and withAntiquot (mkAntiquot "import" …) is what leading_parser would have added — the `(diffCurrentItem| +$imp) quotations need it.

public and meta are still registered by this syntax, 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 table shows the import all row and ir 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-side nonReservedSymbol for Module.all may be the better long-term answer.

Verified

  • import-graph: lake build (148 jobs) and lake test (189 jobs, including ImportGraphTest.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 really Built), lake test --iofail (19205 jobs) and lake lint.
  • repl: lake build and lake test, including the test/Mathlib suite that CI failed in.

Nothing else was adapted: reference-manual is #268's, and cslib is left to mathlib-nightly-testing.

… 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]>
@downstream-lean4
downstream-lean4 Bot requested a review from thorimur November 20, 2026 22:49

@thorimur thorimur left a comment

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.

Wow, that's quite surprising to me—sorrry about this, and thanks for the fix! This adaptation looks good to me.

@thorimur

Copy link
Copy Markdown
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>
@downstream-lean4

Copy link
Copy Markdown
Contributor Author

Build report for chore: one last docs update...

Turned green:

Repo Critical Build Test Lint
mathlib4 ✅ ✅ in 7s ✅ in 34s ✅ in 44s
repl ✅ in 0s ✅ in 36s ⏭️
Stayed red
Repo Critical Build Test Lint
reference-manual ✅ 🟥 in 5s ⏭️ ⏭️
cslib 🟥 in 1s ⏭️ ⏭️
Stayed green
Repo Critical Build Test Lint
aesop ✅ ✅ in 0s ✅ in 4s ⏭️
batteries ✅ ✅ in 0s ✅ in 3s ✅ in 1s
import-graph ✅ ✅ in 2s ✅ in 4s ⏭️
lean4-cli ✅ ✅ in 0s ✅ in 0s ⏭️
plausible ✅ ✅ in 0s ✅ in 2s ⏭️
ProofWidgets4 ✅ ✅ in 0s ✅ in 0s ⏭️
quote4 ✅ ✅ in 0s ✅ in 1s ⏭️
BibtexQuery ✅ in 1s ⏭️ ⏭️
doc-gen4 ✅ in 3s ⏭️ ⏭️
illuminate ✅ in 0s ✅ in 9s ⏭️
lean4-unicode-basic ✅ in 0s ⏭️ ⏭️
lean4export ✅ in 0s ✅ in 5s ⏭️
LeanSearchClient ✅ in 0s ✅ in 0s ⏭️
leansqlite ✅ in 2s ✅ in 16s ⏭️
nerodia ✅ in 0s ✅ in 22s ⏭️
verso ✅ in 17s ✅ in 3m 35s ⏭️
verso-slides ✅ in 4s ✅ in 9s ⏭️
verso-web-components ✅ in 0s ⏭️ ⏭️

View run

@thorimur
thorimur merged commit 762662e into master Nov 23, 2026
21 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant