Skip to content

fix: do not export realizations triggered only from proofs - #15559

Merged
Kha merged 2 commits into
push-srmmnwktrunwfrom
no-export-proof-realizations
Oct 9, 2026
Merged

Kha merged 2 commits into
push-srmmnwktrunwfrom
no-export-proof-realizations

Conversation

@Kha

@Kha Kha commented Oct 8, 2026

Copy link
Copy Markdown
Member

This PR stops a module from exporting constants such as foo.eq_1 when they were realized only inside a proof, so that such proofs no longer trigger downstream rebuilds. Importing modules realize these constants again on demand.

Previously, such a constant reached the exported .olean through the allRealizations fallback of Environment.find?, which returns the private constant info, so the theorem was exported together with its proof. mkModuleData and the exported-level filters of attributes, instances, matcher info, MapDeclarationExtensions, and the axiom extension now consider only constants known on the main environment branch.

@Kha
Kha added this pull request to stack #15560 October 8, 2026 15:31
@Kha Kha added the downstream-force Force creation of a downstream-lean4 adaptation PR. label Oct 8, 2026
This PR stops a `module` from exporting constants such as `foo.eq_1` when they were realized only inside a proof, so that such proofs no longer trigger downstream rebuilds. Importing modules realize these constants again on demand.

Previously, such a constant reached the exported `.olean` through the `allRealizations` fallback of `Environment.find?`, which returns the private constant info, so the theorem was exported together with its proof. `mkModuleData` and the exported-level filters of attributes, instances, matcher info, `MapDeclarationExtension`s, and the axiom extension now consider only constants known on the main environment branch.

As a consequence, such a constant is part of the private scope of its module only. A module that accesses it through `import all` cannot use it in a public scope, which is now reported as an unknown identifier with a corresponding note.

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

Copy link
Copy Markdown

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

@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 Oct 8, 2026
This PR makes the generation of equation theorems such as `f.eq_1` use the values that `backward.isDefEq.respectTransparency`, `backward.isDefEq.respectTransparency.types`, `backward.whnf.reducibleClassField`, and `smartUnfolding` had where `f` was defined. Previously, a definition whose equation theorems can only be generated under a local `set_option` failed with "failed to generate equational theorem" when the theorems were first requested from an importing module.

The options are added to `eqnAffectingOptions`, whose non-default values are stored with the definition and restored when its equation theorems are realized.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Kha
Kha added this pull request to the merge queue Oct 9, 2026
Merged via the queue into master with commit 00f086c Oct 9, 2026
17 checks passed
Kha added a commit that referenced this pull request Oct 13, 2026
…oofs (#15559)"

This PR reverts #15559, which stopped a `module` from exporting constants such as `foo.eq_1` when they were realized only inside a proof. Tactics whose behavior depends on whether such a constant already exists changed behavior in importing modules as a result: `unfold f` on a non-recursive `f` rewrites with `f.eq_def` and reduces the resulting matcher application only if that theorem is visible, so proofs relying on an upstream `fun_cases f` having realized it broke, such as `Batteries.Data.Float.Lemmas.pack_unpack`.

The change can be reapplied once `unfold` no longer depends on the visibility of `eq_def`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yermakoffivan pushed a commit to yermakoffivan/lean4 that referenced this pull request Oct 13, 2026
Kha added a commit that referenced this pull request Nov 19, 2026
This PR stops a `module` from exporting constants such as `foo.eq_1`
when they were realized only inside a proof, so that such proofs no
longer trigger downstream rebuilds. Importing modules realize these
constants again on demand.

Previously, such a constant reached the exported `.olean` through the
`allRealizations` fallback of `Environment.find?`, which returns the
private constant info, so the theorem was exported together with its
proof. `mkModuleData` and the exported-level filters of attributes,
instances, matcher info, `MapDeclarationExtension`s, and the axiom
extension now consider only constants known on the main environment
branch.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Kha added a commit that referenced this pull request Nov 19, 2026
This PR stops a `module` from exporting constants such as `foo.eq_1`
when they were realized only inside a proof, so that such proofs no
longer trigger downstream rebuilds. Importing modules realize these
constants again on demand.

Previously, such a constant reached the exported `.olean` through the
`allRealizations` fallback of `Environment.find?`, which returns the
private constant info, so the theorem was exported together with its
proof. `mkModuleData` and the exported-level filters of attributes,
instances, matcher info, `MapDeclarationExtension`s, and the axiom
extension now consider only constants known on the main environment
branch.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Rob23oba pushed a commit to Rob23oba/lean4 that referenced this pull request Nov 20, 2026
…r#16623)

This PR stops a `module` from exporting constants such as `foo.eq_1`
when they were realized only inside a proof, so that such proofs no
longer trigger downstream rebuilds. Importing modules realize these
constants again on demand.

Previously, such a constant reached the exported `.olean` through the
`allRealizations` fallback of `Environment.find?`, which returns the
private constant info, so the theorem was exported together with its
proof. `mkModuleData` and the exported-level filters of attributes,
instances, matcher info, `MapDeclarationExtension`s, and the axiom
extension now consider only constants known on the main environment
branch.

This re-applies leanprover#15559, which was reverted in leanprover#15655 because `unfold` on
non-recursive definitions depended on the visibility of `eq_def`.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

downstream-force Force creation of 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.

1 participant