fix: do not evaluate left shifts with huge shift amounts This PR adds the option `shiftLeft.threshold` (default: 65536). `whnf`, `simp`, and `grind` no longer evaluate a left shift of literals when the shift amount is above this threshold, and report a warning instead, as they already do for exponents above `exponentiation.threshold`. Previously, a shift amount of 2^32 or more aborted the Lean process with `INTERNAL PANIC: Nat.shiftl exponent is too big`, e.g., in `example : (1 <<< 4294967296 : Nat) = 0 := by simp`. `cbv` and the compiler use the same bound as a constant. The runtime implementation of `Nat.shiftLeft` panics when the shifted value is not `0` and the shift amount does not fit in 32 bits, and several procedures evaluated `<<<` on `Nat`, `Int`, `Fin`, and `BitVec` literals without checking the shift amount. The new functions `isSafeShiftLeft` and `checkShiftLeft` accept a shift when the shifted value is `0`, or the shift amount is at most the threshold and fits in 32 bits. They are now used by `Meta.reduceNat?`, the `Nat`, `Fin`, and `BitVec` shift simprocs, the `grind` propagators for `Nat` and `BitVec` shifts, `Sym` ground evaluation (new field `EvalStepConfig.maxShiftLeft`), and the LCNF constant folder (`natShiftLeftThreshold`). Closes #15193 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This is the repository for Lean 4.
See Install Lean.
Please read our Contribution Guidelines first.
See Building Lean.