Skip to content

experiment: normalize instances in inferInstanceAs#12895

Closed
Kha wants to merge 33 commits intoleanprover:nightly-with-mathlibfrom
Kha:push-zpvupnppupvs
Closed

experiment: normalize instances in inferInstanceAs#12895
Kha wants to merge 33 commits intoleanprover:nightly-with-mathlibfrom
Kha:push-zpvupnppupvs

Conversation

@Kha
Copy link
Member

@Kha Kha commented Mar 12, 2026

@Kha
Copy link
Member Author

Kha commented Mar 12, 2026

!bench

@leanprover-radar
Copy link

leanprover-radar commented Mar 12, 2026

Benchmark results for 19f2533 against e804829 are in. Significant changes detected! @Kha

  • 🟥 build//instructions: +3.2T (+24.99%)

Large changes (151🟥)

Too many entries to display here. View the full report on radar instead.

Medium changes (2✅, 243🟥)

Too many entries to display here. View the full report on radar instead.

Small changes (13✅, 471🟥)

Too many entries to display here. View the full report on radar instead.

@Kha Kha changed the base branch from master to nightly-with-mathlib March 12, 2026 11:29
@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 Mar 12, 2026
@leanprover-bot
Copy link
Collaborator

leanprover-bot commented Mar 12, 2026

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-03-09 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-03-12 12:27:37)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-03-17 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-03-17 10:13:50)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-03-18 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-03-19 05:10:55)

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 12, 2026
@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 Mar 12, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 12, 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 Mar 12, 2026
@mathlib-lean-pr-testing
Copy link

mathlib-lean-pr-testing bot commented Mar 12, 2026

Mathlib CI status (docs):

  • 💥 Mathlib branch lean-pr-testing-12895 build failed against this PR. (2026-03-12 12:31:42) View Log
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-03-17 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-17 10:13:49)

@Kha Kha force-pushed the push-zpvupnppupvs branch from f7a410e to ed712ff Compare March 12, 2026 14:02
@Kha
Copy link
Member Author

Kha commented Mar 12, 2026

!bench

@leanprover-radar
Copy link

leanprover-radar commented Mar 12, 2026

Benchmark results for ed712ff against e804829 are in. There are no significant changes. @Kha

  • 🟥 build//instructions: +3.5G (+0.03%)

Small changes (11✅, 3🟥)

  • build/module/Init.Control.Lawful.MonadAttach.Instances//instructions: -17.4M (-1.32%)
  • build/module/Init.Control.StateRef//instructions: -10.3M (-1.56%)
  • build/module/Init.Data.Iterators.Lemmas.Combinators.Monadic.FilterMap//instructions: -154.1M (-0.33%)
  • build/module/Init.Data.List.MinMaxOn//instructions: -103.5M (-1.32%)
  • build/module/Init.Data.Order.MinMaxOn//instructions: -25.5M (-1.24%)
  • build/module/Init.Data.Order.Ord//instructions: -25.3M (-0.62%)
  • build/module/Lake.Build.Data//instructions: -29.7M (-0.76%)
  • 🟥 build/module/Lean.Elab.BuiltinTerm//instructions: +207.9M (+1.85%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Parser.Term//instructions: +122.5M (+0.71%)
  • build/module/Lean.Util.MonadCache//instructions: -27.2M (-2.26%)
  • build/module/Std.Data.Iterators.Lemmas.Combinators.Monadic.FilterMap//instructions: -93.6M (-1.73%) (reduced significance based on absolute threshold)
  • build/module/Std.Time.Time.Unit.Hour//instructions: -10.7M (-1.39%)
  • build/module/Std.Time.Time.Unit.Nanosecond//instructions: -14.7M (-1.58%)
  • 🟥 compiled/workspaceSymbolsNewRanges//instructions: +2.8M (+0.38%)

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 12, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 12, 2026
@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

@JovanGerb
Copy link
Contributor

I think it would be a bad idea to replace all instances with their synthesized instance, because it would lead to very confusing behaviour. You would get the following:

instance inst1 : A := X
instance inst2 : A := Y
#print inst2 -- value is `inst1`

I'm not saying it is a good idea to write multiple instances of A, but it is a common thing to do when testing.

