chore: add `isDebugEnabled` to `grind` This PR adds `isDebugEnabled` for checking whether `grind.debug` is set to `true` when `grind` was initialized.
diff --git a/src/Lean/Meta/Tactic/Grind/AC/Eq.lean b/src/Lean/Meta/Tactic/Grind/AC/Eq.lean index cd32c3a..c22faad 100644 --- a/src/Lean/Meta/Tactic/Grind/AC/Eq.lean +++ b/src/Lean/Meta/Tactic/Grind/AC/Eq.lean
@@ -228,7 +228,7 @@ if lhs₁.sharesVar lhs₂ then assert! lhs₁ != lhs₂ let some (r₁, c, r₂) := lhs₁.superposeAC? lhs₂ | unreachable! - if grind.debug.get (← getOptions) then + if (← isDebugEnabled) then assert! lhs₁ == r₁.union c assert! lhs₂ == r₂.union c let c ← mkEqCnstr (c₁.rhs.union r₂) (c₂.rhs.union r₁) (.superpose_ac r₁ c r₂ c₁ c₂) @@ -239,7 +239,7 @@ let lhs₂ := c₂.lhs assert! lhs₁ != lhs₂ if let some (p, c, s) := lhs₁.superpose? lhs₂ then - if grind.debug.get (← getOptions) then + if (← isDebugEnabled) then assert! lhs₁ == p ++ c assert! lhs₂ == c ++ s let c ← mkEqCnstr (c₁.rhs ++ s) (p ++ c₂.rhs) (.superpose p c s c₁ c₂)
diff --git a/src/Lean/Meta/Tactic/Grind/AC/Inv.lean b/src/Lean/Meta/Tactic/Grind/AC/Inv.lean index fb652db..d1e8c1c 100644 --- a/src/Lean/Meta/Tactic/Grind/AC/Inv.lean +++ b/src/Lean/Meta/Tactic/Grind/AC/Inv.lean
@@ -53,7 +53,7 @@ checkDiseqs public def checkInvariants : GoalM Unit := do - unless grind.debug.get (← getOptions) do return () + if (← isDebugEnabled) then for opId in *...(← get').structs.size do ACM.run opId checkStructInvs
diff --git a/src/Lean/Meta/Tactic/Grind/Arith/CommRing/Inv.lean b/src/Lean/Meta/Tactic/Grind/Arith/CommRing/Inv.lean index ff30eb4..f2a1933 100644 --- a/src/Lean/Meta/Tactic/Grind/Arith/CommRing/Inv.lean +++ b/src/Lean/Meta/Tactic/Grind/Arith/CommRing/Inv.lean
@@ -49,7 +49,7 @@ checkDiseqs def checkInvariants : GoalM Unit := do - unless grind.debug.get (← getOptions) do return () + if (← isDebugEnabled) then for ringId in *...(← get').rings.size do RingM.run ringId do assert! (← getRingId) == ringId
diff --git a/src/Lean/Meta/Tactic/Grind/Arith/Linear/Inv.lean b/src/Lean/Meta/Tactic/Grind/Arith/Linear/Inv.lean index 2702495..09f54c2 100644 --- a/src/Lean/Meta/Tactic/Grind/Arith/Linear/Inv.lean +++ b/src/Lean/Meta/Tactic/Grind/Arith/Linear/Inv.lean
@@ -97,7 +97,7 @@ checkDiseqCnstrs public def checkInvariants : GoalM Unit := do - unless grind.debug.get (← getOptions) do return () + if (← isDebugEnabled) then for structId in *...(← get').structs.size do LinearM.run structId do assert! (← getStructId) == structId
diff --git a/src/Lean/Meta/Tactic/Grind/Inv.lean b/src/Lean/Meta/Tactic/Grind/Inv.lean index beb17ce..2175436 100644 --- a/src/Lean/Meta/Tactic/Grind/Inv.lean +++ b/src/Lean/Meta/Tactic/Grind/Inv.lean
@@ -119,7 +119,7 @@ /-- Checks invariants if `grind.debug` is enabled. -/ public def checkInvariants (expensive := false) : GoalM Unit := do - if grind.debug.get (← getOptions) then + if (← isDebugEnabled) then for e in (← getExprs) do let node ← getENode e checkParents node.self
diff --git a/src/Lean/Meta/Tactic/Grind/Main.lean b/src/Lean/Meta/Tactic/Grind/Main.lean index 3386771..3ca6c38 100644 --- a/src/Lean/Meta/Tactic/Grind/Main.lean +++ b/src/Lean/Meta/Tactic/Grind/Main.lean
@@ -119,9 +119,11 @@ let symPrios := params.symPrios let extensions := params.extensions let anchorRefs? := params.anchorRefs? + let debug := grind.debug.get (← getOptions) x (← mkMethods evalTactic?).toMethodsRef { config, anchorRefs?, simpMethods, simp, extensions, symPrios - trueExpr, falseExpr, natZExpr, btrueExpr, bfalseExpr, ordEqExpr, intExpr } + trueExpr, falseExpr, natZExpr, btrueExpr, bfalseExpr, ordEqExpr, intExpr + debug } |>.run' { scState } private def mkCleanState (mvarId : MVarId) : GrindM Clean.State := mvarId.withContext do
diff --git a/src/Lean/Meta/Tactic/Grind/Order/Internalize.lean b/src/Lean/Meta/Tactic/Grind/Order/Internalize.lean index aac7023..67b81e4 100644 --- a/src/Lean/Meta/Tactic/Grind/Order/Internalize.lean +++ b/src/Lean/Meta/Tactic/Grind/Order/Internalize.lean
@@ -206,7 +206,7 @@ def internalizeCnstr (e : Expr) (kind : CnstrKind) (lhs rhs : Expr) : OrderM Unit := do let some c ← mkCnstr? e kind lhs rhs | return () trace[grind.order.internalize] "{c.u}, {c.v}, {c.k}" - if grind.debug.get (← getOptions) then + if (← isDebugEnabled) then if let some h := c.h? then check h let u ← mkNode c.u let v ← mkNode c.v
diff --git a/src/Lean/Meta/Tactic/Grind/Types.lean b/src/Lean/Meta/Tactic/Grind/Types.lean index e9ecc29..fc79180 100644 --- a/src/Lean/Meta/Tactic/Grind/Types.lean +++ b/src/Lean/Meta/Tactic/Grind/Types.lean
@@ -167,6 +167,7 @@ bfalseExpr : Expr ordEqExpr : Expr -- `Ordering.eq` intExpr : Expr -- `Int` + debug : Bool -- Cached `grind.debug (← getOptions)` /-- Key for the congruence theorem cache. -/ structure CongrTheoremCacheKey where @@ -252,6 +253,10 @@ @[inline] def mapGrindM [MonadControlT GrindM m] [Monad m] (f : {α : Type} → GrindM α → GrindM α) {α} (x : m α) : m α := controlAt GrindM fun runInBase => f <| runInBase x +/-- Returns `true` if `grind.debug` is set -/ +@[inline] def isDebugEnabled : GrindM Bool := + return (← readThe Context).debug + /-- Backtrackable state for the `GrindM` monad. -/ @@ -1072,7 +1077,7 @@ /-- Adds a new fact `prop` with proof `proof` to the queue for preprocessing and the assertion. -/ def addNewRawFact (proof : Expr) (prop : Expr) (generation : Nat) (splitSource : SplitSource) : GoalM Unit := do - if grind.debug.get (← getOptions) then + if (← isDebugEnabled) then unless (← withGTransparency <| isDefEq (← inferType proof) prop) do throwError "`grind` internal error, trying to assert{indentExpr prop}\n\ with proof{indentExpr proof}\nwhich has type{indentExpr (← inferType proof)}\n\ @@ -1231,7 +1236,7 @@ Otherwise, it pushes `lhs ≍ rhs`. -/ def pushEqCore (lhs rhs proof : Expr) (isHEq : Bool) : GoalM Unit := do - if grind.debug.get (← getOptions) then + if (← isDebugEnabled) then unless (← alreadyInternalized lhs) do throwError "`grind` internal error, lhs of new equality has not been internalized{indentExpr lhs}" unless (← alreadyInternalized rhs) do