Skip to content

Commit

Permalink
fix: fixes #2669 #2281
Browse files Browse the repository at this point in the history
  • Loading branch information
leodemoura committed Oct 22, 2023
1 parent 6cd22c4 commit bc03c21
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/Lean/Meta/Tactic/Simp/Rewrite.lean
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,24 @@ def tryTheorem? (e : Expr) (thm : SimpTheorem) (discharge? : Expr → SimpM (Opt
tryTheoremCore lhs xs bis val type e thm (eNumArgs - lhsNumArgs) discharge?
else
return none

/--
Reture a WHNF configuration for retrieving `[simp]` from the discrimination tree.
If user has disabled `zeta` and/or `beta` reduction in the simplifier, we must also
disabled them when retrieving lemmas from discrimination tree. See issues: #2669 and #2281
-/
def getDtConfig (cfg : Config) : WhnfCoreConfig :=
match cfg.beta, cfg.zeta with
| true, true => simpDtConfig
| true, false => { simpDtConfig with zeta := false }
| false, true => { simpDtConfig with beta := false }
| false, false => { simpDtConfig with beta := false, zeta := false }

/--
Remark: the parameter tag is used for creating trace messages. It is irrelevant otherwise.
-/
def rewrite? (e : Expr) (s : SimpTheoremTree) (erased : PHashSet Origin) (discharge? : Expr → SimpM (Option Expr)) (tag : String) (rflOnly : Bool) : SimpM (Option Result) := do
let candidates ← s.getMatchWithExtra e simpDtConfig
let candidates ← s.getMatchWithExtra e (getDtConfig (← getConfig))
if candidates.isEmpty then
trace[Debug.Meta.Tactic.simp] "no theorems found for {tag}-rewriting {e}"
return none
Expand Down
4 changes: 2 additions & 2 deletions src/Lean/Meta/Tactic/Simp/Types.lean
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def post (e : Expr) : M Step := do
def discharge? (e : Expr) : M (Option Expr) := do
(← read).discharge? e

def getConfig : M Config :=
return (← readThe Context).config
def getConfig : SimpM Config :=
return (← read).config

@[inline] def withParent (parent : Expr) (f : M α) : M α :=
withTheReader Context (fun ctx => { ctx with parent? := parent }) f
Expand Down
15 changes: 15 additions & 0 deletions tests/lean/run/2669.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def f : Nat → Nat := fun x => x - x

@[simp] theorem f_zero (n : Nat) : f n = 0 :=
Nat.sub_self n

example (n : Nat) : False := by
let g := f n
have : g + n = n := by
fail_if_success simp (config := { zeta := false }) [Nat.zero_add] -- Should not succeed
simp
sorry

example (h : a = b) : (fun x => a + x) 0 = b := by
fail_if_success simp (config := { beta := false })
simp [*]

0 comments on commit bc03c21

Please sign in to comment.