Skip to content

Update Lean to v4.33.0-rc2 - #34

Draft
abentkamp wants to merge 2 commits into
devfrom
bump-lean
Draft

Update Lean to v4.33.0-rc2#34
abentkamp wants to merge 2 commits into
devfrom
bump-lean

Conversation

@abentkamp

Copy link
Copy Markdown

Bump the Lean toolchain and mathlib to v4.33.0-rc2 and adapt the backend and tests to the new toolchain.

Toolchain:

  • backends/lean and tests/lean lean-toolchain -> v4.33.0-rc2
  • mathlib tag -> v4.33.0-rc2 in lakefile.lean; regenerate both manifests

API breakage:

  • BvEnumToBitVec / BvTac: BVDecide frontend moved from Lean.Elab.Tactic.BVDecide.Frontend.* to Lean.Meta.Tactic.BVDecide.*
  • Simp: 4.33 no longer inserts the Array->Option coercion; make it explicit
  • ReduceZMod: mathlib Monoid.toPow -> NPow.toPow / Monoid.toNPow

Proof / tactic repair:

  • Make Pre reducible (like Post) so and_imp/exists_imp flatten conjunction/existential post-conditions again in step/let* (4.33's simp only rewrites when the conclusion is recognised as Prop)
  • Fix grind/simp failures on spec (ok ...) goals via spec_ok, and the semireducible-wrapper getElem/setSlice! lemmas in Vec/Slice
  • FlatOrder.mk admissibility, StepStar TaskOrDone annotation, StepArraySpec declModifiers TSyntax category, Step do-block returning Unit
  • Update #guard_msgs for the reworded unusedVariables linter message

Tests:

  • Work around grind causes a kernel error leanprover/lean4#14521 (grind emits a kernel-invalid eq_false_of_decide term for BitVec equalities whose width is defeq but not syntactically 32): route the tutorial get_elem_tactic through scalar_tac, and spell out the one step* demo explicitly

(cherry picked from commit 744f829)

Instructions

Thanks for opening a PR! We welcome external contributions but encourage contributors to
coordinate with us before, either by joining the Zulip or by opening issues with detailed
proposals. In particular, we ask contributors to engage with us before making deep
modifications of the code or implementing non trivial features, as these require in-depth
design discussions and careful reviews. This means for instance that proposals to extend
the translation should be discussed first. On the other hand, you should feel free to
directly submit PRs that fix an issue through a scoped, small fix, or that add theorems to
the standard library. In case of doubt, discuss with us.

Good practices:

  • please keep your PRs small and scoped: they will be a lot easier to review and accept.
  • new models of Rust definitions should be systematically tested (you can annotate unit
    functions with #[verify::test] to generate tests at extraction time)
  • avoid AI generated PR descriptions: they tend to be verbose and imprecise

AI assisted PRs:

Please indicate whether the PR was AI assisted, and by how much: did you use AI in a
limited way or did you completely vibe-code the PR? We welcome AI assisted PRs but need
this information to adjust our level of scrutinee during the review and evaluate whether
it is reasonable to ask for the contributor to completely modify their code. Also note
that we expect contributors to own and understand the code they submit: as we will
carefully review the PR line by line, we expect contributors to have done the same for AI
generated code (reviewing PRs takes time and we have limited resources).

Bump the Lean toolchain and mathlib to v4.33.0-rc2 and adapt the
backend and tests to the new toolchain.

Toolchain:
- backends/lean and tests/lean lean-toolchain -> v4.33.0-rc2
- mathlib tag -> v4.33.0-rc2 in lakefile.lean; regenerate both manifests

API breakage:
- BvEnumToBitVec / BvTac: BVDecide frontend moved from
  Lean.Elab.Tactic.BVDecide.Frontend.* to Lean.Meta.Tactic.BVDecide.*
- Simp: 4.33 no longer inserts the Array->Option coercion; make it explicit
- ReduceZMod: mathlib Monoid.toPow -> NPow.toPow / Monoid.toNPow

Proof / tactic repair:
- Make Pre reducible (like Post) so and_imp/exists_imp flatten
  conjunction/existential post-conditions again in step/let* (4.33's simp
  only rewrites when the conclusion is recognised as Prop)
- Fix grind/simp failures on spec (ok ...) goals via spec_ok, and the
  semireducible-wrapper getElem/setSlice! lemmas in Vec/Slice
- FlatOrder.mk admissibility, StepStar TaskOrDone annotation, StepArraySpec
  declModifiers TSyntax category, Step do-block returning Unit
- Update #guard_msgs for the reworded unusedVariables linter message

Tests:
- Work around leanprover/lean4#14521 (grind emits a kernel-invalid
  eq_false_of_decide term for BitVec equalities whose width is defeq but
  not syntactically 32): route the tutorial get_elem_tactic through
  scalar_tac, and spell out the one step* demo explicitly

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 744f829)

@clementblaudeau clementblaudeau left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the proof changes look fine, even though the grind regressions should be investigated. The main thing that could block upstreaming would be significant change in proof checking time of the lib itself.

Could also be split into several PRs.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be upstreamed regardless of the lean version bump right ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this one

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are those specific to the lean bump ? They seem like reasonable changes anyway

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proof changes like those seem fine to me.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some regression on grind ?

Comment on lines -11 to +12
def Post α := (α -> Prop)
def Pre := Prop
@[reducible] def Post α := (α -> Prop)
@[reducible] def Pre := Prop

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this come from ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment on lines -744 to 745
grind [spec, Std.lift]
simp only [Std.lift, spec_ok, ← h1]
exact h0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, looks fishy

Comment on lines 1015 to 1031
def tryApply (info : SpecInfo) (lifting : Option LiftingInfo) (args : Args) (isLet:Bool) (fExpr : Expr) (kind : String) (th : Option Expr) :
TacticM (Option Goals) := do
let res ← do
match th with
| none =>
trace[Step] "Could not find a {kind}"
pure none
| some th => do
trace[Step] "Lookuped up {kind}: {th}"
-- Apply the theorem
let res ← do
try
let res ← stepWith info lifting args isLet fExpr th
pure (some res)
catch _ => pure none
try
let res ← stepWith info lifting args isLet fExpr th
pure (some res)
catch _ => pure none
match res with
| some res => pure (some res)
| none => pure none

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this code

Comment on lines +5 to 11
-- Workaround for leanprover/lean4#14521: the default `get_elem_tactic` (`grind`)
-- emits kernel-invalid proofs when an index bound depends on `_ ≠ 0#uN` (the
-- BitVec width `numBits U32` is defeq but not syntactically `32`). `scalar_tac`
-- discharges these bounds correctly; `grind` stays as a fallback.
local macro_rules
| `(tactic| get_elem_tactic) => `(tactic| grind)
| `(tactic| get_elem_tactic) => `(tactic| first | scalar_tac | grind)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs some investigation

Lean v4.33 newly enables the `dupNamespace`, `defProp`, and `ambiguousOpen`
linters. They fire on generated Rust-path declaration names, intentional
`Prop`-valued definitions, and `open Std` (now that `Lean.Std` also exists) --
none cleanly fixable in the generated / spec code -- so disable them in the
lakefile to keep CI's `lake build --iofail` green after the toolchain bump.
Also drop a few unused simp arguments and one unnecessary `<;>`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants