Skip to content

feat: add a check for impossible arguments in instance definitions - #13333

Closed
wkrozowski wants to merge 4 commits into
leanprover:masterfrom
wkrozowski:wojciech/impossibleInstance
Closed

wkrozowski wants to merge 4 commits into
leanprover:masterfrom
wkrozowski:wojciech/impossibleInstance

Conversation

@wkrozowski

@wkrozowski wkrozowski commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds a check in addInstance that detects arguments which cannot be inferred by the instance synthesis algorithm. Specifically, it flags arguments that are not instance-implicit and do not appear in any subsequent instance-implicit argument or in the return type. Previously, such instances would be silently accepted but could never be synthesised.

@wkrozowski wkrozowski added the changelog-language Language features and metaprograms label Apr 8, 2026
@wkrozowski

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Apr 8, 2026 •

Copy link
Copy Markdown

Benchmark results for ffa2210 against e44351a are in. Significant changes detected! @wkrozowski

  • 🟥 build exited with code 2
  • 🟥 other exited with code 2

No significant changes detected.

@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 8, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Apr 8, 2026 •

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 e44351add937efe4d286669ccd4c33023ca2e60e --onto 4f6bcc5adac8d6234a9e3def3675402cb89823c6. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-08 17:08:10)
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-04-09 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-09 13:45:21)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase d76e5a1886956bb38dc6bd2868260550dc66c309 --onto d53b46a0f3a7d0822550f4179ca3dab446a3c448. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-12 20:53:36)

@leanprover-bot

leanprover-bot commented Apr 8, 2026 •

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 e44351add937efe4d286669ccd4c33023ca2e60e --onto 861bc19e0c1c45b5766cc5c9ef0488568368b236. You can force reference manual CI using the force-manual-ci label. (2026-04-08 17:08:12)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-04-09 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-04-09 13:45:24)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase d76e5a1886956bb38dc6bd2868260550dc66c309 --onto 861bc19e0c1c45b5766cc5c9ef0488568368b236. You can force reference manual CI using the force-manual-ci label. (2026-04-12 20:53:37)

@wkrozowski
wkrozowski requested review from TwoFX and kim-em as code owners April 9, 2026 12:43
@wkrozowski wkrozowski added the awaiting-mathlib We should not merge this until we have a successful Mathlib build label Apr 9, 2026
@wkrozowski
wkrozowski force-pushed the wojciech/impossibleInstance branch from a6f9c3c to f1fff44 Compare April 12, 2026 19:55
@wkrozowski
wkrozowski force-pushed the wojciech/impossibleInstance branch from f1fff44 to 65112da Compare April 12, 2026 19:57
@wkrozowski
wkrozowski force-pushed the wojciech/impossibleInstance branch from 196ed10 to 65112da Compare April 13, 2026 11:12
@wkrozowski

Copy link
Copy Markdown
Contributor Author

Work continued in #13389

@wkrozowski wkrozowski closed this Apr 13, 2026
github-merge-queue Bot pushed a commit that referenced this pull request Apr 16, 2026
This PR adds two validation checks to `addInstance` that provide early
feedback for common mistakes in instance declarations:

1. **Non-class instance check**: errors when an instance target type is
not a type class. This catches the common mistake of writing `instance`
for a plain structure. Previously handled by the `nonClassInstance`
linter in Batteries (`Batteries.Tactic.Lint.TypeClass`), this is now
checked directly at declaration time.

2. **Impossible argument check**: errors when an instance has arguments
that cannot be inferred by instance synthesis. Specifically, it flags
arguments that are not instance-implicit and do not appear in any
subsequent instance-implicit argument or in the return type. Previously
such instances would be silently accepted but could never be
synthesised.

Supersedes #13237 and #13333.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-mathlib We should not merge this until we have a successful Mathlib build 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.

3 participants