RemoveTermFormulas: Remove ContainsTermITEVisitor (#1782)
authorAndres Noetzli <andres.noetzli@gmail.com>
Mon, 16 Apr 2018 16:42:34 +0000 (09:42 -0700)
committerAndrew Reynolds <andrew.j.reynolds@gmail.com>
Mon, 16 Apr 2018 16:42:34 +0000 (11:42 -0500)
src/smt/term_formula_removal.cpp
src/smt/term_formula_removal.h
src/theory/ite_utilities.cpp
src/theory/ite_utilities.h
src/theory/theory_engine.cpp

index fc10d2b4bb078aa29e6a179bd1634607c658b7e2..ad01848cc4e375d19038a321cdb4e2140cf2d985 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "options/proof_options.h"
 #include "proof/proof_manager.h"
-#include "theory/ite_utilities.h"
 
 using namespace std;
 
@@ -28,20 +27,9 @@ namespace CVC4 {
 RemoveTermFormulas::RemoveTermFormulas(context::UserContext* u)
     : d_tfCache(u), d_skolem_cache(u)
 {
-  d_containsVisitor = new theory::ContainsTermITEVisitor();
 }
 
-RemoveTermFormulas::~RemoveTermFormulas(){
-  delete d_containsVisitor;
-}
-
-void RemoveTermFormulas::garbageCollect(){
-  d_containsVisitor->garbageCollect();
-}
-
-theory::ContainsTermITEVisitor* RemoveTermFormulas::getContainsVisitor() {
-  return d_containsVisitor;
-}
+RemoveTermFormulas::~RemoveTermFormulas() {}
 
 void RemoveTermFormulas::run(std::vector<Node>& output, IteSkolemMap& iteSkolemMap, bool reportDeps)
 {
@@ -65,10 +53,6 @@ void RemoveTermFormulas::run(std::vector<Node>& output, IteSkolemMap& iteSkolemM
   }
 }
 
-bool RemoveTermFormulas::containsTermITE(TNode e) const {
-  return d_containsVisitor->containsTermITE(e);
-}
-
 Node RemoveTermFormulas::run(TNode node, std::vector<Node>& output,
                     IteSkolemMap& iteSkolemMap, bool inQuant, bool inTerm) {
   // Current node
index 63a74a33250f78939c6220023ef487ceeb2cef10..49f2e815fb9e748b3d7748c187db125f378b646c 100644 (file)
 
 namespace CVC4 {
 
-namespace theory {
-  class ContainsTermITEVisitor;
-}/* CVC4::theory namespace */
-
 typedef std::unordered_map<Node, unsigned, NodeHashFunction> IteSkolemMap;
 
 class RemoveTermFormulas {
@@ -151,13 +147,6 @@ public:
 
   /** Garbage collects non-context dependent data-structures. */
   void garbageCollect();
-
-  /** Return the RemoveTermFormulas's containsVisitor. */
-  theory::ContainsTermITEVisitor* getContainsVisitor();
-
-private:
-  theory::ContainsTermITEVisitor* d_containsVisitor;
-
 };/* class RemoveTTE */
 
 }/* CVC4 namespace */
index 6d81dbab0afa5e5367566328be5958ad99df5252..cf273a88adf11aedaf4aa16fa3455b95d71e4bf9 100644 (file)
@@ -79,11 +79,11 @@ struct CTIVStackElement {
 
 } /* CVC4::theory::ite */
 
-ITEUtilities::ITEUtilities(ContainsTermITEVisitor* containsVisitor)
-  : d_containsVisitor(containsVisitor)
-  , d_compressor(NULL)
-  , d_simplifier(NULL)
-  , d_careSimp(NULL)
+ITEUtilities::ITEUtilities()
+    : d_containsVisitor(new ContainsTermITEVisitor()),
+      d_compressor(NULL),
+      d_simplifier(NULL),
+      d_careSimp(NULL)
 {
   Assert(d_containsVisitor != NULL);
 }
@@ -103,7 +103,7 @@ ITEUtilities::~ITEUtilities(){
 
 Node ITEUtilities::simpITE(TNode assertion){
   if(d_simplifier == NULL){
-    d_simplifier = new ITESimplifier(d_containsVisitor);
+    d_simplifier = new ITESimplifier(d_containsVisitor.get());
   }
   return d_simplifier->simpITE(assertion);
 }
@@ -119,7 +119,7 @@ bool ITEUtilities::simpIteDidALotOfWorkHeuristic() const{
 /* returns false if an assertion is discovered to be equal to false. */
 bool ITEUtilities::compress(std::vector<Node>& assertions){
   if(d_compressor == NULL){
-     d_compressor = new ITECompressor(d_containsVisitor);
+    d_compressor = new ITECompressor(d_containsVisitor.get());
   }
   return d_compressor->compress(assertions);
 }
@@ -141,6 +141,7 @@ void ITEUtilities::clear(){
   if(d_careSimp != NULL){
     d_careSimp->clear();
   }
+  d_containsVisitor->garbageCollect();
 }
 
 /*********************                                                        */
index 096393de20de16bfc81fe2087fb237f5a72cad2f..7fb3eae41cb60bb226687a842b7bb86b5e2c7d7d 100644 (file)
 namespace CVC4 {
 namespace theory {
 
-class ContainsTermITEVisitor;
 class IncomingArcCounter;
 class TermITEHeightCounter;
 class ITECompressor;
 class ITESimplifier;
 class ITECareSimplifier;
 
-class ITEUtilities {
-public:
-  ITEUtilities(ContainsTermITEVisitor* containsVisitor);
-  ~ITEUtilities();
-
-  Node simpITE(TNode assertion);
-
-  bool simpIteDidALotOfWorkHeuristic() const;
-
-  /* returns false if an assertion is discovered to be equal to false. */
-  bool compress(std::vector<Node>& assertions);
-
-  Node simplifyWithCare(TNode e);
-
-  void clear();
-
-private:
-  ContainsTermITEVisitor* d_containsVisitor;
-  ITECompressor* d_compressor;
-  ITESimplifier* d_simplifier;
-  ITECareSimplifier* d_careSimp;
-};
-
 /**
  * A caching visitor that computes whether a node contains a term ite.
  */
@@ -84,6 +60,40 @@ private:
   NodeBoolMap d_cache;
 };
 
+class ITEUtilities
+{
+ public:
+  ITEUtilities();
+  ~ITEUtilities();
+
+  Node simpITE(TNode assertion);
+
+  bool simpIteDidALotOfWorkHeuristic() const;
+
+  /* returns false if an assertion is discovered to be equal to false. */
+  bool compress(std::vector<Node>& assertions);
+
+  Node simplifyWithCare(TNode e);
+
+  void clear();
+
+  ContainsTermITEVisitor* getContainsVisitor()
+  {
+    return d_containsVisitor.get();
+  }
+
+  bool containsTermITE(TNode n)
+  {
+    return d_containsVisitor->containsTermITE(n);
+  }
+
+ private:
+  std::unique_ptr<ContainsTermITEVisitor> d_containsVisitor;
+  ITECompressor* d_compressor;
+  ITESimplifier* d_simplifier;
+  ITECareSimplifier* d_careSimp;
+};
+
 class IncomingArcCounter {
 public:
   IncomingArcCounter(bool skipVars = false, bool skipConstants = false);
index 38885db853af68bd01c45b3a186147c762d8d8f8..850c7ed97da6130938d237faaf4d3315fab94947 100644 (file)
@@ -334,7 +334,7 @@ TheoryEngine::TheoryEngine(context::Context* context,
   ProofManager::currentPM()->initTheoryProofEngine();
 #endif
 
-  d_iteUtilities = new ITEUtilities(d_tform_remover.getContainsVisitor());
+  d_iteUtilities = new ITEUtilities();
 
   smtStatisticsRegistry()->registerStat(&d_arithSubstitutionsAdded);
 }
@@ -2010,7 +2010,8 @@ void TheoryEngine::mkAckermanizationAssertions(std::vector<Node>& assertions) {
 
 Node TheoryEngine::ppSimpITE(TNode assertion)
 {
-  if (!d_tform_remover.containsTermITE(assertion)) {
+  if (!d_iteUtilities->containsTermITE(assertion))
+  {
     return assertion;
   } else {
     Node result = d_iteUtilities->simpITE(assertion);
@@ -2051,7 +2052,6 @@ bool TheoryEngine::donePPSimpITE(std::vector<Node>& assertions){
         Chat() << "....node manager contains " << nm->poolSize() << " nodes before cleanup" << endl;
         d_iteUtilities->clear();
         Rewriter::clearCaches();
-        d_tform_remover.garbageCollect();
         nm->reclaimZombiesUntil(options::zombieHuntThreshold());
         Chat() << "....node manager contains " << nm->poolSize() << " nodes after cleanup" << endl;
       }
@@ -2062,7 +2062,8 @@ bool TheoryEngine::donePPSimpITE(std::vector<Node>& assertions){
   if(d_logicInfo.isTheoryEnabled(theory::THEORY_ARITH)
      && !options::incrementalSolving() ){
     if(!simpDidALotOfWork){
-      ContainsTermITEVisitor& contains = *d_tform_remover.getContainsVisitor();
+      ContainsTermITEVisitor& contains =
+          *(d_iteUtilities->getContainsVisitor());
       arith::ArithIteUtils aiteu(contains, d_userContext, getModel());
       bool anyItes = false;
       for(size_t i = 0;  i < assertions.size(); ++i){