Repository navigation
feat: store eqn-affecting options at definition time instead of eager generation - #13475
Merged
Merged
Conversation
… generation This PR replaces the eager equation realization that was triggered by non-default values of equation-affecting options (like `backward.eqns.nonrecursive`) with a `MapDeclarationExtension` that stores non-default option values at definition time. These values are then restored when equations are lazily realized, so the same equations are produced regardless of when generation occurs. Restoring the options is done via a new `withEqnOptions` helper in `Lean.Meta.Eqns`. Because `realizeConst` overrides the caller's options with the options saved in its `RealizationContext` — which are empty for imported constants — the helper must also be applied inside the `realizeConst` callbacks in `mkSimpleEqThm`, `mkEqns` (in `Elab/PreDefinition/Eqns.lean`), `getConstUnfoldEqnFor?`, and `Structural.mkUnfoldEq`. Without that, equation generation code that reads eqn-affecting options inside the realize callback would see the caller-independent defaults rather than the values stored in `eqnOptionsExt` — so the store-at-definition-time behavior would not carry across module boundaries. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Collaborator
Author
|
(This resurrects and bugfixes #13394 which went to the wrong branch) |
nomeata
enabled auto-merge
April 19, 2026 12:15
nomeata
added a commit
that referenced
this pull request
Apr 19, 2026
This PR fixes a benchmark regression introduced in #13475: `eqnOptionsExt` was using `.async .asyncEnv` asyncMode, which accumulates state in the `checked` environment and can block. Switching to `.local` — consistent with the neighbouring `eqnsExt` and the other declaration caches in `src/Lean/Meta` — restores performance (the `build/profile/blocked (unaccounted) wall-clock` bench moves from +33% back to baseline). `.local` is safe here because `saveEqnAffectingOptions` is only called during top-level `def` elaboration and downstream readers see the imported state; modifications on non-main branches are merged into the main branch on completion. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Apr 19, 2026
This PR fixes a benchmark regression introduced in #13475: `eqnOptionsExt` was using `.async .asyncEnv` asyncMode, which accumulates state in the `checked` environment and can block. Switching to `.local` — consistent with the neighbouring `eqnsExt` and the other declaration caches in `src/Lean/Meta` — restores performance (the `build/profile/blocked (unaccounted) wall-clock` bench moves from +33% back to baseline). `.local` is safe here because `saveEqnAffectingOptions` is only called during top-level `def` elaboration and downstream readers see the imported state; modifications on non-main branches are merged into the main branch on completion. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
nomeata
added a commit
that referenced
this pull request
Apr 21, 2026
… generation (#13475) This PR replaces the eager equation realization that was triggered by non-default values of equation-affecting options (like `backward.eqns.nonrecursive`) with a `MapDeclarationExtension` that stores non-default option values at definition time. These values are then restored when equations are lazily realized, so the same equations are produced regardless of when generation occurs. Restoring the options is done via a new `withEqnOptions` helper in `Lean.Meta.Eqns`. Because `realizeConst` overrides the caller's options with the options saved in its `RealizationContext` — which are empty for imported constants — the helper must also be applied inside the `realizeConst` callbacks in `mkSimpleEqThm`, `mkEqns` (in `Elab/PreDefinition/Eqns.lean`), `getConstUnfoldEqnFor?`, and `Structural.mkUnfoldEq`. Without that, equation generation code that reads eqn-affecting options inside the realize callback would see the caller-independent defaults rather than the values stored in `eqnOptionsExt` — so the store-at-definition-time behavior would not carry across module boundaries. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
nomeata
added a commit
that referenced
this pull request
Apr 21, 2026
This PR fixes a benchmark regression introduced in #13475: `eqnOptionsExt` was using `.async .asyncEnv` asyncMode, which accumulates state in the `checked` environment and can block. Switching to `.local` — consistent with the neighbouring `eqnsExt` and the other declaration caches in `src/Lean/Meta` — restores performance (the `build/profile/blocked (unaccounted) wall-clock` bench moves from +33% back to baseline). `.local` is safe here because `saveEqnAffectingOptions` is only called during top-level `def` elaboration and downstream readers see the imported state; modifications on non-main branches are merged into the main branch on completion. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[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 replaces the eager equation realization that was triggered by
non-default values of equation-affecting options (like
backward.eqns.nonrecursive) with aMapDeclarationExtensionthatstores non-default option values at definition time. These values are
then restored when equations are lazily realized, so the same equations
are produced regardless of when generation occurs.
Restoring the options is done via a new
withEqnOptionshelper inLean.Meta.Eqns. BecauserealizeConstoverrides the caller's optionswith the options saved in its
RealizationContext— which are emptyfor imported constants — the helper must also be applied inside the
realizeConstcallbacks inmkSimpleEqThm,mkEqns(inElab/PreDefinition/Eqns.lean),getConstUnfoldEqnFor?, andStructural.mkUnfoldEq. Without that, equation generation code thatreads eqn-affecting options inside the realize callback would see the
caller-independent defaults rather than the values stored in
eqnOptionsExt— so the store-at-definition-time behavior would notcarry across module boundaries.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]