Skip to content

fix: batteries and cslib breakage from the batteries shake and the mathlib uniformOfFinset refactor - #134

Closed
downstream-lean4[bot] wants to merge 2 commits into
masterfrom
push-nuqxlmttpoys
Closed

downstream-lean4[bot] wants to merge 2 commits into
masterfrom
push-nuqxlmttpoys

Conversation

@downstream-lean4

Copy link
Copy Markdown
Contributor

master is red in run 37404438445 on nightly-2026-10-05: batteries fails to build, aesop, mathlib4 and cslib are skipped behind it, and repl's test phase compiles both and fails.

This replaces #133, which downstream: update repo mathlib4 turned CONFLICTING: upstream mathlib resolved that PR's mathlib4 half by itself, in its own way, so only the one-line batteries hunk survives. The same merge unmasked a new cslib failure that CI has never reached.

batteries — Trie.asNode is in Lean.Meta.DiscrTree.Util, not .Types

downstream: update repo batteries merged batteries' main into nightly-testing and so brought in chore: shake (batteries#2005), a repo-wide import minimization computed on the v4.35.0-rc3 toolchain. It replaced public import Lean.Meta.DiscrTree by public import Lean.Meta.DiscrTree.Types in Batteries/Lean/Meta/DiscrTree.lean. That is correct on main, where Trie.mergePreservingDuplicates pattern-matches the node constructor directly. It is not correct on nightly-testing, which carries the adaptation to lean4#14805's new Trie.chain constructor and therefore goes through Trie.asNode / Trie.mkNode — and those live in Lean.Meta.DiscrTree.Util. The merge combined main's import line with nightly-testing's body, so the module fails with

Invalid field `asNode`: The environment does not contain `Lean.Meta.DiscrTree.Trie.asNode`
Unknown constant `Lean.Meta.DiscrTree.Trie.mkNode`

Fixed by importing Lean.Meta.DiscrTree.Util, which publicly imports .Basic and hence .Types, so Key, Trie and DiscrTree stay in scope.

#133 predicted this hunk would be superseded by batteries' own adaptation at the next merge. That has not happened: batteries' nightly-testing is still red the same way (their run of 2026-10-05 17:56), and the downstream: update repo batteries that did land in between carried UnnecessarySeqFocus and Array/Merge changes but nothing for this module.

cslib — PMF.uniformOfFinset and PMF.uniformOfFintype are gone

