Skip to content

feat: add linter for simp arguments triggering TC synthesis at every subterm - #14677

Open
sgraf812 wants to merge 1 commit into
leanprover:masterfrom
sgraf812:blanket-simp-args
Open

feat: add linter for simp arguments triggering TC synthesis at every subterm#14677
sgraf812 wants to merge 1 commit into
leanprover:masterfrom
sgraf812:blanket-simp-args

Conversation

@sgraf812

@sgraf812 sgraf812 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

This PR adds the linter.blanketSimpArgs linter, which warns about a simp argument whose left-hand side is a variable, such as eq_zero {α} [OfNat α 0] [Subsingleton α] (a : α) : a = 0. Such an argument is tried at every subterm and synthesizes its instances at each match, which can dominate the elaboration time of a proof; the warning suggests determining those instances at the use site instead, by fixing the implicit arguments or applying the theorem to a term.

The check runs where simp arguments are elaborated. See also leanprover-community/mathlib4#42056, where this linter was first proposed and rejected because of its overhead. Hooking directly into the elaborator is much more efficient, by contrast.

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

mathlib-lean-pr-testing Bot commented Aug 4, 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 8c72ff8f5b13625c7add73b69139e8ca68edc1c1 --onto 110db9cb751afaee8b2ac344887d6c7e632f77b4. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-04 16:44:12)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 8c72ff8f5b13625c7add73b69139e8ca68edc1c1 --onto 945e78b86645b179655123cd2fdba83d89d28d07. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-05 08:43:33)
  • 💥 Mathlib branch lean-pr-testing-14677 build failed against this PR. (2026-08-05 11:07:36) View Log
  • 💥 Mathlib branch lean-pr-testing-14677 build failed against this PR. (2026-08-05 12:05:47) View Log
  • ❌ Mathlib branch lean-pr-testing-14677 built against this PR, but the counterexamples library failed. (2026-08-05 12:58:23) View Log
  • ✅ Mathlib branch lean-pr-testing-14677 has successfully built against this PR. (2026-08-05 13:13:55) View Log

@leanprover-bot

leanprover-bot commented Aug 4, 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 8c72ff8f5b13625c7add73b69139e8ca68edc1c1 --onto 23393b959b33e3a8d15796b2397f8a04c315b9f4. You can force reference manual CI using the force-manual-ci label. (2026-08-04 16:44:13)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-08-04 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-08-05 10:19:49)

@sgraf812
sgraf812 force-pushed the blanket-simp-args branch from 1eb4e3e to 33ac19b Compare August 4, 2026 17:12
@sgraf812 sgraf812 changed the title feat: linter for simp arguments that rewrite a bare variable feat: linter for simp arguments retrieved at every subterm Aug 4, 2026
@sgraf812
sgraf812 force-pushed the blanket-simp-args branch 5 times, most recently from 4afad45 to e9d6b09 Compare August 5, 2026 08:39
@sgraf812 sgraf812 added the changelog-tactics User facing tactics label Aug 5, 2026
@sgraf812 sgraf812 changed the title feat: linter for simp arguments retrieved at every subterm feat: add linter for simp arguments retrieved at every subterm Aug 5, 2026
@sgraf812 sgraf812 changed the title feat: add linter for simp arguments retrieved at every subterm feat: add linter for simp arguments trigerring discharge at every subterm Aug 5, 2026
@sgraf812
sgraf812 force-pushed the blanket-simp-args branch from e9d6b09 to ae5ae9a Compare August 5, 2026 09:49
@sgraf812 sgraf812 changed the title feat: add linter for simp arguments trigerring discharge at every subterm feat: add linter for simp arguments triggering synthesis at every subterm Aug 5, 2026
@sgraf812 sgraf812 changed the title feat: add linter for simp arguments triggering synthesis at every subterm feat: add linter for simp arguments triggering TC synthesis at every subterm Aug 5, 2026
This PR adds the `linter.blanketSimpArgs` linter, which warns about a `simp` argument whose left-hand side is a variable, such as `eq_zero {α} [Zero α] [Subsingleton α] (a : α) : a = 0`. Such an argument is tried at every subterm and synthesizes its instances at each match, which can dominate the elaboration time of a proof; the warning suggests determining those instances at the use site instead, by fixing the implicit arguments or applying the theorem to a term.

The check runs where `simp` arguments are elaborated.
@sgraf812
sgraf812 force-pushed the blanket-simp-args branch from ae5ae9a to c2dcaeb Compare August 5, 2026 09:54
@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Aug 5, 2026
@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 5, 2026
@sgraf812

sgraf812 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Aug 5, 2026

Copy link
Copy Markdown

Benchmark results for c2dcaeb against 945e78b are in. No significant results found. @sgraf812

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

Small changes (2✅, 3🟥)

  • build/module/Init.Data.Int.DivMod.Lemmas//instructions: -531.7M (-1.37%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Lean.Elab.Tactic.Simp//instructions: +522.2M (+2.80%) (reduced significance based on *//lines)
  • 🟥 compiled/ilean_roundtrip//maxrss: +4MiB (+0.77%)
  • compiled/rbmap_fbip//maxrss: -348kiB (-0.34%)
  • 🟥 vcgen/MatchIota/500/vcgen//wall-clock: +4ms (+5.74%)

sgraf812 added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Aug 5, 2026
Pin `Unique.eq_default` to the type being collapsed at the eight sites that
`linter.blanketSimpArgs` reports. Its left-hand side is a variable of
variable type, so `simp` matched it at every subterm and synthesized
`Unique` at each match.
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Aug 5, 2026
@sgraf812

sgraf812 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

!bench mathlib

@leanprover-radar

leanprover-radar commented Aug 5, 2026

Copy link
Copy Markdown

Benchmark results for leanprover-community/mathlib4-nightly-testing@657fe2a against leanprover-community/mathlib4-nightly-testing@3e9b868 are in. No significant results found. @sgraf812

  • build//instructions: -22.1G (-0.02%)

Small changes (1✅)

  • build/module/Mathlib.RepresentationTheory.Homological.TateCohomology.Basic//instructions: -2.5G (-10.69%)

@sgraf812
sgraf812 marked this pull request as ready for review August 5, 2026 13:57
@sgraf812
sgraf812 requested a review from kim-em as a code owner August 5, 2026 13:57
@sgraf812 sgraf812 added the awaiting-review Waiting for someone to review the PR label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review Waiting for someone to review the PR builds-mathlib CI has verified that Mathlib builds against this PR changelog-tactics User facing tactics 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants