Repository navigation
feat: two-phase stateful linters - #14357
Merged
wkrozowski merged 13 commits intoJul 20, 2026
Merged
Conversation
Collaborator
|
Reference manual CI status:
|
|
Mathlib CI status (docs):
|
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Jul 13, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Jul 13, 2026
leanprover-bot
added a commit
to leanprover/reference-manual
that referenced
this pull request
Jul 13, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Jul 13, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Jul 13, 2026
leanprover-bot
added a commit
to leanprover/reference-manual
that referenced
this pull request
Jul 13, 2026
wkrozowski
force-pushed
the
wojciech/statefulLintersAttempt2
branch
from
July 13, 2026 19:37
f4d3a66 to
8f7f747
Compare
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Jul 13, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Jul 13, 2026
leanprover-bot
added a commit
to leanprover/reference-manual
that referenced
this pull request
Jul 13, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Jul 13, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Jul 13, 2026
leanprover-bot
added a commit
to leanprover/reference-manual
that referenced
this pull request
Jul 13, 2026
wkrozowski
force-pushed
the
wojciech/statefulLintersAttempt2
branch
from
July 14, 2026 14:40
53aa966 to
237c0f8
Compare
wkrozowski
marked this pull request as ready for review
July 14, 2026 14:41
wkrozowski
force-pushed
the
wojciech/statefulLintersAttempt2
branch
from
July 16, 2026 14:07
237c0f8 to
e936a68
Compare
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Jul 16, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Jul 16, 2026
leanprover-bot
added a commit
to leanprover/reference-manual
that referenced
this pull request
Jul 16, 2026
Contributor
Author
|
!bench |
|
Benchmark results for e936a68 against a4b639c are in. No significant results found. @wkrozowski
Small changes (1🟥)
|
JJYYY-JJY
pushed a commit
to JJYYY-JJY/lean4
that referenced
this pull request
Jul 27, 2026
This PR adds the support for code actions to linters. When `Elab.async` is enabled, before a linter task is dispatched, we create a promise for the info tree node. Then, we accumulate newly added info trees through the linter execution and we resolve the promise inside of the linter task. Finally, on the main task, we modify the info tree (wrapped in command context) and add a new leaf, with an mvar id, that will eventually be filled with a promise value. This PR also supports code actions in stateful linters (leanprover#14357), but does not offer such support for module linters, that fire at terminal commands and code actions from there do not surface to the info view. Related to RFC leanprover#4363.
This was referenced Jul 28, 2026
marcelolynch
added a commit
to marcelolynch/mathlib4
that referenced
this pull request
Jul 28, 2026
Rewrite the header linter with the stateful linter API (leanprover/lean4#14357). The linter state caches the library-root check, which replaces the Std.Mutex that guarded the cache against concurrent async linter runs, and records that the checks ran, so the linter checks the header of each module exactly once. A file without a module doc-string gets one set of warnings at its first command; the IO.Ref-era behavior repeated the full header parse and its warnings on every command of such a file. Linter behavior on well-formed files is unchanged; the header linter tests pass as is (validated on a nightly-2026-07-27 toolchain). NOTE: CI stays red until the toolchain bump to v4.34.0-rc1, which first provides `registerStatefulLinter`. Co-Authored-By: Claude Fable 5 <[email protected]>
wkrozowski
pushed a commit
to marcelolynch/lean4
that referenced
this pull request
Jul 29, 2026
This PR adds the support for code actions to linters. When `Elab.async` is enabled, before a linter task is dispatched, we create a promise for the info tree node. Then, we accumulate newly added info trees through the linter execution and we resolve the promise inside of the linter task. Finally, on the main task, we modify the info tree (wrapped in command context) and add a new leaf, with an mvar id, that will eventually be filled with a promise value. This PR also supports code actions in stateful linters (leanprover#14357), but does not offer such support for module linters, that fire at terminal commands and code actions from there do not surface to the info view. Related to RFC leanprover#4363.
wkrozowski
pushed a commit
to marcelolynch/lean4
that referenced
this pull request
Jul 29, 2026
The phases of a stateful linter (leanprover#14357) return values, so they cannot use the CommandElab-only signature. All existing call sites instantiate the result type with Unit and do not change. Co-Authored-By: Claude Fable 5 <[email protected]>
wkrozowski
pushed a commit
to marcelolynch/lean4
that referenced
this pull request
Jul 29, 2026
The phases of a stateful linter (leanprover#14357) return values, so they cannot use the CommandElab-only signature. All existing call sites instantiate the result type with Unit and do not change. Co-Authored-By: Claude Fable 5 <[email protected]>
wkrozowski
pushed a commit
to marcelolynch/lean4
that referenced
this pull request
Jul 29, 2026
The phases of a stateful linter (leanprover#14357) return values, so they cannot use the CommandElab-only signature. All existing call sites instantiate the result type with Unit and do not change. Co-Authored-By: Claude Fable 5 <[email protected]>
JJYYY-JJY
pushed a commit
to JJYYY-JJY/lean4
that referenced
this pull request
Jul 29, 2026
…r#14581) This PR generalizes `withSetOptionIn` over the result type of the wrapped function. The previous signature only accepted a `CommandElab`, which returns `Unit`. The phases of a stateful linter (leanprover#14357) return values, so they could not use the helper (see for example leanprover-community/mathlib4#42186). All existing call sites instantiate the result type with `Unit` and do not change. A new `resultType` section in `tests/elab/withSetOptionIn.lean` checks the generalized signature. The change preserves behavior. Type inference changes in one corner case: a first-class use with no expected type, where the wrapped function does not determine its result type, now needs a type ascription. Core, Batteries, and Mathlib contain no such use. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <[email protected]>
robsimmons
pushed a commit
that referenced
this pull request
Jul 29, 2026
This PR introduces stateful linters, which allow linters to persist and share state across command elaboration. Each stateful linter operates in a two-phase architecture: * **Early Phase**: Reads the linter's previous state and produces an intermediate value passed to the late phase. This intermediate value is wrapped in an `Option` type; if the early phase fails, `none` is passed to the late phase. * **Late Phase**: Reads both the linter's previous state and the early phase's intermediate state to produce and save a new state. If this phase fails, the state remains unchanged. Stateful linters must be initialized with a starting value (before the first top-level command is elaborated). Linters can only be initialized within `initialize` blocks. ### State Access & Sharing * **Global State**: All stateful linters can read the global state of *other* linters (representing the state after the previous command, or the initial state if it's the first command). * **Inter-phase Reading**: The late phase of a linter can read the early-phase intermediate states of other linters. * **Handles**: Access to state is managed via a typed handle returned by the `registerStatefulLinter` method.
robsimmons
pushed a commit
that referenced
this pull request
Jul 29, 2026
This PR adds the support for code actions to linters. When `Elab.async` is enabled, before a linter task is dispatched, we create a promise for the info tree node. Then, we accumulate newly added info trees through the linter execution and we resolve the promise inside of the linter task. Finally, on the main task, we modify the info tree (wrapped in command context) and add a new leaf, with an mvar id, that will eventually be filled with a promise value. This PR also supports code actions in stateful linters (#14357), but does not offer such support for module linters, that fire at terminal commands and code actions from there do not surface to the info view. Related to RFC #4363.
robsimmons
pushed a commit
that referenced
this pull request
Jul 29, 2026
This PR generalizes `withSetOptionIn` over the result type of the wrapped function. The previous signature only accepted a `CommandElab`, which returns `Unit`. The phases of a stateful linter (#14357) return values, so they could not use the helper (see for example leanprover-community/mathlib4#42186). All existing call sites instantiate the result type with `Unit` and do not change. A new `resultType` section in `tests/elab/withSetOptionIn.lean` checks the generalized signature. The change preserves behavior. Type inference changes in one corner case: a first-class use with no expected type, where the wrapped function does not determine its result type, now needs a type ascription. Core, Batteries, and Mathlib contain no such use. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <[email protected]>
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.
This PR introduces stateful linters, which allow linters to persist and share state across command elaboration.
Each stateful linter operates in a two-phase architecture:
Optiontype; if the early phase fails,noneis passed to the late phase.Stateful linters must be initialized with a starting value (before the first top-level command is elaborated). Linters can only be initialized within
initializeblocks.State Access & Sharing
registerStatefulLintermethod.