Skip to content

Commit

Permalink
chore: check whether pointer equality implies structural equality in …
Browse files Browse the repository at this point in the history
…`grind` (#6451)

This PR checks whether in the internal state of the `grind` tactic
pointer equality implies structural equality.
  • Loading branch information
leodemoura authored Dec 26, 2024
1 parent 0ebe9e5 commit bdcb791
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Lean/Meta/Tactic/Grind/Inv.lean
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,27 @@ private def checkParents (e : Expr) : GoalM Unit := do
-- All the parents are stored in the root of the equivalence class.
assert! (← getParents e).isEmpty

private def checkPtrEqImpliesStructEq : GoalM Unit := do
let nodes ← getENodes
for h₁ : i in [: nodes.size] do
let n₁ := nodes[i]
for h₂ : j in [i+1 : nodes.size] do
let n₂ := nodes[i]
-- We don't have multiple nodes for the same expression
assert! !isSameExpr n₁.self n₂.self
-- and the two expressions must not be structurally equal
assert! !Expr.equal n₁.self n₂.self

/--
Check basic invariants if `grind.debug` is enabled.
Checks basic invariants if `grind.debug` is enabled.
-/
def checkInvariants : GoalM Unit := do
def checkInvariants (expensive := false) : GoalM Unit := do
if grind.debug.get (← getOptions) then
for (_, node) in (← get).enodes do
checkParents node.self
if isSameExpr node.self node.root then
checkEqc node
if expensive then
checkPtrEqImpliesStructEq

end Lean.Meta.Grind
2 changes: 2 additions & 0 deletions src/Lean/Meta/Tactic/Grind/Preprocessor.lean
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def preprocess (mvarId : MVarId) : PreM State := do
loop (← mkGoal mvarId)
if (← isTracingEnabledFor `grind.pre) then
trace[grind.pre] (← ppGoals)
for goal in (← get).goals do
discard <| GoalM.run' goal <| checkInvariants (expensive := true)
get

def preprocessAndProbe (mvarId : MVarId) (p : GoalM Unit) : PreM Unit := do
Expand Down

0 comments on commit bdcb791

Please sign in to comment.