Minor refactor for theory of sets (#3924)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Fri, 6 Mar 2020 23:01:45 +0000 (17:01 -0600)
committerGitHub <noreply@github.com>
Fri, 6 Mar 2020 23:01:45 +0000 (17:01 -0600)
Flattens a block of code and refactors the main check loop, will make it easier to incorporate new extensions.

It also avoids a needless call to check() for Relations when there are no relations constraints.

src/theory/sets/theory_sets_private.cpp

index 866c80863e675d21955ed948bec7c58bcc8f80b2..b949be76c0cec495fc8e45a971966aaf372a3fef 100644 (file)
@@ -373,6 +373,8 @@ void TheorySetsPrivate::fullEffortCheck()
   Trace("sets") << "----- Full effort check ------" << std::endl;
   do
   {
+    Assert(!d_im.hasPendingLemmas() || d_im.hasProcessed());
+
     Trace("sets") << "...iterate full effort check..." << std::endl;
     fullEffortReset();
 
@@ -476,71 +478,88 @@ void TheorySetsPrivate::fullEffortCheck()
 
     // We may have sent lemmas while registering the terms in the loop above,
     // e.g. the cardinality solver.
-    if (!d_im.hasProcessed())
+    if (d_im.hasProcessed())
     {
-      if (Trace.isOn("sets-mem"))
+      continue;
+    }
+    if (Trace.isOn("sets-mem"))
+    {
+      const std::vector<Node>& sec = d_state.getSetsEqClasses();
+      for (const Node& s : sec)
       {
-        const std::vector<Node>& sec = d_state.getSetsEqClasses();
-        for (const Node& s : sec)
+        Trace("sets-mem") << "Eqc " << s << " : ";
+        const std::map<Node, Node>& smem = d_state.getMembers(s);
+        if (!smem.empty())
         {
-          Trace("sets-mem") << "Eqc " << s << " : ";
-          const std::map<Node, Node>& smem = d_state.getMembers(s);
-          if (!smem.empty())
-          {
-            Trace("sets-mem") << "Memberships : ";
-            for (const std::pair<const Node, Node>& it2 : smem)
-            {
-              Trace("sets-mem") << it2.first << " ";
-            }
-          }
-          Node ss = d_state.getSingletonEqClass(s);
-          if (!ss.isNull())
+          Trace("sets-mem") << "Memberships : ";
+          for (const std::pair<const Node, Node>& it2 : smem)
           {
-            Trace("sets-mem") << " : Singleton : " << ss;
+            Trace("sets-mem") << it2.first << " ";
           }
-          Trace("sets-mem") << std::endl;
         }
-      }
-      checkSubtypes();
-      d_im.flushPendingLemmas(true);
-      if (!d_im.hasProcessed())
-      {
-        checkDownwardsClosure();
-        if (options::setsInferAsLemmas())
+        Node ss = d_state.getSingletonEqClass(s);
+        if (!ss.isNull())
         {
-          d_im.flushPendingLemmas();
-        }
-        if (!d_im.hasProcessed())
-        {
-          checkUpwardsClosure();
-          d_im.flushPendingLemmas();
-          if (!d_im.hasProcessed())
-          {
-            checkDisequalities();
-            d_im.flushPendingLemmas();
-            if (!d_im.hasProcessed())
-            {
-              checkReduceComprehensions();
-              d_im.flushPendingLemmas();
-
-              if (!d_im.hasProcessed() && d_card_enabled)
-              {
-                // call the check method of the cardinality solver
-                d_cardSolver->check();
-              }
-            }
-          }
+          Trace("sets-mem") << " : Singleton : " << ss;
         }
+        Trace("sets-mem") << std::endl;
+      }
+    }
+    // check subtypes
+    checkSubtypes();
+    d_im.flushPendingLemmas(true);
+    if (d_im.hasProcessed())
+    {
+      continue;
+    }
+    // check downwards closure
+    checkDownwardsClosure();
+    if (options::setsInferAsLemmas())
+    {
+      d_im.flushPendingLemmas();
+    }
+    if (d_im.hasProcessed())
+    {
+      continue;
+    }
+    // check upwards closure
+    checkUpwardsClosure();
+    d_im.flushPendingLemmas();
+    if (d_im.hasProcessed())
+    {
+      continue;
+    }
+    // check disequalities
+    checkDisequalities();
+    d_im.flushPendingLemmas();
+    if (d_im.hasProcessed())
+    {
+      continue;
+    }
+    // check reduce comprehensions
+    checkReduceComprehensions();
+    d_im.flushPendingLemmas();
+    if (d_im.hasProcessed())
+    {
+      continue;
+    }
+    if (d_card_enabled)
+    {
+      // call the check method of the cardinality solver
+      d_cardSolver->check();
+      if (d_im.hasProcessed())
+      {
+        continue;
       }
     }
-    if (!d_im.hasProcessed())
+    if (d_rels_enabled)
     {
-      // invoke relations solver
+      // call the check method of the relations solver
       d_rels->check(Theory::EFFORT_FULL);
     }
-    Assert(!d_im.hasPendingLemmas() || d_im.hasProcessed());
   } while (!d_im.hasSentLemma() && !d_state.isInConflict()
            && d_im.hasAddedFact());
+  Assert(!d_im.hasPendingLemmas() || d_im.hasProcessed());
   Trace("sets") << "----- End full effort check, conflict="
                 << d_state.isInConflict() << ", lemma=" << d_im.hasSentLemma()
                 << std::endl;