Skip to content

feat: store eqn-affecting options at definition time instead of eager generation - #13475

Merged
nomeata merged 1 commit into
masterfrom
joachim/eqn-options-cross-module
Apr 19, 2026
Merged

nomeata merged 1 commit into
masterfrom
joachim/eqn-options-cross-module

Conversation

@nomeata

@nomeata nomeata commented Apr 19, 2026

Copy link
Copy Markdown
Collaborator

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]

… 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]>
@nomeata nomeata added the changelog-language Language features and metaprograms label Apr 19, 2026
@nomeata

nomeata commented Apr 19, 2026

Copy link
Copy Markdown
Collaborator Author

(This resurrects and bugfixes #13394 which went to the wrong branch)

@nomeata
nomeata enabled auto-merge April 19, 2026 12:15
@nomeata
nomeata added this pull request to the merge queue Apr 19, 2026
Merged via the queue into master with commit 1d2cfb4 Apr 19, 2026
23 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-language Language features and metaprograms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant