Skip to content

Commit

Permalink
fix: guard against Nat.reducePow panicking
Browse files Browse the repository at this point in the history
In the Carleson project a non-fatal PANIC occurring in the application
of certain applications of `Nat.reducePow` was discovered
(https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/PANIC.20at.20Lean.2EExpr.2EappArg!.20application.20expected/near/457037665).
We fix this regression from leanprover#4637.

Fixes leanprover#4947.
  • Loading branch information
Parcly-Taxel committed Aug 9, 2024
1 parent 6dd5023 commit 25e18b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Lean/Meta/Tactic/Simp/BuiltinSimprocs/Nat.lean
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ builtin_dsimproc [simp, seval] reduceDiv ((_ / _ : Nat)) := reduceBin ``HDiv.hDi
builtin_dsimproc [simp, seval] reduceMod ((_ % _ : Nat)) := reduceBin ``HMod.hMod 6 (· % ·)

builtin_dsimproc [simp, seval] reducePow ((_ ^ _ : Nat)) := fun e => do
unless e.isAppOfArity ``HPow.hPow 6 do return .continue
let some n ← fromExpr? e.appFn!.appArg! | return .continue
let some m ← fromExpr? e.appArg! | return .continue
unless (← checkExponent m) do return .continue
Expand Down
17 changes: 17 additions & 0 deletions tests/lean/4947.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/-! # Test that safe exponentiation does not cause a panic -/

universe u

class G (A : outParam Nat) where Z : Type u

export G (Z)

/-! Define an abbrev which `reducePow` can work on -/

abbrev f (a : Nat) : Nat := 2 ^ a

variable [G (f 0)]

/-! This should not cause a panic -/

example {s : Z} : s = s := by simp only [Nat.reducePow]
Empty file.

0 comments on commit 25e18b8

Please sign in to comment.