Remove more uses of Expr (#5357)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Wed, 28 Oct 2020 21:21:53 +0000 (16:21 -0500)
committerGitHub <noreply@github.com>
Wed, 28 Oct 2020 21:21:53 +0000 (16:21 -0500)
This PR removes more uses of Expr, mostly related to UnsatCore.

It makes UnsatCore a cvc4_private object storing Node instead of Expr.

15 files changed:
src/api/cvc4cpp.cpp
src/printer/printer.cpp
src/printer/smt2/smt2_printer.cpp
src/printer/tptp/tptp_printer.cpp
src/proof/proof_manager.cpp
src/proof/proof_manager.h
src/proof/unsat_core.h
src/smt/command.cpp
src/smt/command.h
src/smt/smt_engine.cpp
src/smt/smt_engine.h
src/smt_util/boolean_simplification.h
src/theory/quantifiers/expr_miner.h
src/theory/quantifiers/sygus/cegis_core_connective.cpp
src/theory/smt_engine_subsolver.h

index e198c0d89de55a957a68b27d6f70315b6799f0cd..be82a517ffde0f147616510b90e096c46c937c8e 100644 (file)
@@ -51,6 +51,7 @@
 #include "options/main_options.h"
 #include "options/options.h"
 #include "options/smt_options.h"
+#include "proof/unsat_core.h"
 #include "smt/model.h"
 #include "smt/smt_engine.h"
 #include "smt/smt_mode.h"
@@ -5145,7 +5146,7 @@ std::vector<Term> Solver::getUnsatCore(void) const
    *   return std::vector<Term>(core.begin(), core.end());
    * here since constructor is private */
   std::vector<Term> res;
-  for (const Expr& e : core)
+  for (const Node& e : core)
   {
     res.push_back(Term(this, e));
   }
index e760c21aab08fc46de298d3921844715065fd70e..195247df71e0e19181588e6d256861ba1afe4089 100644 (file)
@@ -23,6 +23,7 @@
 #include "printer/cvc/cvc_printer.h"
 #include "printer/smt2/smt2_printer.h"
 #include "printer/tptp/tptp_printer.h"
+#include "proof/unsat_core.h"
 #include "smt/command.h"
 #include "smt/node_command.h"
 
@@ -88,7 +89,7 @@ void Printer::toStream(std::ostream& out, const smt::Model& m) const
 void Printer::toStream(std::ostream& out, const UnsatCore& core) const
 {
   for(UnsatCore::iterator i = core.begin(); i != core.end(); ++i) {
-    toStreamCmdAssert(out, Node::fromExpr(*i));
+    toStreamCmdAssert(out, *i);
     out << std::endl;
   }
 }/* Printer::toStream(UnsatCore) */
index 2024c87b6a141f917c274147d6bd6bb376f96ff2..8815f96322bb11a38d0f5cc73fc7ae8a85e13620 100644 (file)
@@ -31,6 +31,7 @@
 #include "options/printer_options.h"
 #include "options/smt_options.h"
 #include "printer/dagification_visitor.h"
+#include "proof/unsat_core.h"
 #include "smt/command.h"
 #include "smt/node_command.h"
 #include "smt/smt_engine.h"
index 009f78a1da646a3686eddd800dbc7efed387463e..d18d0c1fd23a523fad3b3a5e0e1421b37b9ad60a 100644 (file)
@@ -24,6 +24,7 @@
 #include "expr/node_manager.h"    // for VarNameAttr
 #include "options/language.h"     // for LANG_AST
 #include "options/smt_options.h"  // for unsat cores
+#include "proof/unsat_core.h"
 #include "smt/command.h"
 #include "smt/node_command.h"
 #include "smt/smt_engine.h"
index 93b07b76205c61194b6825dc068a2b4d3740c1f0..20b0e8a927f7b0817aded240fdb13f06155cb594 100644 (file)
@@ -95,17 +95,18 @@ void ProofManager::initCnfProof(prop::CnfStream* cnfStream,
   d_cnfProof->popCurrentAssertion();
 }
 
-
-void ProofManager::traceDeps(TNode n, CDExprSet* coreAssertions) {
+void ProofManager::traceDeps(TNode n, CDNodeSet* coreAssertions)
+{
   Debug("cores") << "trace deps " << n << std::endl;
   if ((n.isConst() && n == NodeManager::currentNM()->mkConst<bool>(true)) ||
       (n.getKind() == kind::NOT && n[0] == NodeManager::currentNM()->mkConst<bool>(false))) {
     return;
   }
-  if(d_inputCoreFormulas.find(n.toExpr()) != d_inputCoreFormulas.end()) {
+  if (d_inputCoreFormulas.find(n) != d_inputCoreFormulas.end())
+  {
     // originating formula was in core set
     Debug("cores") << " -- IN INPUT CORE LIST!" << std::endl;
-    coreAssertions->insert(n.toExpr());
+    coreAssertions->insert(n);
   } else {
     Debug("cores") << " -- NOT IN INPUT CORE LIST!" << std::endl;
     if(d_deps.find(n) == d_deps.end()) {
@@ -151,8 +152,9 @@ bool ProofManager::unsatCoreAvailable() const {
   return d_satProof->derivedEmptyClause();
 }
 
-std::vector<Expr> ProofManager::extractUnsatCore() {
-  std::vector<Expr> result;
+std::vector<Node> ProofManager::extractUnsatCore()
+{
+  std::vector<Node> result;
   output_core_iterator it = begin_unsat_core();
   output_core_iterator end = end_unsat_core();
   while ( it != end ) {
@@ -190,9 +192,10 @@ void ProofManager::getLemmasInUnsatCore(std::vector<Node>& lemmas)
   }
 }
 
-void ProofManager::addCoreAssertion(Expr formula) {
+void ProofManager::addCoreAssertion(Node formula)
+{
   Debug("cores") << "assert: " << formula << std::endl;
-  d_deps[Node::fromExpr(formula)]; // empty vector of deps
+  d_deps[formula];  // empty vector of deps
   d_inputCoreFormulas.insert(formula);
 }
 
@@ -208,7 +211,8 @@ void ProofManager::addDependence(TNode n, TNode dep) {
   }
 }
 
-void ProofManager::addUnsatCore(Expr formula) {
+void ProofManager::addUnsatCore(Node formula)
+{
   Assert(d_inputCoreFormulas.find(formula) != d_inputCoreFormulas.end());
   d_outputCoreFormulas.insert(formula);
 }
index 1c2a1ce9ae80242407b0658d3c7f85055b772f52..7276f640205da34df348395f8e500b991751a1cd 100644 (file)
@@ -57,7 +57,7 @@ namespace prop {
 }/* CVC4::prop namespace */
 
 typedef std::unordered_map<ClauseId, prop::SatClause*> IdToSatClause;
-typedef context::CDHashSet<Expr, ExprHashFunction> CDExprSet;
+typedef context::CDHashSet<Node, NodeHashFunction> CDNodeSet;
 typedef context::CDHashMap<Node, std::vector<Node>, NodeHashFunction> CDNodeToNodes;
 typedef std::unordered_set<ClauseId> IdHashSet;
 
@@ -68,8 +68,8 @@ class ProofManager {
   std::unique_ptr<CnfProof> d_cnfProof;
 
   // information that will need to be shared across proofs
-  CDExprSet    d_inputCoreFormulas;
-  CDExprSet    d_outputCoreFormulas;
+  CDNodeSet d_inputCoreFormulas;
+  CDNodeSet d_outputCoreFormulas;
 
   int d_nextId;
 
@@ -90,16 +90,16 @@ public:
  static CnfProof* getCnfProof();
 
  /** Public unsat core methods **/
- void addCoreAssertion(Expr formula);
+ void addCoreAssertion(Node formula);
 
  void addDependence(TNode n, TNode dep);
- void addUnsatCore(Expr formula);
+ void addUnsatCore(Node formula);
 
  // trace dependences back to unsat core
- void traceDeps(TNode n, CDExprSet* coreAssertions);
+ void traceDeps(TNode n, CDNodeSet* coreAssertions);
  void traceUnsatCore();
 
- typedef CDExprSet::const_iterator output_core_iterator;
+ typedef CDNodeSet::const_iterator output_core_iterator;
 
  output_core_iterator begin_unsat_core() const
  {
@@ -110,7 +110,7 @@ public:
    return d_outputCoreFormulas.end();
  }
  size_t size_unsat_core() const { return d_outputCoreFormulas.size(); }
- std::vector<Expr> extractUnsatCore();
+ std::vector<Node> extractUnsatCore();
 
  bool unsatCoreAvailable() const;
  void getLemmasInUnsatCore(std::vector<Node>& lemmas);
index f50cabbe63cb38b1171a415946526f3a3856303c..b0e3de24ecba910c23a3c0e1dc3837672f8aabfe 100644 (file)
@@ -15,7 +15,7 @@
  ** \todo document this file
  **/
 
-#include "cvc4_public.h"
+#include "cvc4_private.h"
 
 #ifndef CVC4__UNSAT_CORE_H
 #define CVC4__UNSAT_CORE_H
 #include <iosfwd>
 #include <vector>
 
-#include "expr/expr.h"
+#include "expr/node.h"
 
 namespace CVC4 {
 
 class SmtEngine;
-class UnsatCore;
-
-std::ostream& operator<<(std::ostream& out, const UnsatCore& core) CVC4_PUBLIC;
-
-class CVC4_PUBLIC UnsatCore {
-  friend std::ostream& operator<<(std::ostream&, const UnsatCore&);
 
+class UnsatCore
+{
   /** The SmtEngine we're associated with */
   SmtEngine* d_smt;
 
-  std::vector<Expr> d_core;
+  std::vector<Node> d_core;
 
   void initMessage() const;
 
 public:
   UnsatCore() : d_smt(NULL) {}
 
-  UnsatCore(SmtEngine* smt, std::vector<Expr> core) : d_smt(smt), d_core(core) {
+  UnsatCore(SmtEngine* smt, const std::vector<Node>& core)
+      : d_smt(smt), d_core(core)
+  {
     initMessage();
   }
 
@@ -56,8 +54,8 @@ public:
 
   size_t size() const { return d_core.size(); }
 
-  typedef std::vector<Expr>::const_iterator iterator;
-  typedef std::vector<Expr>::const_iterator const_iterator;
+  typedef std::vector<Node>::const_iterator iterator;
+  typedef std::vector<Node>::const_iterator const_iterator;
 
   const_iterator begin() const;
   const_iterator end() const;
@@ -69,6 +67,9 @@ public:
 
 };/* class UnsatCore */
 
+/** Print the unsat core to stream out */
+std::ostream& operator<<(std::ostream& out, const UnsatCore& core);
+
 }/* CVC4 namespace */
 
 #endif /* CVC4__UNSAT_CORE_H */
index eb03edf4f9ffeb256c5ba3fb987249689de96775..9b0784831cc375b6484be158d9fce12f681fe1ec 100644 (file)
@@ -32,6 +32,7 @@
 #include "options/options.h"
 #include "options/smt_options.h"
 #include "printer/printer.h"
+#include "proof/unsat_core.h"
 #include "smt/dump.h"
 #include "smt/model.h"
 #include "smt/smt_engine.h"
@@ -2341,8 +2342,8 @@ void GetUnsatCoreCommand::invoke(api::Solver* solver)
 {
   try
   {
-    d_result = UnsatCore(solver->getSmtEngine(),
-                         api::termVectorToExprs(solver->getUnsatCore()));
+    d_solver = solver;
+    d_result = solver->getUnsatCore();
 
     d_commandStatus = CommandSuccess::instance();
   }
@@ -2365,11 +2366,12 @@ void GetUnsatCoreCommand::printResult(std::ostream& out,
   }
   else
   {
-    d_result.toStream(out);
+    UnsatCore ucr(d_solver->getSmtEngine(), api::termVectorToNodes(d_result));
+    ucr.toStream(out);
   }
 }
 
-const UnsatCore& GetUnsatCoreCommand::getUnsatCore() const
+const std::vector<api::Term>& GetUnsatCoreCommand::getUnsatCore() const
 {
   // of course, this will be empty if the command hasn't been invoked yet
   return d_result;
@@ -2378,6 +2380,7 @@ const UnsatCore& GetUnsatCoreCommand::getUnsatCore() const
 Command* GetUnsatCoreCommand::clone() const
 {
   GetUnsatCoreCommand* c = new GetUnsatCoreCommand;
+  c->d_solver = d_solver;
   c->d_result = d_result;
   return c;
 }
index b81b55b91fa35bf201b075a13872c47bfb57ce2d..7088c09ed358c4c8f7675016f5567aae884416b4 100644 (file)
@@ -31,8 +31,6 @@
 #include "api/cvc4cpp.h"
 #include "expr/expr.h"
 #include "expr/type.h"
-#include "expr/variable_type_map.h"
-#include "proof/unsat_core.h"
 #include "util/result.h"
 #include "util/sexpr.h"
 
@@ -43,6 +41,7 @@ class Solver;
 class Term;
 }  // namespace api
 
+class UnsatCore;
 class SmtEngine;
 class Command;
 class CommandStatus;
@@ -1224,7 +1223,7 @@ class CVC4_PUBLIC GetUnsatCoreCommand : public Command
 {
  public:
   GetUnsatCoreCommand();
-  const UnsatCore& getUnsatCore() const;
+  const std::vector<api::Term>& getUnsatCore() const;
 
   void invoke(api::Solver* solver) override;
   void printResult(std::ostream& out, uint32_t verbosity = 2) const override;
@@ -1239,8 +1238,10 @@ class CVC4_PUBLIC GetUnsatCoreCommand : public Command
       OutputLanguage language = language::output::LANG_AUTO) const override;
 
  protected:
-  // the result of the unsat core call
-  UnsatCore d_result;
+  /** The solver we were invoked with */
+  api::Solver* d_solver;
+  /** the result of the unsat core call */
+  std::vector<api::Term> d_result;
 }; /* class GetUnsatCoreCommand */
 
 class CVC4_PUBLIC GetAssertionsCommand : public Command
index d0906ce98ec87dc2f79b505eedd19f50c14a9413..dc5338199846bc7ee25bd5a9cc0f01443f40bf14 100644 (file)
@@ -1028,7 +1028,7 @@ std::vector<Node> SmtEngine::getUnsatAssumptions(void)
   std::vector<Node>& assumps = d_asserts->getAssumptions();
   for (const Node& e : assumps)
   {
-    if (std::find(core.begin(), core.end(), e.toExpr()) != core.end())
+    if (std::find(core.begin(), core.end(), e) != core.end())
     {
       res.push_back(e);
     }
@@ -1490,7 +1490,7 @@ void SmtEngine::checkUnsatCore() {
 
   Notice() << "SmtEngine::checkUnsatCore(): pushing core assertions (size == " << core.size() << ")" << endl;
   for(UnsatCore::iterator i = core.begin(); i != core.end(); ++i) {
-    Node assertionAfterExpansion = expandDefinitions(Node::fromExpr(*i));
+    Node assertionAfterExpansion = expandDefinitions(*i);
     Notice() << "SmtEngine::checkUnsatCore(): pushing core member " << *i
              << ", expanded to " << assertionAfterExpansion << "\n";
     coreChecker.assertFormula(assertionAfterExpansion);
index 53e982a2d6b90f319bcd6bb273150b3d57e1aacc..de0daffd092c0ce6818c1d2e930d2f469997e95e 100644 (file)
@@ -29,7 +29,6 @@
 #include "expr/expr.h"
 #include "expr/expr_manager.h"
 #include "options/options.h"
-#include "proof/unsat_core.h"
 #include "smt/logic_exception.h"
 #include "smt/output_manager.h"
 #include "smt/smt_mode.h"
@@ -59,6 +58,7 @@ class DecisionEngine;
 class TheoryEngine;
 
 class ProofManager;
+class UnsatCore;
 
 class LogicRequest;
 class StatisticsRegistry;
index a7b3e149decd0139b1d52cc327214ad424066fc8..78d7f8c385b22968b42d547b1a4f3384ff745931 100644 (file)
@@ -201,18 +201,6 @@ class BooleanSimplification {
     }
   }
 
-  /**
-   * Negates an Expr, doing all the double-negation elimination that's
-   * possible.
-   *
-   * @param e the Expr to negate (cannot be the null Expr)
-   */
-  static Expr negate(Expr e)
-  {
-    ExprManagerScope ems(e);
-    return negate(Node::fromExpr(e)).toExpr();
-  }
-
   /**
    * Simplify an OR, AND, or IMPLIES.  This function is the identity
    * for all other kinds.
index 96eae4fa85e21a27f4e7726b0147b6e5f0e94329..aa0e6289101747b2a5eb4adf3887a456557e0331 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "expr/expr.h"
 #include "expr/expr_manager.h"
-#include "expr/variable_type_map.h"
 #include "smt/smt_engine.h"
 #include "theory/quantifiers/sygus_sampler.h"
 
index 06b884b723d342a1b21413ce4c41e7d62d3a4f87..33fce2e84e601c86a4d491b167bee92c72e48cc2 100644 (file)
@@ -611,7 +611,7 @@ bool CegisCoreConnective::getUnsatCore(
   bool hasQuery = false;
   for (UnsatCore::const_iterator i = uc.begin(); i != uc.end(); ++i)
   {
-    Node uassert = Node::fromExpr(*i);
+    Node uassert = *i;
     Trace("sygus-ccore-debug") << "  uc " << uassert << std::endl;
     if (queryAsserts.find(uassert) != queryAsserts.end())
     {
index 139d5f9ff4285aa39c8ae0054dee8728a3e57a85..d34729dec9543a9c01c748f3a8a4252da681ec9c 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "expr/expr_manager.h"
 #include "expr/node.h"
-#include "expr/variable_type_map.h"
 #include "smt/smt_engine.h"
 
 namespace CVC4 {