Skip to content

Commit

Permalink
feat: hide grind auxiliary gadgets in messages (#6882)
Browse files Browse the repository at this point in the history
This PR ensures `grind` auxiliary gadgets are "hidden" in error and
diagnostic messages.
  • Loading branch information
leodemoura authored Jan 31, 2025
1 parent 3331ed9 commit d70a596
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
18 changes: 18 additions & 0 deletions src/Init/Grind/Util.lean
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,22 @@ def MatchCond (p : Prop) : Prop := p
theorem nestedProof_congr (p q : Prop) (h : p = q) (hp : p) (hq : q) : HEq (@nestedProof p hp) (@nestedProof q hq) := by
subst h; apply HEq.refl

@[app_unexpander nestedProof]
def nestedProofUnexpander : PrettyPrinter.Unexpander := fun stx => do
match stx with
| `($_ $p:term) => `(‹$p›)
| _ => throw ()

@[app_unexpander MatchCond]
def matchCondUnexpander : PrettyPrinter.Unexpander := fun stx => do
match stx with
| `($_ $p:term) => `($p)
| _ => throw ()

@[app_unexpander EqMatch]
def eqMatchUnexpander : PrettyPrinter.Unexpander := fun stx => do
match stx with
| `($_ $lhs:term $rhs:term) => `($lhs = $rhs)
| _ => throw ()

end Lean.Grind
5 changes: 2 additions & 3 deletions tests/lean/run/grind_match1.lean
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ info: [grind.assert] (match as, bs with
[grind.assert] a₁ :: f 0 = as
[grind.assert] f 0 = a₂ :: f 1
[grind.assert] ¬d = []
[grind.assert] Lean.Grind.EqMatch
(match a₁ :: a₂ :: f 1, [] with
[grind.assert] (match a₁ :: a₂ :: f 1, [] with
| [], x => bs
| head :: head_1 :: tail, [] => []
| x :: xs, ys => x :: g xs ys)
| x :: xs, ys => x :: g xs ys) =
[]
[grind.split.resolved] match as, bs with
| [], x => bs
Expand Down
8 changes: 2 additions & 6 deletions tests/lean/run/grind_nested_proofs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ detect equalities between array access terms.
-/

/--
info: [Meta.debug] [Lean.Grind.nestedProof (i < a.toList.length),
Lean.Grind.nestedProof (j < a.toList.length),
Lean.Grind.nestedProof (j < b.toList.length)]
info: [Meta.debug] [‹i < a.toList.length›, ‹j < a.toList.length›, ‹j < b.toList.length›]
[Meta.debug] [a[i], b[j], a[j]]
-/
#guard_msgs (info) in
example (i j : Nat) (a b : Array Nat) (h1 : j < a.size) (h : j < b.size) (h2 : i ≤ j) : a[i] < a[j] + b[j] → i = j → a = b → False := by
grind on_failure fallback

/--
info: [Meta.debug] [Lean.Grind.nestedProof (i < a.toList.length),
Lean.Grind.nestedProof (j < a.toList.length),
Lean.Grind.nestedProof (j < b.toList.length)]
info: [Meta.debug] [‹i < a.toList.length›, ‹j < a.toList.length›, ‹j < b.toList.length›]
[Meta.debug] [a[i], a[j]]
-/
#guard_msgs (info) in
Expand Down

0 comments on commit d70a596

Please sign in to comment.