Skip to content

Commit

Permalink
fix: isDefEq when zetaDelta := false (leanprover#6129)
Browse files Browse the repository at this point in the history
This PR fixes a bug at `isDefEq` when `zetaDelta := false`. See new test
for a small example that exposes the issue.
  • Loading branch information
leodemoura authored and JovanGerb committed Jan 21, 2025
1 parent 1062f38 commit 166aeda
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/Lean/Meta/ExprDefEq.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1674,11 +1674,12 @@ private partial def isDefEqQuick (t s : Expr) : MetaM LBool :=
-- | Expr.mdata _ t _, s => isDefEqQuick t s
-- | t, Expr.mdata _ s _ => isDefEqQuick t s
| .fvar fvarId₁, .fvar fvarId₂ => do
if (← fvarId₁.isLetVar <||> fvarId₂.isLetVar) then
return LBool.undef
else if fvarId₁ == fvarId₂ then
return LBool.true
if fvarId₁ == fvarId₂ then
return .true
else if (← fvarId₁.isLetVar <||> fvarId₂.isLetVar) then
return .undef
else
-- If `t` and `s` are not proofs or let-variables, we still return `.undef` and let other rules (e.g., unit-like) kick in.
isDefEqProofIrrel t s
| t, s =>
isDefEqQuickOther t s
Expand Down
6 changes: 3 additions & 3 deletions tests/lean/run/heapSort.lean
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ def Array.toBinaryHeap (lt : α → α → Bool) (a : Array α) : BinaryHeap α
attribute [simp] Array.heapSort.loop

/--
info: Array.heapSort.loop.eq_1.{u_1} {α : Type u_1} (lt : α → α → Bool) (a : BinaryHeap α fun y x => lt x y) (out : Array α) :
Array.heapSort.loop lt a out =
info: Array.heapSort.loop.eq_1.{u_1} {α : Type u_1} (gt : α → α → Bool) (a : BinaryHeap α gt) (out : Array α) :
Array.heapSort.loop gt a out =
match e : a.max with
| none => out
| some x =>
let_fun this := ⋯;
Array.heapSort.loop lt a.popMax (out.push x)
Array.heapSort.loop gt a.popMax (out.push x)
-/
#guard_msgs in
#check Array.heapSort.loop.eq_1
Expand Down
14 changes: 14 additions & 0 deletions tests/lean/run/zetaDeltaFalseDefEqIssue.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Lean

/--
info: true
true
-/
#guard_msgs in
open Lean Meta in
run_meta do
withLetDecl `x (mkConst ``Nat) (mkNatLit 10) fun x => do
IO.println (← isDefEq x x)
withConfig (fun c => { c with zeta := false, zetaDelta := false }) do
IO.println (← isDefEq x x) -- Should return `true` even if `zetaDelta := false`
return ()

0 comments on commit 166aeda

Please sign in to comment.