Skip to content

Commit

Permalink
feat: configure max rewrite steps in bv_normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
hargoniX committed Nov 8, 2024
1 parent 2a0d787 commit b6e610d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Lean/Elab/Tactic/BVDecide/Frontend/Normalize.lean
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ partial def fixpointPipeline (passes : List Pass) (goal : MVarId) : MetaM (Optio
/--
Responsible for applying the Bitwuzla style rewrite rules.
-/
def rewriteRulesPass : Pass := fun goal => do
def rewriteRulesPass (maxSteps : Nat) : Pass := fun goal => do
let bvThms ← bvNormalizeExt.getTheorems
let bvSimprocs ← bvNormalizeSimprocExt.getSimprocs
let sevalThms ← getSEvalTheorems
let sevalSimprocs ← Simp.getSEvalSimprocs

let simpCtx : Simp.Context := {
config := { failIfUnchanged := false, zetaDelta := true }
config := { failIfUnchanged := false, zetaDelta := true, maxSteps }
simpTheorems := #[bvThms, sevalThms]
congrTheorems := (← getSimpCongrTheorems)
}
Expand All @@ -181,7 +181,7 @@ def rewriteRulesPass : Pass := fun goal => do
Substitute embedded constraints. That is look for hypotheses of the form `h : x = true` and use
them to substitute occurences of `x` within other hypotheses
-/
def embeddedConstraintPass : Pass := fun goal =>
def embeddedConstraintPass (maxSteps : Nat) : Pass := fun goal =>
goal.withContext do
let hyps ← goal.getNondepPropHyps
let relevanceFilter acc hyp := do
Expand All @@ -195,7 +195,7 @@ def embeddedConstraintPass : Pass := fun goal =>
let relevantHyps : SimpTheoremsArray ← hyps.foldlM (init := #[]) relevanceFilter

let simpCtx : Simp.Context := {
config := { failIfUnchanged := false }
config := { failIfUnchanged := false, maxSteps }
simpTheorems := relevantHyps
congrTheorems := (← getSimpCongrTheorems)
}
Expand All @@ -222,10 +222,14 @@ def acNormalizePass : Pass := fun goal => do
/--
The normalization passes used by `bv_normalize` and thus `bv_decide`.
-/
def defaultPipeline : List Pass := [rewriteRulesPass, embeddedConstraintPass]
def defaultPipeline (cfg : BVDecideConfig ): List Pass :=
[
rewriteRulesPass cfg.maxSteps,
embeddedConstraintPass cfg.maxSteps
]

def passPipeline (cfg : BVDecideConfig) : List Pass := Id.run do
let mut passPipeline := defaultPipeline
let mut passPipeline := defaultPipeline cfg

if cfg.acNf then
passPipeline := passPipeline ++ [acNormalizePass]
Expand Down
4 changes: 4 additions & 0 deletions src/Std/Tactic/BVDecide/Syntax.lean
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ structure BVDecideConfig where
Lean process.
-/
graphviz : Bool := false
/--
The maximum number of subexpressions to visit when performing simplification.
-/
maxSteps : Nat := Lean.Meta.Simp.defaultMaxSteps

end Lean.Elab.Tactic.BVDecide.Frontend

Expand Down

0 comments on commit b6e610d

Please sign in to comment.