Skip to content

fix: universe normalization in getDecLevel#13391

Open
sgraf812 wants to merge 1 commit intomasterfrom
sg/fix-getDecLevel-normalize
Open

fix: universe normalization in getDecLevel#13391
sgraf812 wants to merge 1 commit intomasterfrom
sg/fix-getDecLevel-normalize

Conversation

@sgraf812
Copy link
Copy Markdown
Contributor

This PR adds level instantiation and normalization in getDecLevel and getDecLevel? before calling decLevel.

getLevel can return levels with uninstantiated metavariables or un-normalized structure, such as max ?u ?v where the metavariables have already been assigned. After instantiation and normalization (via normalizeLevel), a level like max ?u ?v (with ?u := 1, ?v := 0) simplifies to 1 = succ 0, which decLevel can decrement. Without this step, decLevel sees max ?u ?v, tries to decrement both arms, fails on a zero-valued arm, and reports "invalid universe level".

Concretely, this fixes for loops with mut variables of sort-polymorphic type (e.g. PProd Nat True) where the state tuple's universe level ends up as an uninstantiated max.

The expected-output change in doNotation1.lean is because the for loop's unit type now resolves to Unit instead of PUnit due to the improved level handling.

@sgraf812 sgraf812 force-pushed the sg/fix-getDecLevel-normalize branch from bb8e3ed to c992f58 Compare April 13, 2026 15:08
@sgraf812
Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Apr 13, 2026

Benchmark results for c992f58 against d76e5a1 are in. No significant results found. @sgraf812

  • build//instructions: -2.8G (-0.02%)

Small changes (4✅, 2🟥)

  • build/module/Lean.Language.Lean//instructions: -52.9M (-0.73%)
  • build/module/Lean.Meta.Match.MatchEqs//instructions: -36.5M (-0.53%)
  • build/module/Lean.Meta.Match.MatcherApp.Transform//instructions: -37.7M (-0.64%)
  • build/module/Std.Time.DateTime.PlainDateTime//instructions: -26.7M (-0.95%)
  • 🟥 compiled/nat_repr//task-clock: +22ms (+2.19%)
  • 🟥 compiled/nat_repr//wall-clock: +22ms (+2.22%)

@sgraf812 sgraf812 marked this pull request as ready for review April 13, 2026 15:36
@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 Apr 13, 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-04-13 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-04-13 16:09:01)

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-language Language features and metaprograms force-mathlib-ci 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