Registry Mirror
Skip to content

Conversation

@Kha

@Kha Kha commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

This PR makes the .olean files of a module independent of the Elab.async option, so that builds with and without it can share build caches. It also fixes kernel errors such as declaration type mismatch for auxiliary lemmas of backtracking tactics (e.g. grind?) and backward.privateInPublic not exporting private theorems under set_option Elab.async false.

With Elab.async disabled, addDecl, compileDecls and theorem bodies now go through the same code as with it enabled, except that the forked action runs immediately instead of in a task (Core.forkAsSnapshot, Term.forkAsSnapshot). In particular, both modes fork the name generators in the same way, so auxiliary declarations get the same names (foo._proof_1_1 instead of foo._proof_1 without Elab.async), and names are no longer reused after backtracking restores the environment. As a consequence, a theorem's statement is fixed before its proof is elaborated in both modes, so a proof can no longer unify universe levels left open in the statement under Elab.async false.

Only what is elaborated is the same in both modes, not how it is reported: without Elab.async, messages, traces and info trees of these actions are still stored in the current state, in the same order as before.

The remaining differences in the output are removed as follows:

  • Linters advance the name generators in the same way in both modes.
  • Extra module use entries recorded on different environment branches are deduplicated on export.
  • Deferred Verso docstring checks, such as forward references via {name (scope := ...)}, no longer store the Elab.async option.

In addition, lean code blocks in Verso docstrings now also consider messages reported via snapshot tasks.

Fixes #15866
Fixes #13647

@Kha Kha added the downstream Request a downstream-lean4 adaptation PR. label Nov 20, 2026
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Nov 20, 2026
Comment on lines +171 to +172
-- `Elab.async` must not influence the `.olean` output
options := (← getOptions).erase Elab.async.name

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@david-christiansen FYI - this may not be a very principled way to do it but ensures byte-identical output when flipping the option as requested by @kim-em

Kha and others added 15 commits November 20, 2026 14:21
This PR makes `lean` code blocks in Verso docstrings also consider messages reported via snapshot tasks, such as kernel errors and `declaration uses sorry` warnings from `addDecl`, when checking for unexpected errors and warnings and when saving named output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This PR makes `addDecl` and `compileDecls` under `set_option Elab.async false` go through the same code as with `Elab.async` enabled, except for not spawning a task. This fixes kernel errors such as `declaration type mismatch` for auxiliary lemmas created by tactics that backtrack (e.g. `grind?`) under `Elab.async false`.

The new `Core.forkAsSnapshot` runs an action on a forked state as `wrapAsyncAsSnapshot` does and reports its messages, traces, and snapshot tasks as a snapshot task. With `Elab.async`, the action runs in a task as before; otherwise it runs immediately, and its exceptions are rethrown so that callers disabling `Elab.async` to catch kernel or compiler errors keep working. Previously, the synchronous paths did not fork the name generators, so aux declaration names created there were reused after backtracking restored the environment while retained `Meta` caches still referred to the discarded declarations.

As messages of synchronous `addDecl` and `compileDecls` are now reported via snapshot tasks as in asynchronous mode, they are ordered after the command's other messages in `#guard_msgs`. Some aux names created after a discarded declaration, e.g. `native_decide` axioms, have shifted indices.

Fixes #15866
Fixes #8746

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This PR makes theorem elaboration under `set_option Elab.async false` go through the same code as with `Elab.async` enabled, except that the proof is elaborated immediately instead of in a separate task. This fixes `backward.privateInPublic` not exporting private theorems under `Elab.async false`.

The new `Term.forkAsSnapshot` lifts `Core.forkAsSnapshot` to `TermElabM`, and `Core.forkAsSnapshot` gains a `reportingRange` parameter for it. Previously, theorems took the regular definition path when `Elab.async` was disabled, where the theorem itself was added while `backward.privateInPublic` is disabled for elaborating its body.

Fixes #13647

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`forkAsSnapshot` used it as `wrapAsyncAsSnapshot.runIsolatedForSnapshot`, a `where` helper of another function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This PR makes linters under `set_option Elab.async false` see the same info trees and messages as with `Elab.async` enabled, which they need now that theorem bodies and `addDecl` report through info tree holes and snapshot tasks in both modes. Without it, e.g. the `unusedVariables` linter reported variables used only inside a proof.

`runLintersAsync` and `runStatefulLintersAsync` now build the same linter action in both modes and merely run it immediately instead of in a task when `Elab.async` is disabled.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This PR removes duplicate extra module use entries from `.olean.private` files.

