File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -336,7 +336,9 @@ def mkSimpOnly (stx : Syntax) (usedSimps : Simp.UsedSimps) : MetaM Syntax := do
336
336
for (thm, _) in usedSimps.toArray.qsort (·.2 < ·.2 ) do
337
337
match thm with
338
338
| .decl declName post inv => -- global definitions in the environment
339
- if env.contains declName && (inv || !simpOnlyBuiltins.contains declName) then
339
+ if env.contains declName
340
+ && (inv || !simpOnlyBuiltins.contains declName)
341
+ && !Match.isMatchEqnTheorem env declName then
340
342
let decl : Term ← `($(mkIdent (← unresolveNameGlobal declName)):ident)
341
343
let arg ← match post, inv with
342
344
| true , true => `(Parser.Tactic.simpLemma| ← $decl:term)
Original file line number Diff line number Diff line change @@ -19,19 +19,29 @@ def MatchEqns.size (e : MatchEqns) : Nat :=
19
19
20
20
structure MatchEqnsExtState where
21
21
map : PHashMap Name MatchEqns := {}
22
+ eqns : PHashSet Name := {}
22
23
deriving Inhabited
23
24
24
25
/- We generate the equations and splitter on demand, and do not save them on .olean files. -/
25
26
builtin_initialize matchEqnsExt : EnvExtension MatchEqnsExtState ←
26
27
registerEnvExtension (pure {})
27
28
28
- def registerMatchEqns (matchDeclName : Name) (matchEqns : MatchEqns) : CoreM Unit :=
29
- modifyEnv fun env => matchEqnsExt.modifyState env fun s => { s with map := s.map.insert matchDeclName matchEqns }
29
+ def registerMatchEqns (matchDeclName : Name) (matchEqns : MatchEqns) : CoreM Unit := do
30
+ modifyEnv fun env => matchEqnsExt.modifyState env fun { map, eqns } => {
31
+ eqns := matchEqns.eqnNames.foldl (init := eqns) fun eqns eqn => eqns.insert eqn
32
+ map := map.insert matchDeclName matchEqns
33
+ }
30
34
31
35
/-
32
36
Forward definition. We want to use `getEquationsFor` in the simplifier,
33
37
`getEquationsFor` depends on `mkEquationsfor` which uses the simplifier. -/
34
38
@[extern "lean_get_match_equations_for"]
35
39
opaque getEquationsFor (matchDeclName : Name) : MetaM MatchEqns
36
40
41
+ /--
42
+ Returns `true` if `declName` is the name of a `match` equational theorem.
43
+ -/
44
+ def isMatchEqnTheorem (env : Environment) (declName : Name) : Bool :=
45
+ matchEqnsExt.getState env |>.eqns.contains declName
46
+
37
47
end Lean.Meta.Match
Original file line number Diff line number Diff line change
1
+ /--
2
+ info: Try this: simp only [ha, Nat.reduceEqDiff, imp_self]
3
+ -/
4
+ #guard_msgs in
5
+ theorem foo₁ (a : Nat) (ha : a = 37 ) :
6
+ (match h : a with | 42 => by simp_all | n => n) = 37 := by
7
+ simp? [ha]
8
+
9
+ theorem foo₂ (a : Nat) (ha : a = 37 ) (hb : b = 37 ) :
10
+ (match h : a with | 42 => by simp_all | n => n) = b := by
11
+ simp only [ha, Nat.reduceEqDiff, imp_self]
12
+ guard_target =ₛ 37 = b
13
+ rw [hb]
You can’t perform that action at this time.
0 commit comments