Skip to content

fix: make theorems opaque to the kernel as well - #14896

Merged
nomeata merged 10 commits into
masterfrom
joachim/kernel-thms-opaque
Nov 23, 2026
Merged

nomeata merged 10 commits into
masterfrom
joachim/kernel-thms-opaque

Conversation

@nomeata

@nomeata nomeata commented Aug 23, 2026 •

Copy link
Copy Markdown
Collaborator

This PR completes #12973: theorems are now opaque to the kernel as well, which until now would still delta-reduce them. The value of a theorem no longer affects whether a declaration type-checks, so conflicting theorem declarations of the same type can no longer make type checking depend on import order.

The Lean-side ConstantInfo.hasValue was already adjusted in #12973, but the kernel consults the C++ constant_info::has_value, which was missed. That is what type_checker::is_delta looks at, so the kernel's whnf still unfolded theorems even though the elaborator refused to.

has_constructor in src/library/util.cpp switches to an explicit is_constructor check, so it no longer piggybacks on has_value.

This is part of the kernel renovation #14977.

@nomeata
nomeata marked this pull request as ready for review August 23, 2026 07:43
@nomeata
nomeata requested a review from leodemoura as a code owner August 23, 2026 07:43
@nomeata nomeata added the awaiting-mathlib We should not merge this until we have a successful Mathlib build label Aug 23, 2026
@github-actions github-actions Bot added toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN labels Aug 23, 2026
@leanprover-bot leanprover-bot added the builds-manual CI has verified that the Lean Language Reference builds against this PR label Aug 23, 2026
@leanprover-bot

leanprover-bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ✅ Reference manual branch lean-pr-testing-14896 has successfully built against this PR. (2026-08-23 08:11:25) View Log
  • 🟡 Reference manual branch lean-pr-testing-14896 build against this PR didn't complete normally. (2026-08-23 08:12:15) View Log
  • ✅ Reference manual branch lean-pr-testing-14896 has successfully built against this PR. (2026-08-23 10:31:47) View Log
  • 🟡 Reference manual branch lean-pr-testing-14896 build against this PR didn't complete normally. (2026-08-23 10:32:40) View Log
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 47680c2e62831da4daa01abe567b3e4fc509fbae --onto 16e77c407779fde9a649adf3478204d1915371a3. You can force reference manual CI using the force-manual-ci label. (2026-08-23 13:25:48)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 0dc10a41e6be57ef72d7f103c98c263620076b6c --onto 16e77c407779fde9a649adf3478204d1915371a3. You can force reference manual CI using the force-manual-ci label. (2026-08-25 11:47:19)

@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Aug 23, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
  • 💥 Mathlib branch lean-pr-testing-14896 build failed against this PR. (2026-08-23 08:32:57) View Log
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 47680c2e62831da4daa01abe567b3e4fc509fbae --onto 16e77c407779fde9a649adf3478204d1915371a3. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-23 13:25:47)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 47680c2e62831da4daa01abe567b3e4fc509fbae --onto fd0efc4306a7773c2cd4e079ddaa907426d0f5da. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-25 10:30:47)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 0dc10a41e6be57ef72d7f103c98c263620076b6c --onto fd0efc4306a7773c2cd4e079ddaa907426d0f5da. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-25 11:47:17)

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Aug 23, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Aug 23, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Aug 23, 2026
@nomeata nomeata added the changelog-language Language features and metaprograms label Aug 23, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed awaiting-mathlib We should not merge this until we have a successful Mathlib build breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Aug 23, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

@nomeata
nomeata enabled auto-merge August 23, 2026 13:00
@nomeata
nomeata disabled auto-merge August 23, 2026 13:27
@nomeata
nomeata marked this pull request as draft August 23, 2026 17:36
@nomeata

nomeata commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator Author

This is ready to go and painless, it seems. But I’m inclined to bundle it with other kernel logic changes, else the coordination on the arena becomes a mess.

@nomeata

nomeata commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator Author

!perf

nomeata and others added 3 commits August 25, 2026 09:46
This PR completes #12973: theorems are now also opaque to the kernel, which until now would still delta-reduce them. So the value of a theorem no longer affects whether a declaration type-checks, and conflicting theorem declarations with the same type can no longer make type checking depend on import order.

The `Lean`-side `ConstantInfo.hasValue` was already adjusted in #12973, but the kernel uses the C++ `constant_info::has_value`, which was missed. That is what `type_checker::is_delta` consults, so `Acc.rec` applications, for instance, still reduced through theorem proofs in the kernel even though the elaborator refused to.

