feat: split [implicit_reducible] into [instance_reducible] and [implicit_reducible] tiers#13637
Draft
kim-em wants to merge 3 commits intoleanprover:masterfrom
Draft
feat: split [implicit_reducible] into [instance_reducible] and [implicit_reducible] tiers#13637kim-em wants to merge 3 commits intoleanprover:masterfrom
[implicit_reducible] into [instance_reducible] and [implicit_reducible] tiers#13637kim-em wants to merge 3 commits intoleanprover:masterfrom
Conversation
a01b081 to
eb9aefb
Compare
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
9aa2ab2 to
391ecb2
Compare
…implicit_reducible]` tiers This PR splits `TransparencyMode.instances` and `ReducibilityStatus.implicitReducible` into two tiers so that user-written `@[implicit_reducible]` annotations no longer "corrupt" type class search. The transparency hierarchy is now `none < reducible < instances < implicit < default < all`: - `.instances` (TC tier, semantically narrowed): unfolds `[reducible]` and the new `[instance_reducible]` constants. Used during type class synthesis. - `.implicit` (new tier): also unfolds user-written `[implicit_reducible]`. Used when checking definitional equality of implicit value arguments. Correspondingly, `ReducibilityStatus` gains `instanceReducible`. The `instance` command, mutual data-instance defaults, subobject class projections, and match auxiliaries auto-stamp `.instanceReducible`. The user-facing `@[instance_reducible]` attribute (formerly an alias for `@[implicit_reducible]`) is repurposed to set this status; an `instance_reducible -> implicit_reducible` upgrade transition is allowed. Existing core constants previously tagged `@[implicit_reducible]` (e.g. `Nat.add`, `Array.size`, `maxOfLe`/`minOfLe`, integer comparisons, ring auxiliaries, well-founded relations) have been migrated to `@[instance_reducible]` to preserve TC behavior. Mathlib can now use the narrower `@[implicit_reducible]` for functors etc. without affecting type class search. The `withImplicitConfig` helper is split into `withInstanceConfig` (TC-tier) and `withImplicitConfig` (implicit-arg-defeq tier). Per-site callers route to the appropriate tier. Sites previously using `isImplicitReducible` as a proxy for "is an instance / support symbol" now use the new `isInstanceReducible` predicate. The transparency bit-packing in `Config.toKey` has been widened from 2 bits to 3 bits. `TransparencyMode.implicit` is appended at the end of the inductive (out of unfolding order) to preserve existing constructor indices. A new regression test in `tests/elab/splitImplicitReducible.lean` pins the new contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
dcb7fcb to
9d13618
Compare
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
May 8, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
May 8, 2026
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 splits
TransparencyMode.instancesandReducibilityStatus.implicitReducibleinto two tiers so that user-written@[implicit_reducible]annotations no longer "corrupt" type class search.The transparency hierarchy is now
none < reducible < instances < implicit < default < all:.instances(TC tier, semantically narrowed): unfolds[reducible]and the new[instance_reducible]constants. Used during type class synthesis..implicit(new tier): also unfolds user-written[implicit_reducible]. Used when checking definitional equality of implicit value arguments.ReducibilityStatuscorrespondingly gainsinstanceReducible. Theinstancecommand, mutual data-instance defaults, and subobject class projections auto-stamp.instanceReducible. Match auxiliaries are also.instanceReducibleso type class synthesis can unfold them. The user-facing@[instance_reducible]attribute (formerly an alias for@[implicit_reducible]) is repurposed to set this status; aninstance_reducible -> implicit_reducibleupgrade transition is allowed for users who want both tiers.Existing core constants previously tagged
@[implicit_reducible](e.g.Nat.add,Array.size,maxOfLe/minOfLe, integer comparisons, ring auxiliaries, well-founded relations) have been migrated to@[instance_reducible]to preserve TC behavior. Mathlib can now use the narrower@[implicit_reducible]for functors etc. without affecting type class search.The
withImplicitConfighelper is split intowithInstanceConfig(TC-tier) andwithImplicitConfig(implicit-arg-defeq tier). Per-site callers route to the appropriate tier: instance-implicit[..]arguments and class-projection struct args usewithInstanceConfig; other implicit args underimplicitBumpandcheckTypesAndAssignusewithImplicitConfig. The@[defeq]rfl simp-theorem admission check moves to.implicitto match the broader contract simp uses;Generalize.kabstractandreduceCtorEqsimilarly use.implicitto preserve their pre-split behavior.Sites previously using
isImplicitReducibleas a proxy for "is an instance / support symbol" (grind MBTC, grind Internalize, simp/grind locals filters, library suggestions, dup-namespace linter, several LCNF heuristics) now use the newisInstanceReduciblepredicate, which is a precise tag post-split.The transparency bit-packing in
Config.toKeyhas been widened from 2 bits to 3 bits to accommodate the sixth constructor; all subsequent field offsets shift by 1.TransparencyMode.implicitis appended at the end of the inductive (out of unfolding order) to preserve existing constructor indices, matching the existing convention noted onTransparencyMode(constructors are not in unfolding order to avoid bootstrapping pain).A new regression test in
tests/elab/splitImplicitReducible.leanpins the new contract.🤖 Prepared with Claude Code