adding cache for preprocessing datatypes terms to fix bug 475, fix for handling user...
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Tue, 11 Dec 2012 20:47:08 +0000 (14:47 -0600)
committerAndrew Reynolds <andrew.j.reynolds@gmail.com>
Tue, 11 Dec 2012 20:47:08 +0000 (14:47 -0600)
src/theory/datatypes/theory_datatypes.cpp
src/theory/datatypes/theory_datatypes.h
src/theory/quantifiers/quantifiers_attributes.cpp
src/theory/quantifiers/quantifiers_attributes.h
src/theory/quantifiers/theory_quantifiers.cpp
src/theory/quantifiers/theory_quantifiers.h

index e23d9deae6e3d029f31d180fc87a0ccd90d35aa4..9da83ce41563e3b4498ccd1c2de5d96760d8dade 100644 (file)
@@ -45,7 +45,8 @@ TheoryDatatypes::TheoryDatatypes(Context* c, UserContext* u, OutputChannel& out,
   d_equalityEngine(d_notify, c, "theory::datatypes::TheoryDatatypes"),
   d_selector_apps( c ),
   d_labels( c ),
-  d_conflict( c, false ){
+  d_conflict( c, false ),
+  d_collectTermsCache( c ){
 
   // The kinds we are treating as function application in congruence
   d_equalityEngine.addFunctionKind(kind::APPLY_CONSTRUCTOR);
@@ -758,31 +759,34 @@ void TheoryDatatypes::collectModelInfo( TheoryModel* m, bool fullModel ){
 
 
 void TheoryDatatypes::collectTerms( Node n ) {
-  for( int i=0; i<(int)n.getNumChildren(); i++ ) {
-    collectTerms( n[i] );
-  }
-  if( n.getKind() == APPLY_CONSTRUCTOR ){
-    //we must take into account subterm relation when checking for cycles
+  if( d_collectTermsCache.find( n )==d_collectTermsCache.end() ){
+    d_collectTermsCache[n] = true;
     for( int i=0; i<(int)n.getNumChildren(); i++ ) {
-      Debug("datatypes-cycles") << "DtCyc: Subterm " << n << " -> " << n[i] << endl;
-      bool result = d_cycle_check.addEdgeNode( n, n[i] );
-      d_hasSeenCycle.set( d_hasSeenCycle.get() || result );
+      collectTerms( n[i] );
     }
-  }else if( n.getKind() == APPLY_SELECTOR ){
-    if( d_selector_apps.find( n )==d_selector_apps.end() ){
-      d_selector_apps[n] = false;
-      //we must also record which selectors exist
-      Debug("datatypes") << "  Found selector " << n << endl;
-      if (n.getType().isBoolean()) {
-        d_equalityEngine.addTriggerPredicate( n );
-      }else{
-        d_equalityEngine.addTerm( n );
+    if( n.getKind() == APPLY_CONSTRUCTOR ){
+      //we must take into account subterm relation when checking for cycles
+      for( int i=0; i<(int)n.getNumChildren(); i++ ) {
+        Debug("datatypes-cycles") << "DtCyc: Subterm " << n << " -> " << n[i] << endl;
+        bool result = d_cycle_check.addEdgeNode( n, n[i] );
+        d_hasSeenCycle.set( d_hasSeenCycle.get() || result );
       }
-      Node rep = getRepresentative( n[0] );
-      EqcInfo* eqc = getOrMakeEqcInfo( rep, true );
-      if( !eqc->d_selectors ){
-        eqc->d_selectors = true;
-        instantiate( eqc, rep );
+    }else if( n.getKind() == APPLY_SELECTOR ){
+      if( d_selector_apps.find( n )==d_selector_apps.end() ){
+        d_selector_apps[n] = false;
+        //we must also record which selectors exist
+        Debug("datatypes") << "  Found selector " << n << endl;
+        if (n.getType().isBoolean()) {
+          d_equalityEngine.addTriggerPredicate( n );
+        }else{
+          d_equalityEngine.addTerm( n );
+        }
+        Node rep = getRepresentative( n[0] );
+        EqcInfo* eqc = getOrMakeEqcInfo( rep, true );
+        if( !eqc->d_selectors ){
+          eqc->d_selectors = true;
+          instantiate( eqc, rep );
+        }
       }
     }
   }
index 90d82e25570bb92a603225186db7c32f0c9c6778..9846e80f23933833ea24ef4faa850c678de469e9 100644 (file)
@@ -156,6 +156,8 @@ private:
   context::CDO<bool> d_conflict;
   /** The conflict node */
   Node d_conflictNode;
+  /** cache for which terms we have called collectTerms(...) on */
+  BoolMap d_collectTermsCache;
   /** pending assertions/merges */
   std::vector< Node > d_pending;
   std::map< Node, Node > d_pending_exp;
index 493a49e54511c8a192f2ca8de33c9f77473bf804..2f6dc47dbb4e6966e1108dafeb9007266d3aa832 100644 (file)
@@ -22,7 +22,7 @@ using namespace CVC4::context;
 using namespace CVC4::theory;\r
 using namespace CVC4::theory::quantifiers;\r
 \r
-void QuantifiersAttributes::setUserAttribute( std::string& attr, Node n ){\r
+void QuantifiersAttributes::setUserAttribute( const std::string& attr, Node n ){\r
   if( n.getKind()==FORALL ){\r
     if( attr=="axiom" ){\r
       Trace("quant-attr") << "Set axiom " << n << std::endl;\r
index 822d6c59f8aacb8dc944f4980696c1d364efab5e..88bac8bc94f5f5f45cbb06eb0679e272f96d4706 100644 (file)
@@ -40,7 +40,7 @@ struct QuantifiersAttributes
     *   This function will apply a custom set of attributes to all top-level universal\r
     *   quantifiers contained in n\r
     */\r
-  static void setUserAttribute( std::string& attr, Node n );\r
+  static void setUserAttribute( const std::string& attr, Node n );\r
 };\r
 \r
 \r
index cfdb30f38c9321535099fe743e5b76c9d574ace1..b1a7c99270fff2a26820c4410e068c42ca737c08 100644 (file)
@@ -192,6 +192,6 @@ bool TheoryQuantifiers::restart(){
   }
 }
 
-void TheoryQuantifiers::setUserAttribute( std::string& attr, Node n ){
+void TheoryQuantifiers::setUserAttribute( const std::string& attr, Node n ){
   QuantifiersAttributes::setUserAttribute( attr, n );
 }
index c3987144c325500048485f67e2f693094e1ef6f8..b4c8966c70b8633668ad49293900a99e32d635fc 100644 (file)
@@ -70,7 +70,7 @@ public:
   void shutdown() { }
   std::string identify() const { return std::string("TheoryQuantifiers"); }
   bool flipDecision();
-  void setUserAttribute( std::string& attr, Node n );
+  void setUserAttribute( const std::string& attr, Node n );
   eq::EqualityEngine* getMasterEqualityEngine() { return d_masterEqualityEngine; }
 private:
   void assertUniversal( Node n );