Skip to content

refactor: move inductive information in compiler from lazily filled local caches to eager persistent environment extensions#13882

Merged
Kha merged 2 commits into
leanprover:masterfrom
Kha:push-nuyxqomztlon
Jun 2, 2026
Merged

refactor: move inductive information in compiler from lazily filled local caches to eager persistent environment extensions#13882
Kha merged 2 commits into
leanprover:masterfrom
Kha:push-nuyxqomztlon

Conversation

@Kha
Copy link
Copy Markdown
Member

@Kha Kha commented May 29, 2026

This is in preparation for - and already enables in part - correctly compiling code using public types with private constructors and thus potentially inaccessible type references. A follow-up PR will have to further restrict the trivial structure optimization, which is the only case where even this early analysis can still lead to dangling references.

@Kha
Copy link
Copy Markdown
Member Author

Kha commented May 29, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented May 29, 2026

Benchmark results for 52e598e against c47a0c7 are in. There are significant results. @Kha

  • 🟥 build exited with code 1
  • 🟥 other exited with code 1

No significant changes detected.

@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 29, 2026
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-05-28 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-29 10:45:41)

@Kha Kha force-pushed the push-nuyxqomztlon branch from 52e598e to a9515da Compare May 29, 2026 11:21
@Kha
Copy link
Copy Markdown
Member Author

Kha commented May 29, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented May 29, 2026

Benchmark results for a9515da against c47a0c7 are in. There are significant results. @Kha

  • build//instructions: -4.4G (-0.04%)

Small changes (20✅, 4🟥)

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

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request May 29, 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 May 29, 2026
@Kha Kha force-pushed the push-nuyxqomztlon branch from a9515da to 6fae8d0 Compare May 29, 2026 12:57
@Kha Kha marked this pull request as ready for review May 29, 2026 12:57
@Kha Kha requested review from hargoniX and leodemoura as code owners May 29, 2026 12:57
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the builds-mathlib CI has verified that Mathlib builds against this PR label May 29, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

mathlib-lean-pr-testing Bot commented May 29, 2026

Mathlib CI status (docs):

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request May 29, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request May 29, 2026
This PR lets the compiler handle public types whose constructor field types are not available in
importing modules — for example a public structure with a `private` field whose type is only
privately imported. Compiling code that uses such a type in another module previously failed
because the compiler tried to inspect field types it could not see.

The LCNF representation information derived from constructor fields — trivial-structure info, mono
and impure types, and constructor layouts — is now computed and persisted in each inductive's
defining module and reused by importers instead of being recomputed there. Inductive types are
compiled eagerly (`compileInductives`) from `compileDecls`, and the information is stored in
`MapDeclarationExtension`s read by strict lookups.
@Kha Kha force-pushed the push-nuyxqomztlon branch from 6fae8d0 to 79779f6 Compare May 29, 2026 15:32
@Kha Kha changed the title feat: support compiling types with non-imported field types refactor: move inductive information in compiler from lazily filled local caches to eager persistent environment extensions May 29, 2026
@Kha
Copy link
Copy Markdown
Member Author

Kha commented May 29, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented May 29, 2026

Benchmark results for 79779f6 against c47a0c7 are in. There are significant results. @Kha

  • build//instructions: -9.8G (-0.09%)

Large changes (1🟥)

  • 🟥 size/all/.olean//bytes: +3MiB (+0.80%)

Medium changes (1🟥)

  • 🟥 size/Init/.olean//bytes: +399kiB (+0.42%)

Small changes (383✅, 45🟥)

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

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request May 29, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request May 29, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan and removed builds-mathlib CI has verified that Mathlib builds against this PR labels May 29, 2026
@Kha Kha force-pushed the push-nuyxqomztlon branch from 79779f6 to 6d690ec Compare June 1, 2026 15:03
This PR fixes a regression where compiling code that uses a `noncomputable` definition could fail
with an internal compiler error. `noncomputable` definitions reach `getOtherDeclMonoType` the same
way inductive types and constructors do — they have no LCNF code, so `getDecl?` returns `none` —
but they are not eagerly compiled, so the strict reader reported them as not compiled.

`getOtherDeclMonoType` now keeps the strict gap-detection only for inductive types and constructors
(which are eagerly compiled by `compileInductives`), and falls back to lazily computing the mono
type from the signature for any other no-LCNF-code declaration (`noncomputable` definitions, foreign
functions, opaques, ...), persisting it for declarations of the current module.
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jun 1, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jun 1, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Jun 1, 2026
@Kha
Copy link
Copy Markdown
Member Author

Kha commented Jun 1, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Jun 1, 2026

Benchmark results for 6d690ec against c47a0c7 are in. There are significant results. @Kha

  • build//instructions: -10.4G (-0.09%)

Large changes (1🟥)

  • 🟥 size/all/.olean//bytes: +3MiB (+0.80%)

Medium changes (1🟥)

  • 🟥 size/Init/.olean//bytes: +398kiB (+0.42%)

Small changes (383✅, 56🟥)

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

@Kha Kha force-pushed the push-nuyxqomztlon branch from 6d690ec to b13596b Compare June 2, 2026 08:17
@Kha
Copy link
Copy Markdown
Member Author

Kha commented Jun 2, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Jun 2, 2026

Benchmark results for b13596b against c47a0c7 are in. There are significant results. @Kha

  • build//instructions: -10.2G (-0.09%)

Large changes (1🟥)

  • 🟥 size/all/.olean//bytes: +3MiB (+0.80%)

Medium changes (1✅, 1🟥)

  • build/profile/compilation (LCNF mono)//wall-clock: -4s (-7.72%)
  • 🟥 size/Init/.olean//bytes: +399kiB (+0.42%)

Small changes (391✅, 43🟥)

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

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jun 2, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jun 2, 2026
@Kha Kha added this pull request to the merge queue Jun 2, 2026
Merged via the queue into leanprover:master with commit 03aeb71 Jun 2, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR 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.

3 participants