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 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 previous behaviour remains available via simpa using! h — the ! is attached to the using clause, indicating that the close-step match should use the ambient transparency. ! here is purely about close transparency; it does not interact with the existing simpa! prefix (which enables auto-unfolding in the simp set, analogous to simp!). Both modifiers can be combined: simpa! ... using! h.

simpa ... using! e is introduced as a parallel syntax declaration (simpaUsingBang) so the existing simpa AST is unchanged. This keeps the stage0 bootstrap intact — no files in Init/Std need using!.

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

This addresses Jovan's point (1) of the proposal in https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Mathlib.20code.20quality.3A.20simpa, narrowing what simpa can do without the broader behaviour change of also using h as a simp lemma. The PR is branched from nightly-with-mathlib so Mathlib breakage data can be gathered via the existing nightly-testing infrastructure.

🤖 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan 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