Introduce quantifiers registry utility (#5829)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Thu, 4 Feb 2021 22:55:00 +0000 (16:55 -0600)
committerGitHub <noreply@github.com>
Thu, 4 Feb 2021 22:55:00 +0000 (16:55 -0600)
This is a simple module for determining which quantifiers module has ownership of quantified formulas.

This is work towards eliminating dependencies of quantifiers modules.

Note that quantifiers attributes module (which no longer has a dependency on QuantifiersEngine after this PR) will be embedded into this module in a later PR.

31 files changed:
src/CMakeLists.txt
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/fmf/bounded_integers.cpp
src/theory/quantifiers/fmf/bounded_integers.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/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_attributes.cpp
src/theory/quantifiers/quantifiers_attributes.h
src/theory/quantifiers/quantifiers_modules.cpp
src/theory/quantifiers/quantifiers_modules.h
src/theory/quantifiers/quantifiers_registry.cpp [new file with mode: 0644]
src/theory/quantifiers/quantifiers_registry.h [new file with mode: 0644]
src/theory/quantifiers/sygus/synth_engine.cpp
src/theory/quantifiers/sygus/synth_engine.h
src/theory/quantifiers/sygus_inst.cpp
src/theory/quantifiers/sygus_inst.h
src/theory/quantifiers_engine.cpp
src/theory/quantifiers_engine.h

index c5673a396e26ac7d0ec75e447f979b188e42e1ac..7a7a90981ccbd2dea7911c7c470d64da65bda33e 100644 (file)
@@ -731,6 +731,8 @@ libcvc4_add_sources(
   theory/quantifiers/quantifiers_inference_manager.h
   theory/quantifiers/quantifiers_modules.cpp
   theory/quantifiers/quantifiers_modules.h
+  theory/quantifiers/quantifiers_registry.cpp
+  theory/quantifiers/quantifiers_registry.h
   theory/quantifiers/quantifiers_rewriter.cpp
   theory/quantifiers/quantifiers_rewriter.h
   theory/quantifiers/quantifiers_state.cpp
index c539bfdb019e98d0254f1caf2ca28c966c38bf28..037cb74d74355e5b9ecdb0242341e323af91c26b 100644 (file)
@@ -49,8 +49,9 @@ TrustNode InstRewriterCegqi::rewriteInstantiation(Node q,
 
 InstStrategyCegqi::InstStrategyCegqi(QuantifiersEngine* qe,
                                      QuantifiersState& qs,
-                                     QuantifiersInferenceManager& qim)
-    : QuantifiersModule(qs, qim, qe),
+                                     QuantifiersInferenceManager& qim,
+                                     QuantifiersRegistry& qr)
+    : QuantifiersModule(qs, qim, qr, qe),
       d_irew(new InstRewriterCegqi(this)),
       d_cbqi_set_quant_inactive(false),
       d_incomplete_check(false),
@@ -309,11 +310,12 @@ bool InstStrategyCegqi::checkCompleteFor(Node q)
 
 void InstStrategyCegqi::checkOwnership(Node q)
 {
-  if( d_quantEngine->getOwner( q )==NULL && doCbqi( q ) ){
+  if (d_qreg.getOwner(q) == nullptr && doCbqi(q))
+  {
     if (d_do_cbqi[q] == CEG_HANDLED)
     {
       //take full ownership of the quantified formula
-      d_quantEngine->setOwner( q, this );
+      d_qreg.setOwner(q, this);
     }
   }
 }
index d4b78d3068f117dee5f0f07a05a28d280919b8ec..a6a3c36cdb807ba078d96d6a9f74f7d99ec7d798 100644 (file)
@@ -71,7 +71,8 @@ class InstStrategyCegqi : public QuantifiersModule
  public:
   InstStrategyCegqi(QuantifiersEngine* qe,
                     QuantifiersState& qs,
-                    QuantifiersInferenceManager& qim);
+                    QuantifiersInferenceManager& qim,
+                    QuantifiersRegistry& qr);
   ~InstStrategyCegqi();
 
   /** whether to do counterexample-guided instantiation for quantifier q */
index db8bc90d1a780d60e4a347deff58424e321e33e6..83a102633a442dff4d4ceff07da61970e74b49cd 100644 (file)
@@ -86,8 +86,9 @@ void OpArgIndex::getGroundTerms( ConjectureGenerator * s, std::vector< TNode >&
 
 ConjectureGenerator::ConjectureGenerator(QuantifiersEngine* qe,
                                          QuantifiersState& qs,
-                                         QuantifiersInferenceManager& qim)
-    : QuantifiersModule(qs, qim, qe),
+                                         QuantifiersInferenceManager& qim,
+                                         QuantifiersRegistry& qr)
+    : QuantifiersModule(qs, qim, qr, qe),
       d_notify(*this),
       d_uequalityEngine(
           d_notify, qs.getSatContext(), "ConjectureGenerator::ee", false),
index c73abd19b3d35249fe5907c09c529a5f3b02ab76..644461da267cd746517288244e67968eaff6845f 100644 (file)
@@ -438,7 +438,8 @@ private:  //information about ground equivalence classes
  public:
   ConjectureGenerator(QuantifiersEngine* qe,
                       QuantifiersState& qs,
-                      QuantifiersInferenceManager& qim);
+                      QuantifiersInferenceManager& qim,
+                      QuantifiersRegistry& qr);
   ~ConjectureGenerator();
 
   /* needs check */
index 69c33d329b196de6cdd5c6af1a6c7325abd1d779..96b3bd0b02c4b7aa57623426bd3ee47aeb832c43 100644 (file)
@@ -35,8 +35,9 @@ namespace quantifiers {
 
 InstantiationEngine::InstantiationEngine(QuantifiersEngine* qe,
                                          QuantifiersState& qs,
-                                         QuantifiersInferenceManager& qim)
-    : QuantifiersModule(qs, qim, qe),
+                                         QuantifiersInferenceManager& qim,
+                                         QuantifiersRegistry& qr)
+    : QuantifiersModule(qs, qim, qr, qe),
       d_instStrategies(),
       d_isup(),
       d_i_ag(),
@@ -210,7 +211,7 @@ void InstantiationEngine::checkOwnership(Node q)
       }
     }
     if( hasPat ){
-      d_quantEngine->setOwner( q, this, 1 );
+      d_qreg.setOwner(q, this, 1);
     }
   }
 }
@@ -260,7 +261,7 @@ void InstantiationEngine::addUserNoPattern(Node q, Node pat) {
 
 bool InstantiationEngine::shouldProcess(Node q)
 {
-  if (!d_quantEngine->hasOwnership(q, this))
+  if (!d_qreg.hasOwnership(q, this))
   {
     return false;
   }
index f5b999ceaba9f69933d0ce7de0af61fd345ff2e0..016784152ab7db16d84797767fd35cbad9505e77 100644 (file)
@@ -50,7 +50,8 @@ class InstantiationEngine : public QuantifiersModule {
  public:
   InstantiationEngine(QuantifiersEngine* qe,
                       QuantifiersState& qs,
-                      QuantifiersInferenceManager& qim);
+                      QuantifiersInferenceManager& qim,
+                      QuantifiersRegistry& qr);
   ~InstantiationEngine();
   void presolve() override;
   bool needsCheck(Theory::Effort e) override;
index 9144bca2a4062ec328eb8e479705d81e38e72172..a6862f513c8c320d70086b1a3d199b8ed7ba8c61 100644 (file)
@@ -86,8 +86,9 @@ Node BoundedIntegers::IntRangeDecisionHeuristic::proxyCurrentRangeLemma()
 
 BoundedIntegers::BoundedIntegers(QuantifiersEngine* qe,
                                  QuantifiersState& qs,
-                                 QuantifiersInferenceManager& qim)
-    : QuantifiersModule(qs, qim, qe)
+                                 QuantifiersInferenceManager& qim,
+                                 QuantifiersRegistry& qr)
+    : QuantifiersModule(qs, qim, qr, qe)
 {
 }
 
index 685c07d82234aedbbe063ba268e389433d4339c8..74ff8a19ba7cfedd362ffb60b63686b84f04a9c5 100644 (file)
@@ -163,7 +163,8 @@ private:
  public:
   BoundedIntegers(QuantifiersEngine* qe,
                   QuantifiersState& qs,
-                  QuantifiersInferenceManager& qim);
+                  QuantifiersInferenceManager& qim,
+                  QuantifiersRegistry& qr);
   virtual ~BoundedIntegers();
 
   void presolve() override;
index 715002f7b86be038ce84f4b2277e28abfeff6d2a..618a720474dffbe4bb26625d934aba8a6d6d9c3d 100644 (file)
@@ -35,8 +35,9 @@ using namespace CVC4::theory::inst;
 //Model Engine constructor
 ModelEngine::ModelEngine(QuantifiersEngine* qe,
                          QuantifiersState& qs,
-                         QuantifiersInferenceManager& qim)
-    : QuantifiersModule(qs, qim, qe),
+                         QuantifiersInferenceManager& qim,
+                         QuantifiersRegistry& qr)
+    : QuantifiersModule(qs, qim, qr, qe),
       d_incomplete_check(true),
       d_addedLemmas(0),
       d_triedLemmas(0),
