Skip to content

Commit 8a6d13a

Browse files
committed
feat: log split anchors
1 parent ec44a52 commit 8a6d13a

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/Lean/Elab/Tactic/Grind/BuiltinTactic.lean

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,47 @@ where
223223
| .cases _ | .intro | .inj | .ext | .symbol _ =>
224224
throwError "invalid modifier"
225225

226+
def logAnchor (numDigits : Nat) (anchorPrefix : UInt64) (e : Expr) : TermElabM Unit := do
227+
let stx ← getRef
228+
if e.isFVar || e.isConst then
229+
/-
230+
**Note**: When `e` is a constant or free variable, the hover displays `e`
231+
-/
232+
Term.addTermInfo' stx e
233+
else if (← isType e) then
234+
/-
235+
**Note**: If `e` is a type, we create a fake `sorry` to force `e` to be displayed
236+
when we hover over the anchor.
237+
We wrap the `sorry` with `id` to ensure the hover will not display `sorry : e`
238+
-/
239+
let e ← mkSorry e (synthetic := false)
240+
let e ← mkId e
241+
Term.addTermInfo' stx e
242+
else
243+
/-
244+
**Note**: only the `e`s type is displayed when hovering over the anchor.
245+
We add a silent info with the anchor declaration.
246+
-/
247+
Term.addTermInfo' stx e
248+
logAt (severity := .information) (isSilent := true) stx
249+
m!"#{anchorToString numDigits anchorPrefix} := {e}"
250+
226251
@[builtin_grind_tactic cases] def evalCases : GrindTactic := fun stx => do
227252
match stx with
228253
| `(grind| cases #$anchor:hexnum) =>
229254
let (numDigits, val) ← elabAnchor anchor
230255
let goal ← getMainGoal
231256
let candidates := goal.split.candidates
232-
let (goals, genNew) ← liftSearchM do
257+
let (e, goals, genNew) ← liftSearchM do
233258
for c in candidates do
259+
let e := c.getExpr
234260
let anchor ← getAnchor c.getExpr
235261
if isAnchorPrefix numDigits val anchor then
236262
let some result ← split? c
237263
| throwError "`cases` tactic failed, case-split is not ready{indentExpr c.getExpr}"
238-
return result
264+
return (e, result)
239265
throwError "`cases` tactic failed, invalid anchor"
266+
goal.withContext <| withRef anchor <| logAnchor numDigits val e
240267
let goals ← goals.filterMapM fun goal => do
241268
let (goal, _) ← liftGrindM <| SearchM.run goal do
242269
intros genNew

tests/lean/run/grind_interactive.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@ example : (∀ x, q x) → (∀ x, p x → p (f x)) → p x → p (f (f x)) := b
414414
show_thms
415415
instantiate #bfb8
416416

417+
example : (∀ x, q x) → (∀ x, p x → p (f x)) → p x → p (f (f x)) := by
418+
grind =>
419+
show_thms
420+
instantiate #bfb8
421+
417422
/-- error: no local theorems -/
418423
#guard_msgs in
419424
example : (∀ x, q x) → (∀ x, p x → p (f x)) → p x → p (f (f x)) := by

0 commit comments

Comments
 (0)