Skip to content

Commit a2b3ac4

Browse files
committed
refactor: simplify tactics
1 parent 7e8a3af commit a2b3ac4

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ end EMatch
474474
open EMatch
475475

476476
/-- Performs one round of E-matching, and returns new instances. -/
477-
def ematch : GoalM Unit := do
477+
private def ematchCore : GoalM Unit := do
478478
let go (thms newThms : PArray EMatchTheorem) : EMatch.M Unit := do
479479
withReader (fun ctx => { ctx with useMT := true }) <| ematchTheorems thms
480480
withReader (fun ctx => { ctx with useMT := false }) <| ematchTheorems newThms
@@ -489,12 +489,13 @@ def ematch : GoalM Unit := do
489489
ematch.num := s.ematch.num + 1
490490
}
491491

492-
/-- Performs one round of E-matching, and assert new instances. -/
493-
def ematchAndAssert : GrindTactic := fun goal => do
492+
/-- Performs one round of E-matching. -/
493+
def ematch : GrindTactic := fun goal => do
494494
let numInstances := goal.ematch.numInstances
495-
let goal ← GoalM.run' goal ematch
495+
let goal ← GoalM.run' goal ematchCore
496496
if goal.ematch.numInstances == numInstances then
497497
return none
498-
assertAll goal
498+
else
499+
return [goal]
499500

500501
end Lean.Meta.Grind

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ def assertNext : GrindTactic := fun goal => do
263263
assertAt fact.proof fact.prop fact.generation { goal with newRawFacts }
264264

265265
/-- Asserts all facts in the `goal` fact queue. -/
266-
partial def assertAll : GrindTactic :=
267-
assertNext.iterate
266+
partial def assertAll : GrindTactic := fun goal =>
267+
if goal.newRawFacts.isEmpty then
268+
return none
269+
else
270+
assertNext.iterate goal
268271

269272
end Lean.Meta.Grind

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ where
2424
loop (goal : Goal) : GrindM Bool := withIncRecDepth do
2525
if goal.inconsistent then
2626
return true
27-
else if let some goals ← assertNext goal then
27+
else if let some goals ← assertAll goal then
2828
cont goals
2929
else if let some goals ← Arith.check goal then
3030
cont goals
3131
else if let some goals ← splitNext goal then
3232
cont goals
33-
else if let some goals ← ematchAndAssert goal then
33+
else if let some goals ← ematch goal then
3434
cont goals
3535
else
3636
return false

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,24 @@ def applyTac (x : GrindTactic) (goal : Goal) : M Bool := do
5252
return true
5353
stepGuard go goal
5454

55-
def tryAssertNext : Goal → M Bool := applyTac assertNext
55+
-- TODO: it should be assertAll. It may produce multiple goals because of eager splitting.
56+
def tryAssertAll : Goal → M Bool := applyTac assertAll
5657

57-
def tryEmatch : Goal → M Bool := applyTac ematchAndAssert
58-
59-
def trySplit : Goal → M Bool := applyTac splitNext
58+
-- TODO: it doesn't need to invoke assertAll
59+
def tryEmatch : Goal → M Bool := applyTac ematch
6060

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

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

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

70+
-- May fail or produce multiple new goals
71+
def trySplit : Goal → M Bool := applyTac splitNext
72+
6773
partial def main (fallback : Fallback) : M Unit := do
6874
repeat do
6975
if (← get).failure?.isSome then
@@ -72,7 +78,7 @@ partial def main (fallback : Fallback) : M Unit := do
7278
return ()
7379
if goal.inconsistent then
7480
continue
75-
if (← tryAssertNext goal) then
81+
if (← tryAssertAll goal) then
7682
continue
7783
if (← tryArith goal) then
7884
continue

0 commit comments

Comments
 (0)