@@ -187,7 +188,8 @@ int ModelEngine::checkModel(){
   if( Trace.isOn("model-engine") ){
     for( unsigned i=0; i<fm->getNumAssertedQuantifiers(); i++ ){
       Node f = fm->getAssertedQuantifier( i );
-      if( d_quantEngine->getModel()->isQuantifierActive( f ) && d_quantEngine->hasOwnership( f, this ) ){
+      if (fm->isQuantifierActive(f) && d_qreg.hasOwnership(f, this))
+      {
         int totalInst = 1;
         for( unsigned j=0; j<f[0].getNumChildren(); j++ ){
           TypeNode tn = f[0][j].getType();
@@ -213,7 +215,8 @@ int ModelEngine::checkModel(){
       Node q = fm->getAssertedQuantifier( i, true );
       Trace("fmf-exh-inst") << "-> Exhaustive instantiate " << q << ", effort = " << e << "..." << std::endl;
       //determine if we should check this quantifier
-      if( d_quantEngine->getModel()->isQuantifierActive( q ) && d_quantEngine->hasOwnership( q, this ) ){
+      if (fm->isQuantifierActive(q) && d_qreg.hasOwnership(q, this))
+      {
         exhaustiveInstantiate( q, e );
         if (d_qstate.isInConflict())
         {
@@ -318,7 +321,8 @@ void ModelEngine::debugPrint( const char* c ){
   Trace( c ) << "Quantifiers: " << std::endl;
   for( unsigned i=0; i<d_quantEngine->getModel()->getNumAssertedQuantifiers(); i++ ){
     Node q = d_quantEngine->getModel()->getAssertedQuantifier( i );
-    if( d_quantEngine->hasOwnership( q, this ) ){
+    if (d_qreg.hasOwnership(q, this))
+    {
       Trace( c ) << "   ";
       if( !d_quantEngine->getModel()->isQuantifierActive( q ) ){
         Trace( c ) << "*Inactive* ";
index 3e212b3192e3b1b67ff0e4155fa7bab4781b59c2..1cb780dd05794618270018f57ec9fd4a7d32f0c1 100644 (file)
@@ -45,7 +45,8 @@ private:
 public:
  ModelEngine(QuantifiersEngine* qe,
              QuantifiersState& qs,
-             QuantifiersInferenceManager& qim);
+             QuantifiersInferenceManager& qim,
+             QuantifiersRegistry& qr);
  virtual ~ModelEngine();
 
 public:
index c0f2945289d1c2e64605c1f73c425e4fcc604178..f22e678157c1780b1a25109913f620839abeced1 100644 (file)
@@ -35,8 +35,9 @@ namespace quantifiers {
 InstStrategyEnum::InstStrategyEnum(QuantifiersEngine* qe,
                                    QuantifiersState& qs,
                                    QuantifiersInferenceManager& qim,
+                                   QuantifiersRegistry& qr,
                                    RelevantDomain* rd)
-    : QuantifiersModule(qs, qim, qe), d_rd(rd), d_fullSaturateLimit(-1)
+    : QuantifiersModule(qs, qim, qr, qe), d_rd(rd), d_fullSaturateLimit(-1)
 {
 }
 void InstStrategyEnum::presolve()
@@ -130,7 +131,7 @@ void InstStrategyEnum::check(Theory::Effort e, QEffort quant_e)
       for (unsigned i = 0; i < nquant; i++)
       {
         Node q = fm->getAssertedQuantifier(i, true);
-        bool doProcess = d_quantEngine->hasOwnership(q, this)
+        bool doProcess = d_qreg.hasOwnership(q, this)
                          && fm->isQuantifierActive(q)
                          && alreadyProc.find(q) == alreadyProc.end();
         if (doProcess)
index 5687624db3074ba28cf63fb2b7cf9e1b683484d2..35c43d740f6b81cef5440c57640ecd652f55f703 100644 (file)
@@ -65,6 +65,7 @@ class InstStrategyEnum : public QuantifiersModule
   InstStrategyEnum(QuantifiersEngine* qe,
                    QuantifiersState& qs,
                    QuantifiersInferenceManager& qim,
+                   QuantifiersRegistry& qr,
                    RelevantDomain* rd);
   ~InstStrategyEnum() {}
   /** Presolve */
index c025dc29e5573b0436e43001c9f7fd944979dcf1..433de2f85e2820e76ae19125ca29fa213996d933 100644 (file)
@@ -1840,8 +1840,9 @@ bool MatchGen::isHandled( TNode n ) {
 
 QuantConflictFind::QuantConflictFind(QuantifiersEngine* qe,
                                      QuantifiersState& qs,
-                                     QuantifiersInferenceManager& qim)
-    : QuantifiersModule(qs, qim, qe),
+                                     QuantifiersInferenceManager& qim,
+                                     QuantifiersRegistry& qr)
+    : QuantifiersModule(qs, qim, qr, qe),
       d_conflict(qs.getSatContext(), false),
       d_true(NodeManager::currentNM()->mkConst<bool>(true)),
       d_false(NodeManager::currentNM()->mkConst<bool>(false)),
@@ -1852,7 +1853,8 @@ QuantConflictFind::QuantConflictFind(QuantifiersEngine* qe,
 //-------------------------------------------------- registration
 
 void QuantConflictFind::registerQuantifier( Node q ) {
-  if( d_quantEngine->hasOwnership( q, this ) ){
+  if (d_qreg.hasOwnership(q, this))
+  {
     d_quants.push_back( q );
     d_quant_id[q] = d_quants.size();
     if( Trace.isOn("qcf-qregister") ){
@@ -2022,7 +2024,7 @@ void QuantConflictFind::check(Theory::Effort level, QEffort quant_e)
     for (unsigned i = 0; i < nquant; i++)
     {
       Node q = fm->getAssertedQuantifier(i, true);
-      if (d_quantEngine->hasOwnership(q, this)
+      if (d_qreg.hasOwnership(q, this)
           && d_irr_quant.find(q) == d_irr_quant.end()
           && fm->isQuantifierActive(q))
       {
index 15b3d119a0761727b0dcaf755ae90b6c8eb63ee3..5ffe4426a4222c5c3e3c56b44d3fc2a0ca14eb27 100644 (file)
@@ -234,7 +234,8 @@ private:  //for equivalence classes
  public:
   QuantConflictFind(QuantifiersEngine* qe,
                     QuantifiersState& qs,
-                    QuantifiersInferenceManager& qim);
+                    QuantifiersInferenceManager& qim,
+                    QuantifiersRegistry& qr);
 
   /** register quantifier */
   void registerQuantifier(Node q) override;
index ad65c06cdfaa44098f561837a9afcbba262ac644..a1dc5acf337c6f9578252ebd31d6c42aaeee5c77 100644 (file)
@@ -27,8 +27,9 @@ using namespace CVC4::theory::quantifiers;
 
 QuantDSplit::QuantDSplit(QuantifiersEngine* qe,
                          QuantifiersState& qs,
-                         QuantifiersInferenceManager& qim)
-    : QuantifiersModule(qs, qim, qe), d_added_split(qs.getUserContext())
+                         QuantifiersInferenceManager& qim,
+                         QuantifiersRegistry& qr)
+    : QuantifiersModule(qs, qim, qr, qe), d_added_split(qs.getUserContext())
 {
 }
 
@@ -100,7 +101,7 @@ void QuantDSplit::checkOwnership(Node q)
   if (takeOwnership)
   {
     Trace("quant-dsplit-debug") << "Will take ownership." << std::endl;
-    d_quantEngine->setOwner( q, this );
+    d_qreg.setOwner(q, this);
   }
   // Notice we may not take ownership in some cases, meaning that both the
   // original quantified formula and the split one are generated. This may
index 76ac1a974fb1f6608b91875009b10cc178308e25..8fb9b4eb6924c7edea6eaddcca7957ad8bc13601 100644 (file)
@@ -51,7 +51,8 @@ class QuantDSplit : public QuantifiersModule {
  public:
   QuantDSplit(QuantifiersEngine* qe,
               QuantifiersState& qs,
-              QuantifiersInferenceManager& qim);
+              QuantifiersInferenceManager& qim,
+              QuantifiersRegistry& qr);
   /** determine whether this quantified formula will be reduced */
   void checkOwnership(Node q) override;
   /* whether this module needs to check this round */
index 6ce46ad998460fdc2b9c95af7e12efb1eff01cdc..db643d96bb0c7367d630fdcffab39aac253b6c4d 100644 (file)
@@ -26,8 +26,9 @@ namespace theory {
 QuantifiersModule::QuantifiersModule(
     quantifiers::QuantifiersState& qs,
     quantifiers::QuantifiersInferenceManager& qim,
+    quantifiers::QuantifiersRegistry& qr,
     QuantifiersEngine* qe)
-    : d_quantEngine(qe), d_qstate(qs), d_qim(qim)
+    : d_quantEngine(qe), d_qstate(qs), d_qim(qim), d_qreg(qr)
 {
 }
 
index 417e6820d0c87133dc79ee856eba4aef3cf0bb65..9037e94fa1e3f3e8199f0e227544f98284b4039b 100644 (file)
@@ -22,6 +22,7 @@
 #include <vector>
 
 #include "theory/quantifiers/quantifiers_inference_manager.h"
+#include "theory/quantifiers/quantifiers_registry.h"
 #include "theory/quantifiers/quantifiers_state.h"
 #include "theory/theory.h"
 #include "theory/uf/equality_engine.h"
@@ -61,6 +62,7 @@ class QuantifiersModule {
  public:
   QuantifiersModule(quantifiers::QuantifiersState& qs,
                     quantifiers::QuantifiersInferenceManager& qim,
+                    quantifiers::QuantifiersRegistry& qr,
                     QuantifiersEngine* qe);
   virtual ~QuantifiersModule(){}
   /** Presolve.
@@ -168,6 +170,8 @@ class QuantifiersModule {
   quantifiers::QuantifiersState& d_qstate;
   /** The quantifiers inference manager */
   quantifiers::QuantifiersInferenceManager& d_qim;
+  /** The quantifiers registry */
+  quantifiers::QuantifiersRegistry& d_qreg;
 };/* class QuantifiersModule */
 
 /** Quantifiers utility
index 15715152b8315b6a91d6b77a9adcab12219f916a..ad5d5dba770773089a8e1be5b3829ee20aa61a32 100644 (file)
@@ -18,7 +18,6 @@
 #include "theory/arith/arith_msum.h"
 #include "theory/quantifiers/sygus/synth_engine.h"
 #include "theory/quantifiers/term_util.h"
-#include "theory/quantifiers_engine.h"
 
 using namespace std;
 using namespace CVC4::kind;
@@ -34,11 +33,8 @@ bool QAttributes::isStandard() const
          && !d_isInternal;
 }
 
-QuantAttributes::QuantAttributes( QuantifiersEngine * qe ) : 
-d_quantEngine(qe) {
+QuantAttributes::QuantAttributes() {}
 
-}  
-  
 void QuantAttributes::setUserAttribute( const std::string& attr, Node n, std::vector< Node >& node_values, std::string str_value ){
   Trace("quant-attr-debug") << "Set " << attr << " " << n << std::endl;
   if (attr == "fun-def")
@@ -182,8 +178,6 @@ void QuantAttributes::computeAttributes( Node q ) {
     }
     d_fun_defs[f] = true;
   }
-  // set ownership of quantified formula q based on the computed attributes
-  d_quantEngine->setOwner(q, qa);
 }
 
 void QuantAttributes::computeQuantAttributes( Node q, QAttributes& qa ){
index 91a0d504f44d1533d0356902390b455b3925b040..740588b84d5bc99794abfe1b812f47d88e06ee9e 100644 (file)
@@ -25,8 +25,6 @@
 namespace CVC4 {
 namespace theory {
 
-class QuantifiersEngine;
-
 /** Attribute true for function definition quantifiers */
 struct FunDefAttributeId {};
 typedef expr::Attribute< FunDefAttributeId, bool > FunDefAttribute;
@@ -176,8 +174,8 @@ struct QAttributes
 */
 class QuantAttributes
 {
-public:
-  QuantAttributes( QuantifiersEngine * qe );
+ public:
+  QuantAttributes();
   ~QuantAttributes(){}
   /** set user attribute
   * This function applies an attribute
@@ -238,8 +236,6 @@ public:
   static void setInstantiationLevelAttr(Node n, Node qn, uint64_t level);
 
  private:
-  /** pointer to quantifiers engine */
-  QuantifiersEngine * d_quantEngine;
   /** cache of attributes */
   std::map< Node, QAttributes > d_qattr;
   /** function definitions */
index 573824b80bcdb89739bdfa69be7b800b7944a639..f1a05f401d50834a2697269f96c8a28c54624ad0 100644 (file)
@@ -40,49 +40,50 @@ QuantifiersModules::~QuantifiersModules() {}
 void QuantifiersModules::initialize(QuantifiersEngine* qe,
                                     QuantifiersState& qs,
                                     QuantifiersInferenceManager& qim,
+                                    QuantifiersRegistry& qr,
                                     std::vector<QuantifiersModule*>& modules)
 {
   // add quantifiers modules
   if (options::quantConflictFind())
   {
-    d_qcf.reset(new QuantConflictFind(qe, qs, qim));
+    d_qcf.reset(new QuantConflictFind(qe, qs, qim, qr));
     modules.push_back(d_qcf.get());
   }
   if (options::conjectureGen())
   {
-    d_sg_gen.reset(new ConjectureGenerator(qe, qs, qim));
+    d_sg_gen.reset(new ConjectureGenerator(qe, qs, qim, qr));
     modules.push_back(d_sg_gen.get());
   }
   if (!options::finiteModelFind() || options::fmfInstEngine())
   {
-    d_inst_engine.reset(new InstantiationEngine(qe, qs, qim));
+    d_inst_engine.reset(new InstantiationEngine(qe, qs, qim, qr));
     modules.push_back(d_inst_engine.get());
   }
   if (options::cegqi())
   {
-    d_i_cbqi.reset(new InstStrategyCegqi(qe, qs, qim));
+    d_i_cbqi.reset(new InstStrategyCegqi(qe, qs, qim, qr));
     modules.push_back(d_i_cbqi.get());
     qe->getInstantiate()->addRewriter(d_i_cbqi->getInstRewriter());
   }
   if (options::sygus())
   {
-    d_synth_e.reset(new SynthEngine(qe, qs, qim));
+    d_synth_e.reset(new SynthEngine(qe, qs, qim, qr));
     modules.push_back(d_synth_e.get());
   }
   // finite model finding
   if (options::fmfBound())
   {
-    d_bint.reset(new BoundedIntegers(qe, qs, qim));
+    d_bint.reset(new BoundedIntegers(qe, qs, qim, qr));
     modules.push_back(d_bint.get());
   }
   if (options::finiteModelFind() || options::fmfBound())
   {
-    d_model_engine.reset(new ModelEngine(qe, qs, qim));
+    d_model_engine.reset(new ModelEngine(qe, qs, qim, qr));
     modules.push_back(d_model_engine.get());
   }
   if (options::quantDynamicSplit() != options::QuantDSplitMode::NONE)
   {
-    d_qsplit.reset(new QuantDSplit(qe, qs, qim));
+    d_qsplit.reset(new QuantDSplit(qe, qs, qim, qr));
     modules.push_back(d_qsplit.get());
   }
   if (options::quantAlphaEquiv())
@@ -93,12 +94,12 @@ void QuantifiersModules::initialize(QuantifiersEngine* qe,
   if (options::fullSaturateQuant() || options::fullSaturateInterleave())
   {
     d_rel_dom.reset(new RelevantDomain(qe));
-    d_fs.reset(new InstStrategyEnum(qe, qs, qim, d_rel_dom.get()));
+    d_fs.reset(new InstStrategyEnum(qe, qs, qim, qr, d_rel_dom.get()));
     modules.push_back(d_fs.get());
   }
   if (options::sygusInst())
   {
-    d_sygus_inst.reset(new SygusInst(qe, qs, qim));
+    d_sygus_inst.reset(new SygusInst(qe, qs, qim, qr));
     modules.push_back(d_sygus_inst.get());
   }
 }
index ba48cc68b0ca1b5d5d0a31b7bf2ef22df4c963db..08266c8fe97787bab72284f7f35461cf27bb2949 100644 (file)
@@ -54,6 +54,7 @@ class QuantifiersModules
   void initialize(QuantifiersEngine* qe,
                   QuantifiersState& qs,
                   QuantifiersInferenceManager& qim,
+                  QuantifiersRegistry& qr,
                   std::vector<QuantifiersModule*>& modules);
 
  private:
diff --git a/src/theory/quantifiers/quantifiers_registry.cpp b/src/theory/quantifiers/quantifiers_registry.cpp
new file mode 100644 (file)
index 0000000..1633382
--- /dev/null
@@ -0,0 +1,65 @@
+/*********************                                                        */
+/*! \file quantifiers_registry.cpp
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Andrew Reynolds
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
+ ** in the top-level source directory and their institutional affiliations.
+ ** All rights reserved.  See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief The quantifiers registry
+ **/
+
+#include "theory/quantifiers/quantifiers_registry.h"
+
+#include "theory/quantifiers/quant_util.h"
+
+namespace CVC4 {
+namespace theory {
+namespace quantifiers {
+
+QuantifiersModule* QuantifiersRegistry::getOwner(Node q) const
+{
+  std::map<Node, QuantifiersModule*>::const_iterator it = d_owner.find(q);
+  if (it == d_owner.end())
+  {
+    return nullptr;
+  }
+  return it->second;
+}
+
+void QuantifiersRegistry::setOwner(Node q,
+                                   QuantifiersModule* m,
+                                   int32_t priority)
+{
+  QuantifiersModule* mo = getOwner(q);
+  if (mo == m)
+  {
+    return;
+  }
+  if (mo != nullptr)
+  {
+    if (priority <= d_owner_priority[q])
+    {
+      Trace("quant-warn") << "WARNING: setting owner of " << q << " to "
+                          << (m ? m->identify() : "null")
+                          << ", but already has owner " << mo->identify()
+                          << " with higher priority!" << std::endl;
+      return;
+    }
+  }
+  d_owner[q] = m;
+  d_owner_priority[q] = priority;
+}
+
+bool QuantifiersRegistry::hasOwnership(Node q, QuantifiersModule* m) const
+{
+  QuantifiersModule* mo = getOwner(q);
+  return mo == m || mo == nullptr;
+}
+
+}  // namespace quantifiers
+}  // namespace theory
+}  // namespace CVC4
diff --git a/src/theory/quantifiers/quantifiers_registry.h b/src/theory/quantifiers/quantifiers_registry.h
new file mode 100644 (file)
index 0000000..59db1df
--- /dev/null
@@ -0,0 +1,69 @@
+/*********************                                                        */
+/*! \file quantifiers_registry.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Andrew Reynolds
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
+ ** in the top-level source directory and their institutional affiliations.
+ ** All rights reserved.  See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief The quantifiers registry
+ **/
+
+#include "cvc4_private.h"
+
+#ifndef CVC4__THEORY__QUANTIFIERS__QUANTIFIERS_REGISTRY_H
+#define CVC4__THEORY__QUANTIFIERS__QUANTIFIERS_REGISTRY_H
+
+#include "expr/node.h"
+
+namespace CVC4 {
+namespace theory {
+
+class QuantifiersModule;
+
+namespace quantifiers {
+
+/**
+ * The quantifiers registry, which manages basic information about which
+ * quantifiers modules have ownership of quantified formulas.
+ */
+class QuantifiersRegistry
+{
+ public:
+  QuantifiersRegistry() {}
+  ~QuantifiersRegistry() {}
+  /** get the owner of quantified formula q */
+  QuantifiersModule* getOwner(Node q) const;
+  /**
+   * Set owner of quantified formula q to module m with given priority. If
+   * the quantified formula has previously been assigned an owner with
+   * lower priority, that owner is overwritten.
+   */
+  void setOwner(Node q, QuantifiersModule* m, int32_t priority = 0);
+  /**
+   * Return true if module q has no owner registered or if its registered owner is m.
+   */
+  bool hasOwnership(Node q, QuantifiersModule* m) const;
+
+ private:
+  /**
+   * Maps quantified formulas to the module that owns them, if any module has
+   * specifically taken ownership of it.
+   */
+  std::map<Node, QuantifiersModule*> d_owner;
+  /**
+   * The priority value associated with the ownership of quantified formulas
+   * in the domain of the above map, where higher values take higher
+   * precendence.
+   */
+  std::map<Node, int32_t> d_owner_priority;
+};
+
+}  // namespace quantifiers
+}  // namespace theory
+}  // namespace CVC4
+
+#endif /* CVC4__THEORY__QUANTIFIERS__QUANTIFIERS_REGISTRY_H */
index 4b35bc5452252deb47aae774c447d1e416805449..869d22737c6d429b98d2fda5f1c49c664ddde03a 100644 (file)
@@ -31,8 +31,9 @@ namespace quantifiers {
 
 SynthEngine::SynthEngine(QuantifiersEngine* qe,
                          QuantifiersState& qs,
-                         QuantifiersInferenceManager& qim)
-    : QuantifiersModule(qs, qim, qe),
+                         QuantifiersInferenceManager& qim,
+                         QuantifiersRegistry& qr)
+    : QuantifiersModule(qs, qim, qr, qe),
       d_tds(qe->getTermDatabaseSygus()),
       d_conj(nullptr),
       d_sqp(qe)
@@ -164,11 +165,22 @@ void SynthEngine::assignConjecture(Node q)
   d_conjs.back()->assign(q);
 }
 
+void SynthEngine::checkOwnership(Node q)
+{
+  // take ownership of quantified formulas with sygus attribute, and function
+  // definitions when options::sygusRecFun is true.
+  QuantAttributes* qa = d_quantEngine->getQuantAttributes();
+  if (qa->isSygus(q) || (options::sygusRecFun() && qa->isFunDef(q)))
+  {
+    d_qreg.setOwner(q, this, 2);
+  }
+}
+
 void SynthEngine::registerQuantifier(Node q)
 {
   Trace("cegqi-debug") << "SynthEngine: Register quantifier : " << q
                        << std::endl;
-  if (d_quantEngine->getOwner(q) != this)
+  if (d_qreg.getOwner(q) != this)
   {
     return;
   }
index 63175cf0cd0ec5e5a0b2f514a26542c69b004fe4..4cb73d450591e1e747b7fc376ba4818e4a4a7a68 100644 (file)
@@ -35,7 +35,8 @@ class SynthEngine : public QuantifiersModule
  public:
   SynthEngine(QuantifiersEngine* qe,
               QuantifiersState& qs,
-              QuantifiersInferenceManager& qim);
+              QuantifiersInferenceManager& qim,
+              QuantifiersRegistry& qr);
   ~SynthEngine();
   /** presolve
    *
@@ -49,6 +50,8 @@ class SynthEngine : public QuantifiersModule
   QEffort needsModel(Theory::Effort e) override;
   /* Call during quantifier engine's check */
   void check(Theory::Effort e, QEffort quant_e) override;
+  /** check ownership */
+  void checkOwnership(Node q) override;
   /* Called for new quantifiers */
   void registerQuantifier(Node q) override;
   /** Identify this module (for debugging, dynamic configuration, etc..) */
index 66c9cbf7913da91e585bc76db27106d274e84f20..69836febad9f3d7ec920e79781e87cf64d606a90 100644 (file)
@@ -181,8 +181,9 @@ void addSpecialValues(
 
 SygusInst::SygusInst(QuantifiersEngine* qe,
                      QuantifiersState& qs,
-                     QuantifiersInferenceManager& qim)
-    : QuantifiersModule(qs, qim, qe),
+                     QuantifiersInferenceManager& qim,
+                     QuantifiersRegistry& qr)
+    : QuantifiersModule(qs, qim, qr, qe),
       d_ce_lemma_added(qs.getUserContext()),
       d_global_terms(qs.getUserContext()),
       d_notified_assertions(qs.getUserContext())
index 4820398be3afb1e669301a64cb808a2dbec7f559..123ec1f5e13a154f3fbd3f616a9036fb099de200 100644 (file)
@@ -64,7 +64,8 @@ class SygusInst : public QuantifiersModule
  public:
   SygusInst(QuantifiersEngine* qe,
             QuantifiersState& qs,
-            QuantifiersInferenceManager& qim);
+            QuantifiersInferenceManager& qim,
+            QuantifiersRegistry& qr);
   ~SygusInst() = default;
 
   bool needsCheck(Theory::Effort e) override;
index 921c5100fed2c92f09a7f6dd2b0207df2f82e8a0..c7ef88339181136df6f33e9e3f086a2f65236340 100644 (file)
@@ -40,6 +40,7 @@ QuantifiersEngine::QuantifiersEngine(
       d_qim(qim),
       d_te(nullptr),
       d_decManager(nullptr),
+      d_qreg(),
       d_tr_trie(new inst::TriggerTrie),
       d_model(nullptr),
       d_builder(nullptr),
@@ -47,7 +48,7 @@ QuantifiersEngine::QuantifiersEngine(
       d_term_db(new quantifiers::TermDb(qstate, qim, this)),
       d_eq_query(nullptr),
       d_sygus_tdb(nullptr),
-      d_quant_attr(new quantifiers::QuantAttributes(this)),
+      d_quant_attr(new quantifiers::QuantAttributes),
       d_instantiate(new quantifiers::Instantiate(this, qstate, pnm)),
       d_skolemize(new quantifiers::Skolemize(this, qstate, pnm)),
       d_term_enum(new quantifiers::TermEnumeration),
@@ -128,7 +129,7 @@ void QuantifiersEngine::finishInit(TheoryEngine* te, DecisionManager* dm)
   d_decManager = dm;
   // Initialize the modules and the utilities here.
   d_qmodules.reset(new quantifiers::QuantifiersModules);
-  d_qmodules->initialize(this, d_qstate, d_qim, d_modules);
+  d_qmodules->initialize(this, d_qstate, d_qim, d_qreg, d_modules);
   if (d_qmodules->d_rel_dom.get())
   {
     d_util.push_back(d_qmodules->d_rel_dom.get());
@@ -198,49 +199,6 @@ inst::TriggerTrie* QuantifiersEngine::getTriggerDatabase() const
   return d_tr_trie.get();
 }
 
-QuantifiersModule * QuantifiersEngine::getOwner( Node q ) {
-  std::map< Node, QuantifiersModule * >::iterator it = d_owner.find( q );
-  if( it==d_owner.end() ){
-    return NULL;
-  }else{
-    return it->second;
-  }
-}
-
-void QuantifiersEngine::setOwner( Node q, QuantifiersModule * m, int priority ) {
-  QuantifiersModule * mo = getOwner( q );
-  if( mo!=m ){
-    if( mo!=NULL ){
-      if( priority<=d_owner_priority[q] ){
-        Trace("quant-warn") << "WARNING: setting owner of " << q << " to " << ( m ? m->identify() : "null" ) << ", but already has owner " << mo->identify() << " with higher priority!" << std::endl;
-        return;
-      }
-    }
-    d_owner[q] = m;
-    d_owner_priority[q] = priority;
-  }
-}
-
-void QuantifiersEngine::setOwner(Node q, quantifiers::QAttributes& qa)
-{
-  if (qa.d_sygus || (options::sygusRecFun() && !qa.d_fundef_f.isNull()))
-  {
-    if (d_qmodules->d_synth_e.get() == nullptr)
-    {
-      Trace("quant-warn") << "WARNING : synth engine is null, and we have : "
-                          << q << std::endl;
-    }
-    // set synth engine as owner since this is either a conjecture or a function
-    // definition to be used by sygus
-    setOwner(q, d_qmodules->d_synth_e.get(), 2);
-  }
-}
-
-bool QuantifiersEngine::hasOwnership( Node q, QuantifiersModule * m ) {
-  QuantifiersModule * mo = getOwner( q );
-  return mo==m || mo==NULL;
-}
-
 bool QuantifiersEngine::isFiniteBound(Node q, Node v) const
 {
   quantifiers::BoundedIntegers* bi = d_qmodules->d_bint.get();
@@ -592,7 +550,7 @@ void QuantifiersEngine::check( Theory::Effort e ){
                 for( unsigned i=0; i<d_model->getNumAssertedQuantifiers(); i++ ){
                   bool hasCompleteM = false;
                   Node q = d_model->getAssertedQuantifier( i );
-                  QuantifiersModule * qmd = getOwner( q );
+                  QuantifiersModule* qmd = d_qreg.getOwner(q);
                   if( qmd!=NULL ){
                     hasCompleteM = qmd->checkCompleteFor( q );
                   }else{
@@ -719,7 +677,7 @@ void QuantifiersEngine::registerQuantifierInternal(Node f)
                            << "..." << std::endl;
       mdl->checkOwnership(f);
     }
-    QuantifiersModule* qm = getOwner(f);
+    QuantifiersModule* qm = d_qreg.getOwner(f);
     Trace("quant") << " Owner : " << (qm == nullptr ? "[none]" : qm->identify())
                    << std::endl;
     // register with each module
index f38a43757a85705d69fe7ad88e953c30246f9bf1..b7a1df8a624e2c82b4c5adef3ebe9976461e2215 100644 (file)
@@ -113,30 +113,7 @@ class QuantifiersEngine {
    */
   void finishInit(TheoryEngine* te, DecisionManager* dm);
   //---------------------- end private initialization
-  /**
-   * Maps quantified formulas to the module that owns them, if any module has
-   * specifically taken ownership of it.
-   */
-  std::map< Node, QuantifiersModule * > d_owner;
-  /**
-   * The priority value associated with the ownership of quantified formulas
-   * in the domain of the above map, where higher values take higher
-   * precendence.
-   */
-  std::map< Node, int > d_owner_priority;
  public:
-  /** get owner */
-  QuantifiersModule * getOwner( Node q );
-  /**
-   * Set owner of quantified formula q to module m with given priority. If
-   * the quantified formula has previously been assigned an owner with
-   * lower priority, that owner is overwritten.
-   */
-  void setOwner( Node q, QuantifiersModule * m, int priority = 0 );
-  /** set owner of quantified formula q based on its attributes qa. */
-  void setOwner(Node q, quantifiers::QAttributes& qa);
-  /** considers */
-  bool hasOwnership( Node q, QuantifiersModule * m = NULL );
   /** does variable v of quantified formula q have a finite bound? */
   bool isFiniteBound(Node q, Node v) const;
   /** get bound var type
@@ -343,6 +320,8 @@ public:
   /** vector of modules for quantifiers */
   std::vector<QuantifiersModule*> d_modules;
   //------------- quantifiers utilities
+  /** The quantifiers registry */
+  quantifiers::QuantifiersRegistry d_qreg;
   /** all triggers will be stored in this trie */
   std::unique_ptr<inst::TriggerTrie> d_tr_trie;
   /** extended model object */