fix: simp_all was "self-simplifying" simplified hypotheses

fixes #1027
This commit is contained in:
Leonardo de Moura 2022-02-23 16:48:28 -08:00
parent 16b8800607
commit 07d1ec1926
3 changed files with 20 additions and 3 deletions

View file

@ -56,12 +56,21 @@ private partial def loop : M Bool := do
| none => return true -- closed the goal
| some (proofNew, typeNew) =>
unless typeNew == entry.type do
let id ← mkFreshUserName `h
let simpThmsNew ← (← getSimpTheorems).add #[] proofNew (name? := id)
/- The theorem for the simplified entry must use the same `id` of the theorem before simplification. Otherwise,
the previous versions can be used to self-simplify the new version. For example, suppose we have
```
x : Nat
h : x ≠ 0
⊢ Unit
```
In the first round, `h : x ≠ 0` is simplified to `h : ¬ x = 0`. If we don't use the same `id`, in the next round
the first version would simplify it to `h : True`.
-/
let simpThmsNew ← (← getSimpTheorems).add #[] proofNew (name? := entry.id)
modify fun s => { s with
modified := true
ctx.simpTheorems := simpThmsNew
entries[i] := { entry with type := typeNew, proof := proofNew, id := id }
entries[i] := { entry with type := typeNew, proof := proofNew, id := entry.id }
}
-- simplify target
let mvarId := (← get).mvarId

4
tests/lean/1027.lean Normal file
View file

@ -0,0 +1,4 @@
example (h : x ≠ 0) : Unit := by
simp_all
trace_state
sorry

View file

@ -0,0 +1,4 @@
x : Nat
h : ¬x = 0
⊢ Unit
1027.lean:4:2-4:7: warning: declaration uses 'sorry'