Skip to content

feat: restrict simpa using h close to reducible transparency#13636

Open
kim-em wants to merge 5 commits into
leanprover:masterfrom
kim-em:simpa-reducible-impl
Open

feat: restrict simpa using h close to reducible transparency#13636
kim-em wants to merge 5 commits into
leanprover:masterfrom
kim-em:simpa-reducible-impl

Conversation

@kim-em
Copy link
Copy Markdown
Collaborator

@kim-em kim-em commented May 5, 2026

This PR makes simpa using h close at reducible transparency rather than the ambient (default/semireducible) transparency used previously, making simpa using h more predictable under changes to the simp set. The previous behaviour is available as simpa using! h.

The new using! clause is introduced as a parallel simpaUsingBang syntax (registered as @[tactic_alt simpa]), so the existing simpa AST is unchanged and stage0 keeps building. ! here only affects the close-step match; it does not interact with the existing simpa! prefix (auto-unfolding in the simp set, analogous to simp!). The two modifiers can be combined: simpa! ... using! h.

Motivated by Jovan's point (1) in https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Mathlib.20code.20quality.3A.20simpa.

🤖 Prepared with Claude Code

@kim-em kim-em requested a review from digama0 as a code owner May 5, 2026 03:44
@kim-em kim-em added the changelog-tactics User facing tactics label May 5, 2026
@kim-em kim-em force-pushed the simpa-reducible-impl branch from d8a5f33 to ef196db Compare May 5, 2026 23:16
@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 May 6, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

mathlib-lean-pr-testing Bot commented May 6, 2026

Mathlib CI status (docs):

@leanprover-bot
Copy link
Copy Markdown
Collaborator

leanprover-bot commented May 6, 2026

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase ea6e76707835317858b7dd36c95322679c50aaac --onto 3fc99eef102549c743c6c63547983319bfae6f01. You can force reference manual CI using the force-manual-ci label. (2026-05-06 00:08:50)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-05-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-05-06 02:11:15)

This PR makes `simpa using h` require the simplified `h` and the simplified
goal to match at reducible transparency, rather than at the ambient
(default/semireducible) transparency used previously. This makes `simpa using h`
more predictable: it no longer succeeds via incidental β/δ-reduction at the
closing step, so adding new `simp` lemmas is less likely to silently break
unrelated `simpa` calls.

The new behaviour is gated by a backward-compat option
`backward.simpa.using.reducibleClose` (defaulting to `true`); set it to
`false` per-call, per-section, or globally to restore the previous
behaviour. Two existing in-tree tests (`getElemV.lean`, `scopeCacheProofs.lean`)
relied on the old behaviour; they are annotated with the option and an
explanatory comment so the breakage is visible.

The change wraps only the precondition `isDefEq` check inside `Lean.Elab.Tactic.Simpa.evalSimpa`.
The downstream metavariable-assignment check (`MVarId.checkedAssign` →
`checkTypesAndAssign`) still escalates transparency internally, but the
reducible-transparency precondition strictly dominates it, so the escalation
is benign.

Motivated by Floris's Zulip thread on `simpa` code quality:
https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Mathlib.20code.20quality.3A.20simpa

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kim-em kim-em force-pushed the simpa-reducible-impl branch from ef196db to e62206c Compare May 6, 2026 01:05
@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 May 6, 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 May 6, 2026
@kim-em
Copy link
Copy Markdown
Collaborator Author

kim-em commented May 6, 2026

I've asked for help fixing Mathlib in #mathlib4 > Mathlib code quality: simpa @ 💬.

…ackward option

This switches the opt-out for the new reducible-transparency close from a
`backward.simpa.using.reducibleClose` option to the existing `simpa!` form.
Users who need the previous default-transparency close write `simpa! using h`;
the `backward` option is removed.

Updates the two in-tree tests that previously used the option, and the
`simpa_reducible.lean` test to exercise the new `simpa!` form.

Per Johan's request in
https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Mathlib.20code.20quality.3A.20simpa.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request May 12, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request May 12, 2026
kim-em and others added 2 commits May 12, 2026 13:51
…lose

Replaces the prefix-`!` conflation (where `simpa!` would both auto-unfold the
simp set *and* close at default transparency) with a dedicated `using!`
clause that affects only the close step.

`simpa! using h` retains its existing meaning (auto-unfold during simp).
`simpa using! h` opts into the permissive default-transparency close.
The two can be combined as `simpa! ... using! h`.

The new tactic is introduced as a parallel syntax declaration `simpaUsingBang`
(`simpa ... using! e`) with its own elaborator that delegates to a shared
core. This keeps the existing `simpa` syntax tree unchanged so stage0 keeps
building.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…uniqueness

`tacticDocUserName.lean` checks that user-facing tactics have unambiguous
first tokens. Registering the new `simpaUsingBang` syntax as a `@[tactic_alt
simpa]` groups it with the canonical `simpa` for documentation purposes and
silences the ambiguity check.

The own docstring is removed (the `simpa` docstring already covers `using!`)
to satisfy the `linter.tactic.docsOnAlt` linter, which warns when an
alternative has its own documentation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request May 12, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request May 12, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request May 12, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request May 12, 2026
…ause

Adds parallel macro variants that accept a `simpaUsingBangArgsRest`, so
`simpa? using! h`, `simpa! ... using! h`, and `simpa?! ... using! h` all
parse correctly. Each variant is tagged `@[tactic_alt simpa]` to keep the
first-token uniqueness check happy.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request May 12, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request May 12, 2026
@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 May 13, 2026
@kim-em kim-em added this pull request to the merge queue May 13, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants