Refactor quantifiers engine initialization (#5813)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Tue, 26 Jan 2021 18:43:50 +0000 (12:43 -0600)
committerGitHub <noreply@github.com>
Tue, 26 Jan 2021 18:43:50 +0000 (12:43 -0600)
This is a step towards breaking up the quantifiers engine.

The key change is that QuantifiersEngine will not be passed as a pointer to the modules it contains. This PR makes it so that necessary modules take a QuantifiersState, which will eventually be extended as needed with additional query methods. For now, modules will take both until the dependencies on QuantifersEngine are removed.

This required that QuantifiersEngine now lives in TheoryQuantifiers, instead of in TheoryEngine, since the QuantifiersEngine must be initialized with QuantifiersState, which is a member of TheoryQuantifiers. Now, TheoryEngine retrieves the QuantifiersEngine from TheoryQuantifiers prior to finishing initialization on theories.

54 files changed:
src/theory/quantifiers/anti_skolem.cpp
src/theory/quantifiers/anti_skolem.h
src/theory/quantifiers/cegqi/inst_strategy_cegqi.cpp
src/theory/quantifiers/cegqi/inst_strategy_cegqi.h
src/theory/quantifiers/conjecture_generator.cpp
src/theory/quantifiers/conjecture_generator.h
src/theory/quantifiers/ematching/instantiation_engine.cpp
src/theory/quantifiers/ematching/instantiation_engine.h
src/theory/quantifiers/equality_query.cpp
src/theory/quantifiers/equality_query.h
src/theory/quantifiers/first_order_model.cpp
src/theory/quantifiers/first_order_model.h
src/theory/quantifiers/fmf/bounded_integers.cpp
src/theory/quantifiers/fmf/bounded_integers.h
src/theory/quantifiers/fmf/full_model_check.cpp
src/theory/quantifiers/fmf/full_model_check.h
src/theory/quantifiers/fmf/model_builder.cpp
src/theory/quantifiers/fmf/model_builder.h
src/theory/quantifiers/fmf/model_engine.cpp
src/theory/quantifiers/fmf/model_engine.h
src/theory/quantifiers/inst_strategy_enumerative.cpp
src/theory/quantifiers/inst_strategy_enumerative.h
src/theory/quantifiers/instantiate.cpp
src/theory/quantifiers/instantiate.h
src/theory/quantifiers/quant_conflict_find.cpp
src/theory/quantifiers/quant_conflict_find.h
src/theory/quantifiers/quant_split.cpp
src/theory/quantifiers/quant_split.h
src/theory/quantifiers/quant_util.cpp
src/theory/quantifiers/quant_util.h
src/theory/quantifiers/quantifiers_modules.cpp
src/theory/quantifiers/quantifiers_modules.h
src/theory/quantifiers/skolemize.cpp
src/theory/quantifiers/skolemize.h
src/theory/quantifiers/sygus/cegis_unif.cpp
src/theory/quantifiers/sygus/cegis_unif.h
src/theory/quantifiers/sygus/synth_conjecture.cpp
src/theory/quantifiers/sygus/synth_conjecture.h
src/theory/quantifiers/sygus/synth_engine.cpp
src/theory/quantifiers/sygus/synth_engine.h
src/theory/quantifiers/sygus/term_database_sygus.cpp
src/theory/quantifiers/sygus/term_database_sygus.h
src/theory/quantifiers/sygus_inst.cpp
src/theory/quantifiers/sygus_inst.h
src/theory/quantifiers/term_database.cpp
src/theory/quantifiers/term_database.h
src/theory/quantifiers/theory_quantifiers.cpp
src/theory/quantifiers/theory_quantifiers.h
src/theory/quantifiers_engine.cpp
src/theory/quantifiers_engine.h
src/theory/theory.cpp
src/theory/theory.h
src/theory/theory_engine.cpp
src/theory/theory_engine.h

index 531dd8d215fb8e95e868c923d47aa0b2c68ffff2..c91ba419ba7e6dd1e8875e98237c6141b2b736c3 100644 (file)
@@ -84,9 +84,10 @@ QuantAntiSkolem::CDSkQuantCache::~CDSkQuantCache() {
   }
 }
 
-QuantAntiSkolem::QuantAntiSkolem(QuantifiersEngine* qe)
-    : QuantifiersModule(qe) {
-  d_sqc = new CDSkQuantCache(qe->getUserContext());
+QuantAntiSkolem::QuantAntiSkolem(QuantifiersEngine* qe, QuantifiersState& qs)
+    : QuantifiersModule(qs, qe)
+{
+  d_sqc = new CDSkQuantCache(qs.getUserContext());
 }
 
 QuantAntiSkolem::~QuantAntiSkolem() { delete d_sqc; }
@@ -160,7 +161,8 @@ void QuantAntiSkolem::check(Theory::Effort e, QEffort quant_e)
 bool QuantAntiSkolem::sendAntiSkolemizeLemma( std::vector< Node >& quants, bool pconnected ) {
   Assert(!quants.empty());
   std::sort( quants.begin(), quants.end() );
-  if( d_sqc->add( d_quantEngine->getUserContext(), quants ) ){
+  if (d_sqc->add(d_qstate.getUserContext(), quants))
+  {
     //partition into connected components
     if( pconnected && quants.size()>1 ){
       Trace("anti-sk-debug") << "Partition into connected components..." << std::endl;
index 93834d7cea1c7390cc4f5ab94fd285621c8e3b2b..21faa036159f7c433536bdea5654c7bf8b313e4c 100644 (file)
@@ -32,8 +32,8 @@ namespace theory {
 namespace quantifiers {
 
 class QuantAntiSkolem : public QuantifiersModule {
-public:
-  QuantAntiSkolem( QuantifiersEngine * qe );
+ public:
+  QuantAntiSkolem(QuantifiersEngine* qe, QuantifiersState& qs);
   virtual ~QuantAntiSkolem();
 
   bool sendAntiSkolemizeLemma( std::vector< Node >& quants,
index 16c7476ab798345ca389157085c4caacf74393cd..539dc1474da15c8c52604695675f09d191070213 100644 (file)
@@ -49,12 +49,13 @@ TrustNode InstRewriterCegqi::rewriteInstantiation(Node q,
   return d_parent->rewriteInstantiation(q, terms, inst, doVts);
 }
 
-InstStrategyCegqi::InstStrategyCegqi(QuantifiersEngine* qe)
-    : QuantifiersModule(qe),
+InstStrategyCegqi::InstStrategyCegqi(QuantifiersEngine* qe,
+                                     QuantifiersState& qs)
+    : QuantifiersModule(qs, qe),
       d_irew(new InstRewriterCegqi(this)),
       d_cbqi_set_quant_inactive(false),
       d_incomplete_check(false),
-      d_added_cbqi_lemma(qe->getUserContext()),
+      d_added_cbqi_lemma(qs.getUserContext()),
       d_vtsCache(new VtsTermCache(qe)),
       d_bv_invert(nullptr)
 {
@@ -68,7 +69,7 @@ InstStrategyCegqi::InstStrategyCegqi(QuantifiersEngine* qe)
   }
   if (options::cegqiNestedQE())
   {
-    d_nestedQe.reset(new NestedQe(qe->getUserContext()));
+    d_nestedQe.reset(new NestedQe(qs.getUserContext()));
   }
 }
 
@@ -168,7 +169,7 @@ bool InstStrategyCegqi::registerCbqiLemma(Node q)
       d_dstrat[q].reset(
           new DecisionStrategySingleton("CexLiteral",
                                         ceLit,
-                                        d_quantEngine->getSatContext(),
+                                        d_qstate.getSatContext(),
                                         d_quantEngine->getValuation()));
       dlds = d_dstrat[q].get();
     }
index 1860962c755b3573b216a91b0e1ffd540a890f13..f98ea8549ccdb07e1ab8193a285f66d94112a04d 100644 (file)
@@ -69,7 +69,7 @@ class InstStrategyCegqi : public QuantifiersModule
   typedef context::CDHashMap< Node, int, NodeHashFunction> NodeIntMap;
 
  public:
-  InstStrategyCegqi(QuantifiersEngine* qe);
+  InstStrategyCegqi(QuantifiersEngine* qe, QuantifiersState& qs);
   ~InstStrategyCegqi();
 
   /** whether to do counterexample-guided instantiation for quantifier q */
index e1390207799a5f1a207c9eac88f39f578a6d66c0..2b3bb807afea0e0e12948bccceed727fcc219399 100644 (file)
@@ -86,11 +86,12 @@ void OpArgIndex::getGroundTerms( ConjectureGenerator * s, std::vector< TNode >&
 }
 
 ConjectureGenerator::ConjectureGenerator(QuantifiersEngine* qe,
-                                         context::Context* c)
-    : QuantifiersModule(qe),
+                                         QuantifiersState& qs)
+    : QuantifiersModule(qs, qe),
       d_notify(*this),
-      d_uequalityEngine(d_notify, c, "ConjectureGenerator::ee", false),
-      d_ee_conjectures(c),
+      d_uequalityEngine(
+          d_notify, qs.getSatContext(), "ConjectureGenerator::ee", false),
+      d_ee_conjectures(qs.getSatContext()),
       d_conj_count(0),
       d_subs_confirmCount(0),
       d_subs_unkCount(0),
@@ -163,7 +164,7 @@ ConjectureGenerator::EqcInfo* ConjectureGenerator::getOrMakeEqcInfo( TNode n, bo
   if( eqc_i!=d_eqc_info.end() ){
     return eqc_i->second;
   }else if( doMake ){
-    EqcInfo* ei = new EqcInfo( d_quantEngine->getSatContext() );
+    EqcInfo* ei = new EqcInfo(d_qstate.getSatContext());
     d_eqc_info[n] = ei;
     return ei;
   }else{
index 0c8106ad56d0b63bf2e4839534c53409b3e3d1d4..79c6f3f29fb1a6e84132382a87ebb6c201889fe5 100644 (file)
@@ -433,8 +433,9 @@ private:  //information about ground equivalence classes
   bool d_hasAddedLemma;
   //flush the waiting conjectures
   unsigned flushWaitingConjectures( unsigned& addedLemmas, int ldepth, int rdepth );
-public:
-  ConjectureGenerator( QuantifiersEngine * qe, context::Context* c );
+
+ public:
+  ConjectureGenerator(QuantifiersEngine* qe, QuantifiersState& qs);
   ~ConjectureGenerator();
 
   /* needs check */
index 7eb5a13786de323bc06d8a02c2b6b275c968f8b6..d4904ebe8696626b4993b038098751544856acf4 100644 (file)
@@ -34,8 +34,9 @@ namespace CVC4 {
 namespace theory {
 namespace quantifiers {
 
-InstantiationEngine::InstantiationEngine(QuantifiersEngine* qe)
-    : QuantifiersModule(qe),
+InstantiationEngine::InstantiationEngine(QuantifiersEngine* qe,
+                                         QuantifiersState& qs)
+    : QuantifiersModule(qs, qe),
       d_instStrategies(),
       d_isup(),
       d_i_ag(),
index 9304c84aeb5c345a529cbac7c0e669a2481bff08..f22da6ec17350b54f2cbb0b906a818c05c78952b 100644 (file)
@@ -48,7 +48,7 @@ class InstantiationEngine : public QuantifiersModule {
   void doInstantiationRound(Theory::Effort effort);
 
  public:
-  InstantiationEngine(QuantifiersEngine* qe);
+  InstantiationEngine(QuantifiersEngine* qe, QuantifiersState& qs);
   ~InstantiationEngine();
   void presolve() override;
   bool needsCheck(Theory::Effort e) override;
index 0b4539d7a33fccfd241788deaaab4d7465bf1e94..3887c583b39fafdd8e1d8917a4c9f4be7bfa8562 100644 (file)
@@ -33,8 +33,8 @@ namespace theory {
 namespace quantifiers {
 
 EqualityQueryQuantifiersEngine::EqualityQueryQuantifiersEngine(
-    context::Context* c, QuantifiersEngine* qe)
-    : d_qe(qe), d_eqi_counter(c), d_reset_count(0)
+    QuantifiersState& qs, QuantifiersEngine* qe)
+    : d_qe(qe), d_eqi_counter(qs.getSatContext()), d_reset_count(0)
 {
 }
 
index b11dbe033a74c2b55946c4bb2fd88c5e99ffd0ca..b82b9ae6451488ef7e830d868693140c9e7786f8 100644 (file)
@@ -21,6 +21,7 @@
 #include "context/context.h"
 #include "expr/node.h"
 #include "theory/quantifiers/quant_util.h"
+#include "theory/quantifiers/quantifiers_state.h"
 
 namespace CVC4 {
 namespace theory {
@@ -43,7 +44,7 @@ namespace quantifiers {
 class EqualityQueryQuantifiersEngine : public EqualityQuery
 {
  public:
-  EqualityQueryQuantifiersEngine(context::Context* c, QuantifiersEngine* qe);
+  EqualityQueryQuantifiersEngine(QuantifiersState& qs, QuantifiersEngine* qe);
   virtual ~EqualityQueryQuantifiersEngine();
   /** reset */
   bool reset(Theory::Effort e) override;
index ba91960e15520903968d585dffb466ae9f8bc47e..8f587c09d9a5337999846d902d2edc9ce7d892e4 100644 (file)
@@ -34,11 +34,11 @@ namespace theory {
 namespace quantifiers {
 
 FirstOrderModel::FirstOrderModel(QuantifiersEngine* qe,
-                                 context::Context* c,
+                                 QuantifiersState& qs,
                                  std::string name)
-    : TheoryModel(c, name, true),
+    : TheoryModel(qs.getSatContext(), name, true),
       d_qe(qe),
-      d_forall_asserts(c),
+      d_forall_asserts(qs.getSatContext()),
       d_forallRlvComputed(false)
 {
 }
@@ -335,9 +335,11 @@ unsigned FirstOrderModel::getModelBasisArg(Node n)
   return n.getAttribute(ModelBasisArgAttribute());
 }
 
-FirstOrderModelFmc::FirstOrderModelFmc(QuantifiersEngine * qe, context::Context* c, std::string name) :
-FirstOrderModel(qe, c, name){
-
+FirstOrderModelFmc::FirstOrderModelFmc(QuantifiersEngine* qe,
+                                       QuantifiersState& qs,
+                                       std::string name)
+    : FirstOrderModel(qe, qs, name)
+{
 }
 
 FirstOrderModelFmc::~FirstOrderModelFmc()
index a26401dd14f0e22f3aae9bdf559e0ec80958156c..e4236a95dfa9365749adde2656b70fdb9f7ffd01 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "context/cdlist.h"
 #include "expr/attribute.h"
+#include "theory/quantifiers/quantifiers_state.h"
 #include "theory/theory_model.h"
 #include "theory/uf/theory_uf_model.h"
 
@@ -54,7 +55,9 @@ typedef expr::Attribute<IsStarAttributeId, bool> IsStarAttribute;
 class FirstOrderModel : public TheoryModel
 {
  public:
-  FirstOrderModel(QuantifiersEngine* qe, context::Context* c, std::string name);
+  FirstOrderModel(QuantifiersEngine* qe,
+                  QuantifiersState& qs,
+                  std::string name);
 
   virtual fmcheck::FirstOrderModelFmc* asFirstOrderModelFmc() { return nullptr; }
   /** assert quantifier */
@@ -198,7 +201,9 @@ class FirstOrderModelFmc : public FirstOrderModel
   void processInitializeModelForTerm(Node n) override;
 
  public:
-  FirstOrderModelFmc(QuantifiersEngine * qe, context::Context* c, std::string name);
+  FirstOrderModelFmc(QuantifiersEngine* qe,
+                     QuantifiersState& qs,
+                     std::string name);
   ~FirstOrderModelFmc() override;
   FirstOrderModelFmc* asFirstOrderModelFmc() override { return this; }
   // initialize the model
index 2d6af9a6356e75ad8c3b592b161b2dfdcd420eab..51f88ad449f7552302b75c554931dcda965e38c3 100644 (file)
@@ -84,8 +84,8 @@ Node BoundedIntegers::IntRangeDecisionHeuristic::proxyCurrentRangeLemma()
   return lem;
 }
 
-BoundedIntegers::BoundedIntegers(context::Context* c, QuantifiersEngine* qe)
-    : QuantifiersModule(qe)
+BoundedIntegers::BoundedIntegers(QuantifiersEngine* qe, QuantifiersState& qs)
+    : QuantifiersModule(qs, qe)
 {
 }
 
@@ -493,8 +493,8 @@ void BoundedIntegers::checkOwnership(Node f)
             d_ranges.push_back( r );
             d_rms[r].reset(
                 new IntRangeDecisionHeuristic(r,
-                                              d_quantEngine->getSatContext(),
-                                              d_quantEngine->getUserContext(),
+                                              d_qstate.getSatContext(),
+                                              d_qstate.getUserContext(),
                                               d_quantEngine->getValuation(),
                                               isProxy));
             d_quantEngine->getTheoryEngine()
index bc509d78addc09a6b871d2e5e2b7f883ed84f5c2..ff971bc12b0eb4a15114898474e37a58c1a46cbc 100644 (file)
@@ -159,8 +159,9 @@ private:
     }
   };
   std::map< Node, std::map< Node, BoundInstTrie > > d_bnd_it;
-public:
-  BoundedIntegers( context::Context* c, QuantifiersEngine* qe );
+
+ public:
+  BoundedIntegers(QuantifiersEngine* qe, QuantifiersState& qs);
   virtual ~BoundedIntegers();
 
   void presolve() override;
index 173803a7f08a3af2e8ff3158e79a084924269951..effb5938c34c638497c9316457dfe53c652974c6 100644 (file)
@@ -280,9 +280,8 @@ void Def::debugPrint(const char * tr, Node op, FullModelChecker * m) {
   }
 }
 
-
-FullModelChecker::FullModelChecker(context::Context* c, QuantifiersEngine* qe) :
-QModelBuilder( c, qe ){
+FullModelChecker::FullModelChecker(QuantifiersEngine* qe) : QModelBuilder(qe)
+{
   d_true = NodeManager::currentNM()->mkConst(true);
   d_false = NodeManager::currentNM()->mkConst(false);
 }
index c49cd596bd1ceb752882f6ab16019f7eaab39754..89a4729485285800c19bb24c272f14f7cd23ed2e 100644 (file)
@@ -147,8 +147,9 @@ private:
   void mkCondVec( Node n, std::vector< Node > & cond );
   Node evaluateInterpreted( Node n, std::vector< Node > & vals );
   Node getSomeDomainElement( FirstOrderModelFmc * fm, TypeNode tn );
-public:
-  FullModelChecker( context::Context* c, QuantifiersEngine* qe );
+
+ public:
+  FullModelChecker(QuantifiersEngine* qe);
 
   void debugPrintCond(const char * tr, Node n, bool dispStar = false);
   void debugPrint(const char * tr, Node n, bool dispStar = false);
index 796ee85fad2b0fc795fabb6f83ebf2bf32749d05..4f34c3baa2b815fbc2c9b04fd9bb82a98be1d8da 100644 (file)
@@ -29,11 +29,13 @@ using namespace CVC4::context;
 using namespace CVC4::theory;
 using namespace CVC4::theory::quantifiers;
 
-QModelBuilder::QModelBuilder(context::Context* c, QuantifiersEngine* qe)
+QModelBuilder::QModelBuilder(QuantifiersEngine* qe)
     : TheoryEngineModelBuilder(qe->getTheoryEngine()),
       d_qe(qe),
       d_addedLemmas(0),
-      d_triedLemmas(0) {}
+      d_triedLemmas(0)
+{
+}
 
 bool QModelBuilder::optUseModel() {
   return options::mbqiMode() != options::MbqiMode::NONE || options::fmfBound();
index 052f6f8022b5793f3866475f133bc40a359f6fb6..16e6f2a0bfa0f197c668fa4f35be05611a8df5c5 100644 (file)
@@ -29,7 +29,7 @@ namespace quantifiers {
 
 class QModelBuilder : public TheoryEngineModelBuilder
 {
-protected:
+ protected:
   //quantifiers engine
   QuantifiersEngine* d_qe;
   // must call preProcessBuildModelStd
@@ -38,8 +38,9 @@ protected:
   /** number of lemmas generated while building model */
   unsigned d_addedLemmas;
   unsigned d_triedLemmas;
-public:
-  QModelBuilder( context::Context* c, QuantifiersEngine* qe );
+
+ public:
+  QModelBuilder(QuantifiersEngine* qe);
 
   //do exhaustive instantiation  
   // 0 :  failed, but resorting to true exhaustive instantiation may work
index 07840655a09b1432bafba45cd0a89576f62a8b27..8803fdb2c1704520596025ce8590a095c45e5d67 100644 (file)
@@ -35,12 +35,12 @@ using namespace CVC4::theory::quantifiers;
 using namespace CVC4::theory::inst;
 
 //Model Engine constructor
-ModelEngine::ModelEngine( context::Context* c, QuantifiersEngine* qe ) :
-QuantifiersModule( qe ),
-d_incomplete_check(true),
-d_addedLemmas(0),
-d_triedLemmas(0),
-d_totalLemmas(0)
+ModelEngine::ModelEngine(QuantifiersEngine* qe, QuantifiersState& qs)
+    : QuantifiersModule(qs, qe),
+      d_incomplete_check(true),
+      d_addedLemmas(0),
+      d_triedLemmas(0),
+      d_totalLemmas(0)
 {
 
 }
index 6d9d3bfe374d28313b8024e4f36f2a5393cb3887..5616eaf5e51b3fc925bcbdda1ef9817b219e4cc0 100644 (file)
@@ -43,8 +43,9 @@ private:
   int d_triedLemmas;
   int d_totalLemmas;
 public:
-  ModelEngine( context::Context* c, QuantifiersEngine* qe );
-  virtual ~ModelEngine();
+ ModelEngine(QuantifiersEngine* qe, QuantifiersState& qs);
+ virtual ~ModelEngine();
+
 public:
  bool needsCheck(Theory::Effort e) override;
  QEffort needsModel(Theory::Effort e) override;
index 9d84ea5757cf900b446ef34db48f8f34cac98f73..c064819fca6029a209c7b22e59a6d7cb0ae76390 100644 (file)
@@ -32,8 +32,10 @@ using namespace inst;
 
 namespace quantifiers {
 
-InstStrategyEnum::InstStrategyEnum(QuantifiersEngine* qe, RelevantDomain* rd)
-    : QuantifiersModule(qe), d_rd(rd), d_fullSaturateLimit(-1)
+InstStrategyEnum::InstStrategyEnum(QuantifiersEngine* qe,
+                                   QuantifiersState& qs,
+                                   RelevantDomain* rd)
+    : QuantifiersModule(qs, qe), d_rd(rd), d_fullSaturateLimit(-1)
 {
 }
 void InstStrategyEnum::presolve()
index a77eb8a907c452579603ba703de8a9bc4ce66477..a24aeedabfef6304416ba73ed5c4521aaa13d1b5 100644 (file)
@@ -62,7 +62,9 @@ namespace quantifiers {
 class InstStrategyEnum : public QuantifiersModule
 {
  public:
-  InstStrategyEnum(QuantifiersEngine* qe, RelevantDomain* rd);
+  InstStrategyEnum(QuantifiersEngine* qe,
+                   QuantifiersState& qs,
+                   RelevantDomain* rd);
   ~InstStrategyEnum() {}
   /** Presolve */
   void presolve() override;
index 7592f22c77a1819c3a036afd9ef13c16618818c2..b123c3e15930bc1ec3fb3ab4f1669a0006d06e19 100644 (file)
@@ -36,14 +36,15 @@ namespace theory {
 namespace quantifiers {
 
 Instantiate::Instantiate(QuantifiersEngine* qe,
-                         context::UserContext* u,
+                         QuantifiersState& qs,
                          ProofNodeManager* pnm)
     : d_qe(qe),
+      d_qstate(qs),
       d_pnm(pnm),
       d_term_db(nullptr),
       d_term_util(nullptr),
-      d_total_inst_debug(u),
-      d_c_inst_match_trie_dom(u),
+      d_total_inst_debug(qs.getUserContext()),
+      d_c_inst_match_trie_dom(qs.getUserContext()),
       d_pfInst(pnm ? new CDProof(pnm) : nullptr)
 {
 }
@@ -429,7 +430,7 @@ bool Instantiate::existsInstantiation(Node q,
     if (it != d_c_inst_match_trie.end())
     {
       return it->second->existsInstMatch(
-          d_qe, q, terms, d_qe->getUserContext(), modEq);
+          d_qe, q, terms, d_qstate.getUserContext(), modEq);
     }
   }
   else
@@ -524,11 +525,11 @@ bool Instantiate::recordInstantiationInternal(Node q,
     }
     else
     {
-      imt = new inst::CDInstMatchTrie(d_qe->getUserContext());
+      imt = new inst::CDInstMatchTrie(d_qstate.getUserContext());
       d_c_inst_match_trie[q] = imt;
     }
     d_c_inst_match_trie_dom.insert(q);
-    return imt->addInstMatch(d_qe, q, terms, d_qe->getUserContext(), modEq);
+    return imt->addInstMatch(d_qe, q, terms, d_qstate.getUserContext(), modEq);
   }
   Trace("inst-add-debug") << "Adding into inst trie" << std::endl;
   return d_inst_match_trie[q].addInstMatch(d_qe, q, terms, modEq);
index 4cc3c3d6da48956f1a0ea8c4fa2969141f02a4d9..3a51c89042118e045e3bf1043832a420f27b3c2d 100644 (file)
@@ -89,7 +89,7 @@ class Instantiate : public QuantifiersUtil
 
  public:
   Instantiate(QuantifiersEngine* qe,
-              context::UserContext* u,
+              QuantifiersState& qs,
               ProofNodeManager* pnm = nullptr);
   ~Instantiate();
 
@@ -341,6 +341,8 @@ class Instantiate : public QuantifiersUtil
 
   /** pointer to the quantifiers engine */
   QuantifiersEngine* d_qe;
+  /** Reference to the quantifiers state */
+  QuantifiersState& d_qstate;
   /** pointer to the proof node manager */
   ProofNodeManager* d_pnm;
   /** cache of term database for quantifiers engine */
index fa89827601dab433a976a10f86a565a3968c2069..23942ba7e3b98a124f4f96ffa265788bf9d01558 100644 (file)
@@ -1837,9 +1837,10 @@ bool MatchGen::isHandled( TNode n ) {
   return true;
 }
 
-QuantConflictFind::QuantConflictFind(QuantifiersEngine* qe, context::Context* c)
-    : QuantifiersModule(qe),
-      d_conflict(c, false),
+QuantConflictFind::QuantConflictFind(QuantifiersEngine* qe,
+                                     QuantifiersState& qs)
+    : QuantifiersModule(qs, qe),
+      d_conflict(qs.getSatContext(), false),
       d_true(NodeManager::currentNM()->mkConst<bool>(true)),
       d_false(NodeManager::currentNM()->mkConst<bool>(false)),
       d_effort(EFFORT_INVALID)
index 90385865b8688c431f0817909275b0298821e0ad..f90f1db18321e141b39cbef503d7e49622d9bc3c 100644 (file)
@@ -230,8 +230,9 @@ private:  //for equivalence classes
  public:
   bool areMatchEqual( TNode n1, TNode n2 );
   bool areMatchDisequal( TNode n1, TNode n2 );
-public:
-  QuantConflictFind( QuantifiersEngine * qe, context::Context* c );
+
+ public:
+  QuantConflictFind(QuantifiersEngine* qe, QuantifiersState& qs);
 
   /** register quantifier */
   void registerQuantifier(Node q) override;
index 615ff987ac2609735dbdb259f09b19b4599baa16..588d4de7663118b5559a3c7c045c56df193d7bb9 100644 (file)
@@ -25,10 +25,9 @@ using namespace CVC4::context;
 using namespace CVC4::theory;
 using namespace CVC4::theory::quantifiers;
 
-
-QuantDSplit::QuantDSplit( QuantifiersEngine * qe, context::Context* c ) :
-QuantifiersModule( qe ), d_added_split( qe->getUserContext() ){
-
+QuantDSplit::QuantDSplit(QuantifiersEngine* qe, QuantifiersState& qs)
+    : QuantifiersModule(qs, qe), d_added_split(qs.getUserContext())
+{
 }
 
 void QuantDSplit::checkOwnership(Node q)
index 12cf5e5af320cdcd4e2bd311fa3d54493f94d1b8..6f9e74fadbaa87dcec5d382648bac4928eaf93a7 100644 (file)
@@ -49,7 +49,7 @@ class QuantDSplit : public QuantifiersModule {
   typedef context::CDHashSet<Node, NodeHashFunction> NodeSet;
 
  public:
-  QuantDSplit( QuantifiersEngine * qe, context::Context* c );
+  QuantDSplit(QuantifiersEngine* qe, QuantifiersState& qs);
   /** determine whether this quantified formula will be reduced */
   void checkOwnership(Node q) override;
   /* whether this module needs to check this round */
index 23815dc37b80a03e5a987de59cbcfdf727b0a49c..cbaa8bfe6a01cd959e8f021a4d9393ef0626b7ae 100644 (file)
 #include "theory/quantifiers/term_util.h"
 #include "theory/quantifiers_engine.h"
 
-using namespace std;
 using namespace CVC4::kind;
-using namespace CVC4::context;
 
 namespace CVC4 {
 namespace theory {
 
+QuantifiersModule::QuantifiersModule(quantifiers::QuantifiersState& qs,
+                                     QuantifiersEngine* qe)
+    : d_quantEngine(qe), d_qstate(qs)
+{
+}
+
 QuantifiersModule::QEffort QuantifiersModule::needsModel(Theory::Effort e)
 {
   return QEFFORT_NONE;
index 507c71698283550bacf4f661931392228dcc2a4e..240282d3d22231917ba0ac4f198b7b559ad15431 100644 (file)
@@ -21,6 +21,7 @@
 #include <map>
 #include <vector>
 
+#include "theory/quantifiers/quantifiers_state.h"
 #include "theory/theory.h"
 #include "theory/uf/equality_engine.h"
 
@@ -57,7 +58,7 @@ class QuantifiersModule {
   };
 
  public:
-  QuantifiersModule( QuantifiersEngine* qe ) : d_quantEngine( qe ){}
+  QuantifiersModule(quantifiers::QuantifiersState& qs, QuantifiersEngine* qe);
   virtual ~QuantifiersModule(){}
   /** Presolve.
    *
@@ -156,6 +157,8 @@ class QuantifiersModule {
  protected:
   /** pointer to the quantifiers engine that owns this module */
   QuantifiersEngine* d_quantEngine;
+  /** The state of the quantifiers engine */
+  quantifiers::QuantifiersState& d_qstate;
 };/* class QuantifiersModule */
 
 /** Quantifiers utility
index 9dbca674e2a4fbe3b016151e2aa54eeaf0a4edd2..d8b4062fc98f00e37d997ec5ab13b6ca63f88b87 100644 (file)
@@ -39,71 +39,71 @@ QuantifiersModules::QuantifiersModules()
 }
 QuantifiersModules::~QuantifiersModules() {}
 void QuantifiersModules::initialize(QuantifiersEngine* qe,
-                                    context::Context* c,
+                                    QuantifiersState& qs,
                                     std::vector<QuantifiersModule*>& modules)
 {
   // add quantifiers modules
   if (options::quantConflictFind())
   {
-    d_qcf.reset(new quantifiers::QuantConflictFind(qe, c));
+    d_qcf.reset(new QuantConflictFind(qe, qs));
     modules.push_back(d_qcf.get());
   }
   if (options::conjectureGen())
   {
-    d_sg_gen.reset(new quantifiers::ConjectureGenerator(qe, c));
+    d_sg_gen.reset(new ConjectureGenerator(qe, qs));
     modules.push_back(d_sg_gen.get());
   }
   if (!options::finiteModelFind() || options::fmfInstEngine())
   {
-    d_inst_engine.reset(new quantifiers::InstantiationEngine(qe));
+    d_inst_engine.reset(new InstantiationEngine(qe, qs));
     modules.push_back(d_inst_engine.get());
   }
   if (options::cegqi())
   {
-    d_i_cbqi.reset(new quantifiers::InstStrategyCegqi(qe));
+    d_i_cbqi.reset(new InstStrategyCegqi(qe, qs));
     modules.push_back(d_i_cbqi.get());
     qe->getInstantiate()->addRewriter(d_i_cbqi->getInstRewriter());
   }
   if (options::sygus())
   {
-    d_synth_e.reset(new quantifiers::SynthEngine(qe, c));
+    d_synth_e.reset(new SynthEngine(qe, qs));
     modules.push_back(d_synth_e.get());
   }
   // finite model finding
   if (options::fmfBound())
   {
-    d_bint.reset(new quantifiers::BoundedIntegers(c, qe));
+    d_bint.reset(new BoundedIntegers(qe, qs));
     modules.push_back(d_bint.get());
   }
   if (options::finiteModelFind() || options::fmfBound())
   {
-    d_model_engine.reset(new quantifiers::ModelEngine(c, qe));
+    d_model_engine.reset(new ModelEngine(qe, qs));
     modules.push_back(d_model_engine.get());
   }
   if (options::quantDynamicSplit() != options::QuantDSplitMode::NONE)
   {
-    d_qsplit.reset(new quantifiers::QuantDSplit(qe, c));
+    d_qsplit.reset(new QuantDSplit(qe, qs));
     modules.push_back(d_qsplit.get());
   }
   if (options::quantAntiSkolem())
   {
-    d_anti_skolem.reset(new quantifiers::QuantAntiSkolem(qe));
+    d_anti_skolem.reset(new QuantAntiSkolem(qe, qs));
     modules.push_back(d_anti_skolem.get());
   }
   if (options::quantAlphaEquiv())
   {
-    d_alpha_equiv.reset(new quantifiers::AlphaEquivalence(qe));
+    d_alpha_equiv.reset(new AlphaEquivalence(qe));
   }
   // full saturation : instantiate from relevant domain, then arbitrary terms
   if (options::fullSaturateQuant() || options::fullSaturateInterleave())
   {
-    d_rel_dom.reset(new quantifiers::RelevantDomain(qe));
-    d_fs.reset(new quantifiers::InstStrategyEnum(qe, d_rel_dom.get()));
+    d_rel_dom.reset(new RelevantDomain(qe));
+    d_fs.reset(new InstStrategyEnum(qe, qs, d_rel_dom.get()));
     modules.push_back(d_fs.get());
   }
   if (options::sygusInst())
   {
-    d_sygus_inst.reset(new quantifiers::SygusInst(qe));
+    d_sygus_inst.reset(new SygusInst(qe, qs));
     modules.push_back(d_sygus_inst.get());
   }
 }
index a4c5dfb6e3305c109ad510d05d98083894e436d8..e83a13ea74616615e157c549835e098952463971 100644 (file)
@@ -53,37 +53,38 @@ class QuantifiersModules
    * a pointer to each module it constructs to modules.
    */
   void initialize(QuantifiersEngine* qe,
-                  context::Context* c,
+                  QuantifiersState& qs,
                   std::vector<QuantifiersModule*>& modules);
+
  private:
   //------------------------------ quantifier utilities
   /** relevant domain */
-  std::unique_ptr<quantifiers::RelevantDomain> d_rel_dom;
+  std::unique_ptr<RelevantDomain> d_rel_dom;
   //------------------------------ quantifiers modules
   /** alpha equivalence */
-  std::unique_ptr<quantifiers::AlphaEquivalence> d_alpha_equiv;
+  std::unique_ptr<AlphaEquivalence> d_alpha_equiv;
   /** instantiation engine */
-  std::unique_ptr<quantifiers::InstantiationEngine> d_inst_engine;
+  std::unique_ptr<InstantiationEngine> d_inst_engine;
   /** model engine */
-  std::unique_ptr<quantifiers::ModelEngine> d_model_engine;
+  std::unique_ptr<ModelEngine> d_model_engine;
   /** bounded integers utility */
-  std::unique_ptr<quantifiers::BoundedIntegers> d_bint;
+  std::unique_ptr<BoundedIntegers> d_bint;
   /** Conflict find mechanism for quantifiers */
-  std::unique_ptr<quantifiers::QuantConflictFind> d_qcf;
+  std::unique_ptr<QuantConflictFind> d_qcf;
   /** subgoal generator */
-  std::unique_ptr<quantifiers::ConjectureGenerator> d_sg_gen;
+  std::unique_ptr<ConjectureGenerator> d_sg_gen;
   /** ceg instantiation */
-  std::unique_ptr<quantifiers::SynthEngine> d_synth_e;
+  std::unique_ptr<SynthEngine> d_synth_e;
   /** full saturation */
-  std::unique_ptr<quantifiers::InstStrategyEnum> d_fs;
+  std::unique_ptr<InstStrategyEnum> d_fs;
   /** counterexample-based quantifier instantiation */
-  std::unique_ptr<quantifiers::InstStrategyCegqi> d_i_cbqi;
+  std::unique_ptr<InstStrategyCegqi> d_i_cbqi;
   /** quantifiers splitting */
-  std::unique_ptr<quantifiers::QuantDSplit> d_qsplit;
+  std::unique_ptr<QuantDSplit> d_qsplit;
   /** quantifiers anti-skolemization */
-  std::unique_ptr<quantifiers::QuantAntiSkolem> d_anti_skolem;
+  std::unique_ptr<QuantAntiSkolem> d_anti_skolem;
   /** SyGuS instantiation engine */
-  std::unique_ptr<quantifiers::SygusInst> d_sygus_inst;
+  std::unique_ptr<SygusInst> d_sygus_inst;
 };
 
 }  // namespace quantifiers
index 61dd0c15e4c6c05e7a24be65dd3b849dd22407ba..901b7ad82e8aa0bf2d7fdfcbca268e19f91ac78b 100644 (file)
@@ -29,13 +29,14 @@ namespace theory {
 namespace quantifiers {
 
 Skolemize::Skolemize(QuantifiersEngine* qe,
-                     context::UserContext* u,
+                     QuantifiersState& qs,
                      ProofNodeManager* pnm)
     : d_quantEngine(qe),
-      d_skolemized(u),
+      d_skolemized(qs.getUserContext()),
       d_pnm(pnm),
       d_epg(pnm == nullptr ? nullptr
-                           : new EagerProofGenerator(pnm, u, "Skolemize::epg"))
+                           : new EagerProofGenerator(
+                                 pnm, qs.getUserContext(), "Skolemize::epg"))
 {
 }
 
index cb81a5c3a51786ab2e4ca6d240f7d12ab13ba176..8cf3e3176be5526b271ad1b75e22069b0b19e401 100644 (file)
@@ -64,9 +64,7 @@ class Skolemize
   typedef context::CDHashMap<Node, Node, NodeHashFunction> NodeNodeMap;
 
  public:
-  Skolemize(QuantifiersEngine* qe,
-            context::UserContext* u,
-            ProofNodeManager* pnm);
+  Skolemize(QuantifiersEngine* qe, QuantifiersState& qs, ProofNodeManager* pnm);
   ~Skolemize() {}
   /** skolemize quantified formula q
    * If the return value ret of this function is non-null, then ret is a trust
index 4588e8952b4d12bbdee2b309f1a55fe23e86f588..42e7e2f1316d7dd20d8f9ee2cc69bc25b326545d 100644 (file)
@@ -29,8 +29,10 @@ namespace CVC4 {
 namespace theory {
 namespace quantifiers {
 
-CegisUnif::CegisUnif(QuantifiersEngine* qe, SynthConjecture* p)
-    : Cegis(qe, p), d_sygus_unif(p), d_u_enum_manager(qe, p)
+CegisUnif::CegisUnif(QuantifiersEngine* qe,
+                     QuantifiersState& qs,
+                     SynthConjecture* p)
+    : Cegis(qe, p), d_sygus_unif(p), d_u_enum_manager(qe, qs, p)
 {
 }
 
@@ -398,8 +400,8 @@ void CegisUnif::registerRefinementLemma(const std::vector<Node>& vars,
 }
 
 CegisUnifEnumDecisionStrategy::CegisUnifEnumDecisionStrategy(
-    QuantifiersEngine* qe, SynthConjecture* parent)
-    : DecisionStrategyFmf(qe->getSatContext(), qe->getValuation()),
+    QuantifiersEngine* qe, QuantifiersState& qs, SynthConjecture* parent)
+    : DecisionStrategyFmf(qs.getSatContext(), qe->getValuation()),
       d_qe(qe),
       d_parent(parent)
 {
index aca85a69155b42829922c07c51a7cde0c377caf3..ee9ae013246460b82b0e5732559c612839fbbbea 100644 (file)
@@ -47,7 +47,9 @@ namespace quantifiers {
 class CegisUnifEnumDecisionStrategy : public DecisionStrategyFmf
 {
  public:
-  CegisUnifEnumDecisionStrategy(QuantifiersEngine* qe, SynthConjecture* parent);
+  CegisUnifEnumDecisionStrategy(QuantifiersEngine* qe,
+                                QuantifiersState& qs,
+                                SynthConjecture* parent);
   /** Make the n^th literal of this strategy (G_uq_n).
    *
    * This call may add new lemmas of the form described above
@@ -202,7 +204,7 @@ class CegisUnifEnumDecisionStrategy : public DecisionStrategyFmf
 class CegisUnif : public Cegis
 {
  public:
-  CegisUnif(QuantifiersEngine* qe, SynthConjecture* p);
+  CegisUnif(QuantifiersEngine* qe, QuantifiersState& qs, SynthConjecture* p);
   ~CegisUnif() override;
   /** Retrieves enumerators for constructing solutions
    *
index ad125a70f7ee45b587cadb521b118b6ef925e3a0..b007f8716710159476ef06d95d111ca216d7bc63 100644 (file)
@@ -43,8 +43,10 @@ namespace theory {
 namespace quantifiers {
 
 SynthConjecture::SynthConjecture(QuantifiersEngine* qe,
+                                 QuantifiersState& qs,
                                  SygusStatistics& s)
     : d_qe(qe),
+      d_qstate(qs),
       d_stats(s),
       d_tds(qe->getTermDatabaseSygus()),
       d_hasSolution(false),
@@ -56,7 +58,7 @@ SynthConjecture::SynthConjecture(QuantifiersEngine* qe,
       d_exampleInfer(new ExampleInfer(d_tds)),
       d_ceg_pbe(new SygusPbe(qe, this)),
       d_ceg_cegis(new Cegis(qe, this)),
-      d_ceg_cegisUnif(new CegisUnif(qe, this)),
+      d_ceg_cegisUnif(new CegisUnif(qe, qs, this)),
       d_sygus_ccore(new CegisCoreConnective(qe, this)),
       d_master(nullptr),
       d_set_ce_sk_vars(false),
@@ -235,7 +237,7 @@ void SynthConjecture::assign(Node q)
   d_feasible_strategy.reset(
       new DecisionStrategySingleton("sygus_feasible",
                                     d_feasible_guard,
-                                    d_qe->getSatContext(),
+                                    d_qstate.getSatContext(),
                                     d_qe->getValuation()));
   d_qe->getDecisionManager()->registerStrategy(
       DecisionManager::STRAT_QUANT_SYGUS_FEASIBLE, d_feasible_strategy.get());
index 7786f57ad1ce3f9728a58c8f0b63c2c4d5f0f17f..1d43e30ffea13e7058a5c44c31315f278978bd86 100644 (file)
@@ -82,7 +82,9 @@ class EnumValGenerator
 class SynthConjecture
 {
  public:
-  SynthConjecture(QuantifiersEngine* qe, SygusStatistics& s);
+  SynthConjecture(QuantifiersEngine* qe,
+                  QuantifiersState& qs,
+                  SygusStatistics& s);
   ~SynthConjecture();
   /** presolve */
   void presolve();
@@ -199,6 +201,8 @@ class SynthConjecture
  private:
   /** reference to quantifier engine */
   QuantifiersEngine* d_qe;
+  /** Reference to the quantifiers state */
+  QuantifiersState& d_qstate;
   /** reference to the statistics of parent */
   SygusStatistics& d_stats;
   /** term database sygus of d_qe */
index f49cc962f23faa1e8d16b52964840c99979d7571..09a6add1caf3f18dc7a8409e4feee85b78c01fc8 100644 (file)
@@ -30,14 +30,14 @@ namespace CVC4 {
 namespace theory {
 namespace quantifiers {
 
-SynthEngine::SynthEngine(QuantifiersEngine* qe, context::Context* c)
-    : QuantifiersModule(qe),
+SynthEngine::SynthEngine(QuantifiersEngine* qe, QuantifiersState& qs)
+    : QuantifiersModule(qs, qe),
       d_tds(qe->getTermDatabaseSygus()),
       d_conj(nullptr),
       d_sqp(qe)
 {
   d_conjs.push_back(std::unique_ptr<SynthConjecture>(
-      new SynthConjecture(d_quantEngine, d_statistics)));
+      new SynthConjecture(d_quantEngine, qs, d_statistics)));
   d_conj = d_conjs.back().get();
 }
 
@@ -159,7 +159,7 @@ void SynthEngine::assignConjecture(Node q)
   if (d_conjs.back()->isAssigned())
   {
     d_conjs.push_back(std::unique_ptr<SynthConjecture>(
-        new SynthConjecture(d_quantEngine, d_statistics)));
+        new SynthConjecture(d_quantEngine, d_qstate, d_statistics)));
   }
   d_conjs.back()->assign(q);
 }
index 25981748edd3b831ed59f8e19ee0a09d5593cfd1..e3cf2e47b4d4a4333be90edf364a2bd2be1b87aa 100644 (file)
@@ -33,7 +33,7 @@ class SynthEngine : public QuantifiersModule
   typedef context::CDHashMap<Node, bool, NodeHashFunction> NodeBoolMap;
 
  public:
-  SynthEngine(QuantifiersEngine* qe, context::Context* c);
+  SynthEngine(QuantifiersEngine* qe, QuantifiersState& qs);
   ~SynthEngine();
   /** presolve
    *
index ccc23f109cd85faddd864fc746ad708549de0395..210ebb921a4dc6bd6d6953d9446f1169ab7ca3b8 100644 (file)
@@ -46,8 +46,9 @@ std::ostream& operator<<(std::ostream& os, EnumeratorRole r)
   return os;
 }
 
-TermDbSygus::TermDbSygus(context::Context* c, QuantifiersEngine* qe)
+TermDbSygus::TermDbSygus(QuantifiersEngine* qe, QuantifiersState& qs)
     : d_quantEngine(qe),
+      d_qstate(qs),
       d_syexp(new SygusExplain(this)),
       d_ext_rw(new ExtendedRewriter(true)),
       d_eval(new Evaluator),
index e082cf15b4ab0abaadac8fd806a911a93616091f..1bf6b6ca7e44b793eb26dcb1b4066ea16fccd819 100644 (file)
@@ -54,7 +54,7 @@ std::ostream& operator<<(std::ostream& os, EnumeratorRole r);
 // TODO :issue #1235 split and document this class
 class TermDbSygus {
  public:
-  TermDbSygus(context::Context* c, QuantifiersEngine* qe);
+  TermDbSygus(QuantifiersEngine* qe, QuantifiersState& qs);
   ~TermDbSygus() {}
   /** Reset this utility */
   bool reset(Theory::Effort e);
@@ -316,6 +316,8 @@ class TermDbSygus {
  private:
   /** reference to the quantifiers engine */
   QuantifiersEngine* d_quantEngine;
+  /** Reference to the quantifiers state */
+  QuantifiersState& d_qstate;
 
   //------------------------------utilities
   /** sygus explanation */
index 50c983ee7b8aa9856c5e46cd6b0f183fb72d0f74..12ce544d3b7aa1822b664cb0108efc5a39e74dd8 100644 (file)
@@ -180,11 +180,11 @@ void addSpecialValues(
 
 }  // namespace
 
-SygusInst::SygusInst(QuantifiersEngine* qe)
-    : QuantifiersModule(qe),
-      d_ce_lemma_added(qe->getUserContext()),
-      d_global_terms(qe->getUserContext()),
-      d_notified_assertions(qe->getUserContext())
+SygusInst::SygusInst(QuantifiersEngine* qe, QuantifiersState& qs)
+    : QuantifiersModule(qs, qe),
+      d_ce_lemma_added(qs.getUserContext()),
+      d_global_terms(qs.getUserContext()),
+      d_notified_assertions(qs.getUserContext())
 {
 }
 
@@ -518,7 +518,7 @@ void SygusInst::registerCeLemma(Node q, std::vector<TypeNode>& types)
   DecisionStrategy* ds =
       new DecisionStrategySingleton("CeLiteral",
                                     lit,
-                                    d_quantEngine->getSatContext(),
+                                    d_qstate.getSatContext(),
                                     d_quantEngine->getValuation());
 
   d_dstrat[q].reset(ds);
index 0358b4984ce06c1f3b8d9a8b67b579a686deb96f..10363f5a2d9cba145a803e73210323bba4db6311 100644 (file)
@@ -62,7 +62,7 @@ namespace quantifiers {
 class SygusInst : public QuantifiersModule
 {
  public:
-  SygusInst(QuantifiersEngine* qe);
+  SygusInst(QuantifiersEngine* qe, QuantifiersState& qs);
   ~SygusInst() = default;
 
   bool needsCheck(Theory::Effort e) override;
index 0ed488891f9675fbee68068eba0934847f1d5a9d..047a3cd41ffcebee0773ae8f904caf622b1ad927 100644 (file)
@@ -33,10 +33,9 @@ namespace CVC4 {
 namespace theory {
 namespace quantifiers {
 
-TermDb::TermDb(context::Context* c, context::UserContext* u,
-               QuantifiersEngine* qe)
-    : d_quantEngine(qe),
-      d_inactive_map(c) {
+TermDb::TermDb(QuantifiersState& qs, QuantifiersEngine* qe)
+    : d_quantEngine(qe), d_inactive_map(qs.getSatContext())
+{
   d_consistent_ee = true;
   d_true = NodeManager::currentNM()->mkConst(true);
   d_false = NodeManager::currentNM()->mkConst(false);
index dff5957578283b5bf032fe8ba5aa4021ed062807..afb8d0c0c14aecdca15a2034daa136ef72e8296f 100644 (file)
@@ -76,7 +76,7 @@ class TermDb : public QuantifiersUtil {
   typedef context::CDHashMap<Node, bool, NodeHashFunction> NodeBoolMap;
 
  public:
-  TermDb(context::Context* c, context::UserContext* u, QuantifiersEngine* qe);
+  TermDb(QuantifiersState& qs, QuantifiersEngine* qe);
   ~TermDb();
   /** presolve (called once per user check-sat) */
   void presolve();
index 387a3e9d8598a95cb8fe94623d248fcbee92984d..aaf8f347c3987cc166e951feda11aa584d2838d1 100644 (file)
@@ -43,7 +43,8 @@ TheoryQuantifiers::TheoryQuantifiers(Context* c,
                                      const LogicInfo& logicInfo,
                                      ProofNodeManager* pnm)
     : Theory(THEORY_QUANTIFIERS, c, u, out, valuation, logicInfo, pnm),
-      d_qstate(c, u, valuation)
+      d_qstate(c, u, valuation),
+      d_qengine(d_qstate, pnm)
 {
   out.handleUserAttribute( "fun-def", this );
   out.handleUserAttribute("qid", this);
@@ -59,6 +60,11 @@ TheoryQuantifiers::TheoryQuantifiers(Context* c,
   }
   // indicate we are using the quantifiers theory state object
   d_theoryState = &d_qstate;
+
+  // Set the pointer to the quantifiers engine, which this theory owns. This
+  // pointer will be retreived by TheoryEngine and set to all theories
+  // post-construction.
+  d_quantEngine = &d_qengine;
 }
 
 TheoryQuantifiers::~TheoryQuantifiers() {
index b463902849136617233d43dcaea3e2996069fae4..82a5880090c5cfc581a37bdebbabe9b92cddb6b9 100644 (file)
@@ -23,6 +23,7 @@
 #include "theory/quantifiers/proof_checker.h"
 #include "theory/quantifiers/quantifiers_rewriter.h"
 #include "theory/quantifiers/quantifiers_state.h"
+#include "theory/quantifiers_engine.h"
 #include "theory/theory.h"
 #include "theory/valuation.h"
 
@@ -80,6 +81,8 @@ class TheoryQuantifiers : public Theory {
   QuantifiersProofRuleChecker d_qChecker;
   /** The quantifiers state */
   QuantifiersState d_qstate;
+  /** The quantifiers engine, which lives here */
+  QuantifiersEngine d_qengine;
 };/* class TheoryQuantifiers */
 
 }/* CVC4::theory::quantifiers namespace */
index 8b3ea8622ecaa4e973c7c9b77040fad3e195b7b7..f60bb724f241dc36e8fc8f787a85ad1c5f4a8263 100644 (file)
@@ -30,37 +30,34 @@ using namespace CVC4::kind;
 namespace CVC4 {
 namespace theory {
 
-QuantifiersEngine::QuantifiersEngine(TheoryEngine* te,
-                                     DecisionManager& dm,
+QuantifiersEngine::QuantifiersEngine(quantifiers::QuantifiersState& qstate,
                                      ProofNodeManager* pnm)
-    : d_te(te),
-      d_context(te->getSatContext()),
-      d_userContext(te->getUserContext()),
-      d_decManager(dm),
+    : d_qstate(qstate),
+      d_te(nullptr),
+      d_decManager(nullptr),
       d_masterEqualityEngine(nullptr),
-      d_eq_query(
-          new quantifiers::EqualityQueryQuantifiersEngine(d_context, this)),
+      d_eq_query(new quantifiers::EqualityQueryQuantifiersEngine(qstate, this)),
       d_tr_trie(new inst::TriggerTrie),
       d_model(nullptr),
       d_builder(nullptr),
       d_term_util(new quantifiers::TermUtil(this)),
       d_term_canon(new expr::TermCanonize),
-      d_term_db(new quantifiers::TermDb(d_context, d_userContext, this)),
+      d_term_db(new quantifiers::TermDb(qstate, this)),
       d_sygus_tdb(nullptr),
       d_quant_attr(new quantifiers::QuantAttributes(this)),
-      d_instantiate(new quantifiers::Instantiate(this, d_userContext, pnm)),
-      d_skolemize(new quantifiers::Skolemize(this, d_userContext, pnm)),
+      d_instantiate(new quantifiers::Instantiate(this, qstate, pnm)),
+      d_skolemize(new quantifiers::Skolemize(this, qstate, pnm)),
       d_term_enum(new quantifiers::TermEnumeration),
-      d_conflict_c(d_context, false),
-      d_quants_prereg(d_userContext),
-      d_quants_red(d_userContext),
-      d_lemmas_produced_c(d_userContext),
-      d_ierCounter_c(d_context),
-      d_presolve(d_userContext, true),
-      d_presolve_in(d_userContext),
-      d_presolve_cache(d_userContext),
-      d_presolve_cache_wq(d_userContext),
-      d_presolve_cache_wic(d_userContext)
+      d_conflict_c(qstate.getSatContext(), false),
+      d_quants_prereg(qstate.getUserContext()),
+      d_quants_red(qstate.getUserContext()),
+      d_lemmas_produced_c(qstate.getUserContext()),
+      d_ierCounter_c(qstate.getSatContext()),
+      d_presolve(qstate.getUserContext(), true),
+      d_presolve_in(qstate.getUserContext()),
+      d_presolve_cache(qstate.getUserContext()),
+      d_presolve_cache_wq(qstate.getUserContext()),
+      d_presolve_cache_wic(qstate.getUserContext())
 {
   //---- utilities
   d_util.push_back(d_eq_query.get());
@@ -71,7 +68,7 @@ QuantifiersEngine::QuantifiersEngine(TheoryEngine* te,
   if (options::sygus() || options::sygusInst())
   {
     // must be constructed here since it is required for datatypes finistInit
-    d_sygus_tdb.reset(new quantifiers::TermDbSygus(d_context, this));
+    d_sygus_tdb.reset(new quantifiers::TermDbSygus(this, qstate));
   }
 
   d_util.push_back(d_instantiate.get());
@@ -106,53 +103,43 @@ QuantifiersEngine::QuantifiersEngine(TheoryEngine* te,
     {
       Trace("quant-engine-debug") << "...make fmc builder." << std::endl;
       d_model.reset(new quantifiers::fmcheck::FirstOrderModelFmc(
-          this, d_context, "FirstOrderModelFmc"));
-      d_builder.reset(
-          new quantifiers::fmcheck::FullModelChecker(d_context, this));
+          this, qstate, "FirstOrderModelFmc"));
+      d_builder.reset(new quantifiers::fmcheck::FullModelChecker(this));
     }else{
       Trace("quant-engine-debug") << "...make default model builder." << std::endl;
       d_model.reset(
-          new quantifiers::FirstOrderModel(this, d_context, "FirstOrderModel"));
-      d_builder.reset(new quantifiers::QModelBuilder(d_context, this));
+          new quantifiers::FirstOrderModel(this, qstate, "FirstOrderModel"));
+      d_builder.reset(new quantifiers::QModelBuilder(this));
     }
   }else{
     d_model.reset(
-        new quantifiers::FirstOrderModel(this, d_context, "FirstOrderModel"));
+        new quantifiers::FirstOrderModel(this, qstate, "FirstOrderModel"));
   }
 }
 
 QuantifiersEngine::~QuantifiersEngine() {}
 
-void QuantifiersEngine::finishInit()
+void QuantifiersEngine::finishInit(TheoryEngine* te,
+                                   DecisionManager* dm,
+                                   eq::EqualityEngine* mee)
 {
-  // Initialize the modules and the utilities here. We delay their
-  // initialization to here, since this is after TheoryQuantifiers finishInit,
-  // which has initialized the state and inference manager of this engine.
+  d_te = te;
+  d_decManager = dm;
+  d_masterEqualityEngine = mee;
+  // Initialize the modules and the utilities here.
   d_qmodules.reset(new quantifiers::QuantifiersModules);
-  d_qmodules->initialize(this, d_context, d_modules);
+  d_qmodules->initialize(this, d_qstate, d_modules);
   if (d_qmodules->d_rel_dom.get())
   {
     d_util.push_back(d_qmodules->d_rel_dom.get());
   }
 }
 
-void QuantifiersEngine::setMasterEqualityEngine(eq::EqualityEngine* mee)
-{
-  d_masterEqualityEngine = mee;
-}
-
 TheoryEngine* QuantifiersEngine::getTheoryEngine() const { return d_te; }
 
 DecisionManager* QuantifiersEngine::getDecisionManager()
 {
-  return &d_decManager;
-}
-
-context::Context* QuantifiersEngine::getSatContext() { return d_context; }
-
-context::UserContext* QuantifiersEngine::getUserContext()
-{
-  return d_userContext;
+  return d_decManager;
 }
 
 OutputChannel& QuantifiersEngine::getOutputChannel()
index 0c3bb181e307937dc7599843bef8b66b254a96ee..7ed183342c00945d9dcb06d94bbbf2c80cd10625 100644 (file)
@@ -31,6 +31,7 @@
 #include "theory/quantifiers/instantiate.h"
 #include "theory/quantifiers/quant_util.h"
 #include "theory/quantifiers/quantifiers_attributes.h"
+#include "theory/quantifiers/quantifiers_state.h"
 #include "theory/quantifiers/skolemize.h"
 #include "theory/quantifiers/sygus/term_database_sygus.h"
 #include "theory/quantifiers/term_database.h"
@@ -59,20 +60,14 @@ class QuantifiersEngine {
   typedef context::CDHashSet<Node, NodeHashFunction> NodeSet;
 
  public:
-  QuantifiersEngine(TheoryEngine* te, DecisionManager& dm,
+  QuantifiersEngine(quantifiers::QuantifiersState& qstate,
                     ProofNodeManager* pnm);
   ~QuantifiersEngine();
-  /** finish initialize */
-  void finishInit();
   //---------------------- external interface
   /** get theory engine */
   TheoryEngine* getTheoryEngine() const;
   /** Get the decision manager */
   DecisionManager* getDecisionManager();
-  /** get default sat context for quantifiers engine */
-  context::Context* getSatContext();
-  /** get default sat context for quantifiers engine */
-  context::UserContext* getUserContext();
   /** get default output channel for the quantifiers engine */
   OutputChannel& getOutputChannel();
   /** get default valuation for the quantifiers engine */
@@ -110,8 +105,19 @@ class QuantifiersEngine {
   //---------------------- end utilities
  private:
   //---------------------- private initialization
-  /** Set the master equality engine */
-  void setMasterEqualityEngine(eq::EqualityEngine* mee);
+  /**
+   * Finish initialize, which passes pointers to the objects that quantifiers
+   * engine needs but were not available when it was created. This is
+   * called after theories have been created but before they have finished
+   * initialization.
+   *
+   * @param te The theory engine
+   * @param dm The decision manager of the theory engine
+   * @param mee The master equality engine of the theory engine
+   */
+  void finishInit(TheoryEngine* te,
+                  DecisionManager* dm,
+                  eq::EqualityEngine* mee);
   //---------------------- end private initialization
   /**
    * Maps quantified formulas to the module that owns them, if any module has
@@ -329,14 +335,12 @@ public:
   Statistics d_statistics;
 
  private:
+  /** The quantifiers state object */
+  quantifiers::QuantifiersState& d_qstate;
   /** Pointer to theory engine object */
   TheoryEngine* d_te;
-  /** The SAT context */
-  context::Context* d_context;
-  /** The user context */
-  context::UserContext* d_userContext;
   /** Reference to the decision manager of the theory engine */
-  DecisionManager& d_decManager;
+  DecisionManager* d_decManager;
   /** Pointer to the master equality engine */
   eq::EqualityEngine* d_masterEqualityEngine;
   /** vector of utilities for quantifiers */
index 5bea454e8e3207c902867dd6ace54706b32055cd..fef3fdc67704151ad41fa049e52dd9c869d32588 100644 (file)
@@ -68,8 +68,7 @@ Theory::Theory(TheoryId id,
       d_facts(satContext),
       d_factsHead(satContext, 0),
       d_sharedTermsIndex(satContext, 0),
-      d_careGraph(NULL),
-      d_quantEngine(NULL),
+      d_careGraph(nullptr),
       d_decManager(nullptr),
       d_instanceName(name),
       d_checkTime(getStatsPrefix(id) + name + "::checkTime"),
@@ -82,6 +81,7 @@ Theory::Theory(TheoryId id,
       d_allocEqualityEngine(nullptr),
       d_theoryState(nullptr),
       d_inferManager(nullptr),
+      d_quantEngine(nullptr),
       d_pnm(pnm)
 {
   smtStatisticsRegistry()->registerStat(&d_checkTime);
@@ -115,7 +115,6 @@ void Theory::setEqualityEngine(eq::EqualityEngine* ee)
 
 void Theory::setQuantifiersEngine(QuantifiersEngine* qe)
 {
-  Assert(d_quantEngine == nullptr);
   // quantifiers engine may be null if not in quantified logic
   d_quantEngine = qe;
 }
index 0eb3d9a33f013cbfef77e736dbde3b25943c51cf..fa26ab65e9ccb9b7d49d570e6386d94b8002486f 100644 (file)
@@ -140,12 +140,6 @@ class Theory {
   /** The care graph the theory will use during combination. */
   CareGraph* d_careGraph;
 
-  /**
-   * Pointer to the quantifiers engine (or NULL, if quantifiers are not
-   * supported or not enabled). Not owned by the theory.
-   */
-  QuantifiersEngine* d_quantEngine;
-
   /** Pointer to the decision manager. */
   DecisionManager* d_decManager;
 
@@ -234,6 +228,12 @@ class Theory {
    */
   TheoryInferenceManager* d_inferManager;
 
+  /**
+   * Pointer to the quantifiers engine (or NULL, if quantifiers are not
+   * supported or not enabled). Not owned by the theory.
+   */
+  QuantifiersEngine* d_quantEngine;
+
   /** Pointer to proof node manager */
   ProofNodeManager* d_pnm;
 
index 27ae0018e8907f960ce4bfd6987437bfc2a184cc..16d68ea5c3902731f0c32c2f3166698320facc00 100644 (file)
@@ -169,8 +169,10 @@ void TheoryEngine::finishInit()
   // initialize the quantifiers engine
   if (d_logicInfo.isQuantified())
   {
-    // initialize the quantifiers engine
-    d_quantEngine = new QuantifiersEngine(this, *d_decManager.get(), d_pnm);
+    // get the quantifiers engine, which is initialized by the quantifiers
+    // theory
+    d_quantEngine = d_theoryTable[THEORY_QUANTIFIERS]->getQuantifiersEngine();
+    Assert(d_quantEngine != nullptr);
   }
   // initialize the theory combination manager, which decides and allocates the
   // equality engines to use for all theories.
@@ -178,10 +180,11 @@ void TheoryEngine::finishInit()
   // get pointer to the shared solver
   d_sharedSolver = d_tc->getSharedSolver();
 
-  // set the core equality engine on quantifiers engine
+  // finish initializing the quantifiers engine
   if (d_logicInfo.isQuantified())
   {
-    d_quantEngine->setMasterEqualityEngine(d_tc->getCoreEqualityEngine());
+    d_quantEngine->finishInit(
+        this, d_decManager.get(), d_tc->getCoreEqualityEngine());
   }
 
   // finish initializing the theories by linking them with the appropriate
@@ -205,12 +208,6 @@ void TheoryEngine::finishInit()
     // finish initializing the theory
     t->finishInit();
   }
-
-  // finish initializing the quantifiers engine
-  if (d_logicInfo.isQuantified())
-  {
-    d_quantEngine->finishInit();
-  }
 }
 
 ProofNodeManager* TheoryEngine::getProofNodeManager() const { return d_pnm; }
@@ -283,8 +280,6 @@ TheoryEngine::~TheoryEngine() {
     }
   }
 
-  delete d_quantEngine;
-
   smtStatisticsRegistry()->unregisterStat(&d_combineTheoriesTime);
   smtStatisticsRegistry()->unregisterStat(&d_arithSubstitutionsAdded);
 }
index df57d9903b6e2dd60a4989cd38c9634bf551a67f..0be511e47450dbf19b4f3d1031b423080ac13774 100644 (file)
@@ -156,9 +156,7 @@ class TheoryEngine {
   std::unique_ptr<theory::CombinationEngine> d_tc;
   /** The shared solver of the above combination engine. */
   theory::SharedSolver* d_sharedSolver;
-  /**
-   * The quantifiers engine
-   */
+  /** The quantifiers engine, which is owned by the quantifiers theory */
   theory::QuantifiersEngine* d_quantEngine;
   /**
    * The decision manager