Skip to content

fix: make delta-derived Prop-valued instances theorems#13304

Merged
kim-em merged 2 commits intomasterfrom
issue-13295
Apr 8, 2026
Merged

fix: make delta-derived Prop-valued instances theorems#13304
kim-em merged 2 commits intomasterfrom
issue-13295

Conversation

@kim-em
Copy link
Copy Markdown
Collaborator

@kim-em kim-em commented Apr 7, 2026

This PR makes the delta-deriving handler create theorem declarations instead of def declarations when the instance type is a Prop. Previously, deriving instance Nonempty for Foo would always create a def, which is inconsistent with the behavior of a handwritten instance declaration.

For example, given:

def Foo (α : Type u) := List α
deriving instance Nonempty for Foo

Before: @[implicit_reducible] def instNonemptyFoo ...
After: @[implicit_reducible] theorem instNonemptyFoo ...

The implementation checks isProp result.type after constructing the instance closure, and uses mkThmOrUnsafeDef for the Prop case (which also handles the unsafe fallback correctly). The noncomputable check is skipped for Prop-typed instances since theorems can freely reference noncomputable constants.

Closes #13295

🤖 Prepared with Claude Code

This PR makes the delta-deriving handler create `theorem` declarations
instead of `def` declarations when the instance type is a `Prop`.
Previously, `deriving instance Nonempty for Foo` would always create a
`def`, which is inconsistent with the behavior of a handwritten
`instance` declaration.

Closes #13295

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kim-em kim-em added the changelog-language Language features and metaprograms label Apr 7, 2026
@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 Apr 7, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase ec727859274c18a82f26dd66028e36f380fdd35c --onto 4f6bcc5adac8d6234a9e3def3675402cb89823c6. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-07 13:40:07)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase ec727859274c18a82f26dd66028e36f380fdd35c --onto 861bc19e0c1c45b5766cc5c9ef0488568368b236. You can force reference manual CI using the force-manual-ci label. (2026-04-07 13:40:08)

@thorimur
Copy link
Copy Markdown
Contributor

thorimur commented Apr 7, 2026

Nice! Though, we should avoid setting @[implicit_reducible] on theorems, right? Or at least, the frontend prevents me from doing so; if we need to do it anyway here, a comment would be useful! :)

Address review feedback: skip setting `@[implicit_reducible]` on
Prop-valued instances (theorems), matching the behavior of the
handwritten `instance` command in `MutualDef.lean`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kim-em kim-em added this pull request to the merge queue Apr 8, 2026
Merged via the queue into master with commit 30dca7b Apr 8, 2026
25 checks passed
github-actions bot pushed a commit that referenced this pull request Apr 8, 2026
This PR makes the delta-deriving handler create `theorem` declarations
instead of `def` declarations when the instance type is a `Prop`.
Previously, `deriving instance Nonempty for Foo` would always create a
`def`, which is inconsistent with the behavior of a handwritten
`instance` declaration.

For example, given:
```lean
def Foo (α : Type u) := List α
deriving instance Nonempty for Foo
```

Before: `@[implicit_reducible] def instNonemptyFoo ...`
After: `@[implicit_reducible] theorem instNonemptyFoo ...`

The implementation checks `isProp result.type` after constructing the
instance closure, and uses `mkThmOrUnsafeDef` for the Prop case (which
also handles the unsafe fallback correctly). The noncomputable check is
skipped for Prop-typed instances since theorems can freely reference
noncomputable constants.

Closes #13295

🤖 Prepared with Claude Code

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
(cherry picked from commit 30dca7b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport releases/v4.30.0 changelog-language Language features and metaprograms 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.

Delta-derived instances are never theorems, even when Prop-typed

3 participants