The merge with mathlib master brought in refactor(Probability/Distributions/Uniform): change uniformOfFinset and ofMultiset from PMF to Measure (mathlib4#42909), which removes both definitions and replaces them by MeasureTheory.Measure.uniformOfFinset : Finset α → Measure α. The deprecated aliases point at the measure, so they do not type-check at the old call sites:

Application type mismatch: The argument Seed has type Type u_1 but is expected to have
type Finset ?m.1 in the application PMF.uniformOfFintype Seed

Nothing in mathlib supplies a uniform PMF any more, and all of Cslib.Crypto is phrased with PMFs — bind, map, normalize, support — so moving the call sites to Measure would be a rewrite of the crypto development rather than an adaptation. Instead mathlib's two former definitions move, unchanged, into Cslib.Probability.PMF, which already exists as a temporary holding place for PMF material awaiting upstreaming, along with the three lemmas the call sites use (uniformOfFinset_apply, mem_support_uniformOfFinset_iff, uniformOfFintype_apply). The call sites drop the PMF. prefix and pick the names up from open Cslib.Probability.PMF, which OneTimePad and Shamir already had; PRG.Defs, PRG.Basic and CslibTests.PRG gain it.

This half is not nightly-specific: upstream cslib meets it at its next mathlib bump.

mathlib4 — superseded upstream, nothing to do here

For the record, since #133 carried five hunks here: downstream: update repo mathlib4 brought mathlib's own resolution of the same shake fallout. Mathlib/Basic/Logic/Basic.lean, Mathlib/Data/Nat/Init.lean and Mathlib/Data/Int/Init.lean now public import Batteries.Tactic.Alias themselves (which also covers Basic/Logic/Lemmas.lean transitively), and Counterexamples/ZeroDivisorsInAddMonoidAlgebras.lean's guard_decl elaborator compares module indices with == instead of =, so it no longer needs the DecidableEq ModuleIdx instance from Batteries.Tactic.OpenPrivate.

Verified locally on nightly-2026-10-05

Every phase below was re-run from scratch on the final tree, all green:

repo result
batteries lake build --wfail ✔, lake test ✔, lake lint ✔
aesop lake build --wfail ✔, lake test ✔ (no change needed)
mathlib4 lake build --wfail Mathlib Archive Counterexamples Wanted cache ✔, lake test --iofail ✔, lake lint ✔ (no change needed)
cslib lake build --wfail --iofail ✔, lake test --wfail --iofail ✔, lake lint ✔
repl lake build ✔, lake test ✔ (no change needed)

Nothing was left unfinished: this is the whole red set of run 37404438445.

🤖 Generated with Claude Code

downstream-lean4 Bot and others added 2 commits October 6, 2026 02:50
`downstream: update repo batteries` merged batteries `main` into
`nightly-testing` and so brought in `chore: shake` (batteries#2005), a
repo-wide import minimization computed on the `v4.35.0-rc3` toolchain. It
narrowed `Batteries/Lean/Meta/DiscrTree.lean` to `public import
Lean.Meta.DiscrTree.Types`, which is correct on `main`, where
`Trie.mergePreservingDuplicates` matches the `node` constructor directly,
but not on `nightly-testing`, which carries the adaptation to lean4#14805
and its new `Trie.chain` constructor and therefore goes through
`Trie.asNode` / `Trie.mkNode`. Those live in `Lean.Meta.DiscrTree.Util`,
so the module failed with

    Invalid field `asNode`: The environment does not contain
    `Lean.Meta.DiscrTree.Trie.asNode`
    Unknown constant `Lean.Meta.DiscrTree.Trie.mkNode`

Import `Lean.Meta.DiscrTree.Util` instead; it publicly imports `.Basic`
and hence `.Types`, so `Key`, `Trie` and `DiscrTree` stay in scope.

Verified with `lake build --wfail`, `lake test` and `lake lint`.

Co-Authored-By: Claude Opus 5 <[email protected]>
The merge with mathlib master brought in `refactor(Probability/Distributions/Uniform):
change uniformOfFinset and ofMultiset from PMF to Measure`
([mathlib4#42909](leanprover-community/mathlib4#42909)), which
removes `PMF.uniformOfFinset` and `PMF.uniformOfFintype` and replaces them by
`MeasureTheory.Measure.uniformOfFinset : Finset α → Measure α`. The deprecated aliases
point at the measure, so they do not type-check at the old call sites:

    Application type mismatch: The argument Seed has type Type u_1 but is expected to
    have type Finset ?m.1 in the application PMF.uniformOfFintype Seed

Nothing in mathlib supplies a uniform `PMF` any more, and all of `Cslib.Crypto` is phrased
with `PMF`s — `bind`, `map`, `normalize`, `support` — so porting the call sites to
`Measure` would be a rewrite of the crypto development rather than an adaptation. Instead
the two `PMF` definitions move into `Cslib.Probability.PMF`, which already exists as a
temporary holding place for `PMF` material awaiting upstreaming, together with the three
lemmas the call sites use (`uniformOfFinset_apply`, `mem_support_uniformOfFinset_iff`,
`uniformOfFintype_apply`). The definitions are mathlib's former ones unchanged. Call sites
drop the `PMF.` prefix and pick the names up from `open Cslib.Probability.PMF`, which
`OneTimePad` and `Shamir` already had.

CI never saw this: it stopped at `batteries` and skipped `mathlib4` and `cslib` behind it.
It is not nightly-specific — upstream cslib meets it at its next mathlib bump.

Verified with `lake build --wfail --iofail`, `lake test --wfail --iofail` and `lake lint`.

Co-Authored-By: Claude Opus 5 <[email protected]>
@downstream-lean4

Copy link
Copy Markdown
Contributor Author

Build report for fix: cslib breakage from the mathlib uniformOfFinset refactor

Turned green:

Repo Critical Build Test Lint
aesop ✅ ✅ in 16s ✅ in 4s ⏭️
batteries ✅ ✅ in 1s ✅ in 4s ✅ in 2s
mathlib4 ✅ ✅ in 16m 7s ✅ in 42s ✅ in 1m 33s
cslib ✅ in 30s ✅ in 9s ✅ in 3s
repl ✅ in 0s ✅ in 54s ⏭️
Stayed green
Repo Critical Build Test Lint
import-graph ✅ ✅ in 2s ✅ in 4s ⏭️
lean4-cli ✅ ✅ in 0s ✅ in 0s ⏭️
plausible ✅ ✅ in 0s ✅ in 2s ⏭️
ProofWidgets4 ✅ ✅ in 1s ✅ in 1s ⏭️
quote4 ✅ ✅ in 0s ✅ in 1s ⏭️
reference-manual ✅ ✅ in 1m 14s ⏭️ ⏭️
BibtexQuery ✅ in 3s ⏭️ ⏭️
comparator ✅ in 2s ⏭️ ⏭️
doc-gen4 ✅ in 7s ⏭️ ⏭️
illuminate ✅ in 1s ✅ in 11s ⏭️
lean4-unicode-basic ✅ in 0s ⏭️ ⏭️
lean4export ✅ in 0s ✅ in 8s ⏭️
LeanSearchClient ✅ in 0s ✅ in 0s ⏭️
leansqlite ✅ in 7s ✅ in 21s ⏭️
nerodia ✅ in 1s ✅ in 21s ⏭️
verso ✅ in 1m 20s ✅ in 2m 57s ⏭️
verso-slides ✅ in 45s ✅ in 9s ⏭️
verso-web-components ✅ in 31s ⏭️ ⏭️

View run

Kha added a commit that referenced this pull request Oct 6, 2026
…#137)

Split out of
[#134](#134): this is
its `batteries` commit on its own, unchanged (`b3bd4b838`), so it can
land independently of the `cslib` half.

`master` is red in [run
37404438445](https://github.com/leanprover/downstream-lean4/actions/runs/37404438445)
on `nightly-2026-10-05`: `batteries` fails to build, and `aesop`,
`mathlib4` and `cslib` are skipped behind it.

## batteries — `Trie.asNode` is in `Lean.Meta.DiscrTree.Util`, not
`.Types`

`downstream: update repo batteries` merged batteries' `main` into
`nightly-testing` and so brought in [`chore: shake`
(batteries#2005)](leanprover-community/batteries#2005),
a repo-wide import minimization computed on the `v4.35.0-rc3` toolchain.
It replaced `public import Lean.Meta.DiscrTree` by `public import
Lean.Meta.DiscrTree.Types` in `Batteries/Lean/Meta/DiscrTree.lean`. That
is correct on `main`, where `Trie.mergePreservingDuplicates`
pattern-matches the `node` constructor directly. It is not correct on
`nightly-testing`, which carries the adaptation to lean4#14805's new
`Trie.chain` constructor and therefore goes through `Trie.asNode` /
`Trie.mkNode` — and those live in `Lean.Meta.DiscrTree.Util`. The merge
combined `main`'s import line with `nightly-testing`'s body, so the
module fails with

```
Invalid field `asNode`: The environment does not contain `Lean.Meta.DiscrTree.Trie.asNode`
Unknown constant `Lean.Meta.DiscrTree.Trie.mkNode`
```

Fixed by importing `Lean.Meta.DiscrTree.Util`, which publicly imports
`.Basic` and hence `.Types`, so `Key`, `Trie` and `DiscrTree` stay in
scope.

## Not covered here

With `batteries` building again, CI reaches `cslib`, which then fails on
the removal of `PMF.uniformOfFinset` / `PMF.uniformOfFintype`
([mathlib4#42909](leanprover-community/mathlib4#42909)).
That fix stays in #134, so this PR alone is not expected to turn
`master` fully green.

## Verification

Not re-run for this split: the commit is byte-identical to the one in
#134 and sits on the same `master` parent (`7768fa695`). There it was
verified on `nightly-2026-10-05` with `lake build --wfail`, `lake test`
and `lake lint` in `batteries`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01XyR8dP17VkvXwNSrqLMRcq

Co-authored-by: downstream-lean4[bot] <downstream-lean4[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <[email protected]>
@downstream-lean4

Copy link
Copy Markdown
Contributor Author

Superseded on both halves, closing.

The batteries hunk landed as #137 — batteries/Batteries/Lean/Meta/DiscrTree.lean on master now carries public import Lean.Meta.DiscrTree.Util.

The cslib half arrived from upstream, as the 2026-10-05 decision on this PR's split anticipated: the downstream: update repo cslib merges brought cslib's own Cslib/Probability/PMF.lean with uniformOfFinset, uniformOfFinset_apply, mem_support_uniformOfFinset_iff, uniformOfFintype and uniformOfFintype_apply, and every call site in Cslib.Crypto now picks the names up from open Cslib.Probability.PMF — the same shape this PR proposed. Nothing here still applies to master, and the PR had gone CONFLICTING against those merges.

(cslib is still red in the current triage, but only as skipped behind the mathlib4 blocker lean4#15506; its own phases have not run since the merges.)

@downstream-lean4 downstream-lean4 Bot closed this Oct 7, 2026
@downstream-lean4
downstream-lean4 Bot deleted the push-nuqxlmttpoys branch October 7, 2026 04:47
hargoniX pushed a commit that referenced this pull request Oct 7, 2026
`master` went red with the bump to `nightly-2026-10-06`
([run
37451416455](https://github.com/leanprover/downstream-lean4/actions/runs/37451416455),
toolchain-only commit 0c29ffc). Four repos are red; this PR fixes the
one that
can be fixed downstream.

## reference-manual (critical) — fixed

Two expectation blocks went stale, from two different lean4 changes.

**`Manual/Runtime.lean`** — lean4#15486 ("chore: pre-compute information
about
IR decls") renumbers IR variables and join points, so the `leanOutput
discardElems` block no longer matched: `block_4`/`block_9` are now
`block_1`/`block_2` and the variables shift accordingly. The block is
regenerated from the new output. The prose below it names two of those
variables; both are re-pointed at the new numbering — `x_11` for the
discarded
element whose reference count is decremented and `x_9` for the freshly
allocated `List.cons`. (The old `x_5` was already stale: it named the
reused
cons cell rather than the decremented element, and after the renumbering
it
names a `u8`.)

**`extended-examples/IndexMapGrind.lean`** — lean4#15506 ("fix: `grind`
runs
upward propagation from the `toProcess` queue") changes the order in
which
terms enter cutsat's equivalence classes, which reorders the members of
two
`[eqc]` lines in the `grind` diagnostics that the tutorial's
`#check_msgs`
docstring captures verbatim. Eighteen lines, pure reordering — nothing
about
the proof or the diagnostics' content changed. Expect this block to move
again
when the blocker below is fixed.

Verified: full `lake build` locally, 1577/1577 jobs, exit 0.
`reference-manual`
defines neither a test nor a lint driver, so `lake build` is the whole
phase
set (matching `test`/`lint` being `null` in the build reports).

## mathlib4 (critical) — blocker, not fixable downstream

`grind` throws the internal error ``unknown free variable
`_fvar.771.11634` ``
on `List.pairwise_iff_forall_infix` in
`Mathlib/Data/List/Pairwise.lean:49`.
Roughly 110 Mathlib modules sit behind it, and with them `repl`'s test
phase
(which compiles Mathlib) and `cslib` (skipped, no build for `mathlib4`).

Bisected to lean4#15506 against the pr-release toolchains, with a repro
that
needs core only — no Mathlib, no Batteries:

```lean
namespace List

theorem test {α : Type u} {l : List α} {R : α → α → Prop} :
    l.Pairwise R ↔
      ∀ l', (h : 1 < l'.length) → l' <:+: l → R (l'.head <| by grind) (l'.getLast <| by grind) := by
  refine l.pairwise_iff_getElem.trans ⟨fun h l' hne ⟨l₁, l₂, hl⟩ ↦ ?_, fun h i j hi hj hij ↦ ?_⟩
  · grind [getElem_append_left', getElem_append_right']
  · grind [h _ _ <| List.drop_suffix i _ |>.isInfix.trans <| l.take_prefix (j + 1) |>.isInfix]
```

| toolchain | result |
| --- | --- |
| `nightly-2026-10-05` | clean |
| `pr-release-15503` | clean |
| `pr-release-15506` | `unknown free variable` |
| `nightly-2026-10-06` | `unknown free variable` |

Dropping either bullet makes the error disappear, so it is the
interaction of
the two `grind` calls, not either one alone. An internal error is not
something
downstream can adapt to, so this is left to lean4 and `master` stays red
until
it is fixed.

## Left unfinished

- **mathlib4** — the blocker above. Note that its build stopped at
`Mathlib.Data.List.Pairwise`, so whatever sits behind those ~110 modules
has
never been elaborated on this nightly; more may appear once the internal
  error is gone.
- **repl** — behind mathlib4, nothing of its own.
- **cslib** — skipped behind mathlib4; its own breakage from the mathlib
  `uniformOfFinset` refactor is still open in #134.

<!-- downstream-watch: unattended -->

Co-authored-by: downstream-lean4[bot] <downstream-lean4[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <[email protected]>
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.

0 participants