Also switches `has_constructor` in `src/library/util.cpp` to an explicit `is_constructor` check, so it no longer piggybacks on `has_value`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01XzL163q5FYpbZmT8EHQb3j
This PR makes `casesOn` and `recOn` of a proposition apply the minor premise to the projections of the major premise, instead of going through the recursor. A recursor only reduces once its major premise is a constructor application, which a proof may never become, so `And.casesOn` and friends no longer require the proof itself to reduce.

This matters for proofs that `abstractNestedProofs` has moved into auxiliary theorems, whose values are not available for reduction: the module system does not expose them outside their defining module, and theorems are opaque. An abstracted proof of an `And` that is stored in a `Subtype` and later pattern-matched, or eliminated into data directly, otherwise makes the enclosing definition ill-typed.

`Lean.mkCasesOnViaProjs?` applies to a proposition with a single constructor, no indices and no recursion, whose recursor supports large elimination. Large elimination forces every field to be a proof, which is what makes the projections available, since projecting data out of a proposition is what `Exists` may not do. The minor premise expects the fields of `I.mk x₁ … xₙ` rather than those of the major premise, but both are proofs of the same proposition, so proof irrelevance identifies them.

`tests/elab_fail/etaStructIssue.lean` moves to `tests/elab`: both of its sides now reduce to `mkNat e` applied to a proof of `F e`, which proof irrelevance identifies, and the elaborator and the kernel agree on that.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01XzL163q5FYpbZmT8EHQb3j
Passed inline, these proofs are abstracted into theorems, which the kernel
no longer unfolds, so `Acc.rec` gets stuck on them and the test's defeq gate
fails before it reaches its actual assertion.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01M5jcJjLLjxhiAueieK4KEj
@nomeata
nomeata force-pushed the joachim/kernel-thms-opaque branch from 8da35e5 to cec8033 Compare August 25, 2026 09:55
@nomeata
nomeata changed the base branch from master to joachim/prop-casesOn-projections August 25, 2026 09:55
@nomeata

nomeata commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator Author

!bench

@leanprover-radar

leanprover-radar commented Aug 25, 2026 •

Copy link
Copy Markdown

Benchmark results for cec8033 against 8f5e057 are in. No significant results found. @nomeata

  • 🟥 build//instructions: +892.3M (+0.01%)

Small changes (2✅, 1🟥)

  • ✅ elab/bv_decide_mul//wall-clock: -74ms (-3.14%)
  • 🟥 elab/bv_decide_realworld//instructions: +485.0M (+1.01%)
  • ✅ elab/cbv_arm_ldst//instructions: -163.2M (-0.30%)

nomeata and others added 2 commits August 25, 2026 11:02
Replaces the inline level-parameter comparison with the predicate from #14909, which documents the extra-motive-universe encoding at its own definition.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GSbnoYQjyFAGmX75t7snrX
@nomeata
nomeata changed the base branch from joachim/prop-casesOn-projections to master November 23, 2026 08:46
@nomeata nomeata removed builds-mathlib CI has verified that Mathlib builds against this PR builds-manual CI has verified that the Lean Language Reference builds against this PR mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN labels Nov 23, 2026
@nomeata nomeata mentioned this pull request Nov 23, 2026
7 of 12 tasks
@nomeata nomeata added the downstream Request a downstream-lean4 adaptation PR. label Nov 23, 2026
@nomeata
nomeata marked this pull request as ready for review November 23, 2026 09:26
…eKernel

Since #15371 the kernel does not whnf a major premise that is a proof, so the `def` proof variant is now rejected by the kernel too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 23, 2026
@nomeata
nomeata added this pull request to the merge queue Nov 23, 2026
@nomeata
nomeata removed this pull request from the merge queue due to a manual request Nov 23, 2026
@nomeata
nomeata added this pull request to the merge queue Nov 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 23, 2026
@nomeata
nomeata added this pull request to the merge queue Nov 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 23, 2026
nomeata and others added 2 commits November 23, 2026 13:24
Since #13851, `Acc.rec` no longer eliminates into `Type` and the kernel no longer reduces proofs in major premise position, so the test's `Acc` example no longer applies. Test kernel opacity of theorems directly via `Kernel.whnf`, and use a non-recursive, non-K, indexed Prop inductive for the recursor example.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nomeata
nomeata added this pull request to the merge queue Nov 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 23, 2026
@nomeata
nomeata enabled auto-merge November 23, 2026 14:20
@nomeata
nomeata added this pull request to the merge queue Nov 23, 2026
@downstream-lean4

Copy link
Copy Markdown

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

Merged via the queue into master with commit 6e59fcc Nov 23, 2026
21 checks passed
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 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.

3 participants