(proof-new) Replace LazyCDProofSet by generic CDProofSet (#5487)
authorGereon Kremer <gereon.kremer@cs.rwth-aachen.de>
Fri, 20 Nov 2020 19:04:37 +0000 (20:04 +0100)
committerGitHub <noreply@github.com>
Fri, 20 Nov 2020 19:04:37 +0000 (13:04 -0600)
This PR replaces the LazyCDProofSet, that was hardcoded to use LazyCDProof objects, by a templated CDProofSet.

src/expr/CMakeLists.txt
src/expr/lazy_proof_set.cpp [deleted file]
src/expr/lazy_proof_set.h [deleted file]
src/expr/proof_set.h [new file with mode: 0644]
src/smt/preprocess_proof_generator.cpp
src/smt/preprocess_proof_generator.h
src/theory/trust_substitutions.cpp
src/theory/trust_substitutions.h

index 430303f6b7ef06804f49b2b8765a1c312bb7d690..18de83e90246b5380fd9e0bb56ce71784c7a6527 100644 (file)
@@ -32,8 +32,6 @@ libcvc4_add_sources(
   lazy_proof.h
   lazy_proof_chain.cpp
   lazy_proof_chain.h
-  lazy_proof_set.cpp
-  lazy_proof_set.h
   match_trie.cpp
   match_trie.h
   node.cpp
@@ -72,6 +70,7 @@ libcvc4_add_sources(
   proof_node_updater.h
   proof_rule.cpp
   proof_rule.h
+  proof_set.h
   proof_step_buffer.cpp
   proof_step_buffer.h
   skolem_manager.cpp
diff --git a/src/expr/lazy_proof_set.cpp b/src/expr/lazy_proof_set.cpp
deleted file mode 100644 (file)
index be6abbb..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*********************                                                        */
-/*! \file lazy_proof_set.cpp
- ** \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 Lazy proof set utility
- **/
-
-#include "expr/lazy_proof_set.h"
-
-namespace CVC4 {
-
-LazyCDProofSet::LazyCDProofSet(ProofNodeManager* pnm,
-                               context::Context* c,
-                               std::string namePrefix)
-    : d_pnm(pnm),
-      d_contextUse(c ? c : &d_context),
-      d_pfs(d_contextUse),
-      d_namePrefix(namePrefix)
-{
-}
-
-LazyCDProof* LazyCDProofSet::allocateProof(bool isCd)
-{
-  std::stringstream ss;
-  ss << d_namePrefix << "_" << d_pfs.size();
-  std::shared_ptr<LazyCDProof> pf = std::make_shared<LazyCDProof>(
-      d_pnm, nullptr, isCd ? d_contextUse : nullptr, ss.str());
-  d_pfs.push_back(pf);
-  return pf.get();
-}
-
-}  // namespace CVC4
diff --git a/src/expr/lazy_proof_set.h b/src/expr/lazy_proof_set.h
deleted file mode 100644 (file)
index 3501aab..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*********************                                                        */
-/*! \file lazy_proof_set.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 Lazy proof set utility
- **/
-
-#include "cvc4_private.h"
-
-#ifndef CVC4__EXPR__LAZY_PROOF_SET_H
-#define CVC4__EXPR__LAZY_PROOF_SET_H
-
-#include <memory>
-
-#include "context/cdlist.h"
-#include "context/context.h"
-#include "expr/lazy_proof.h"
-
-namespace CVC4 {
-
-/**
- * A (context-dependent) set of lazy proofs, which is used for memory
- * management purposes.
- */
-class LazyCDProofSet
-{
- public:
-  LazyCDProofSet(ProofNodeManager* pnm,
-                 context::Context* c = nullptr,
-                 std::string namePrefix = "LazyCDProof");
-  ~LazyCDProofSet() {}
-  /**
-   * Allocate a lazy proof. This returns a fresh lazy proof object that
-   * remains alive in the context given to this class.  Internally, this adds a
-   * LazyCDProof to the list d_pfs below.
-   *
-   * @param isCd Whether the proof is context-dependent (using the same context
-   * that is provided to this class).
-   */
-  LazyCDProof* allocateProof(bool isCd = false);
-
- protected:
-  /** The proof node manager */
-  ProofNodeManager* d_pnm;
-  /** A dummy context used by this class if none is provided */
-  context::Context d_context;
-  /**
-   * The context we are using (either the one provided in the constructor or
-   * d_context).
-   */
-  context::Context* d_contextUse;
-  /** A context-dependent list of lazy proofs. */
-  context::CDList<std::shared_ptr<LazyCDProof> > d_pfs;
-  /** The name prefix of the lazy proofs */
-  std::string d_namePrefix;
-};
-
-}  // namespace CVC4
-
-#endif /* CVC4__EXPR__LAZY_PROOF_SET_H */
diff --git a/src/expr/proof_set.h b/src/expr/proof_set.h
new file mode 100644 (file)
index 0000000..20ef67e
--- /dev/null
@@ -0,0 +1,75 @@
+/*********************                                                        */
+/*! \file proof_set.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 Proof set utility
+ **/
+
+#include "cvc4_private.h"
+
+#ifndef CVC4__EXPR__PROOF_SET_H
+#define CVC4__EXPR__PROOF_SET_H
+
+#include <memory>
+
+#include "context/cdlist.h"
+#include "context/context.h"
+#include "expr/proof_node_manager.h"
+
+namespace CVC4 {
+
+/**
+ * A (context-dependent) set of proofs, which is used for memory
+ * management purposes.
+ */
+template <typename T>
+class CDProofSet
+{
+ public:
+  CDProofSet(ProofNodeManager* pnm,
+             context::Context* c,
+             std::string namePrefix = "Proof")
+      : d_pnm(pnm), d_proofs(c), d_namePrefix(namePrefix)
+  {
+  }
+  /**
+   * Allocate a new proof.
+   *
+   * This returns a fresh proof object that remains alive in the context given
+   * to this class. Internally, this adds a new proof of type T to a
+   * context-dependent list of proofs and passes the following arguments to the
+   * T constructor:
+   *   pnm, args..., name
+   * where pnm is the proof node manager
+   * provided to this proof set upon construction, args... are the arguments to
+   * allocateProof() and name is the namePrefix with an appended index.
+   */
+  template <typename... Args>
+  T* allocateProof(Args&&... args)
+  {
+    d_proofs.push_back(std::make_shared<T>(
+        d_pnm,
+        std::forward<Args>(args)...,
+        d_namePrefix + "_" + std::to_string(d_proofs.size())));
+    return d_proofs.back().get();
+  }
+
+ protected:
+  /** The proof node manager */
+  ProofNodeManager* d_pnm;
+  /** A context-dependent list of lazy proofs. */
+  context::CDList<std::shared_ptr<T>> d_proofs;
+  /** The name prefix of the lazy proofs */
+  std::string d_namePrefix;
+};
+
+}  // namespace CVC4
+
+#endif /* CVC4__EXPR__LAZY_PROOF_SET_H */
index 465e7a471117dc26bb07c0c50a9ddd228ebf061d..bab56a0d2aa30e0ea4218bad899fd702b32c0116 100644 (file)
@@ -28,8 +28,9 @@ PreprocessProofGenerator::PreprocessProofGenerator(ProofNodeManager* pnm,
                                                    PfRule ra,
                                                    PfRule rpp)
     : d_pnm(pnm),
-      d_src(c ? c : &d_context),
-      d_helperProofs(pnm, c ? c : &d_context),
+      d_ctx(c ? c : &d_context),
+      d_src(d_ctx),
+      d_helperProofs(pnm, d_ctx),
       d_inputPf(pnm, nullptr),
       d_name(name),
       d_ra(ra),
@@ -227,7 +228,7 @@ ProofNodeManager* PreprocessProofGenerator::getManager() { return d_pnm; }
 
 LazyCDProof* PreprocessProofGenerator::allocateHelperProof()
 {
-  return d_helperProofs.allocateProof();
+  return d_helperProofs.allocateProof(nullptr, d_ctx);
 }
 
 std::string PreprocessProofGenerator::identify() const { return d_name; }
index a0c090ad73e0d374d4638ceea12d06c114c15b1e..41add5583be7b6dd1ca9a86353cf573a27a65bf0 100644 (file)
@@ -22,7 +22,7 @@
 #include "context/cdhashmap.h"
 #include "context/cdlist.h"
 #include "expr/lazy_proof.h"
-#include "expr/lazy_proof_set.h"
+#include "expr/proof_set.h"
 #include "expr/proof_generator.h"
 #include "expr/proof_node_manager.h"
 #include "theory/eager_proof_generator.h"
@@ -118,6 +118,8 @@ class PreprocessProofGenerator : public ProofGenerator
   ProofNodeManager* d_pnm;
   /** A dummy context used by this class if none is provided */
   context::Context d_context;
+  /** The context used here */
+  context::Context* d_ctx;
   /**
    * The trust node that was the source of each node constructed during
    * preprocessing. For each n, d_src[n] is a trust node whose node is n. This
@@ -127,7 +129,7 @@ class PreprocessProofGenerator : public ProofGenerator
    */
   NodeTrustNodeMap d_src;
   /** A context-dependent list of LazyCDProof, allocated for conjoin steps */
-  LazyCDProofSet d_helperProofs;
+  CDProofSet<LazyCDProof> d_helperProofs;
   /**
    * A cd proof for input assertions, this is an empty proof that intentionally
    * returns (ASSUME f) for all f.
index 27159f96437a8aa9744bf61159e2853d5eafb2d0..aaa3b44f7e61785852d495086f475909cd2ed645 100644 (file)
@@ -24,7 +24,8 @@ TrustSubstitutionMap::TrustSubstitutionMap(context::Context* c,
                                            std::string name,
                                            PfRule trustId,
                                            MethodId ids)
-    : d_subs(c),
+    : d_ctx(c),
+      d_subs(c),
       d_pnm(pnm),
       d_tsubs(c),
       d_tspb(pnm ? new TheoryProofStepBuffer(pnm->getChecker()) : nullptr),
@@ -68,7 +69,7 @@ void TrustSubstitutionMap::addSubstitution(TNode x,
     addSubstitution(x, t, nullptr);
     return;
   }
-  LazyCDProof* stepPg = d_helperPf.allocateProof();
+  LazyCDProof* stepPg = d_helperPf.allocateProof(nullptr, d_ctx);
   Node eq = x.eqNode(t);
   stepPg->addStep(eq, id, {}, args);
   addSubstitution(x, t, stepPg);
@@ -99,7 +100,7 @@ ProofGenerator* TrustSubstitutionMap::addSubstitutionSolved(TNode x,
     Trace("trust-subs") << "...use generator directly" << std::endl;
     return tn.getGenerator();
   }
-  LazyCDProof* solvePg = d_helperPf.allocateProof();
+  LazyCDProof* solvePg = d_helperPf.allocateProof(nullptr, d_ctx);
   // Try to transform tn.getProven() to (= x t) here, if necessary
   if (!d_tspb->applyPredTransform(proven, eq, {}))
   {
index d7f48d05462e51ef1151543824637a0f61ed7e7b..c316f08c544d265773ad9aac1bbfb825f18f8207 100644 (file)
@@ -20,8 +20,8 @@
 #include "context/cdlist.h"
 #include "context/context.h"
 #include "expr/lazy_proof.h"
-#include "expr/lazy_proof_set.h"
 #include "expr/proof_node_manager.h"
+#include "expr/proof_set.h"
 #include "expr/term_conversion_proof_generator.h"
 #include "theory/eager_proof_generator.h"
 #include "theory/substitutions.h"
@@ -94,6 +94,8 @@ class TrustSubstitutionMap
    * Moreover, it ensures that d_subsPg has a proof of the returned value.
    */
   Node getCurrentSubstitution();
+  /** The context used here */
+  context::Context* d_ctx;
   /** The substitution map */
   SubstitutionMap d_subs;
   /** The proof node manager */
@@ -109,7 +111,7 @@ class TrustSubstitutionMap
   /**
    * A context-dependent list of LazyCDProof, allocated for internal steps.
    */
-  LazyCDProofSet d_helperPf;
+  CDProofSet<LazyCDProof> d_helperPf;
   /**
    * The formula corresponding to the current substitution. This is of the form
    *   (and (= x1 t1) ... (= xn tn))