Skip to content

Commit ce8c418

Browse files
committed
feat: ensure we see grind diagnostics at maxHeartbeats
1 parent a2b3ac4 commit ce8c418

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

src/Lean/Meta/Tactic/Grind/Solve.lean

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ def setFailure (goal : Goal) : M Unit := do
3535
modify fun s => { s with failure? := some goal }
3636

3737
@[inline] def stepGuard (x : Goal → M Bool) (goal : Goal) : M Bool := do
38-
try
39-
x goal
40-
catch ex =>
41-
if ex.isMaxHeartbeat || ex.isMaxRecDepth then
42-
reportIssue! ex.toMessageData
43-
setFailure goal
44-
return true
45-
else
46-
throw ex
38+
tryCatchRuntimeEx
39+
(x goal)
40+
fun ex => do
41+
if ex.isMaxHeartbeat || ex.isMaxRecDepth then
42+
reportIssue! ex.toMessageData
43+
setFailure goal
44+
return true
45+
else
46+
throw ex
4747

4848
def applyTac (x : GrindTactic) (goal : Goal) : M Bool := do
4949
let go (goal : Goal) : M Bool := do
@@ -52,22 +52,16 @@ def applyTac (x : GrindTactic) (goal : Goal) : M Bool := do
5252
return true
5353
stepGuard go goal
5454

55-
-- TODO: it should be assertAll. It may produce multiple goals because of eager splitting.
5655
def tryAssertAll : Goal → M Bool := applyTac assertAll
5756

58-
-- TODO: it doesn't need to invoke assertAll
5957
def tryEmatch : Goal → M Bool := applyTac ematch
6058

61-
-- Can only fail or produce a new updated goal
6259
def tryArith : Goal → M Bool := applyTac Arith.check
6360

64-
-- Can only fail or produce a new updated goal
6561
def tryLookahead : Goal → M Bool := applyTac lookahead
6662

67-
-- Can only fail or produce a new updated goal
6863
def tryMBTC : Goal → M Bool := applyTac Arith.Cutsat.mbtcTac
6964

70-
-- May fail or produce multiple new goals
7165
def trySplit : Goal → M Bool := applyTac splitNext
7266

7367
partial def main (fallback : Fallback) : M Unit := do
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
set_option grind.warning false
2+
3+
opaque f : Nat → Nat
4+
opaque op : Nat → Nat → Nat
5+
@[grind] theorem op_comm : op x y = op y x := sorry
6+
@[grind] theorem op_assoc : op (op x y) z = op x (op y z) := sorry
7+
8+
syntax "gen! " num : term
9+
10+
macro_rules
11+
| `(gen! 0) => `(f 0)
12+
| `(gen! $n:num) => `(op (f $n) (gen! $(Lean.quote (n.getNat - 1))))
13+
14+
/--
15+
trace: [grind.issues] (deterministic) timeout at `isDefEq`, maximum number of heartbeats (5000) has been reached
16+
Use `set_option maxHeartbeats <num>` to set the limit.
17+
18+
Additional diagnostic information may be available using the `set_option diagnostics true` command.
19+
-/
20+
#guard_msgs (trace, drop error) in
21+
set_option trace.grind.issues true in
22+
set_option maxHeartbeats 5000 in
23+
example : gen! 10 = 0 ∧ True := by
24+
grind (instances := 10000)

0 commit comments

Comments
 (0)