Initialize theory rewriters in theories (#4197)
authorAndres Noetzli <andres.noetzli@gmail.com>
Thu, 2 Apr 2020 02:35:25 +0000 (19:35 -0700)
committerGitHub <noreply@github.com>
Thu, 2 Apr 2020 02:35:25 +0000 (19:35 -0700)
Until now, the `Rewriter` was responsible for creating `TheoryRewriter`
instances. This commit adds a method `mkTheoryRewriter()` that theories
override to create an instance of their corresponding theory rewriter.
The advantage is that the theories can pass additional information to
their theory rewriter (e.g. a statistics object).

45 files changed:
src/preprocessing/passes/bv_gauss.cpp
src/preprocessing/passes/bv_gauss.h
src/theory/arith/theory_arith.cpp
src/theory/arith/theory_arith.h
src/theory/arrays/theory_arrays.cpp
src/theory/arrays/theory_arrays.h
src/theory/booleans/theory_bool.cpp
src/theory/booleans/theory_bool.h
src/theory/builtin/theory_builtin.cpp
src/theory/builtin/theory_builtin.h
src/theory/bv/theory_bv.cpp
src/theory/bv/theory_bv.h
src/theory/datatypes/theory_datatypes.cpp
src/theory/datatypes/theory_datatypes.h
src/theory/fp/theory_fp.cpp
src/theory/fp/theory_fp.h
src/theory/mkrewriter
src/theory/quantifiers/theory_quantifiers.cpp
src/theory/quantifiers/theory_quantifiers.h
src/theory/rewriter.cpp
src/theory/rewriter.h
src/theory/rewriter_tables_template.h
src/theory/sep/theory_sep.cpp
src/theory/sep/theory_sep.h
src/theory/sets/theory_sets.cpp
src/theory/sets/theory_sets.h
src/theory/strings/theory_strings.cpp
src/theory/strings/theory_strings.h
src/theory/theory.h
src/theory/theory_engine.cpp
src/theory/theory_engine.h
src/theory/uf/theory_uf.cpp
src/theory/uf/theory_uf.h
test/unit/preprocessing/pass_bv_gauss_white.h
test/unit/theory/evaluator_white.h
test/unit/theory/regexp_operation_black.h
test/unit/theory/sequences_rewriter_white.h
test/unit/theory/theory_black.h
test/unit/theory/theory_bv_rewriter_white.h
test/unit/theory/theory_engine_white.h
test/unit/theory/theory_quantifiers_bv_instantiator_white.h
test/unit/theory/theory_sets_type_enumerator_white.h
test/unit/theory/theory_strings_skolem_cache_black.h
test/unit/theory/theory_white.h
test/unit/theory/type_enumerator_white.h

index 68371641019192241e753a6cde78848dd68d7839..b08f69b5012448b19f49b4a38221f0565c28493f 100644 (file)
@@ -687,8 +687,9 @@ BVGauss::Result BVGauss::gaussElimRewriteForUrem(
   return ret;
 }
 
-BVGauss::BVGauss(PreprocessingPassContext* preprocContext)
-    : PreprocessingPass(preprocContext, "bv-gauss")
+BVGauss::BVGauss(PreprocessingPassContext* preprocContext,
+                 const std::string& name)
+    : PreprocessingPass(preprocContext, name)
 {
 }
 
index 93d61be9e51c2d318cae6e9087292bfbdf4c0c25..7fb23814a50be8f33f7563f282dbdfa354f4a378 100644 (file)
@@ -30,7 +30,8 @@ namespace passes {
 class BVGauss : public PreprocessingPass
 {
  public:
-  BVGauss(PreprocessingPassContext* preprocContext);
+  BVGauss(PreprocessingPassContext* preprocContext,
+          const std::string& name = "bv-gauss");
 
  protected:
   /**
index 8986e68945aee3ce36ad98a7cbd26be6f66ff3d1..2c748f1885359e527f68d2df75b7cca4b38ffd74 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "options/smt_options.h"
 #include "smt/smt_statistics_registry.h"
+#include "theory/arith/arith_rewriter.h"
 #include "theory/arith/infer_bounds.h"
 #include "theory/arith/theory_arith_private.h"
 #include "theory/ext_theory.h"
@@ -53,6 +54,11 @@ TheoryArith::~TheoryArith(){
   delete d_internal;
 }
 
+std::unique_ptr<TheoryRewriter> TheoryArith::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new ArithRewriter());
+}
+
 void TheoryArith::preRegisterTerm(TNode n){
   d_internal->preRegisterTerm(n);
 }
index b39ab961fe739cee2abfb25aec9adac785c97455..92892d2ae89aafeb401c89cdd36d72ee3906011b 100644 (file)
@@ -51,6 +51,8 @@ public:
               Valuation valuation, const LogicInfo& logicInfo);
   virtual ~TheoryArith();
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   /**
    * Does non-context dependent setup for a node connected to a theory.
    */
index dcf82e6b4b2658e8710a402021eee12c6359f519..787ae84e2104533bb24f749c7da9002eb70eeee3 100644 (file)
@@ -29,6 +29,7 @@
 #include "smt/command.h"
 #include "smt/logic_exception.h"
 #include "smt/smt_statistics_registry.h"
+#include "theory/arrays/theory_arrays_rewriter.h"
 #include "theory/rewriter.h"
 #include "theory/theory_model.h"
 #include "theory/valuation.h"
@@ -178,6 +179,11 @@ TheoryArrays::~TheoryArrays() {
   smtStatisticsRegistry()->unregisterStat(&d_numSetModelValConflicts);
 }
 
+std::unique_ptr<TheoryRewriter> TheoryArrays::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new TheoryArraysRewriter());
+}
+
 void TheoryArrays::setMasterEqualityEngine(eq::EqualityEngine* eq) {
   d_equalityEngine.setMasterEqualityEngine(eq);
 }
index 3d6d0692ecd9aa08a7457020e8d7cd502b010213..d1f912d950263b8c4a5a7d0317762bf0e06ec3d9 100644 (file)
@@ -144,6 +144,8 @@ class TheoryArrays : public Theory {
                std::string name = "");
   ~TheoryArrays();
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   void setMasterEqualityEngine(eq::EqualityEngine* eq) override;
 
   std::string identify() const override { return std::string("TheoryArrays"); }
index 8fbe8395159bcf0861e302b76af4e91fa893cd2e..e670121d1440363f8e275f3fdfe7f8b363ae3fee 100644 (file)
  ** The theory of booleans.
  **/
 
-#include "theory/theory.h"
 #include "theory/booleans/theory_bool.h"
-#include "theory/booleans/circuit_propagator.h"
-#include "theory/valuation.h"
-#include "smt_util/boolean_simplification.h"
-#include "theory/substitutions.h"
 
-#include <vector>
 #include <stack>
+#include <vector>
+
+#include "smt_util/boolean_simplification.h"
+#include "theory/booleans/circuit_propagator.h"
+#include "theory/booleans/theory_bool_rewriter.h"
+#include "theory/substitutions.h"
+#include "theory/theory.h"
+#include "theory/valuation.h"
 #include "util/hash.h"
 
 using namespace std;
@@ -31,6 +33,11 @@ namespace CVC4 {
 namespace theory {
 namespace booleans {
 
+std::unique_ptr<TheoryRewriter> TheoryBool::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new TheoryBoolRewriter());
+}
+
 Theory::PPAssertStatus TheoryBool::ppAssert(TNode in, SubstitutionMap& outSubstitutions) {
 
   if (in.getKind() == kind::CONST_BOOLEAN && !in.getConst<bool>()) {
index abe0242824b8a61a5d6627f48ad591a336785397..75e375ee61dc188d4b4d81a167b9b477ff1c66af 100644 (file)
@@ -33,6 +33,8 @@ public:
       : Theory(THEORY_BOOL, c, u, out, valuation, logicInfo)
   {}
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   PPAssertStatus ppAssert(TNode in, SubstitutionMap& outSubstitutions) override;
 
   //void check(Effort);
index 505aa503f5e5297e752e0e9defa78e60a4a44d65..8df5a8535aae9c4dfbaa4aae1382619176358b5f 100644 (file)
@@ -17,6 +17,7 @@
 #include "theory/builtin/theory_builtin.h"
 
 #include "expr/kind.h"
+#include "theory/builtin/theory_builtin_rewriter.h"
 #include "theory/theory_model.h"
 #include "theory/valuation.h"
 
@@ -35,6 +36,11 @@ TheoryBuiltin::TheoryBuiltin(context::Context* c,
 {
 }
 
+std::unique_ptr<TheoryRewriter> TheoryBuiltin::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new TheoryBuiltinRewriter());
+}
+
 std::string TheoryBuiltin::identify() const
 {
   return std::string("TheoryBuiltin");
index 6e99ef04049379b74cd34ea1a498fa34a67253d7..d240f4f635eb5fec06c315e3e07c5ea22789c4f4 100644 (file)
@@ -34,6 +34,8 @@ class TheoryBuiltin : public Theory
                 Valuation valuation,
                 const LogicInfo& logicInfo);
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   std::string identify() const override;
 
   /** finish initialization */
index 94fc1e34c8c31e6dbb6ad9d9a7acd6f0f7c6767d..27718b63f9f2bb2fd218149ebf0674e3e4180e1b 100644 (file)
@@ -112,6 +112,11 @@ TheoryBV::TheoryBV(context::Context* c,
 
 TheoryBV::~TheoryBV() {}
 
+std::unique_ptr<TheoryRewriter> TheoryBV::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new TheoryBVRewriter());
+}
+
 void TheoryBV::setMasterEqualityEngine(eq::EqualityEngine* eq) {
   if (options::bitblastMode() == options::BitblastMode::EAGER)
   {
index 196535a1938fdb4e908e234c41a2e1ef7a1f75e9..ff1c9245ad725b713ab253c5ced13acf76884054 100644 (file)
@@ -72,6 +72,8 @@ public:
 
   ~TheoryBV();
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   void setMasterEqualityEngine(eq::EqualityEngine* eq) override;
 
   void finishInit() override;
index 7fbe5bc68188d6864b88a4bb81857ece88842755..15220b9dc0adaf66bda73bdb35059c06c1793b19 100644 (file)
@@ -25,6 +25,7 @@
 #include "options/quantifiers_options.h"
 #include "options/smt_options.h"
 #include "options/theory_options.h"
+#include "theory/datatypes/datatypes_rewriter.h"
 #include "theory/datatypes/theory_datatypes_type_rules.h"
 #include "theory/datatypes/theory_datatypes_utils.h"
 #include "theory/quantifiers_engine.h"
@@ -85,6 +86,11 @@ TheoryDatatypes::~TheoryDatatypes() {
   }
 }
 
+std::unique_ptr<TheoryRewriter> TheoryDatatypes::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new DatatypesRewriter());
+}
+
 void TheoryDatatypes::setMasterEqualityEngine(eq::EqualityEngine* eq) {
   d_equalityEngine.setMasterEqualityEngine(eq);
 }
index a878647bc6e63700ef420fbf1055d0c22f0a3af9..7ccd04f3931360185d052c94431bac7ef8fe0f18 100644 (file)
@@ -271,6 +271,8 @@ private:
                   const LogicInfo& logicInfo);
   ~TheoryDatatypes();
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   void setMasterEqualityEngine(eq::EqualityEngine* eq) override;
 
   /** propagate */
