diff options
author | Andrew Reynolds <andrew.j.reynolds@gmail.com> | 2020-07-16 12:10:58 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-16 12:10:58 -0500 |
commit | f7559c879d1ebc7d4d9b9f72b0858bdf42c9ed8c (patch) | |
tree | f4ceec82dfec21737b4cc1c555706bd8426fc9e9 /src/theory/bv | |
parent | 051106d0033c8108008acba65ad02a77b5ddd19c (diff) |
Make ExtTheory a utility and not a member of Theory (#4753)
Previously, we assumed that ExtTheory, the module for doing context-dependent simplification, was one-to-one with Theory. This design is not necessary. This makes this class a utility, which can be used as needed. This makes e.g. the initialization of TheoryStrings much easier, since the ExtTheory object can be created first.
Diffstat (limited to 'src/theory/bv')
-rw-r--r-- | src/theory/bv/bv_subtheory_core.cpp | 28 | ||||
-rw-r--r-- | src/theory/bv/bv_subtheory_core.h | 30 | ||||
-rw-r--r-- | src/theory/bv/theory_bv.cpp | 23 | ||||
-rw-r--r-- | src/theory/bv/theory_bv.h | 8 |
4 files changed, 49 insertions, 40 deletions
diff --git a/src/theory/bv/bv_subtheory_core.cpp b/src/theory/bv/bv_subtheory_core.cpp index 668d7b87e..02570b12c 100644 --- a/src/theory/bv/bv_subtheory_core.cpp +++ b/src/theory/bv/bv_subtheory_core.cpp @@ -32,17 +32,18 @@ using namespace CVC4::theory; using namespace CVC4::theory::bv; using namespace CVC4::theory::bv::utils; -CoreSolver::CoreSolver(context::Context* c, TheoryBV* bv) - : SubtheorySolver(c, bv), - d_notify(*this), - d_equalityEngine(d_notify, c, "theory::bv::ee", true), - d_slicer(new Slicer()), - d_isComplete(c, true), - d_lemmaThreshold(16), - d_useSlicer(false), - d_preregisterCalled(false), - d_checkCalled(false), - d_reasons(c) +CoreSolver::CoreSolver(context::Context* c, TheoryBV* bv, ExtTheory* extt) + : SubtheorySolver(c, bv), + d_notify(*this), + d_equalityEngine(d_notify, c, "theory::bv::ee", true), + d_slicer(new Slicer()), + d_isComplete(c, true), + d_lemmaThreshold(16), + d_useSlicer(false), + d_preregisterCalled(false), + d_checkCalled(false), + d_extTheory(extt), + d_reasons(c) { // The kinds we are treating as function application in congruence d_equalityEngine.addFunctionKind(kind::BITVECTOR_CONCAT, true); @@ -411,10 +412,7 @@ void CoreSolver::conflict(TNode a, TNode b) { d_bv->setConflict(conflict); } -void CoreSolver::eqNotifyNewClass(TNode t) { - Assert(d_bv->getExtTheory() != NULL); - d_bv->getExtTheory()->registerTerm( t ); -} +void CoreSolver::eqNotifyNewClass(TNode t) { d_extTheory->registerTerm(t); } bool CoreSolver::isCompleteForTerm(TNode term, TNodeBoolMap& seen) { if (d_useSlicer) diff --git a/src/theory/bv/bv_subtheory_core.h b/src/theory/bv/bv_subtheory_core.h index a9ca57fb4..8f4f9089a 100644 --- a/src/theory/bv/bv_subtheory_core.h +++ b/src/theory/bv/bv_subtheory_core.h @@ -24,6 +24,7 @@ #include "context/cdhashmap.h" #include "context/cdhashset.h" #include "theory/bv/bv_subtheory.h" +#include "theory/ext_theory.h" namespace CVC4 { namespace theory { @@ -90,7 +91,10 @@ class CoreSolver : public SubtheorySolver { bool d_useSlicer; bool d_preregisterCalled; bool d_checkCalled; - + + /** Pointer to the extended theory module. */ + ExtTheory* d_extTheory; + /** To make sure we keep the explanations */ context::CDHashSet<Node, NodeHashFunction> d_reasons; ModelValue d_modelValues; @@ -101,18 +105,18 @@ class CoreSolver : public SubtheorySolver { bool isCompleteForTerm(TNode term, TNodeBoolMap& seen); Statistics d_statistics; public: - CoreSolver(context::Context* c, TheoryBV* bv); - ~CoreSolver(); - bool isComplete() override { return d_isComplete; } - void setMasterEqualityEngine(eq::EqualityEngine* eq); - void preRegister(TNode node) override; - bool check(Theory::Effort e) override; - void explain(TNode literal, std::vector<TNode>& assumptions) override; - bool collectModelInfo(TheoryModel* m, bool fullModel) override; - Node getModelValue(TNode var) override; - void addSharedTerm(TNode t) override - { - d_equalityEngine.addTriggerTerm(t, THEORY_BV); + CoreSolver(context::Context* c, TheoryBV* bv, ExtTheory* extt); + ~CoreSolver(); + bool isComplete() override { return d_isComplete; } + void setMasterEqualityEngine(eq::EqualityEngine* eq); + void preRegister(TNode node) override; + bool check(Theory::Effort e) override; + void explain(TNode literal, std::vector<TNode>& assumptions) override; + bool collectModelInfo(TheoryModel* m, bool fullModel) override; + Node getModelValue(TNode var) override; + void addSharedTerm(TNode t) override + { + d_equalityEngine.addTriggerTerm(t, THEORY_BV); } EqualityStatus getEqualityStatus(TNode a, TNode b) override { diff --git a/src/theory/bv/theory_bv.cpp b/src/theory/bv/theory_bv.cpp index c8e585d88..0a4499c11 100644 --- a/src/theory/bv/theory_bv.cpp +++ b/src/theory/bv/theory_bv.cpp @@ -66,6 +66,7 @@ TheoryBV::TheoryBV(context::Context* c, d_invalidateModelCache(c, true), d_literalsToPropagate(c), d_literalsToPropagateIndex(c, 0), + d_extTheory(new ExtTheory(this)), d_propagatedBy(c), d_eagerSolver(), d_abstractionModule(new AbstractionModule(getStatsPrefix(THEORY_BV))), @@ -75,9 +76,8 @@ TheoryBV::TheoryBV(context::Context* c, d_extf_range_infer(u), d_extf_collapse_infer(u) { - setupExtTheory(); - getExtTheory()->addFunctionKind(kind::BITVECTOR_TO_NAT); - getExtTheory()->addFunctionKind(kind::INT_TO_BITVECTOR); + d_extTheory->addFunctionKind(kind::BITVECTOR_TO_NAT); + d_extTheory->addFunctionKind(kind::INT_TO_BITVECTOR); if (options::bitblastMode() == options::BitblastMode::EAGER) { d_eagerSolver.reset(new EagerBitblastSolver(c, this)); @@ -86,7 +86,7 @@ TheoryBV::TheoryBV(context::Context* c, if (options::bitvectorEqualitySolver() && !options::proof()) { - d_subtheories.emplace_back(new CoreSolver(c, this)); + d_subtheories.emplace_back(new CoreSolver(c, this, d_extTheory.get())); d_subtheoryMap[SUB_CORE] = d_subtheories.back().get(); } @@ -262,9 +262,10 @@ void TheoryBV::preRegisterTerm(TNode node) { for (unsigned i = 0; i < d_subtheories.size(); ++i) { d_subtheories[i]->preRegister(node); } - - // AJR : equality solver currently registers all terms to ExtTheory, if we want a lazy reduction without the bv equality solver, need to call this - //getExtTheory()->registerTermRec( node ); + + // AJR : equality solver currently registers all terms to ExtTheory, if we + // want a lazy reduction without the bv equality solver, need to call this + // d_extTheory->registerTermRec( node ); } void TheoryBV::sendConflict() { @@ -319,7 +320,7 @@ void TheoryBV::check(Effort e) //last call : do reductions on extended bitvector functions if (e == Theory::EFFORT_LAST_CALL) { - std::vector<Node> nred = getExtTheory()->getActive(); + std::vector<Node> nred = d_extTheory->getActive(); doExtfReductions(nred); return; } @@ -404,7 +405,8 @@ void TheoryBV::check(Effort e) if (Theory::fullEffort(e)) { //do inferences (adds external lemmas) TODO: this can be improved to add internal inferences std::vector< Node > nred; - if( getExtTheory()->doInferences( 0, nred ) ){ + if (d_extTheory->doInferences(0, nred)) + { return; } d_needsLastCallCheck = false; @@ -513,7 +515,8 @@ bool TheoryBV::doExtfInferences(std::vector<Node>& terms) bool TheoryBV::doExtfReductions( std::vector< Node >& terms ) { std::vector< Node > nredr; - if( getExtTheory()->doReductions( 0, terms, nredr ) ){ + if (d_extTheory->doReductions(0, terms, nredr)) + { return true; } Assert(nredr.empty()); diff --git a/src/theory/bv/theory_bv.h b/src/theory/bv/theory_bv.h index c98de0f18..b0991c8b0 100644 --- a/src/theory/bv/theory_bv.h +++ b/src/theory/bv/theory_bv.h @@ -38,10 +38,11 @@ namespace CVC4 { namespace proof { class BitVectorProof; } -} // namespace CVC4 -namespace CVC4 { namespace theory { + +class ExtTheory; + namespace bv { class CoreSolver; @@ -180,6 +181,9 @@ class TheoryBV : public Theory { /** Index of the next literal to propagate */ context::CDO<unsigned> d_literalsToPropagateIndex; + /** Extended theory module, for context-dependent simplification. */ + std::unique_ptr<ExtTheory> d_extTheory; + /** * Keeps a map from nodes to the subtheory that propagated it so that we can explain it * properly. |