fix: make delta-derived Prop-valued instances theorems#13304
Merged
Conversation
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>
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
Contributor
|
Nice! Though, we should avoid setting |
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>
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)
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 makes the delta-deriving handler create
theoremdeclarations instead ofdefdeclarations when the instance type is aProp. Previously,deriving instance Nonempty for Foowould always create adef, which is inconsistent with the behavior of a handwritteninstancedeclaration.For example, given:
Before:
@[implicit_reducible] def instNonemptyFoo ...After:
@[implicit_reducible] theorem instNonemptyFoo ...The implementation checks
isProp result.typeafter constructing the instance closure, and usesmkThmOrUnsafeDeffor 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