index 2632a6f3813d7f3651c5cc301379e593ab4a6506..5ab285766449338f34a89cdc20e96052191d3185 100644 (file)
  ** \todo document this file
  **/
 
-
-#include "options/fp_options.h"
-#include "theory/rewriter.h"
-#include "theory/theory_model.h"
 #include "theory/fp/theory_fp.h"
 
-
 #include <set>
 #include <stack>
 #include <unordered_set>
 #include <vector>
 
+#include "options/fp_options.h"
+#include "theory/fp/theory_fp_rewriter.h"
+#include "theory/rewriter.h"
+#include "theory/theory_model.h"
+
 using namespace std;
 
 namespace CVC4 {
@@ -177,6 +177,11 @@ TheoryFp::TheoryFp(context::Context *c,
 
 } /* TheoryFp::TheoryFp() */
 
+std::unique_ptr<TheoryRewriter> TheoryFp::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new TheoryFpRewriter());
+}
+
 Node TheoryFp::minUF(Node node) {
   Assert(node.getKind() == kind::FLOATINGPOINT_MIN);
   TypeNode t(node.getType());
index ad093f924858e28060de57e81b6b13a33076eb90..802a70435647d05d83f2717c64b86547e2781023 100644 (file)
@@ -38,6 +38,8 @@ class TheoryFp : public Theory {
   TheoryFp(context::Context* c, context::UserContext* u, OutputChannel& out,
            Valuation valuation, const LogicInfo& logicInfo);
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   Node expandDefinition(LogicRequest& lr, Node node) override;
 
   void preRegisterTerm(TNode node) override;
index dd5abd219323f9223f0647211802b9a7b9c6b475..3c27f1b530f05785a5d9cad68ec421562cc36db7 100755 (executable)
@@ -37,7 +37,6 @@ me=$(basename "$0")
 template=$1; shift
 
 rewriter_includes=
-rewrite_init=
 
 pre_rewrite_get_cache=
 pre_rewrite_set_cache=
@@ -139,8 +138,6 @@ function rewriter {
   header="$2"
 
   rewriter_includes="${rewriter_includes}#include \"$header\"
-"
-  rewrite_init="${rewrite_init}   d_theoryRewriters[${theory_id}].reset(new ${class});
 "
   pre_rewrite_attribute_ids="${pre_rewrite_attribute_ids} preids.push_back(expr::attr::AttributeManager::getAttributeId(RewriteAttibute<${theory_id}>::pre_rewrite()));
 "
@@ -257,7 +254,6 @@ for var in \
     post_rewrite_get_cache \
     pre_rewrite_set_cache \
     post_rewrite_set_cache \
-    rewrite_init \
     pre_rewrite_attribute_ids \
     post_rewrite_attribute_ids \
     template \
index 227f4d5b5e0cf082c28f7ea3ebc466ee1043ee9d..e3e3c3824473b1d74269f03406df7a77a593b50d 100644 (file)
@@ -22,6 +22,7 @@
 #include "theory/quantifiers/ematching/instantiation_engine.h"
 #include "theory/quantifiers/fmf/model_engine.h"
 #include "theory/quantifiers/quantifiers_attributes.h"
+#include "theory/quantifiers/quantifiers_rewriter.h"
 #include "theory/quantifiers/term_database.h"
 #include "theory/quantifiers/term_util.h"
 #include "theory/quantifiers_engine.h"
@@ -53,6 +54,11 @@ TheoryQuantifiers::TheoryQuantifiers(Context* c, context::UserContext* u, Output
 TheoryQuantifiers::~TheoryQuantifiers() {
 }
 
+std::unique_ptr<TheoryRewriter> TheoryQuantifiers::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new QuantifiersRewriter());
+}
+
 void TheoryQuantifiers::finishInit()
 {
   // quantifiers are not evaluated in getModelValue
index b5b07f2e6d3e22f7c9837678c6043d39809c7238..7efe7419ca1f278da787d2f5f4649fd8eb9e2c1a 100644 (file)
@@ -39,6 +39,8 @@ class TheoryQuantifiers : public Theory {
                     const LogicInfo& logicInfo);
   ~TheoryQuantifiers();
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   /** finish initialization */
   void finishInit() override;
   void preRegisterTerm(TNode n) override;
index b3f1e23d7e28a0edd2103717de04d1bf45c651ab..54b9f319df9f4bce5e49a2f21b6be35a9b08b2f3 100644 (file)
@@ -96,6 +96,12 @@ Node Rewriter::rewrite(TNode node) {
   return getInstance().rewriteTo(theoryOf(node), node);
 }
 
+void Rewriter::registerTheoryRewriter(theory::TheoryId tid,
+                                      std::unique_ptr<TheoryRewriter> trew)
+{
+  getInstance().d_theoryRewriters[tid] = std::move(trew);
+}
+
 void Rewriter::registerPreRewrite(
     Kind k, std::function<RewriteResponse(RewriteEnvironment*, TNode)> fn)
 {
index f7298e1fb00a99e3d9dfe7fb3daffefaa6e23e77..8a641743b33dcdead88f106f393f7c24c8c08401 100644 (file)
@@ -62,6 +62,16 @@ class Rewriter {
    */
   static void clearCaches();
 
+  /**
+   * Registers a theory rewriter with this rewriter. This transfers the
+   * ownership of the theory rewriter to the rewriter.
+   *
+   * @param tid The theory that the theory rewriter should be associated with.
+   * @param trew The theory rewriter to register.
+   */
+  static void registerTheoryRewriter(theory::TheoryId tid,
+                                     std::unique_ptr<TheoryRewriter> trew);
+
   /**
    * Register a prerewrite for a given kind.
    *
index 1bb03e253a443027c70041822f19db5b5b6bfba2..9f6b0738975577219bca2bc5f2cf2e3fe25a0488 100644 (file)
@@ -63,8 +63,6 @@ ${post_rewrite_set_cache}
 
 Rewriter::Rewriter()
 {
-${rewrite_init}
-
 for (size_t i = 0; i < kind::LAST_KIND; ++i)
 {
   d_preRewriters[i] = nullptr;
@@ -75,7 +73,6 @@ for (size_t i = 0; i < theory::THEORY_LAST; ++i)
 {
   d_preRewritersEqual[i] = nullptr;
   d_postRewritersEqual[i] = nullptr;
-  d_theoryRewriters[i]->registerRewrites(this);
 }
 }
 
index 0b6e7a5fbaef9c725915d189fa566d859679cc11..1d0ad904c4533ec23052cc2cdb3978d56fcb7b05 100644 (file)
@@ -29,6 +29,7 @@
 #include "theory/quantifiers/term_util.h"
 #include "theory/quantifiers_engine.h"
 #include "theory/rewriter.h"
+#include "theory/sep/theory_sep_rewriter.h"
 #include "theory/theory_model.h"
 #include "theory/valuation.h"
 
@@ -64,6 +65,11 @@ TheorySep::~TheorySep() {
   }
 }
 
+std::unique_ptr<TheoryRewriter> TheorySep::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new TheorySepRewriter());
+}
+
 void TheorySep::setMasterEqualityEngine(eq::EqualityEngine* eq) {
   d_equalityEngine.setMasterEqualityEngine(eq);
 }
index ae044f6d7b9413c3a33d7cbd6a577ccd473edfe3..df329488259f1f475daacc0d9edab71a6eebc452 100644 (file)
@@ -66,6 +66,8 @@ class TheorySep : public Theory {
   TheorySep(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo);
   ~TheorySep();
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   void setMasterEqualityEngine(eq::EqualityEngine* eq) override;
 
   std::string identify() const override { return std::string("TheorySep"); }
index 3b0427ec5bee0f52572f65725a47b22d3cfa7cf5..0b9e6d934238b1e76a0150527ebdee90e0108ace 100644 (file)
  **/
 
 #include "theory/sets/theory_sets.h"
+
 #include "options/sets_options.h"
 #include "theory/sets/theory_sets_private.h"
+#include "theory/sets/theory_sets_rewriter.h"
 #include "theory/theory_model.h"
 
 using namespace CVC4::kind;
@@ -44,6 +46,11 @@ TheorySets::~TheorySets()
   // Do not move me to the header. See explanation in the constructor.
 }
 
+std::unique_ptr<TheoryRewriter> TheorySets::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new TheorySetsRewriter());
+}
+
 void TheorySets::finishInit()
 {
   TheoryModel* tm = d_valuation.getModel();
index ed2459b32dcd885f3de4d987235f90c67b081780..a55a226002fdc244d30d6d7ae8bfbe6e86744712 100644 (file)
@@ -42,6 +42,8 @@ class TheorySets : public Theory
              const LogicInfo& logicInfo);
   ~TheorySets() override;
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   /** finish initialization */
   void finishInit() override;
   void addSharedTerm(TNode) override;
index a81c96318d103bd7b238aceec0754266d082848a..f9eeb2010415ff3f8d6e0d613d5ab6b9bb265133 100644 (file)
@@ -26,6 +26,7 @@
 #include "smt/smt_statistics_registry.h"
 #include "theory/ext_theory.h"
 #include "theory/rewriter.h"
+#include "theory/strings/sequences_rewriter.h"
 #include "theory/strings/theory_strings_utils.h"
 #include "theory/strings/type_enumerator.h"
 #include "theory/strings/word.h"
@@ -129,6 +130,11 @@ TheoryStrings::~TheoryStrings() {
 
 }
 
+std::unique_ptr<TheoryRewriter> TheoryStrings::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new SequencesRewriter());
+}
+
 bool TheoryStrings::areCareDisequal( TNode x, TNode y ) {
   Assert(d_equalityEngine.hasTerm(x));
   Assert(d_equalityEngine.hasTerm(y));
index 76c8f0469af892fcb100ddc7fbaa42a90f747f1d..0e95628bccba7b4b853a17a487357c5b9e663f4a 100644 (file)
@@ -109,6 +109,8 @@ class TheoryStrings : public Theory {
                 const LogicInfo& logicInfo);
   ~TheoryStrings();
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   void setMasterEqualityEngine(eq::EqualityEngine* eq) override;
 
   std::string identify() const override { return std::string("TheoryStrings"); }
index d6b02e070de07ccfa1b1ba294730fb444d206f52..63ca46b418cfe7a8b807ed5db333aace067a233e 100644 (file)
@@ -42,6 +42,7 @@
 #include "theory/logic_info.h"
 #include "theory/output_channel.h"
 #include "theory/theory_id.h"
+#include "theory/theory_rewriter.h"
 #include "theory/valuation.h"
 #include "util/statistics_registry.h"
 
@@ -316,6 +317,11 @@ public:
    */
   virtual ~Theory();
 
+  /**
+   * Creates a new theory rewriter for the theory.
+   */
+  virtual std::unique_ptr<TheoryRewriter> mkTheoryRewriter() = 0;
+
   /**
    * Subclasses of Theory may add additional efforts.  DO NOT CHECK
    * equality with one of these values (e.g. if STANDARD xxx) but
index e665f6115af40f1f85c61461a7af6cfbf2dd1d08..2c27c60545fde0cfce400547b9d868d93b8e33ad 100644 (file)
@@ -266,7 +266,6 @@ void TheoryEngine::EngineOutputChannel::conflict(TNode conflictNode,
 }
 
 void TheoryEngine::finishInit() {
-
   //initialize the quantifiers engine, master equality engine, model, model builder
   if( d_logicInfo.isQuantified() ) {
     // initialize the quantifiers engine
index 840d42417e6cced4e5f6b5d132fb424ace46b003..dec654e76adf6ff69be1e609d7074f1451e285ae 100644 (file)
@@ -494,6 +494,8 @@ class TheoryEngine {
                                               *d_theoryOut[theoryId],
                                               theory::Valuation(this),
                                               d_logicInfo);
+    theory::Rewriter::registerTheoryRewriter(
+        theoryId, d_theoryTable[theoryId]->mkTheoryRewriter());
   }
 
   void setPropEngine(prop::PropEngine* propEngine)
index 3b42fa6a1d4084f3f71ff6d874b1baa8fd92f242..1ea5449b700bec0dc86cc6e275232a2a533cc65d 100644 (file)
@@ -66,6 +66,11 @@ TheoryUF::TheoryUF(context::Context* c,
 TheoryUF::~TheoryUF() {
 }
 
+std::unique_ptr<TheoryRewriter> TheoryUF::mkTheoryRewriter()
+{
+  return std::unique_ptr<TheoryRewriter>(new TheoryUfRewriter());
+}
+
 void TheoryUF::setMasterEqualityEngine(eq::EqualityEngine* eq) {
   d_equalityEngine.setMasterEqualityEngine(eq);
 }
index 93a709fe59bd00e5fd4456d127d5900483330342..623c5c64bd733aebcf0eb78de5e87518cffa04d6 100644 (file)
@@ -188,6 +188,8 @@ private:
 
   ~TheoryUF();
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override;
+
   void setMasterEqualityEngine(eq::EqualityEngine* eq) override;
   void finishInit() override;
 
index 4037c7191fe8ae81e8e7adb6ae642edfba9db5c2..bd21ed69c1e52cfdc1347b1d7c3bc65d8ba6f451 100644 (file)
@@ -176,6 +176,7 @@ class TheoryBVGaussWhite : public CxxTest::TestSuite
     d_nm = NodeManager::fromExprManager(d_em);
     d_smt = new SmtEngine(d_em);
     d_scope = new SmtScope(d_smt);
+    d_smt->finalOptionsAreSet();
 
     d_zero = bv::utils::mkZero(16);
 
@@ -2373,7 +2374,7 @@ class TheoryBVGaussWhite : public CxxTest::TestSuite
 
     AssertionPipeline apipe;
     apipe.push_back(a);
-    passes::BVGauss bgauss(nullptr);
+    passes::BVGauss bgauss(nullptr, "bv-gauss-unit");
     std::unordered_map<Node, Node, NodeHashFunction> res;
     PreprocessingPassResult pres = bgauss.applyInternal(&apipe);
     TS_ASSERT (pres == PreprocessingPassResult::NO_CONFLICT);
@@ -2457,7 +2458,7 @@ class TheoryBVGaussWhite : public CxxTest::TestSuite
     apipe.push_back(a);
     apipe.push_back(eq4);
     apipe.push_back(eq5);
-    passes::BVGauss bgauss(nullptr);
+    passes::BVGauss bgauss(nullptr, "bv-gauss-unit");
     std::unordered_map<Node, Node, NodeHashFunction> res;
     PreprocessingPassResult pres = bgauss.applyInternal(&apipe);
     TS_ASSERT (pres == PreprocessingPassResult::NO_CONFLICT);
@@ -2507,7 +2508,7 @@ class TheoryBVGaussWhite : public CxxTest::TestSuite
     AssertionPipeline apipe;
     apipe.push_back(eq1);
     apipe.push_back(eq2);
-    passes::BVGauss bgauss(nullptr);
+    passes::BVGauss bgauss(nullptr, "bv-gauss-unit");
     std::unordered_map<Node, Node, NodeHashFunction> res;
     PreprocessingPassResult pres = bgauss.applyInternal(&apipe);
     TS_ASSERT (pres == PreprocessingPassResult::NO_CONFLICT);
index c02aaaed8c74149faf73381d854f406d10772711..547ce27cf8744431427ec80459eda576459a66f6 100644 (file)
@@ -52,6 +52,7 @@ class TheoryEvaluatorWhite : public CxxTest::TestSuite
     d_nm = NodeManager::fromExprManager(d_em);
     d_smt = new SmtEngine(d_em);
     d_scope = new SmtScope(d_smt);
+    d_smt->finalOptionsAreSet();
   }
 
   void tearDown() override
index 81f5cf34aee4dcbcad9626b37be689d694c04f94..826e14a319157b97668280c3e9f058481c65ae3d 100644 (file)
@@ -45,6 +45,10 @@ class RegexpOperationBlack : public CxxTest::TestSuite
     d_scope = new SmtScope(d_smt);
     d_regExpOpr = new RegExpOpr();
 
+    // Ensure that the SMT engine is fully initialized (required for the
+    // rewriter)
+    d_smt->push();
+
     d_nm = NodeManager::currentNM();
   }
 
index 200a36d0be1ef9e68d5f548af9e537ac3e3a1af7..c823c07049d35116ee01d1d525a587092902b78b 100644 (file)
@@ -45,6 +45,7 @@ class SequencesRewriterWhite : public CxxTest::TestSuite
     d_em = new ExprManager(opts);
     d_smt = new SmtEngine(d_em);
     d_scope = new SmtScope(d_smt);
+    d_smt->finalOptionsAreSet();
     d_rewriter = new ExtendedRewriter(true);
 
     d_nm = NodeManager::currentNM();
index 8ae90c4c37dc091dc59a515a42ce6d0bc31ee15b..72b74a7b90689b23b0add07a7de60e34d8d2dfa9 100644 (file)
@@ -37,19 +37,15 @@ using namespace CVC4::theory;
 using namespace CVC4::smt;
 
 class TheoryBlack : public CxxTest::TestSuite {
-private:
-
-  ExprManager* d_em;
-  SmtEngine* d_smt;
-  NodeManager* d_nm;
-  SmtScope* d_scope;
-
  public:
   void setUp() override
   {
     d_em = new ExprManager();
     d_smt = new SmtEngine(d_em);
     d_scope = new SmtScope(d_smt);
+    // Ensure that the SMT engine is fully initialized (required for the
+    // rewriter)
+    d_smt->push();
 
     d_nm = NodeManager::fromExprManager(d_em);
   }
@@ -152,4 +148,9 @@ private:
 
   }
 
+ private:
+  ExprManager* d_em;
+  SmtEngine* d_smt;
+  NodeManager* d_nm;
+  SmtScope* d_scope;
 };
index bf0ca73b374f1e7dbd9718e9ca5845218a25aa98..b6348339b6f11fb08bf7eda069ef9d0b108899a8 100644 (file)
@@ -43,6 +43,7 @@ class TheoryBvRewriterWhite : public CxxTest::TestSuite
     d_em = new ExprManager(opts);
     d_smt = new SmtEngine(d_em);
     d_scope = new SmtScope(d_smt);
+    d_smt->finalOptionsAreSet();
 
     d_nm = NodeManager::currentNM();
   }
index 5af670d5ee35df5cbd3286b1c3dfc2cf6199dd04..4a019ac088016b7223ca8c1a94c138c322a715b8 100644 (file)
@@ -38,6 +38,7 @@
 #include "theory/rewriter.h"
 #include "theory/theory.h"
 #include "theory/theory_engine.h"
+#include "theory/theory_rewriter.h"
 #include "theory/valuation.h"
 #include "util/integer.h"
 #include "util/proof.h"
@@ -91,118 +92,72 @@ struct RewriteItem {
   bool d_topLevel;
 };/* struct RewriteItem */
 
+class FakeTheoryRewriter : public TheoryRewriter
+{
+ public:
+  RewriteResponse preRewrite(TNode n) override
+  {
+    return RewriteResponse(REWRITE_DONE, n);
+  }
+
+  RewriteResponse postRewrite(TNode n) override
+  {
+    return RewriteResponse(REWRITE_DONE, n);
+  }
+};
+
 /**
- * Fake Theory interface.  Looks like a Theory, but really all it does is note when and
- * how rewriting behavior is requested.
+ * Fake Theory interface.  Looks like a Theory, but really all it does is note
+ * when and how rewriting behavior is requested.
  */
-template<TheoryId theoryId>
-class FakeTheory : public Theory {
+template <TheoryId theoryId>
+class FakeTheory : public Theory
+{
   /**
-   * This fake theory class is equally useful for bool, uf, arith, etc.  It keeps an
-   * identifier to identify itself.
+   * This fake theory class is equally useful for bool, uf, arith, etc.  It
+   * keeps an identifier to identify itself.
    */
   std::string d_id;
 
   /**
-   * The expected sequence of rewrite calls.  Filled by FakeTheory::expect() and consumed
-   * by FakeTheory::preRewrite() and FakeTheory::postRewrite().
+   * The expected sequence of rewrite calls.  Filled by FakeTheory::expect() and
+   * consumed by FakeTheory::preRewrite() and FakeTheory::postRewrite().
    */
   // static std::deque<RewriteItem> s_expected;
 
-public:
-  FakeTheory(context::Context* ctxt, context::UserContext* uctxt, OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo) :
-      Theory(theoryId, ctxt, uctxt, out, valuation, logicInfo)
-  { }
-
-  /** Register an expected rewrite call */
-  static void expect(RewriteType type, FakeTheory* thy, TNode n, bool topLevel)
-      throw()
+ public:
+  FakeTheory(context::Context* ctxt,
+             context::UserContext* uctxt,
+             OutputChannel& out,
+             Valuation valuation,
+             const LogicInfo& logicInfo)
+      : Theory(theoryId, ctxt, uctxt, out, valuation, logicInfo)
   {
-    RewriteItem item = { type, thy, n, topLevel };
-    //s_expected.push_back(item);
   }
 
-  /**
-   * Returns whether the expected queue is empty.  This is done after a call into
-   * the rewriter to ensure that the actual set of observed rewrite calls completed
-   * the sequence of expected rewrite calls.
-   */
-  static bool nothingMoreExpected() throw() {
-    return true; // s_expected.empty();
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter() override
+  {
+    return std::unique_ptr<TheoryRewriter>(new FakeTheoryRewriter());
   }
 
-  /**
-   * Overrides Theory::preRewrite().  This "fake theory" version ensures that
-   * this actual, observed pre-rewrite call matches the next "expected" call set up
-   * by the test.
-   */
-  RewriteResponse preRewrite(TNode n, bool topLevel) {
-//    if(false) { //s_expected.empty()) {
-//      cout << std::endl
-//           << "didn't expect anything more, but got" << std::endl
-//           << "     PRE  " << topLevel << " " << identify() << " " << n
-//           << std::endl;
-//    }
-//    TS_ASSERT(!s_expected.empty());
-//
-//    RewriteItem expected = s_expected.front();
-//    s_expected.pop_front();
-//
-//    if(expected.d_type != PRE ||
-////       expected.d_theory != this ||
-//       expected.d_node != n ||
-//       expected.d_topLevel != topLevel) {
-//      cout << std::endl
-//           << "HAVE PRE  " << topLevel << " " << identify() << " " << n
-//           << std::endl
-//           << "WANT " << (expected.d_type == PRE ? "PRE  " : "POST ")
-//  //         << expected.d_topLevel << " " << expected.d_theory->identify()
-//           << " " << expected.d_node << std::endl << std::endl;
-//    }
-//
-//    TS_ASSERT_EQUALS(expected.d_type, PRE);
-////    TS_ASSERT_EQUALS(expected.d_theory, this);
-//    TS_ASSERT_EQUALS(expected.d_node, n);
-//    TS_ASSERT_EQUALS(expected.d_topLevel, topLevel);
-
-    return RewriteResponse(REWRITE_DONE, n);
+  /** Register an expected rewrite call */
+  static void expect(RewriteType type,
+                     FakeTheory* thy,
+                     TNode n,
+                     bool topLevel) throw()
+  {
+    RewriteItem item = {type, thy, n, topLevel};
+    // s_expected.push_back(item);
   }
 
   /**
-   * Overrides Theory::postRewrite().  This "fake theory" version ensures that
-   * this actual, observed post-rewrite call matches the next "expected" call set up
-   * by the test.
+   * Returns whether the expected queue is empty.  This is done after a call
+   * into the rewriter to ensure that the actual set of observed rewrite calls
+   * completed the sequence of expected rewrite calls.
    */
-  RewriteResponse postRewrite(TNode n, bool topLevel) {
-//    if(s_expected.empty()) {
-//      cout << std::endl
-//           << "didn't expect anything more, but got" << std::endl
-//           << "     POST " << topLevel << " " << identify() << " " << n
-//           << std::endl;
-//    }
-//    TS_ASSERT(!s_expected.empty());
-//
-//    RewriteItem expected = s_expected.front();
-//    s_expected.pop_front();
-//
-//    if(expected.d_type != POST ||
-////       expected.d_theory != this ||
-//       expected.d_node != n ||
-//       expected.d_topLevel != topLevel) {
-//      cout << std::endl
-//           << "HAVE POST " << topLevel << " " << identify() << " " << n
-//           << std::endl
-//           << "WANT " << (expected.d_type == PRE ? "PRE  " : "POST ")
-////           << expected.d_topLevel << " " << expected.d_theory->identify()
-//           << " " << expected.d_node << std::endl << std::endl;
-//    }
-//
-//    TS_ASSERT_EQUALS(expected.d_type, POST);
-//    TS_ASSERT_EQUALS(expected.d_theory, this);
-//    TS_ASSERT_EQUALS(expected.d_node, n);
-//    TS_ASSERT_EQUALS(expected.d_topLevel, topLevel);
-
-    return RewriteResponse(REWRITE_DONE, n);
+  static bool nothingMoreExpected() throw()
+  {
+    return true;  // s_expected.empty();
   }
 
   std::string identify() const override {
@@ -221,8 +176,7 @@ public:
     return Node::null();
   }
   Node getValue(TNode n) { return Node::null(); }
-};/* class FakeTheory */
-
+}; /* class FakeTheory */
 
 /* definition of the s_expected static field in FakeTheory; see above */
 // std::deque<RewriteItem> FakeTheory::s_expected;
index 0fa7a3f825a240361e80f652a5062b90b20e2654..7c37b1a853d298a669fe0cc4c137bfc9d1975220 100644 (file)
@@ -65,6 +65,7 @@ void BvInstantiatorWhite::setUp()
   d_nm = NodeManager::fromExprManager(d_em);
   d_smt = new SmtEngine(d_em);
   d_scope = new SmtScope(d_smt);
+  d_smt->finalOptionsAreSet();
 }
 
 void BvInstantiatorWhite::tearDown()
index 3b5016fad2aab346f9bc9fd5cdb003b7f8dc7d3b..0ece5a056a2799be5c3f7e489118f2d5d62c36b4 100644 (file)
 
 #include <cxxtest/TestSuite.h>
 
+#include "smt/smt_engine.h"
+#include "smt/smt_engine_scope.h"
 #include "theory/sets/theory_sets_type_enumerator.h"
 
 using namespace CVC4;
+using namespace CVC4::smt;
 using namespace CVC4::theory;
 using namespace CVC4::kind;
 using namespace CVC4::theory::sets;
@@ -28,21 +31,20 @@ using namespace std;
 
 class SetEnumeratorWhite : public CxxTest::TestSuite
 {
-  ExprManager* d_em;
-  NodeManager* d_nm;
-  NodeManagerScope* d_scope;
-
  public:
   void setUp() override
   {
     d_em = new ExprManager();
+    d_smt = new SmtEngine(d_em);
     d_nm = NodeManager::fromExprManager(d_em);
-    d_scope = new NodeManagerScope(d_nm);
+    d_scope = new SmtScope(d_smt);
+    d_smt->finalOptionsAreSet();
   }
 
   void tearDown() override
   {
     delete d_scope;
+    delete d_smt;
     delete d_em;
   }
 
@@ -68,8 +70,9 @@ class SetEnumeratorWhite : public CxxTest::TestSuite
     TS_ASSERT_EQUALS(expected2, actual2);
     TS_ASSERT(!setEnumerator.isFinished());
 
-    Node actual3 = *++setEnumerator;
-    Node expected3 = d_nm->mkNode(Kind::UNION, expected1, expected2);
+    Node actual3 = Rewriter::rewrite(*++setEnumerator);
+    Node expected3 =
+        Rewriter::rewrite(d_nm->mkNode(Kind::UNION, expected1, expected2));
     TS_ASSERT_EQUALS(expected3, actual3);
     TS_ASSERT(!setEnumerator.isFinished());
 
@@ -301,4 +304,9 @@ class SetEnumeratorWhite : public CxxTest::TestSuite
     TS_ASSERT(setEnumerator.isFinished());
   }
 
+ private:
+  ExprManager* d_em;
+  SmtEngine* d_smt;
+  NodeManager* d_nm;
+  SmtScope* d_scope;
 }; /* class SetEnumeratorWhite */
index e1b84492c1e94e0e002e438fb65ed68fcf5239f2..8f41153f3987d053790a2dfd126b9c658c717ba1 100644 (file)
 
 #include <memory>
 
+#include "expr/expr_manager.h"
 #include "expr/node.h"
 #include "expr/node_manager.h"
+#include "smt/smt_engine.h"
+#include "smt/smt_engine_scope.h"
 #include "theory/strings/skolem_cache.h"
 #include "util/rational.h"
 #include "util/string.h"
 
 using namespace CVC4;
+using namespace CVC4::smt;
 using namespace CVC4::theory::strings;
 
 class TheoryStringsSkolemCacheBlack : public CxxTest::TestSuite
@@ -30,8 +34,14 @@ class TheoryStringsSkolemCacheBlack : public CxxTest::TestSuite
  public:
   void setUp() override
   {
-    d_nm.reset(new NodeManager(nullptr));
-    d_scope.reset(new NodeManagerScope(d_nm.get()));
+    d_em.reset(new ExprManager());
+    d_smt.reset(new SmtEngine(d_em.get()));
+    d_scope.reset(new SmtScope(d_smt.get()));
+    // Ensure that the SMT engine is fully initialized (required for the
+    // rewriter)
+    d_smt->push();
+
+    d_nm = NodeManager::fromExprManager(d_em.get());
   }
 
   void tearDown() override {}
@@ -87,6 +97,8 @@ class TheoryStringsSkolemCacheBlack : public CxxTest::TestSuite
   }
 
  private:
-  std::unique_ptr<NodeManager> d_nm;
-  std::unique_ptr<NodeManagerScope> d_scope;
+  std::unique_ptr<ExprManager> d_em;
+  std::unique_ptr<SmtEngine> d_smt;
+  NodeManager* d_nm;
+  std::unique_ptr<SmtScope> d_scope;
 };
