Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure #guard_* uses syntactic equality #6483

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Lean/Elab/Tactic/Guard.lean
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ have to be to pass the tactic.
This inductive gives the different specifiers that can be selected.
-/
inductive MatchKind
/-- A syntactic match means that the `Expr`s are `==` after stripping `MData` -/
/-- A syntactic match means that the `Expr`s are `=` after stripping `MData` -/
| syntactic
/-- A defeq match `isDefEqGuarded` returns true. (Note that unification is allowed here.) -/
| defEq (red : TransparencyMode := .reducible)
Expand Down Expand Up @@ -54,7 +54,7 @@ def equal.toMatchKind : TSyntax ``equal → Option MatchKind

/-- Applies the selected matching rule to two expressions. -/
def MatchKind.isEq (a b : Expr) : MatchKind → MetaM Bool
| .syntactic => return a.consumeMData == b.consumeMData
| .syntactic => return a.consumeMData.equal b.consumeMData
| .alphaEq => return a.eqv b
| .defEq red => withoutModifyingState <| withTransparency red <| Lean.Meta.isDefEqGuarded a b

Expand Down
12 changes: 6 additions & 6 deletions tests/lean/run/3943.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ example (f : Nat → Nat) : (if f x = 0 then f x else f x + 1) + f x = y := by

example (f : Nat → Nat) : f x = 0 → f x + 1 = y := by
simp (config := { contextual := true })
guard_target = f x = 0 → 1 = y
guard_target = f x = 0 → 1 = y
sorry

example (f : Nat → Nat) : let _ : f x = 0 := sorryAx _ false; f x + 1 = y := by
simp (config := { contextual := true, zeta := false })
guard_target = let _ : f x = 0 := sorryAx _ false; 1 = y
guard_target = let _ : f x = 0 := sorryAx _ false; 1 = y
sorry

def overlap : Nat → Nat
Expand All @@ -20,20 +20,20 @@ def overlap : Nat → Nat

example : (if (n = 0 → False) then overlap (n+1) else overlap (n+1)) = overlap n := by
simp (config := { contextual := true }) only [overlap]
guard_target = (if (n = 0 → False) then overlap n else overlap (n+1)) = overlap n
guard_target = (if (n = 0 → False) then overlap n else overlap (n+1)) = overlap n
sorry

example : (if (n = 0 → False) then overlap (n+1) else overlap (n+1)) = overlap n := by
-- The following tactic should because the default discharger only uses assumptions available
-- when `simp` was invoked unless `contextual := true`
fail_if_success simp only [overlap]
guard_target = (if (n = 0 → False) then overlap (n+1) else overlap (n+1)) = overlap n
guard_target = (if (n = 0 → False) then overlap (n+1) else overlap (n+1)) = overlap n
sorry

example : (if (n = 0 → False) then overlap (n+1) else overlap (n+1)) = overlap n := by
-- assumption is not a well-behaved discharger, and the following should still work as expected
simp (discharger := assumption) only [overlap]
guard_target = (if (n = 0 → False) then overlap n else overlap (n+1)) = overlap n
guard_target = (if (n = 0 → False) then overlap n else overlap (n+1)) = overlap n
sorry

opaque p : Nat → Bool
Expand All @@ -47,5 +47,5 @@ example : (if p x then g x else g x + 1) + g x = y := by

example : (let _ : p x := sorryAx _ false; g x + 1 = y) ↔ g x = y := by
simp (config := { zeta := false }) (discharger := assumption)
guard_target = (let _ : p x := sorryAx _ false; x + 1 = y) ↔ g x = y
guard_target = (let _ : p x := sorryAx _ false; x + 1 = y) ↔ g x = y
sorry
2 changes: 1 addition & 1 deletion tests/lean/run/6065.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def foo (r : Nat) : Nat :=

example {r : Nat} : foo r = 0 := by
simp only [foo.eq_def]
guard_target =
guard_target =
(match r with
| Nat.zero => 0
| l@h:(Nat.succ n) =>
Expand Down
4 changes: 2 additions & 2 deletions tests/lean/run/6263.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ open Lean.Elab.Tactic
variable (p q : Prop)
theorem foo (h : p ∧ q) : q ∧ p := by
run_tac liftMetaTactic1 (·.revertAll)
guard_target = ∀ (p q : Prop), p ∧ q → q ∧ p
guard_target = ∀ (p q : Prop), p ∧ q → q ∧ p
sorry

theorem bla (h : p ∧ q) : q ∧ p := by
revert p q
guard_target = ∀ (p q : Prop), p ∧ q → q ∧ p
guard_target = ∀ (p q : Prop), p ∧ q → q ∧ p
sorry
2 changes: 1 addition & 1 deletion tests/lean/run/grind_canon_insts.lean
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ warning: declaration uses 'sorry'
example (a b c d : Nat) : b * a = d * b → False := by
rw [CommMonoid.mul_comm d b] -- Introduces a new (non-canonical) instance for `Mul Nat`
-- See target here
guard_target =
guard_target =
@HMul.hMul Nat Nat Nat (@instHMul Nat instMulNat) b a
=
@HMul.hMul Nat Nat Nat (@instHMul Nat (@Semigroup.toMul Nat (@Monoid.toSemigroup Nat (@CommMonoid.toMonoid Nat instCommMonoidNat)))) b d
Expand Down
2 changes: 1 addition & 1 deletion tests/lean/run/grind_revertAll.lean
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ elab "ensure_no_mvar" : tactic => do
example {α : Type u} [Inhabited α] (a : α) (f : α → α) (h : f a = default) : default = f a := by
revert_all
ensure_no_mvar
guard_target =∀ {α : Type u} [inst : Inhabited α] (a : α) (f : α → α), f a = default → default = f a
guard_target =∀ {α : Type u} [inst : Inhabited α] (a : α) (f : α → α), f a = default → default = f a
intro α inst a f h
exact h.symm

Expand Down
2 changes: 1 addition & 1 deletion tests/lean/run/simpLetFunIssue.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ example : (λ x => x)
let_fun foo := λ y => id (id y)
foo (0 + x)) := by
simp -zeta only [id]
guard_target =
guard_target =
(λ x => x)
=
(λ x : Nat =>
Expand Down
Loading