You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: warn when simp theorem LHS has variable or unrecognized head symbol (#13325)
This PR adds warnings when registering `@[simp]` theorems whose
left-hand side has a problematic head symbol in the discrimination tree:
- **Variable head** (`.star` key): The theorem will be tried on every
`simp` step, which can be expensive. The warning notes this may be
acceptable for `local` or `scoped` simp lemmas. Controlled by
`warning.simp.varHead` (default: `true`).
- **Unrecognized head** (`.other` key, e.g. a lambda expression): The
theorem is unlikely to ever be applied by `simp`. Controlled by
`warning.simp.otherHead` (default: `true`).
warning: Left-hand side of simp theorem has a variable as head symbol. This means the theorem will be tried on every simp step, which can be expensive. This may be acceptable for `local` or `scoped` simp lemmas.
8
+
Use `set_option warning.simp.varHead false` to disable this warning.
9
+
-/
10
+
#guard_msgsin
11
+
attribute [local simp] broken1
12
+
end
13
+
14
+
section
15
+
theorembroken2 (x : Nat) : x + 0 = x := by simp
16
+
17
+
-- Works in the usual direction
18
+
attribute [local simp] broken2
19
+
20
+
-- Breaks in the other direction
21
+
/--
22
+
warning: Left-hand side of simp theorem has a variable as head symbol. This means the theorem will be tried on every simp step, which can be expensive. This may be acceptable for `local` or `scoped` simp lemmas.
23
+
Use `set_option warning.simp.varHead false` to disable this warning.
24
+
-/
25
+
#guard_msgsin
26
+
attribute [local simp ←] broken2
27
+
end
28
+
29
+
theorembroken3 (x : Nat → Nat) : x 0 = x 0 + 0 := by simp
30
+
31
+
/--
32
+
warning: Left-hand side of simp theorem has a variable as head symbol. This means the theorem will be tried on every simp step, which can be expensive. This may be acceptable for `local` or `scoped` simp lemmas.
33
+
Use `set_option warning.simp.varHead false` to disable this warning.
34
+
-/
35
+
#guard_msgsin
36
+
attribute [simp] broken3
37
+
38
+
theorembroken4 (x : Nat → Nat) : x 0 + 0 = x 0 := by rfl
39
+
40
+
/--
41
+
warning: Left-hand side of simp theorem has a variable as head symbol. This means the theorem will be tried on every simp step, which can be expensive. This may be acceptable for `local` or `scoped` simp lemmas.
42
+
Use `set_option warning.simp.varHead false` to disable this warning.
43
+
-/
44
+
#guard_msgsin
45
+
attribute [simp ←] broken4
46
+
47
+
section
48
+
/--
49
+
warning: Left-hand side of simp theorem has a variable as head symbol. This means the theorem will be tried on every simp step, which can be expensive. This may be acceptable for `local` or `scoped` simp lemmas.
50
+
Use `set_option warning.simp.varHead false` to disable this warning.
51
+
-/
52
+
#guard_msgsin
53
+
@[local simp] theorembroken5 (x : Prop) : x ↔ x ∧ True := by simp
54
+
end
55
+
56
+
theorembroken6 (x : Prop → Prop) : x False ∧ True ↔ x False := by simp
57
+
58
+
/--
59
+
warning: Left-hand side of simp theorem has a variable as head symbol. This means the theorem will be tried on every simp step, which can be expensive. This may be acceptable for `local` or `scoped` simp lemmas.
60
+
Use `set_option warning.simp.varHead false` to disable this warning.
61
+
-/
62
+
#guard_msgsin
63
+
attribute [simp ←] broken6
64
+
65
+
-- Abbrev as head symbol should not trigger the warning (mathlib false positive regression test)
theorembroken8 : (fun x : Nat => x + 0) = (fun x => x) := by ext; omega
78
+
79
+
/--
80
+
warning: Left-hand side of simp theorem is headed by a `.other` key in the discrimination tree (e.g. because it is a lambda expression). This theorem will be tried against all expressions that also have a `.other` key as head, which can cause slowdowns. This may be acceptable for `local` or `scoped` simp lemmas.
81
+
Use `set_option warning.simp.otherHead false` to disable this warning.
0 commit comments