Conversation
Elaboration- and compile-time evaluation of `a <<< b` on literals called the runtime `Nat.shiftLeft`, which aborts the process when `a ≠ 0` and `b` does not fit in 32 bits. Check the new `canEvalNatShiftLeft` before evaluating in `Meta.reduceNat?`, the `Nat`/`Fin`/`BitVec` shift simprocs, `Sym` ground evaluation, the `grind` shift propagators and the LCNF constant folder. Closes leanprover#15193 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR stops elaboration-time and compile-time evaluation of
Natleft shifts whose shift amount does not fit in 32 bits, so they no longer abort the Lean process with "Nat.shiftl exponent is too big".The runtime's
lean_nat_shiftlcallslean_internal_panicwhen the shifted value is nonzero and the shift amount is at least2^32. The kernel already refuses such shifts with a kernel exception, andNat.powis protected on the elaborator side bycheckExponent, but several procedures evaluated<<<on literals unconditionally. A new predicate,Lean.canEvalNatShiftLeft a b(a = 0 ∨ b < UInt32.size), is now checked before evaluating a left shift in:Meta.reduceNat?(whnf,rfl,decide)Nat.reduceShiftLeft,Fin.reduceShiftLeft,BitVec.reduceShiftLeft,BitVec.reduceHShiftLeftandBitVec.reduceShiftLeftZeroExtendsimprocsSymground evaluation of shifts onNat,Int,FinandBitVecand ofBitVec.shiftLeft/shiftLeftZeroExtend(cbv,bv_decidenormalization)grindpropagators forNatandBitVecleft shiftsNat.shiftLeftWhen the predicate fails, the shift is left unevaluated, so the affected tactics report an ordinary failure (for
cbv, which then unfoldsNat.shiftLeft, "maximum recursion depth has been reached"). Shifts the runtime can evaluate are unaffected; unlikecheckExponent, no size threshold is introduced.Closes #15193
AI assistance: the bug was found with, and this change and its tests were drafted with, an AI assistant (Claude). The new test and the full stage1 test suite (4219 tests) pass on a local build of this branch (aarch64 Linux).
🤖 Generated with Claude Code