Skip to content

feat: allow overriding inductives in the compiler - #14626

Draft
Rob23oba wants to merge 22 commits into
leanprover:masterfrom
Rob23oba:inductive-override
Draft

Rob23oba wants to merge 22 commits into
leanprover:masterfrom
Rob23oba:inductive-override

Conversation

@Rob23oba

@Rob23oba Rob23oba commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

This PR changes the compiler to allow for overriding which types the compiler perceives as inductive types and which constructors it thinks they have. These overrides come in different forms:

First, you can mark an inductive type as a non-runtime inductive, i.e. override it to make the compiler see it as a simple type. As a consequence, all constructors, projections and matchers will become noncomputable by default. You can however reimplement them using csimp. This replaces the previous runtimeBuiltinTypes hardcoding: The types that were previously hardcoded now simply have the attribute @[override_runtime_type].

Second, you can change which declarations the compiler perceives as constructors of an inductive type or even make a non-inductive into an inductive type. The is now used to implement computed fields, but it can also be used for much more: In fact, I believe that you can implement everything mentioned in #9508 using this feature in a way that the compiler understands directly.

@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 Aug 1, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase bb3c22f9fb288c803f7d5ba96fec210976db65c5 --onto 5b8d06c1764fa367a1e27b3e89f64667eac425af. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-01 02:12:59)

@leanprover-bot

leanprover-bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase bb3c22f9fb288c803f7d5ba96fec210976db65c5 --onto a39eab69e1eee9ad38f4efe507907b1026a77808. You can force reference manual CI using the force-manual-ci label. (2026-08-01 02:13:00)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase bb3c22f9fb288c803f7d5ba96fec210976db65c5 --onto 23393b959b33e3a8d15796b2397f8a04c315b9f4. You can force reference manual CI using the force-manual-ci label. (2026-08-01 21:21:59)

@Rob23oba

Rob23oba commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Aug 3, 2026 •

Copy link
Copy Markdown

Benchmark results for 6d10b27 against bb3c22f are in. There are significant results. @Rob23oba

  • 🟥 build//instructions: +627.7G (+5.37%)

Large changes (6✅, 34🟥)

  • 🟥 build//task-clock: +2m 1s (+5.85%)
  • 🟥 build/module/Lean.Elab.Tactic.Omega.Frontend//instructions: +5.7G (+23.17%)
  • 🟥 build/module/Std.Data.DHashMap.Internal.RawLemmas//instructions: +42.1G (+16.93%)
  • 🟥 build/module/Std.Data.DHashMap.RawLemmas//instructions: +18.2G (+12.32%)
  • 🟥 build/module/Std.Data.DTreeMap.Internal.Lemmas//instructions: +12.8G (+5.79%)
  • 🟥 build/profile/compilation (LCNF mono)//wall-clock: +6s (+12.66%)
  • 🟥 build/profile/tactic execution//wall-clock: +1m 4s (+21.60%)
  • 🟥 compiled/parser//instructions: +605.0M (+1.76%)
  • ✅ elab/big_beq//instructions: -562.0M (-6.38%)
  • ✅ elab/big_beq//wall-clock: -62ms (-7.27%)
  • 🟥 elab/big_do//instructions: +1.5G (+8.15%)
  • 🟥 elab/big_match//instructions: +201.5M (+1.96%)
  • 🟥 elab/big_match_nat_split//instructions: +433.0M (+4.18%)
  • ✅ elab/big_match_partial//instructions: -419.0M (-3.05%)
  • 🟥 elab/big_struct_dep//instructions: +857.6M (+6.33%)
  • 🟥 elab/bv_stress_structures_2//instructions: +1.1G (+5.38%)
  • 🟥 elab/cbv_arm_ldst//instructions: +1.5G (+2.68%)
  • 🟥 elab/cbv_divisors//instructions: +1.2G (+2.46%)
  • 🟥 elab/cbv_leroy//instructions: +939.2M (+2.26%)
  • 🟥 elab/cbv_system_f//instructions: +2.2G (+2.14%)
  • and 19 more
  • and 1 hidden

Medium changes (9✅, 142🟥)

  • 🟥 build//wall-clock: +7s (+5.23%)
  • 🟥 build/lakeprof/longest rebuild path//instructions: +37.9G (+6.18%)
  • 🟥 build/module/Init.Data.Array.Lemmas//instructions: +1.6G (+2.84%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.BitVec.Bitblast//instructions: +1.9G (+3.59%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.BitVec.Lemmas//instructions: +3.4G (+2.80%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.Int.DivMod.Lemmas//instructions: +1.0G (+2.66%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.Iterators.Lemmas.Combinators.Monadic.FilterMap//instructions: +1.4G (+3.93%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.List.Lemmas//instructions: +1.1G (+2.83%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.Range.Polymorphic.Lemmas//instructions: +1.6G (+3.71%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.SInt.Lemmas//instructions: +2.2G (+3.86%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.String.Lemmas.Pattern.String.ForwardSearcher//instructions: +1.4G (+7.03%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.UInt.Lemmas//instructions: +3.8G (+7.22%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.Vector.Lemmas//instructions: +1.2G (+2.76%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Grind.Ring.CommSolver//instructions: +1.7G (+4.84%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Notation//instructions: +1.0G (+6.66%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Tactics//instructions: +1.0G (+9.03%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Lake.Build.Common//instructions: +1.2G (+5.94%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Lake.Build.Module//instructions: +2.7G (+6.24%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Lake.CLI.Main//instructions: +2.4G (+7.42%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Lake.CLI.Translate.Lean//instructions: +1.3G (+9.15%) (reduced significance based on absolute threshold)
  • and 131 more

Small changes (35✅, 1823🟥)

  • 🟥 build/lakeprof/longest build path//wall-clock: +10s (+7.33%)
  • 🟥 build/module/Init.BinderPredicates//instructions: +125.4M (+5.90%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.ByCases//instructions: +23.8M (+3.04%)
  • 🟥 build/module/Init.CbvSimproc//instructions: +134.7M (+6.43%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Classical//instructions: +12.5M (+1.16%)
  • 🟥 build/module/Init.Coe//instructions: +16.3M (+2.37%)
  • 🟥 build/module/Init.Control.Basic//instructions: +105.5M (+4.87%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.EState//instructions: +10.0M (+1.45%)
  • 🟥 build/module/Init.Control.Except//instructions: +51.1M (+3.69%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.ExceptCps//instructions: +28.4M (+2.61%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.Basic//instructions: +49.2M (+2.29%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.Instances//instructions: +203.2M (+2.97%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadAttach.Instances//instructions: +29.6M (+1.86%)
  • 🟥 build/module/Init.Control.Lawful.MonadLift.Instances//instructions: +21.2M (+1.82%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Option//instructions: +24.2M (+2.81%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.State//instructions: +38.3M (+3.52%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.StateCps//instructions: +24.7M (+2.45%)
  • 🟥 build/module/Init.Control.StateRef//instructions: +20.9M (+2.30%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Conv//instructions: +338.7M (+9.05%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Core//instructions: +158.0M (+1.60%) (reduced significance based on absolute threshold)
  • and 1838 more

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants