bv: Use EnvObj::rewrite() and EnvObj::options() in BvSolver. (#7171)
authorMathias Preiner <mathias.preiner@gmail.com>
Fri, 10 Sep 2021 01:54:12 +0000 (18:54 -0700)
committerGitHub <noreply@github.com>
Fri, 10 Sep 2021 01:54:12 +0000 (01:54 +0000)
src/theory/bv/bv_solver.h
src/theory/bv/bv_solver_bitblast.cpp
src/theory/bv/bv_solver_bitblast.h
src/theory/bv/bv_solver_bitblast_internal.cpp
src/theory/bv/bv_solver_bitblast_internal.h
src/theory/bv/bv_solver_layered.cpp
src/theory/bv/bv_solver_layered.h
src/theory/bv/theory_bv.cpp

index c959fb64891ac73c70896ebeafc45979427f4d4e..510c8a29aae4bd230453430aa1e3b6d08717708b 100644 (file)
 #ifndef CVC5__THEORY__BV__BV_SOLVER_H
 #define CVC5__THEORY__BV__BV_SOLVER_H
 
+#include "smt/env.h"
+#include "smt/env_obj.h"
 #include "theory/theory.h"
 
 namespace cvc5 {
 namespace theory {
 namespace bv {
 
-class BVSolver
+class BVSolver : protected EnvObj
 {
  public:
-  BVSolver(TheoryState& state, TheoryInferenceManager& inferMgr)
-      : d_state(state), d_im(inferMgr){};
+  BVSolver(Env& env, TheoryState& state, TheoryInferenceManager& inferMgr)
+      : EnvObj(env), d_state(state), d_im(inferMgr){};
 
   virtual ~BVSolver() {}
 
index ecd42e4a0a7cf4750657af5bd1c34543455d77a9..9d316e91e66118dc32595146bb7ce779129386bc 100644 (file)
@@ -108,10 +108,11 @@ class BBRegistrar : public prop::Registrar
   std::unordered_set<TNode> d_registeredAtoms;
 };
 
-BVSolverBitblast::BVSolverBitblast(TheoryState* s,
+BVSolverBitblast::BVSolverBitblast(Env& env,
+                                   TheoryState* s,
                                    TheoryInferenceManager& inferMgr,
                                    ProofNodeManager* pnm)
-    : BVSolver(*s, inferMgr),
+    : BVSolver(env, *s, inferMgr),
       d_bitblaster(new NodeBitblaster(s)),
       d_bbRegistrar(new BBRegistrar(d_bitblaster.get())),
       d_nullContext(new context::Context()),
@@ -123,7 +124,7 @@ BVSolverBitblast::BVSolverBitblast(TheoryState* s,
                 : nullptr),
       d_factLiteralCache(s->getSatContext()),
       d_literalFactCache(s->getSatContext()),
-      d_propagate(options::bitvectorPropagate()),
+      d_propagate(options().bv.bitvectorPropagate),
       d_resetNotify(new NotifyResetAssertions(s->getUserContext()))
 {
   if (pnm != nullptr)
@@ -147,7 +148,7 @@ void BVSolverBitblast::postCheck(Theory::Effort level)
 
   // If we permanently added assertions to the SAT solver and the assertions
   // were reset, we have to reset the SAT solver and the CNF stream.
-  if (options::bvAssertInput() && d_resetNotify->doneResetAssertions())
+  if (options().bv.bvAssertInput && d_resetNotify->doneResetAssertions())
   {
     d_satSolver.reset(nullptr);
     d_cnfStream.reset(nullptr);
@@ -248,7 +249,7 @@ bool BVSolverBitblast::preNotifyFact(
    * If this is the case we can assert `fact` to the SAT solver instead of
    * using assumptions.
    */
-  if (options::bvAssertInput() && val.isSatLiteral(fact)
+  if (options().bv.bvAssertInput && val.isSatLiteral(fact)
       && val.getDecisionLevel(fact) == 0 && val.getIntroLevel(fact) == 0)
   {
     Assert(!val.isDecision(fact));
@@ -277,7 +278,7 @@ void BVSolverBitblast::computeRelevantTerms(std::set<Node>& termSet)
    * in BitblastMode::EAGER and therefore add all variables from the
    * bit-blaster to `termSet`.
    */
-  if (options::bitblastMode() == options::BitblastMode::EAGER)
+  if (options().bv.bitblastMode == options::BitblastMode::EAGER)
   {
     d_bitblaster->computeRelevantTerms(termSet);
   }
@@ -303,7 +304,7 @@ bool BVSolverBitblast::collectModelValues(TheoryModel* m,
 
   // In eager bitblast mode we also have to collect the model values for
   // Boolean variables in the CNF stream.
-  if (options::bitblastMode() == options::BitblastMode::EAGER)
+  if (options().bv.bitblastMode == options::BitblastMode::EAGER)
   {
     NodeManager* nm = NodeManager::currentNM();
     std::vector<TNode> vars;
@@ -327,7 +328,7 @@ bool BVSolverBitblast::collectModelValues(TheoryModel* m,
 
 void BVSolverBitblast::initSatSolver()
 {
-  switch (options::bvSatSolver())
+  switch (options().bv.bvSatSolver)
   {
     case options::SatSolverMode::CRYPTOMINISAT:
       d_satSolver.reset(prop::SatSolverFactory::createCryptoMinisat(
index 3f4ab50250797335c13391241e4ef3cce5736f16..e8931acff3f0c0e1e82d1225b1cef3135970b659 100644 (file)
@@ -42,7 +42,8 @@ class BBRegistrar;
 class BVSolverBitblast : public BVSolver
 {
  public:
-  BVSolverBitblast(TheoryState* state,
+  BVSolverBitblast(Env& env,
+                   TheoryState* state,
                    TheoryInferenceManager& inferMgr,
                    ProofNodeManager* pnm);
   ~BVSolverBitblast() = default;
index 1b606a0e9343791eb6fa79113ad6c28dab2783c6..71a29f472f264b23baa6da71cc419f757364a8b3 100644 (file)
@@ -68,8 +68,11 @@ void collectBVAtoms(TNode n, std::unordered_set<Node>& atoms)
 }  // namespace
 
 BVSolverBitblastInternal::BVSolverBitblastInternal(
-    TheoryState* s, TheoryInferenceManager& inferMgr, ProofNodeManager* pnm)
-    : BVSolver(*s, inferMgr),
+    Env& env,
+    TheoryState* s,
+    TheoryInferenceManager& inferMgr,
+    ProofNodeManager* pnm)
+    : BVSolver(env, *s, inferMgr),
       d_pnm(pnm),
       d_bitblaster(new BBProof(s, pnm, false))
 {
index 2fc7173d13aa0affa4535275213a229f48a11930..cc365e109ecb6b5d7234e47f3eb33310bf611c44 100644 (file)
@@ -37,7 +37,8 @@ namespace bv {
 class BVSolverBitblastInternal : public BVSolver
 {
  public:
-  BVSolverBitblastInternal(TheoryState* state,
+  BVSolverBitblastInternal(Env& env,
+                           TheoryState* state,
                            TheoryInferenceManager& inferMgr,
                            ProofNodeManager* pnm);
   ~BVSolverBitblastInternal() = default;
index 40daf1cb49679c1b3765d99e90ec21b08baff0c0..bf76ed2f98308f468d6e5df9f46f8da5cf8cc6e6 100644 (file)
@@ -38,11 +38,12 @@ namespace theory {
 namespace bv {
 
 BVSolverLayered::BVSolverLayered(TheoryBV& bv,
+                                 Env& env,
                                  context::Context* c,
                                  context::UserContext* u,
                                  ProofNodeManager* pnm,
                                  std::string name)
-    : BVSolver(bv.d_state, bv.d_im),
+    : BVSolver(env, bv.d_state, bv.d_im),
       d_bv(bv),
       d_context(c),
       d_alreadyPropagatedSet(c),
@@ -61,32 +62,32 @@ BVSolverLayered::BVSolverLayered(TheoryBV& bv,
       d_abstractionModule(new AbstractionModule(getStatsPrefix(THEORY_BV))),
       d_calledPreregister(false)
 {
-  if (options::bitblastMode() == options::BitblastMode::EAGER)
+  if (options().bv.bitblastMode == options::BitblastMode::EAGER)
   {
     d_eagerSolver.reset(new EagerBitblastSolver(c, this));
     return;
   }
 
-  if (options::bitvectorEqualitySolver())
+  if (options().bv.bitvectorEqualitySolver)
   {
     d_subtheories.emplace_back(new CoreSolver(c, this));
     d_subtheoryMap[SUB_CORE] = d_subtheories.back().get();
   }
 
-  if (options::bitvectorInequalitySolver())
+  if (options().bv.bitvectorInequalitySolver)
   {
     d_subtheories.emplace_back(new InequalitySolver(c, u, this));
     d_subtheoryMap[SUB_INEQUALITY] = d_subtheories.back().get();
   }
 
-  if (options::bitvectorAlgebraicSolver())
+  if (options().bv.bitvectorAlgebraicSolver)
   {
     d_subtheories.emplace_back(new AlgebraicSolver(c, this));
     d_subtheoryMap[SUB_ALGEBRAIC] = d_subtheories.back().get();
   }
 
   BitblastSolver* bb_solver = new BitblastSolver(c, this);
-  if (options::bvAbstraction())
+  if (options().bv.bvAbstraction)
   {
     bb_solver->setAbstraction(d_abstractionModule.get());
   }
@@ -141,7 +142,7 @@ void BVSolverLayered::preRegisterTerm(TNode node)
   Debug("bitvector-preregister")
       << "BVSolverLayered::preRegister(" << node << ")" << std::endl;
 
-  if (options::bitblastMode() == options::BitblastMode::EAGER)
+  if (options().bv.bitblastMode == options::BitblastMode::EAGER)
   {
     // the aig bit-blaster option is set heuristically
     // if bv abstraction is used
@@ -235,7 +236,7 @@ void BVSolverLayered::check(Theory::Effort e)
   // we may be getting new assertions so the model cache may not be sound
   d_invalidateModelCache.set(true);
   // if we are using the eager solver
-  if (options::bitblastMode() == options::BitblastMode::EAGER)
+  if (options().bv.bitblastMode == options::BitblastMode::EAGER)
   {
     // this can only happen on an empty benchmark
     if (!d_eagerSolver->isInitialized())
@@ -322,7 +323,7 @@ bool BVSolverLayered::collectModelValues(TheoryModel* m,
                                          const std::set<Node>& termSet)
 {
   Assert(!inConflict());
-  if (options::bitblastMode() == options::BitblastMode::EAGER)
+  if (options().bv.bitblastMode == options::BitblastMode::EAGER)
   {
     if (!d_eagerSolver->collectModelInfo(m, true))
     {
@@ -355,7 +356,7 @@ Node BVSolverLayered::getModelValue(TNode var)
 void BVSolverLayered::propagate(Theory::Effort e)
 {
   Debug("bitvector") << indent() << "BVSolverLayered::propagate()" << std::endl;
-  if (options::bitblastMode() == options::BitblastMode::EAGER)
+  if (options().bv.bitblastMode == options::BitblastMode::EAGER)
   {
     return;
   }
@@ -394,15 +395,15 @@ TrustNode BVSolverLayered::ppRewrite(TNode t)
 {
   Debug("bv-pp-rewrite") << "BVSolverLayered::ppRewrite " << t << "\n";
   Node res = t;
-  if (options::bitwiseEq() && RewriteRule<BitwiseEq>::applies(t))
+  if (options().bv.bitwiseEq && RewriteRule<BitwiseEq>::applies(t))
   {
     Node result = RewriteRule<BitwiseEq>::run<false>(t);
-    res = Rewriter::rewrite(result);
+    res = rewrite(result);
   }
   else if (RewriteRule<UltAddOne>::applies(t))
   {
     Node result = RewriteRule<UltAddOne>::run<false>(t);
-    res = Rewriter::rewrite(result);
+    res = rewrite(result);
   }
   else if (res.getKind() == kind::EQUAL
            && ((res[0].getKind() == kind::BITVECTOR_ADD
@@ -419,7 +420,7 @@ TrustNode BVSolverLayered::ppRewrite(TNode t)
     Node rewr_eq = RewriteRule<SolveEq>::run<true>(new_eq);
     if (rewr_eq[0].isVar() || rewr_eq[1].isVar())
     {
-      res = Rewriter::rewrite(rewr_eq);
+      res = rewrite(rewr_eq);
     }
     else
     {
@@ -451,7 +452,7 @@ TrustNode BVSolverLayered::ppRewrite(TNode t)
   //   if (RewriteRule<MultSlice>::applies(mult)) {
   //     Node new_mult = RewriteRule<MultSlice>::run<false>(mult);
   //     Node new_eq =
-  //     Rewriter::rewrite(NodeManager::currentNM()->mkNode(kind::EQUAL,
+  //     rewrite(NodeManager::currentNM()->mkNode(kind::EQUAL,
   //     new_mult, add));
 
   //     // the simplification can cause the formula to blow up
@@ -475,7 +476,7 @@ TrustNode BVSolverLayered::ppRewrite(TNode t)
   //   }
   // }
 
-  if (options::bvAbstraction() && t.getType().isBoolean())
+  if (options().bv.bvAbstraction && t.getType().isBoolean())
   {
     d_abstractionModule->addInputAtom(res);
   }
@@ -595,9 +596,9 @@ void BVSolverLayered::notifySharedTerm(TNode t)
 
 EqualityStatus BVSolverLayered::getEqualityStatus(TNode a, TNode b)
 {
-  if (options::bitblastMode() == options::BitblastMode::EAGER)
+  if (options().bv.bitblastMode == options::BitblastMode::EAGER)
     return EQUALITY_UNKNOWN;
-  Assert(options::bitblastMode() == options::BitblastMode::LAZY);
+  Assert(options().bv.bitblastMode == options::BitblastMode::LAZY);
   for (unsigned i = 0; i < d_subtheories.size(); ++i)
   {
     EqualityStatus status = d_subtheories[i]->getEqualityStatus(a, b);
@@ -665,8 +666,8 @@ bool BVSolverLayered::applyAbstraction(const std::vector<Node>& assertions,
 {
   bool changed =
       d_abstractionModule->applyAbstraction(assertions, new_assertions);
-  if (changed && options::bitblastMode() == options::BitblastMode::EAGER
-      && options::bitvectorAig())
+  if (changed && options().bv.bitblastMode == options::BitblastMode::EAGER
+      && options().bv.bitvectorAig)
   {
     // disable AIG mode
     AlwaysAssert(!d_eagerSolver->isInitialized());
@@ -678,7 +679,7 @@ bool BVSolverLayered::applyAbstraction(const std::vector<Node>& assertions,
 
 void BVSolverLayered::setConflict(Node conflict)
 {
-  if (options::bvAbstraction())
+  if (options().bv.bvAbstraction)
   {
     NodeManager* const nm = NodeManager::currentNM();
     Node new_conflict = d_abstractionModule->simplifyConflict(conflict);
index 023ff5a466003c5147e3902c6ba7f05246ed0650..325f2fc72369bde45e33cd6a698486f04d4aa2b3 100644 (file)
@@ -58,6 +58,7 @@ class BVSolverLayered : public BVSolver
 
  public:
   BVSolverLayered(TheoryBV& bv,
+                  Env& env,
                   context::Context* c,
                   context::UserContext* u,
                   ProofNodeManager* pnm = nullptr,
index 7493a54c71692e63af95f73ba966c6967ec58ff2..96eccea57705ce2916648bd64e22fb83caedff4d 100644 (file)
@@ -43,20 +43,22 @@ TheoryBV::TheoryBV(Env& env,
       d_invalidateModelCache(context(), true),
       d_stats("theory::bv::")
 {
-  switch (options::bvSolver())
+  switch (options().bv.bvSolver)
   {
     case options::BVSolver::BITBLAST:
-      d_internal.reset(new BVSolverBitblast(&d_state, d_im, d_pnm));
+      d_internal.reset(new BVSolverBitblast(d_env, &d_state, d_im, d_pnm));
       break;
 
     case options::BVSolver::LAYERED:
-      d_internal.reset(
-          new BVSolverLayered(*this, context(), userContext(), d_pnm, name));
+      d_internal.reset(new BVSolverLayered(
+          *this, d_env, context(), userContext(), d_pnm, name));
       break;
 
     default:
-      AlwaysAssert(options::bvSolver() == options::BVSolver::BITBLAST_INTERNAL);
-      d_internal.reset(new BVSolverBitblastInternal(&d_state, d_im, d_pnm));
+      AlwaysAssert(options().bv.bvSolver
+                   == options::BVSolver::BITBLAST_INTERNAL);
+      d_internal.reset(
+          new BVSolverBitblastInternal(d_env, &d_state, d_im, d_pnm));
   }
   d_theoryState = &d_state;
   d_inferManager = &d_im;
@@ -68,7 +70,7 @@ TheoryRewriter* TheoryBV::getTheoryRewriter() { return &d_rewriter; }
 
 ProofRuleChecker* TheoryBV::getProofChecker()
 {
-  if (options::bvSolver() == options::BVSolver::BITBLAST_INTERNAL)
+  if (options().bv.bvSolver == options::BVSolver::BITBLAST_INTERNAL)
   {
     return static_cast<BVSolverBitblastInternal*>(d_internal.get())
         ->getProofChecker();
@@ -222,7 +224,7 @@ Theory::PPAssertStatus TheoryBV::ppAssert(
      * x = c::sk2       if h == bw(x)-1, where bw(sk2) = l
      * x = sk1::c::sk2  otherwise, where bw(sk1) = bw(x)-1-h and bw(sk2) = l
      */
-    Node node = Rewriter::rewrite(in);
+    Node node = rewrite(in);
     if ((node[0].getKind() == kind::BITVECTOR_EXTRACT && node[1].isConst())
         || (node[1].getKind() == kind::BITVECTOR_EXTRACT
             && node[0].isConst()))
@@ -391,7 +393,7 @@ Node TheoryBV::getValue(TNode node)
         Assert(iit->second.isConst());
         nb << iit->second;
       }
-      it->second = Rewriter::rewrite(nb.constructNode());
+      it->second = rewrite(nb.constructNode());
     }
   } while (!visit.empty());