feat: use explicit allowlist instead of transparency bump in whnfMatcher#13363
Open
nomeata wants to merge 21 commits intonightly-with-mathlibfrom
Open
feat: use explicit allowlist instead of transparency bump in whnfMatcher#13363nomeata wants to merge 21 commits intonightly-with-mathlibfrom
nomeata wants to merge 21 commits intonightly-with-mathlibfrom
Conversation
Previously, `whnfMatcher` would increase the transparency from `.reducible` to `.instances` when reducing match expressions. This caused surprising over-unfolding when `implicit_reducible` definitions appeared in match discriminants, as reported in the discussion around `whnfMatcher`'s TODO comment. This PR removes the `withTransparency .instances` call so that `whnfMatcher` now runs at the ambient transparency. To ensure match discriminants involving class projections (e.g. `OfNat.ofNat`, `NatCast.natCast`, `Pure.pure`) still reduce to expose constructors, `canUnfoldAtMatcher` now allows unfolding any class projection (`projInfo.fromClass`). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
|
Reference manual CI status:
|
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 10, 2026
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 10, 2026
|
Mathlib CI status (docs):
|
…fMatcher` Replace the `implicitReducible` and `fromClass` checks in `canUnfoldAtMatcher` with an explicit allowlist of class projections and instances. Delegate to `canUnfoldDefault` first so that `withCanUnfoldPred` does not accidentally block sub-calls at different transparencies. This ensures that marking more definitions as `implicit_reducible` in the future will not silently change which terms get unfolded in match discriminants. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 13, 2026
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 13, 2026
|
Mathlib CI status (docs):
|
Remove entries that are not needed for tests or stage 2 to pass: Std.Stream.next?, MonadStateOf.get, MonadState.get, Bind.bind, Ord.compare, LT.lt, LE.le, HAppend.hAppend, Append.append, GetElem?.getElem?, BEq.beq, HSub.hSub, Sub.sub, HMod.hMod, Mod.mod. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove: instDecidableEqBool, instBEqOfDecidableEq, String.decEq, List.hasDecEq, Char.ofNat, Char.ofNatAux. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…` allowlist Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Nat.add → instAddNat → instHAdd chain is not needed because these definitions are already handled by canUnfoldDefault or matchPattern attributes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…eeded Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use `Nat.decEq` (which is reducible) directly instead of the generic `decEq` (which is semireducible) when comparing constructor indices in derived BEq instances. This removes the need for `decEq`, `instDecidableEqNat`, and `Nat.decEq` in the `canUnfoldAtMatcher` allowlist. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The `unfold` tactic no longer over-unfolds `2 * x` to `Nat.mul 2 x` in match discriminants. Update `unfold1` test expected output accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 13, 2026
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 13, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
.instances in whnfMatcher
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 13, 2026
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 13, 2026
|
Mathlib CI status (docs):
|
f78cd68 to
d76e5a1
Compare
Fin literals like `(1 : Fin 4)` need `Fin.ofNat` to unfold in match discriminants so the match can reduce to constructor form. This is needed for Fin-indexed category theory (e.g. ComposableArrows). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 14, 2026
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 14, 2026
|
Mathlib CI status (docs):
|
…tcher Add `HMod.hMod` and `Mod.mod` to the `canUnfoldAtMatcher` allowlist. These are needed because `Fin.ofNat` reduces to `⟨a % n, _⟩`, so the modulo operator must also unfold to expose the `Fin.mk` constructor in match discriminants. Also add `consumeMData` calls in `reduceMatcher?` and `reduceRecMatcher?` to handle mdata-wrapped matcher expressions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Mathlib CI status (docs):
|
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 15, 2026
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 15, 2026
|
Mathlib CI status (docs):
|
Restore explicit allowlist entries that were on master (decEq, Nat.decEq, Char.ofNat, String.decEq, UInt*.ofNat, UInt*.decEq, etc.) to minimize downstream mathlib adaptation. These entries are not affected by the core change (removing the transparency bump and fromClass/implicitReducible checks). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Mathlib CI status (docs):
|
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 15, 2026
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 15, 2026
|
Mathlib CI status (docs):
|
|
Mathlib CI status (docs):
|
|
Mathlib CI status (docs):
|
|
Mathlib CI status (docs):
|
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 replaces the transparency bump from
.reducibleto.instancesinwhnfMatcherwith an explicit allowlist incanUnfoldAtMatcher. Previously,whnfMatcherwould unfold allimplicitReducibledefinitions and allfromClassprojections when reducing match discriminants. This made it impossible to mark definitions asimplicit_reduciblewithout silently affecting match reduction behavior.The new
canUnfoldAtMatcherdelegates tocanUnfoldDefaultfirst (respecting the ambient transparency), then allows unfolding ofmatch_pattern-attributed definitions, and finally checks an explicit allowlist:OfNat.ofNat— numeric literals in match discriminantsNatCast.natCast—↑mcoercions (pervasive in Int proofs)Fin.ofNat,HMod.hMod,Mod.mod— Fin literal reductiondecEq,Nat.decEq— decidable equalityChar.ofNat,Char.ofNatAux— character literalsString.decEq,List.hasDecEq— string/list equalityUInt{8,16,32,64}.{ofNat,decEq}— unsigned integer literals and equalityThe key change is removing the blanket
implicitReducibleandfromClasschecks, so that marking definitions asimplicit_reducibleno longer silently affects match reduction.Additionally,
reduceMatcher?andreduceRecMatcher?now callconsumeMDataon their input to handle mdata-wrapped matcher expressions.Derived BEq instances now use
Nat.decEqinstead of genericdecEqfor constructor index comparison (extracted to separate PR #13390).Mathlib adaptation: the removal of the
fromClassprojection check means class projections likeCategoryStruct.comp,CategoryStruct.id,Stream.next?,One.oneetc. are no longer auto-unfolded in match discriminants. Affected proofs add these projections explicitly tosimp/dsimpcalls.