`recordExtraModUse` can only check for an existing entry on the current environment branch, so e.g. two proofs recording the same module each added an entry. The entries are now deduplicated on export.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This PR fixes realized theorems such as `f.congr_simp` being stored with their proofs in the public `.olean` file of a module when they were realized only inside a proof instead of on the main environment branch.

Constants realized on other environment branches are found through `Environment.allRealizations`, which only held their private view and so returned it in the public scope as well. It now holds both views, and a lookup in the public scope prefers the exported one. Constants that are not exported are still found there in their private form, which existing code relies on.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This PR removes the `Elab.async` option from the options stored with deferred Verso docstring checks, such as forward references via `{name (scope := ...)}`, so that the `.olean` file no longer depends on its value.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This PR adds a test that compiles a module with and without `Elab.async` and checks that all `.olean` parts are identical.

The module covers the known sources of differences: auxiliary declaration names and extra module uses from proofs, theorems realized inside proofs, linter results, and deferred docstring checks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The theorem's proof is elaborated on a forked name generator under `Elab.async false` as well now, so its auxiliary theorem is `disj6._proof_1_1`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`runLintersAsync`, `runModuleLintersAsync` and `runStatefulLintersAsync` each decided on their own whether to run the linter action in a task or immediately depending on `Elab.async`. The new `Command.forkAsSnapshot`, the `CommandElabM` counterpart of `Core.forkAsSnapshot`, does that for all three.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This PR makes `Core.forkAsSnapshot` report into the current state when `Elab.async` is disabled: messages, traces, info trees and snapshot tasks of the forked action are kept in place and exceptions propagate, as callers that drive elaboration without `Elab.async` expect. Only what is elaborated is the same in both modes, not the channel it is reported through.

The forked action still runs on forked name generators and its remaining state is discarded, and the theorem path creates the name of its info tree hole in both modes, so generated names do not depend on the option. As the message order under `Elab.async false` is thus unchanged, the test for #8746 is removed and the `#guard_msgs` expectations of `1234`, `impossibleTactic` and `wf_preprocess` are back to their previous state.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This PR makes running linters without `Elab.async` advance the name generators in the same way as with it, where they are forked for the linter task and provide the name of an info tree hole. Otherwise all names generated by later commands depend on the option.

Without `Elab.async`, linters run on the current state again as messages and info trees are available there, which replaces `Command.forkAsSnapshot`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…pendencies

Without `Elab.async`, `Core.forkAsSnapshot` carried the forked action's `State.recordedDeps` over to the current state, while `wrapAsync` asserts that no recording is active when forking. It now asserts the same in both modes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This reverts "fix: export theorems realized inside proofs as axioms" and its test. Since #16623, a constant realized only inside a proof is not exported at all, which covers the same case.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Kha
Kha force-pushed the olean-async-determinism branch from af6fa29 to 6f8c110 Compare November 21, 2026 17:13
@downstream-lean4

Copy link
Copy Markdown

The adaptation PR for this PR is leanprover/downstream-lean4#267.

Garmelon pushed a commit to leanprover/downstream that referenced this pull request Nov 23, 2026
The `adaptation-pr-create` action checks that the upstream PR's merge
base coincides with a ref that has green downstream CI, but only while
the adaptation branch does not exist yet. Once it exists, every later
push is accepted: the action bumps the toolchain of the adaptation
branch to the new head, whatever that head is based on.

This happened on leanprover/lean4#16633: after its adaptation PR
(leanprover/downstream-lean4#267) had gone green, the PR was rebased
from `downstream-green` onto `master`, 45 commits ahead. The action
followed, and the adaptation branch was built against upstream changes
it had not been adapted to. The resulting failures (batteries,
reference-manual) had nothing to do with the PR but were reported on it
like any other adaptation result.

Skipping the check for existing branches was needed while the merge base
had to coincide with the tip of a single branch, which moves on. Since
any ref with green downstream CI is accepted now, the check can run on
every update, so a PR rebased onto a commit that is not known to be
green gets the usual "merge base does not coincide" message. The force
label still bypasses it.

Only `actions/adaptation-pr-create` changes; `dist/index.js` is rebuilt
with `pnpm build`.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
@roy7

roy7 commented Dec 1, 2026

Copy link
Copy Markdown

I ran some local testing and this fixes the [csimp] form as well.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

downstream Request a downstream-lean4 adaptation PR. toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grind?: kernel error with set_option Elab.async false Setting -D Elab.async=false breaks backward.privateInPublic

2 participants