Add TheoryState objects to each Theory (#4920)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Thu, 20 Aug 2020 20:50:38 +0000 (15:50 -0500)
committerGitHub <noreply@github.com>
Thu, 20 Aug 2020 20:50:38 +0000 (15:50 -0500)
This initializes all theories with a TheoryState object (apart from bool and builtin which do not require one).

Two additional theories are known to require special state objects: TheoryArith, which has a custom way of detecting when in conflict, and TheoryQuantifiers, which can leverage a special state object for the purposes of refactoring and splitting apart QuantifiersEngine further. All other theories use default TheoryState objects.

Notice this PR does not update the theories to use these states yet, it simply adds the objects.

22 files changed:
src/CMakeLists.txt
src/theory/arith/arith_state.cpp [new file with mode: 0644]
src/theory/arith/arith_state.h [new file with mode: 0644]
src/theory/arith/theory_arith.cpp
src/theory/arith/theory_arith.h
src/theory/arith/theory_arith_private.h
src/theory/arrays/theory_arrays.cpp
src/theory/arrays/theory_arrays.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/quantifiers/quantifiers_state.cpp [new file with mode: 0644]
src/theory/quantifiers/quantifiers_state.h [new file with mode: 0644]
src/theory/quantifiers/theory_quantifiers.cpp
src/theory/quantifiers/theory_quantifiers.h
src/theory/sep/theory_sep.cpp
src/theory/sep/theory_sep.h
src/theory/uf/theory_uf.cpp
src/theory/uf/theory_uf.h

index f1e01a7cb931e841110e06d3e986c28f493da016..f9d7f833ec7d8a16a75824fb133cf117365cc45a 100644 (file)
@@ -292,6 +292,8 @@ libcvc4_add_sources(
   theory/arith/arith_msum.h
   theory/arith/arith_rewriter.cpp
   theory/arith/arith_rewriter.h
+  theory/arith/arith_state.cpp
+  theory/arith/arith_state.h
   theory/arith/arith_static_learner.cpp
   theory/arith/arith_static_learner.h
   theory/arith/arith_utilities.cpp
@@ -604,6 +606,8 @@ libcvc4_add_sources(
   theory/quantifiers/quantifiers_attributes.h
   theory/quantifiers/quantifiers_rewriter.cpp
   theory/quantifiers/quantifiers_rewriter.h
+  theory/quantifiers/quantifiers_state.cpp
+  theory/quantifiers/quantifiers_state.h
   theory/quantifiers/query_generator.cpp
   theory/quantifiers/query_generator.h
   theory/quantifiers/relevant_domain.cpp
diff --git a/src/theory/arith/arith_state.cpp b/src/theory/arith/arith_state.cpp
new file mode 100644 (file)
index 0000000..c4678fa
--- /dev/null
@@ -0,0 +1,38 @@
+/*********************                                                        */
+/*! \file arith_state.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Andrew Reynolds
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2020 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 Arithmetic theory state.
+ **/
+
+#include "theory/arith/arith_state.h"
+
+#include "theory/arith/theory_arith_private.h"
+
+namespace CVC4 {
+namespace theory {
+namespace arith {
+
+ArithState::ArithState(TheoryArithPrivate& parent,
+                       context::Context* c,
+                       context::UserContext* u,
+                       Valuation val)
+    : TheoryState(c, u, val), d_parent(parent)
+{
+}
+
+bool ArithState::isInConflict() const
+{
+  return d_parent.anyConflict() || d_conflict;
+}
+
+}  // namespace arith
+}  // namespace theory
+}  // namespace CVC4
diff --git a/src/theory/arith/arith_state.h b/src/theory/arith/arith_state.h
new file mode 100644 (file)
index 0000000..5d77575
--- /dev/null
@@ -0,0 +1,57 @@
+/*********************                                                        */
+/*! \file arith_state.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Andrew Reynolds
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2020 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 Arithmetic theory state.
+ **/
+
+#include "cvc4_private.h"
+
+#ifndef CVC4__THEORY__ARITH__ARITH_STATE_H
+#define CVC4__THEORY__ARITH__ARITH_STATE_H
+
+#include "theory/theory_state.h"
+
+namespace CVC4 {
+namespace theory {
+namespace arith {
+
+class TheoryArithPrivate;
+
+/**
+ * The arithmetic state.
+ *
+ * Note this object is intended to use TheoryArithPrivate
+ * as a black box, and moreover the internals of TheoryArithPrivate will not
+ * be refactored to use this state. Instead, the main theory solver TheoryArith
+ * will be refactored to be a standard layer on top of TheoryArithPrivate,
+ * which will include using this state in the standard way.
+ */
+class ArithState : public TheoryState
+{
+ public:
+  ArithState(TheoryArithPrivate& parent,
+             context::Context* c,
+             context::UserContext* u,
+             Valuation val);
+  ~ArithState() {}
+  /** Are we currently in conflict? */
+  bool isInConflict() const override;
+
+ private:
+  /** reference to parent */
+  TheoryArithPrivate& d_parent;
+};
+
+}  // namespace arith
+}  // namespace theory
+}  // namespace CVC4
+
+#endif
index b95b5e243380020c45ba2a2e818e52483822551e..4e0582f50175b998f48aa83a519565947216a32c 100644 (file)
@@ -41,9 +41,13 @@ TheoryArith::TheoryArith(context::Context* c,
       d_internal(
           new TheoryArithPrivate(*this, c, u, out, valuation, logicInfo, pnm)),
       d_ppRewriteTimer("theory::arith::ppRewriteTimer"),
-      d_proofRecorder(nullptr)
+      d_proofRecorder(nullptr),
+      d_astate(*d_internal, c, u, valuation)
 {
   smtStatisticsRegistry()->registerStat(&d_ppRewriteTimer);
+
+  // indicate we are using the theory state object
+  d_theoryState = &d_astate;
 }
 
 TheoryArith::~TheoryArith(){
index ad3b91b07cd4eb19d86076824d6e4fffe12476f9..d0147fe9f813c1e741147397041698fade383c33 100644 (file)
 
 #pragma once
 
-#include "theory/theory.h"
 #include "expr/node.h"
 #include "proof/arith_proof_recorder.h"
+#include "theory/arith/arith_state.h"
 #include "theory/arith/theory_arith_private_forward.h"
-
+#include "theory/theory.h"
 
 namespace CVC4 {
 namespace theory {
@@ -115,6 +115,9 @@ class TheoryArith : public Theory {
     d_proofRecorder = proofRecorder;
   }
 
+ private:
+  /** The state object wrapping TheoryArithPrivate  */
+  ArithState d_astate;
 };/* class TheoryArith */
 
 }/* CVC4::theory::arith namespace */
index 4c4aedf006badeb55215e87c6b97e48c2e88784a..d96b5e2d3de8496327d8a1a14756b3b1c2d47225 100644 (file)
@@ -324,17 +324,20 @@ public:
   /** This is a conflict that is magically known to hold. */
   void raiseBlackBoxConflict(Node bb);
 
-private:
+  /**
+   * Returns true iff a conflict has been raised. This method is public since
+   * it is needed by the ArithState class to know whether we are in conflict.
+   */
+  bool anyConflict() const
+  {
+    return !conflictQueueEmpty() || !d_blackBoxConflict.get().isNull();
+  }
 
+ private:
   inline bool conflictQueueEmpty() const {
     return d_conflicts.empty();
   }
 
-  /** Returns true iff a conflict has been raised. */
-  inline bool anyConflict() const {
-    return !conflictQueueEmpty() || !d_blackBoxConflict.get().isNull();
-  }
-
   /**
    * Outputs the contents of d_conflicts onto d_out.
    * The conditions of anyConflict() must hold.
index 4cc51a87eadd02c239ed5d46787d8b416918f7bb..9c1e22940f1b3dfa2b06b8f9ef95f08ffb98211c 100644 (file)
@@ -82,7 +82,7 @@ TheoryArrays::TheoryArrays(context::Context* c,
           name + "theory::arrays::number of setModelVal conflicts", 0),
       d_ppEqualityEngine(u, name + "theory::arrays::pp", true),
       d_ppFacts(u),
-      //      d_ppCache(u),
+      d_state(c, u, valuation),
       d_literalsToPropagate(c),
       d_literalsToPropagateIndex(c, 0),
       d_isPreRegistered(c),
@@ -132,6 +132,9 @@ TheoryArrays::TheoryArrays(context::Context* c,
   // The preprocessing congruence kinds
   d_ppEqualityEngine.addFunctionKind(kind::SELECT);
   d_ppEqualityEngine.addFunctionKind(kind::STORE);
+
+  // indicate we are using the default theory state object
+  d_theoryState = &d_state;
 }
 
 TheoryArrays::~TheoryArrays() {
index b69450ac45189224686ab5db1f4ad9303700d51a..2d09c55fe4fdd36ebf42192aa45ebc1ee26dc415 100644 (file)
@@ -194,6 +194,8 @@ class TheoryArrays : public Theory {
 
   /** The theory rewriter for this theory. */
   TheoryArraysRewriter d_rewriter;
+  /** A (default) theory state object */
+  TheoryState d_state;
 
  public:
   PPAssertStatus ppAssert(TNode in, SubstitutionMap& outSubstitutions) override;
index ced320d92a87ff89b4dd1d479f18f5339358224c..2c095e19851543d9332c2dd39de79342a48117fa 100644 (file)
@@ -74,7 +74,8 @@ TheoryBV::TheoryBV(context::Context* c,
       d_calledPreregister(false),
       d_needsLastCallCheck(false),
       d_extf_range_infer(u),
-      d_extf_collapse_infer(u)
+      d_extf_collapse_infer(u),
+      d_state(c, u, valuation)
 {
   d_extTheory->addFunctionKind(kind::BITVECTOR_TO_NAT);
   d_extTheory->addFunctionKind(kind::INT_TO_BITVECTOR);
@@ -109,6 +110,9 @@ TheoryBV::TheoryBV(context::Context* c,
   }
   d_subtheories.emplace_back(bb_solver);
   d_subtheoryMap[SUB_BITBLAST] = bb_solver;
+
+  // indicate we are using the default theory state object
+  d_theoryState = &d_state;
 }
 
 TheoryBV::~TheoryBV() {}
index 0e8877359833c58b36d68abac8493639c15d898b..11440cb8188abf36405ba15f9b3a06226729ed47 100644 (file)
@@ -275,6 +275,8 @@ class TheoryBV : public Theory {
 
   /** The theory rewriter for this theory. */
   TheoryBVRewriter d_rewriter;
+  /** A (default) theory state object */
+  TheoryState d_state;
 
   friend class LazyBitblaster;
   friend class TLazyBitblaster;
index ee750e6465aedd8ea177c30c3233911d3cb058eb..08ec4322e3cd725a3ecf361fa9630fce13a66d1d 100644 (file)
@@ -61,12 +61,16 @@ TheoryDatatypes::TheoryDatatypes(Context* c,
       d_functionTerms(c),
       d_singleton_eq(u),
       d_lemmas_produced_c(u),
-      d_sygusExtension(nullptr)
+      d_sygusExtension(nullptr),
+      d_state(c, u, valuation)
 {
 
   d_true = NodeManager::currentNM()->mkConst( true );
   d_zero = NodeManager::currentNM()->mkConst( Rational(0) );
   d_dtfCounter = 0;
+
+  // indicate we are using the default theory state object
+  d_theoryState = &d_state;
 }
 
 TheoryDatatypes::~TheoryDatatypes() {
index 37848f10e1073b4d9a95755c4cd14befd722a2f8..0465a7788c1aa4c99b7b9d7bcfb3dd7cd6ff2507 100644 (file)
@@ -366,6 +366,8 @@ private:
 
   /** The theory rewriter for this theory. */
   DatatypesRewriter d_rewriter;
+  /** A (default) theory state object */
+  TheoryState d_state;
 };/* class TheoryDatatypes */
 
 }/* CVC4::theory::datatypes namespace */
index ff08558895aef1138ecdec8e1fea34f5a4d2b469..82086aafe577bfe72a3fbe71baeb7ddb4146df82 100644 (file)
@@ -119,8 +119,11 @@ TheoryFp::TheoryFp(context::Context* c,
       d_toRealMap(u),
       realToFloatMap(u),
       floatToRealMap(u),
-      abstractionMap(u)
+      abstractionMap(u),
+      d_state(c, u, valuation)
 {
+  // indicate we are using the default theory state object
+  d_theoryState = &d_state;
 } /* TheoryFp::TheoryFp() */
 
 TheoryRewriter* TheoryFp::getTheoryRewriter() { return &d_rewriter; }
index 2584d574e3d6c48100087772099dfb6bcd8e5957..ad052f92aedc17efc232b0ee07dbde49192aab1b 100644 (file)
@@ -153,6 +153,8 @@ class TheoryFp : public Theory {
 
   /** The theory rewriter for this theory. */
   TheoryFpRewriter d_rewriter;
+  /** A (default) theory state object */
+  TheoryState d_state;
 }; /* class TheoryFp */
 
 }  // namespace fp
diff --git a/src/theory/quantifiers/quantifiers_state.cpp b/src/theory/quantifiers/quantifiers_state.cpp
new file mode 100644 (file)
index 0000000..67fad6f
--- /dev/null
@@ -0,0 +1,30 @@
+/*********************                                                        */
+/*! \file quantifiers_state.cpp
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Andrew Reynolds, Mathias Preiner
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2020 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 Utility for quantifiers state
+ **/
+
+#include "theory/quantifiers/quantifiers_state.h"
+
+namespace CVC4 {
+namespace theory {
+namespace quantifiers {
+
+QuantifiersState::QuantifiersState(context::Context* c,
+                                   context::UserContext* u,
+                                   Valuation val)
+    : TheoryState(c, u, val)
+{
+}
+
+}  // namespace quantifiers
+}  // namespace theory
+}  // namespace CVC4
diff --git a/src/theory/quantifiers/quantifiers_state.h b/src/theory/quantifiers/quantifiers_state.h
new file mode 100644 (file)
index 0000000..a6611e7
--- /dev/null
@@ -0,0 +1,40 @@
+/*********************                                                        */
+/*! \file quantifiers_state.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Andrew Reynolds, Mathias Preiner
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2020 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 Utility for quantifiers state
+ **/
+
+#include "cvc4_private.h"
+
+#ifndef CVC4__THEORY__QUANTIFIERS__QUANTIFIERS_STATE_H
+#define CVC4__THEORY__QUANTIFIERS__QUANTIFIERS_STATE_H
+
+#include "theory/theory_state.h"
+
+namespace CVC4 {
+namespace theory {
+namespace quantifiers {
+
+/**
+ * The quantifiers state.
+ */
+class QuantifiersState : public TheoryState
+{
+ public:
+  QuantifiersState(context::Context* c, context::UserContext* u, Valuation val);
+  ~QuantifiersState() {}
+};
+
+}  // namespace quantifiers
+}  // namespace theory
+}  // namespace CVC4
+
+#endif /* CVC4__THEORY__QUANTIFIERS__QUANTIFIERS_STATE_H */
index 04e83032bf935bce98639db069f1e589feeb8890..261fd65e6ba9e88d0c88df98b01d9913f127ceb9 100644 (file)
@@ -42,7 +42,8 @@ TheoryQuantifiers::TheoryQuantifiers(Context* c,
                                      Valuation valuation,
                                      const LogicInfo& logicInfo,
                                      ProofNodeManager* pnm)
-    : Theory(THEORY_QUANTIFIERS, c, u, out, valuation, logicInfo, pnm)
+    : Theory(THEORY_QUANTIFIERS, c, u, out, valuation, logicInfo, pnm),
+      d_qstate(c, u, valuation)
 {
   out.handleUserAttribute( "fun-def", this );
   out.handleUserAttribute( "sygus", this );
@@ -59,6 +60,8 @@ TheoryQuantifiers::TheoryQuantifiers(Context* c,
     // add the proof rules
     d_qChecker.registerTo(pc);
   }
+  // indicate we are using the quantifiers theory state object
+  d_theoryState = &d_qstate;
 }
 
 TheoryQuantifiers::~TheoryQuantifiers() {
index c378f35378694fb2b1b2fe5c1b0b44c9607daf53..6f8256c211bdc7fd2eb01470b955f70981cde3b6 100644 (file)
@@ -24,9 +24,9 @@
 #include "theory/output_channel.h"
 #include "theory/quantifiers/proof_checker.h"
 #include "theory/quantifiers/quantifiers_rewriter.h"
+#include "theory/quantifiers/quantifiers_state.h"
 #include "theory/theory.h"
 #include "theory/valuation.h"
-#include "util/statistics_registry.h"
 
 namespace CVC4 {
 namespace theory {
@@ -69,6 +69,8 @@ class TheoryQuantifiers : public Theory {
   QuantifiersRewriter d_rewriter;
   /** The proof rule checker */
   QuantifiersProofRuleChecker d_qChecker;
+  /** The quantifiers state */
+  QuantifiersState d_qstate;
 };/* class TheoryQuantifiers */
 
 }/* CVC4::theory::quantifiers namespace */
index edb5dd0ae9680a541d3d1702495c4c75890abda4..f75eb44726e196e59a710902c4d4c2d9074af734 100644 (file)
@@ -47,6 +47,8 @@ TheorySep::TheorySep(context::Context* c,
                      ProofNodeManager* pnm)
     : Theory(THEORY_SEP, c, u, out, valuation, logicInfo, pnm),
       d_lemmas_produced_c(u),
+      d_bounds_init(false),
+      d_state(c, u, valuation),
       d_notify(*this),
       d_conflict(c, false),
       d_reduce(u),
@@ -56,7 +58,9 @@ TheorySep::TheorySep(context::Context* c,
 {
   d_true = NodeManager::currentNM()->mkConst<bool>(true);
   d_false = NodeManager::currentNM()->mkConst<bool>(false);
-  d_bounds_init = false;
+
+  // indicate we are using the default theory state object
+  d_theoryState = &d_state;
 }
 
 TheorySep::~TheorySep() {
index 40182fc1926b16608a682048abbf43937ac9a4ab..b178b97db39a8af437ceae194d34eece1d4dcd78 100644 (file)
@@ -58,6 +58,8 @@ class TheorySep : public Theory {
   bool d_bounds_init;
 
   TheorySepRewriter d_rewriter;
+  /** A (default) theory state object */
+  TheoryState d_state;
 
   Node mkAnd( std::vector< TNode >& assumptions );
 
index 7bca9da74dd0342009add45b727c3445814824fc..c8ae3d8442c0fec28b3ea659d281c87fcf1fdb68 100644 (file)
@@ -56,7 +56,8 @@ TheoryUF::TheoryUF(context::Context* c,
       d_ho(nullptr),
       d_conflict(c, false),
       d_functionsTerms(c),
-      d_symb(u, instanceName)
+      d_symb(u, instanceName),
+      d_state(c, u, valuation)
 {
   d_true = NodeManager::currentNM()->mkConst( true );
 
@@ -65,6 +66,8 @@ TheoryUF::TheoryUF(context::Context* c,
   {
     d_ufProofChecker.registerTo(pc);
   }
+  // indicate we are using the default theory state object
+  d_theoryState = &d_state;
 }
 
 TheoryUF::~TheoryUF() {
index 414a2dd6aa43aea4e1e7bd412ff95293f8fd4e1d..4d0a3126f1759222c4fdf6818018d700b3afd16d 100644 (file)
@@ -219,6 +219,8 @@ private:
   TheoryUfRewriter d_rewriter;
   /** Proof rule checker */
   UfProofRuleChecker d_ufProofChecker;
+  /** A (default) theory state object */
+  TheoryState d_state;
 };/* class TheoryUF */
 
 }/* CVC4::theory::uf namespace */