-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user-defined fallback procedure for the
grind
tactic (#6512)
This PR introduces support for user-defined fallback code in the `grind` tactic. The fallback code can be utilized to inspect the state of failing `grind` subgoals and/or invoke user-defined automation. Users can now write `grind on_failure <code>`, where `<code>` should have the type `GoalM Unit`. See the modified tests in this PR for examples.
- Loading branch information
1 parent
9d62227
commit 3e2f1fa
Showing
12 changed files
with
170 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,22 @@ | ||
import Lean | ||
import Lean.Meta.Tactic.Grind | ||
|
||
def g (s : Type) := s | ||
def f (a : α) := a | ||
|
||
open Lean Meta Elab Tactic Grind in | ||
elab "grind_test" : tactic => withMainContext do | ||
let declName := (← Term.getDeclName?).getD `_main | ||
Meta.Grind.preprocessAndProbe (← getMainGoal) declName do | ||
let nodes ← filterENodes fun e => return e.self.isAppOf ``f | ||
logInfo (nodes.toList.map (·.self)) | ||
|
||
open Lean Meta Grind in | ||
def fallback : Fallback := do | ||
let nodes ← filterENodes fun e => return e.self.isAppOf ``f | ||
logInfo (nodes.toList.map (·.self)) | ||
(← get).mvarId.admit | ||
|
||
set_option pp.explicit true | ||
/-- | ||
info: [@f Nat a, @f Nat b] | ||
--- | ||
warning: declaration uses 'sorry' | ||
-/ | ||
#guard_msgs in | ||
#guard_msgs (info) in | ||
example (a b c d : Nat) : @f Nat a = b → @f (g Nat) a = c → @f (g Nat) b = d → a = b → False := by | ||
-- State should have only two `f`-applications: `@f Nat a`, `@f Nat b` | ||
-- Note that `@f (g Nat) b` has been canonicalized to `@f Nat b`. | ||
-- Thus, if `a` and `b` equivalence classes are merged, `grind` can still detect that | ||
-- `@f Nat a` and `@f Nat b` are equal too. | ||
grind_test | ||
sorry | ||
grind on_failure fallback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.