@Kha
Copy link
Member Author

Kha commented Mar 12, 2026

Yes I limited the normalization to inferInstanceAs for now though it would still be nice to remove the need for fast_instance% as well. I'm not actually sure we want to run trySynthInstance in the general case instead of doing some more restricted "is this already an instance" check but for inferInstanceAs specifically it does seem to be the right thing to do.

@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

@Kha Kha changed the title experiment: transform all instances into instance normal form experiment: normalize instances in inferInstanceAs Mar 12, 2026
@Kha
Copy link
Member Author

Kha commented Mar 15, 2026

!bench

@leanprover-radar
Copy link

Benchmark results for ed712ff against e804829 are in. There are no significant changes. @Kha

  • 🟥 build//instructions: +3.5G (+0.03%)

Small changes (11✅, 3🟥)

  • build/module/Init.Control.Lawful.MonadAttach.Instances//instructions: -17.4M (-1.32%)
  • build/module/Init.Control.StateRef//instructions: -10.3M (-1.56%)
  • build/module/Init.Data.Iterators.Lemmas.Combinators.Monadic.FilterMap//instructions: -154.1M (-0.33%)
  • build/module/Init.Data.List.MinMaxOn//instructions: -103.5M (-1.32%)
  • build/module/Init.Data.Order.MinMaxOn//instructions: -25.5M (-1.24%)
  • build/module/Init.Data.Order.Ord//instructions: -25.3M (-0.62%)
  • build/module/Lake.Build.Data//instructions: -29.7M (-0.76%)
  • 🟥 build/module/Lean.Elab.BuiltinTerm//instructions: +207.9M (+1.85%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Parser.Term//instructions: +122.5M (+0.71%)
  • build/module/Lean.Util.MonadCache//instructions: -27.2M (-2.26%)
  • build/module/Std.Data.Iterators.Lemmas.Combinators.Monadic.FilterMap//instructions: -93.6M (-1.73%) (reduced significance based on absolute threshold)
  • build/module/Std.Time.Time.Unit.Hour//instructions: -10.7M (-1.39%)
  • build/module/Std.Time.Time.Unit.Nanosecond//instructions: -14.7M (-1.58%)
  • 🟥 compiled/workspaceSymbolsNewRanges//instructions: +2.8M (+0.38%)

@Kha Kha force-pushed the push-zpvupnppupvs branch from ed712ff to c1b6c35 Compare March 17, 2026 08:24
@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

@Kha Kha force-pushed the push-zpvupnppupvs branch from c1b6c35 to cb766bd Compare March 17, 2026 09:24
mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 17, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 17, 2026
kim-em and others added 3 commits March 19, 2026 03:38
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add three new options (all defaulting to false) for wrapping constructor
fields in auxiliary definitions to fix their types:
- instance.normalForm.wrapFields.proofs: wraps proof fields via mkAuxTheorem
- instance.normalForm.wrapFields.instances: wraps instance fields via
  mkAuxDefinition marked implicit_reducible
- instance.normalForm.wrapFields.data: wraps data fields via mkAuxDefinition

Also wrap the normalizeInstance call in withNewMCtxDepth to prevent
isDefEq side effects from leaking, matching the Mathlib fast_instance%
pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kim-em kim-em force-pushed the push-zpvupnppupvs branch from 84ed9ed to 5026406 Compare March 19, 2026 03:39
mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 19, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 19, 2026
@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 19, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 19, 2026
@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

Kha and others added 14 commits March 19, 2026 12:28
…alizeInstance

This PR passes `compile := false` when creating auxiliary definitions inside
`normalizeInstance` if the surrounding declaration is noncomputable or we are in
a noncomputable section, preventing spurious "Failed to find LCNF signature" errors.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Auxiliary definitions created by normalizeInstance in inferInstanceAs now
propagate sorry warnings from the instances they wrap.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Kha Kha force-pushed the push-zpvupnppupvs branch from d055c1a to eb7e509 Compare March 19, 2026 12:47
mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 19, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 19, 2026
@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

@Kha
Copy link
Member Author

Kha commented Mar 22, 2026

Superseded by #12897

@Kha Kha closed this Mar 22, 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 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.

5 participants