Skip to content

Commit 8753239

Browse files
authored
chore: remove Grind.Config.failures options (#8423)
Option is not very useful.
1 parent f4ee72b commit 8753239

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed

src/Init/Grind/Tactics.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ structure Config where
6767
if the implication is true. Otherwise, it will split only if `p` is an arithmetic predicate.
6868
-/
6969
splitImp : Bool := false
70-
/-- By default, `grind` halts as soon as it encounters a sub-goal where no further progress can be made. -/
71-
failures : Nat := 1
7270
/-- Maximum number of heartbeats (in thousands) the canonicalizer can spend per definitional equality test. -/
7371
canonHeartbeats : Nat := 1000
7472
/-- If `ext` is `true`, `grind` uses extensionality theorems that have been marked with `[grind ext]`. -/

src/Lean/Elab/Tactic/Grind.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def grind
141141
let type ← mvarId.getType
142142
let mvar' ← mkFreshExprSyntheticOpaqueMVar type
143143
let result ← Grind.main mvar'.mvarId! params fallback
144-
if result.hasFailures then
144+
if result.hasFailed then
145145
throwError "`grind` failed\n{← result.toMessageData}"
146146
-- `grind` proofs are often big
147147
let e ← if (← isProp type) then

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private def initCore (mvarId : MVarId) (params : Params) : GrindM (List Goal) :=
105105
return goals.filter fun goal => !goal.inconsistent
106106

107107
structure Result where
108-
failures : List Goal
108+
failure? : Option Goal
109109
skipped : List Goal
110110
issues : List MessageData
111111
config : Grind.Config
@@ -140,11 +140,11 @@ private def mkGlobalDiag (cs : Counters) (simp : Simp.Stats) : MetaM (Option Mes
140140
else
141141
return some <| .trace { cls := `grind } "Diagnostics" msgs
142142

143-
def Result.hasFailures (r : Result) : Bool :=
144-
!r.failures.isEmpty
143+
def Result.hasFailed (r : Result) : Bool :=
144+
r.failure?.isSome
145145

146146
def Result.toMessageData (result : Result) : MetaM MessageData := do
147-
let mut msgs ← result.failures.mapM (goalToMessageData · result.config)
147+
let mut msgs ← result.failure?.toList.mapM (goalToMessageData · result.config)
148148
if result.config.verbose then
149149
let mut issues := result.issues
150150
-- We did not find the following very useful in practice.
@@ -163,23 +163,23 @@ def main (mvarId : MVarId) (params : Params) (fallback : Fallback) : MetaM Resul
163163
if debug.terminalTacticsAsSorry.get (← getOptions) then
164164
mvarId.admit
165165
return {
166-
failures := [], skipped := [], issues := [], config := params.config, trace := {}, counters := {}, simp := {}
166+
failure? := none, skipped := [], issues := [], config := params.config, trace := {}, counters := {}, simp := {}
167167
}
168168
else
169169
let go : GrindM Result := withReducible do
170170
let goals ← initCore mvarId params
171-
let (failures, skipped) ← solve goals fallback
171+
let (failure?, skipped) ← solve goals fallback
172172
trace[grind.debug.final] "{← ppGoals goals}"
173173
let issues := (← get).issues
174174
let trace := (← get).trace
175175
let counters := (← get).counters
176176
let simp := (← get).simpStats
177-
if failures.isEmpty then
177+
if failure?.isNone then
178178
-- If there are no failures and diagnostics are enabled, we still report the performance counters.
179179
if (← isDiagnosticsEnabled) then
180180
if let some msg ← mkGlobalDiag counters simp then
181181
logInfo msg
182-
return { failures, skipped, issues, config := params.config, trace, counters, simp }
182+
return { failure?, skipped, issues, config := params.config, trace, counters, simp }
183183
go.run params fallback
184184

185185
end Lean.Meta.Grind

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ namespace Solve
1616

1717
structure State where
1818
todo : List Goal
19-
failures : List Goal := []
20-
stop : Bool := false
19+
failure? : Option Goal := none
2120

2221
private abbrev M := StateRefT State GrindM
2322

@@ -32,18 +31,16 @@ def pushGoal (goal : Goal) : M Unit :=
3231
def pushGoals (goals : List Goal) : M Unit :=
3332
modify fun s => { s with todo := goals ++ s.todo }
3433

35-
def pushFailure (goal : Goal) : M Unit := do
36-
modify fun s => { s with failures := goal :: s.failures }
37-
if (← get).failures.length ≥ (← getConfig).failures then
38-
modify fun s => { s with stop := true }
34+
def setFailure (goal : Goal) : M Unit := do
35+
modify fun s => { s with failure? := some goal }
3936

4037
@[inline] def stepGuard (x : Goal → M Bool) (goal : Goal) : M Bool := do
4138
try
4239
x goal
4340
catch ex =>
4441
if ex.isMaxHeartbeat || ex.isMaxRecDepth then
4542
reportIssue! ex.toMessageData
46-
pushFailure goal
43+
setFailure goal
4744
return true
4845
else
4946
throw ex
@@ -67,12 +64,9 @@ def tryLookahead : Goal → M Bool := applyTac lookahead
6764

6865
def tryMBTC : Goal → M Bool := applyTac Arith.Cutsat.mbtcTac
6966

70-
def maxNumFailuresReached : M Bool := do
71-
return (← get).failures.length ≥ (← getConfig).failures
72-
7367
partial def main (fallback : Fallback) : M Unit := do
7468
repeat do
75-
if (← get).stop then
69+
if (← get).failure?.isSome then
7670
return ()
7771
let some goal ← getNext? |
7872
return ()
@@ -93,15 +87,15 @@ partial def main (fallback : Fallback) : M Unit := do
9387
let goal ← GoalM.run' goal fallback
9488
if goal.inconsistent || (← goal.mvarId.isAssigned) then
9589
continue
96-
pushFailure goal
90+
setFailure goal
9791

9892
end Solve
9993

10094
/--
10195
Try to solve/close the given goals, and returns the ones that could not be solved.
10296
-/
103-
def solve (goals : List Goal) (fallback : Fallback) : GrindM (List Goal × List Goal) := do
97+
def solve (goals : List Goal) (fallback : Fallback) : GrindM (Option Goal × List Goal) := do
10498
let (_, s) ← Solve.main fallback |>.run { todo := goals }
105-
return (s.failures.reverse, s.todo)
99+
return (s.failure?, s.todo)
106100

107101
end Lean.Meta.Grind

0 commit comments

Comments
 (0)