index 0dd52be8c61cd86b2bb9530d4c52787f0903814c..eb43e00cb3a9b09a7dd5a2f7cb8a029e8b1d709b 100644 (file)
@@ -93,7 +93,7 @@ class TestOutputChannel : public OutputChannel {
 };
 
 class DummyTheory : public Theory {
-public:
+ public:
   set<Node> d_registered;
   vector<Node> d_getSequence;
 
@@ -102,6 +102,11 @@ public:
       : Theory(theory::THEORY_BUILTIN, ctxt, uctxt, out, valuation, logicInfo)
   {}
 
+  std::unique_ptr<TheoryRewriter> mkTheoryRewriter()
+  {
+    return std::unique_ptr<TheoryRewriter>();
+  }
+
   void registerTerm(TNode n) {
     // check that we registerTerm() a term only once
     TS_ASSERT(d_registered.find(n) == d_registered.end());
index da915b7ee87a1826cae8783130e820c0c69b76c9..58dadd27aa0d1b4b3831f0889d2ef84c59c33425 100644 (file)
 #include "expr/node_manager.h"
 #include "expr/type_node.h"
 #include "options/language.h"
+#include "smt/smt_engine.h"
+#include "smt/smt_engine_scope.h"
 #include "theory/type_enumerator.h"
 
 using namespace CVC4;
+using namespace CVC4::smt;
 using namespace CVC4::theory;
 using namespace CVC4::kind;
 
 using namespace std;
 
 class TypeEnumeratorWhite : public CxxTest::TestSuite {
-  ExprManager* d_em;
-  NodeManager* d_nm;
-  NodeManagerScope* d_scope;
-
  public:
   void setUp() override
   {
     d_em = new ExprManager();
+    d_smt = new SmtEngine(d_em);
     d_nm = NodeManager::fromExprManager(d_em);
-    d_scope = new NodeManagerScope(d_nm);
+    d_scope = new SmtScope(d_smt);
+    d_smt->finalOptionsAreSet();
   }
 
   void tearDown() override
   {
     delete d_scope;
+    delete d_smt;
     delete d_em;
   }
 
@@ -272,4 +274,9 @@ class TypeEnumeratorWhite : public CxxTest::TestSuite {
     TS_ASSERT_THROWS(*++te, NoMoreValuesException&);
   }
 
+ private:
+  ExprManager* d_em;
+  SmtEngine* d_smt;
+  NodeManager* d_nm;
+  SmtScope* d_scope;
 };/* class TypeEnumeratorWhite */