Eliminate more hard coded uses of user context (#7309)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Wed, 6 Oct 2021 15:12:17 +0000 (10:12 -0500)
committerGitHub <noreply@github.com>
Wed, 6 Oct 2021 15:12:17 +0000 (15:12 +0000)
This is in preparation to make the "lemma context" configurable.

18 files changed:
src/theory/arith/congruence_manager.cpp
src/theory/arith/congruence_manager.h
src/theory/arith/nl/nonlinear_extension.cpp
src/theory/ext_theory.cpp
src/theory/ext_theory.h
src/theory/quantifiers/candidate_rewrite_filter.cpp
src/theory/quantifiers/candidate_rewrite_filter.h
src/theory/quantifiers/dynamic_rewrite.cpp
src/theory/quantifiers/dynamic_rewrite.h
src/theory/relevance_manager.cpp
src/theory/relevance_manager.h
src/theory/shared_terms_database.cpp
src/theory/shared_terms_database.h
src/theory/strings/theory_strings.cpp
src/theory/theory_engine_proof_generator.cpp
src/theory/theory_engine_proof_generator.h
src/theory/uf/proof_equality_engine.cpp
src/theory/uf/proof_equality_engine.h

index f7d274484b9f507abe9895a2370e3f246035347d..e419f3ae1d54dafbfe79d306935277a5a1b051f6 100644 (file)
@@ -53,8 +53,6 @@ ArithCongruenceManager::ArithCongruenceManager(
       d_setupLiteral(setup),
       d_avariables(avars),
       d_ee(nullptr),
-      d_satContext(context()),
-      d_userContext(userContext()),
       d_pnm(d_env.isTheoryProofProducing() ? d_env.getProofNodeManager()
                                            : nullptr),
       // Construct d_pfGenEe with the SAT context, since its proof include
@@ -84,13 +82,13 @@ void ArithCongruenceManager::finishInit(eq::EqualityEngine* ee)
   {
     // use our own copy
     d_allocEe.reset(
-        new eq::EqualityEngine(d_notify, d_satContext, "arithCong::ee", true));
+        new eq::EqualityEngine(d_notify, context(), "arithCong::ee", true));
     d_ee = d_allocEe.get();
     if (d_pnm != nullptr)
     {
       // allocate an internal proof equality engine
       d_allocPfee.reset(
-          new eq::ProofEqEngine(d_satContext, d_userContext, *d_ee, d_pnm));
+          new eq::ProofEqEngine(context(), userContext(), *d_ee, d_pnm));
       d_ee->setProofEqualityEngine(d_allocPfee.get());
     }
   }
index 3050f5821216be08f990b845ea59b2ee02656bec..b847c63ae91b19330aec507c4e842b6ff3fb230b 100644 (file)
@@ -114,11 +114,6 @@ class ArithCongruenceManager : protected EnvObj
   eq::EqualityEngine* d_ee;
   /** The equality engine we allocated */
   std::unique_ptr<eq::EqualityEngine> d_allocEe;
-  /** The sat context */
-  context::Context* d_satContext;
-  /** The user context */
-  context::UserContext* d_userContext;
-
   /** proof manager */
   ProofNodeManager* d_pnm;
   /** A proof generator for storing proofs of facts that are asserted to the EQ
index 207907fcc651d2404059bfc20fae946ddcf98c97..a970abc457e5e60a429366b82586f2d34ccb8090 100644 (file)
@@ -47,7 +47,7 @@ NonlinearExtension::NonlinearExtension(Env& env,
       d_hasNlTerms(false),
       d_checkCounter(0),
       d_extTheoryCb(state.getEqualityEngine()),
-      d_extTheory(d_extTheoryCb, context(), userContext(), d_im),
+      d_extTheory(env, d_extTheoryCb, d_im),
       d_model(),
       d_trSlv(d_im, d_model, d_env),
       d_extState(d_im, d_model, d_env),
index 627129c3ab5a5a06f5e0819ee8d7e54f1d62bd28..9eb6e3cdc4bb96c9002156cff066a884a6bb5766 100644 (file)
@@ -81,18 +81,16 @@ bool ExtTheoryCallback::getReduction(int effort,
   return false;
 }
 
-ExtTheory::ExtTheory(ExtTheoryCallback& p,
-                     context::Context* c,
-                     context::UserContext* u,
-                     TheoryInferenceManager& im)
-    : d_parent(p),
+ExtTheory::ExtTheory(Env& env, ExtTheoryCallback& p, TheoryInferenceManager& im)
+    : EnvObj(env),
+      d_parent(p),
       d_im(im),
-      d_ext_func_terms(c),
-      d_extfExtReducedIdMap(c),
-      d_ci_inactive(u),
-      d_has_extf(c),
-      d_lemmas(u),
-      d_pp_lemmas(u)
+      d_ext_func_terms(context()),
+      d_extfExtReducedIdMap(context()),
+      d_ci_inactive(userContext()),
+      d_has_extf(context()),
+      d_lemmas(userContext()),
+      d_pp_lemmas(userContext())
 {
   d_true = NodeManager::currentNM()->mkConst(true);
 }
@@ -260,7 +258,7 @@ bool ExtTheory::doInferencesInternal(int effort,
         bool processed = false;
         if (sterms[i] != terms[i])
         {
-          Node sr = Rewriter::rewrite(sterms[i]);
+          Node sr = rewrite(sterms[i]);
           // ask the theory if this term is reduced, e.g. is it constant or it
           // is a non-extf term.
           ExtReducedId id;
index 01b191e0afc79029af98f30b7a0e44b8e16a4bda..998dac14627739e6cce14a41681a3f65b5f86332 100644 (file)
@@ -41,6 +41,7 @@
 #include "context/cdo.h"
 #include "context/context.h"
 #include "expr/node.h"
+#include "smt/env_obj.h"
 #include "theory/theory_inference_manager.h"
 
 namespace cvc5 {
@@ -163,7 +164,7 @@ class ExtTheoryCallback
  * underlying theory for a "derivable substitution", whereby extended functions
  * may be reducable.
  */
-class ExtTheory
+class ExtTheory : protected EnvObj
 {
   using NodeBoolMap = context::CDHashMap<Node, bool>;
   using NodeExtReducedIdMap = context::CDHashMap<Node, ExtReducedId>;
@@ -174,10 +175,7 @@ class ExtTheory
    *
    * If cacheEnabled is false, we do not cache results of getSubstitutedTerm.
    */
-  ExtTheory(ExtTheoryCallback& p,
-            context::Context* c,
-            context::UserContext* u,
-            TheoryInferenceManager& im);
+  ExtTheory(Env& env, ExtTheoryCallback& p, TheoryInferenceManager& im);
   virtual ~ExtTheory() {}
   /** Tells this class to treat terms with Kind k as extended functions */
   void addFunctionKind(Kind k) { d_extf_kind[k] = true; }
index d5f06b6e9ffc6dba7aa78a05bb2785c92066dee5..da3e506fc0563cc8d203ba8cabe0a2c6abec5b5e 100644 (file)
@@ -54,7 +54,7 @@ void CandidateRewriteFilter::initialize(SygusSampler* ss,
   ssn << "_dyn_rewriter_" << drewrite_counter;
   drewrite_counter++;
   d_drewrite = std::unique_ptr<DynamicRewriter>(
-      new DynamicRewriter(ssn.str(), &d_fake_context));
+      new DynamicRewriter(ssn.str(), &d_fakeContext));
 }
 
 bool CandidateRewriteFilter::filterPair(Node n, Node eq_n)
index 4995dc7c2494921af2036568377de2686b0280d5..5276327867bf6cd9a4822bd5edd7737bac96010d 100644 (file)
@@ -104,8 +104,8 @@ class CandidateRewriteFilter
   bool d_use_sygus_type;
 
   //----------------------------congruence filtering
-  /** a (dummy) user context, used for d_drewrite */
-  context::UserContext d_fake_context;
+  /** a (dummy) context, used for d_drewrite */
+  context::Context d_fakeContext;
   /** dynamic rewriter class */
   std::unique_ptr<DynamicRewriter> d_drewrite;
   //----------------------------end congruence filtering
index 4d69ea73212ebe9fed4aed6f6dd9d5f5342248c5..1fc08b288ef2cad82ae0579a82157f2a197ca8f5 100644 (file)
@@ -25,9 +25,8 @@ namespace cvc5 {
 namespace theory {
 namespace quantifiers {
 
-DynamicRewriter::DynamicRewriter(const std::string& name,
-                                 context::UserContext* u)
-    : d_equalityEngine(u, "DynamicRewriter::" + name, true), d_rewrites(u)
+DynamicRewriter::DynamicRewriter(const std::string& name, context::Context* c)
+    : d_equalityEngine(c, "DynamicRewriter::" + name, true), d_rewrites(c)
 {
   d_equalityEngine.addFunctionKind(kind::APPLY_UF);
 }
index 3187b7c03ef06c015bc413bf25519c4fcc7c5dbe..5e1f45b3500bab5c8250357caeabad981e667dde 100644 (file)
@@ -55,7 +55,7 @@ class DynamicRewriter
   typedef context::CDList<Node> NodeList;
 
  public:
-  DynamicRewriter(const std::string& name, context::UserContext* u);
+  DynamicRewriter(const std::string& name, context::Context* c);
   ~DynamicRewriter() {}
   /** inform this class that the equality a = b holds. */
   void addRewrite(Node a, Node b);
index e1a3421788564226231f626ba677e5575c254f5a..a83167591d9054858509aa3989075a1019d96881 100644 (file)
@@ -25,10 +25,9 @@ using namespace cvc5::kind;
 namespace cvc5 {
 namespace theory {
 
-RelevanceManager::RelevanceManager(context::UserContext* userContext,
-                                   Valuation val)
+RelevanceManager::RelevanceManager(context::Context* lemContext, Valuation val)
     : d_val(val),
-      d_input(userContext),
+      d_input(lemContext),
       d_computed(false),
       d_success(false),
       d_trackRSetExp(false),
@@ -36,7 +35,7 @@ RelevanceManager::RelevanceManager(context::UserContext* userContext,
 {
   if (options::produceDifficulty())
   {
-    d_dman.reset(new DifficultyManager(userContext, val));
+    d_dman.reset(new DifficultyManager(lemContext, val));
     d_trackRSetExp = true;
     // we cannot miniscope AND at the top level, since we need to
     // preserve the exact form of preprocessed assertions so the dependencies
index f8cd8e1eece9f4285d984b45650bb8600ee9d171..287694445c0bc5f58d84d71a3f7a7a8a2e35bd59 100644 (file)
@@ -76,7 +76,11 @@ class RelevanceManager
   typedef context::CDList<Node> NodeList;
 
  public:
-  RelevanceManager(context::UserContext* userContext, Valuation val);
+  /**
+   * @param lemContext The context which lemmas live at
+   * @param val The valuation class, for computing what is relevant.
+   */
+  RelevanceManager(context::Context* lemContext, Valuation val);
   /**
    * Notify (preprocessed) assertions. This is called for input formulas or
    * lemmas that need justification that have been fully processed, just before
index e4f1b6fabd014d0a8f3cb0bcfcdf3e43f99a0258..6c0f6ae10dbec384612db0141143a85ce2f4e6c2 100644 (file)
@@ -37,8 +37,6 @@ SharedTermsDatabase::SharedTermsDatabase(Env& env, TheoryEngine* theoryEngine)
       d_theoryEngine(theoryEngine),
       d_inConflict(env.getContext(), false),
       d_conflictPolarity(),
-      d_satContext(env.getContext()),
-      d_userContext(env.getUserContext()),
       d_equalityEngine(nullptr),
       d_pfee(nullptr)
 {
@@ -55,8 +53,8 @@ void SharedTermsDatabase::setEqualityEngine(eq::EqualityEngine* ee)
     if (d_pfee == nullptr)
     {
       ProofNodeManager* pnm = d_env.getProofNodeManager();
-      d_pfeeAlloc.reset(
-          new eq::ProofEqEngine(d_satContext, d_userContext, *ee, pnm));
+      d_pfeeAlloc.reset(new eq::ProofEqEngine(
+          d_env.getContext(), d_env.getUserContext(), *ee, pnm));
       d_pfee = d_pfeeAlloc.get();
       d_equalityEngine->setProofEqualityEngine(d_pfee);
     }
index 3b21c27a8dad195a48b30e19463ee1555d33ba1c..2bdb9d57425fc175bd122f3013f1e91d34dff865 100644 (file)
@@ -266,10 +266,6 @@ class SharedTermsDatabase : public context::ContextNotifyObj {
    * This method gets called on backtracks from the context manager.
    */
   void contextNotifyPop() override { backtrack(); }
-  /** The SAT search context. */
-  context::Context* d_satContext;
-  /** The user level assertion context. */
-  context::UserContext* d_userContext;
   /** Equality engine */
   theory::eq::EqualityEngine* d_equalityEngine;
   /** Proof equality engine, if we allocated one */
index ac6d9b6118316cca6f9724492e940797219b667c..27640341add5eac034dce4704e361dcee0fb1016 100644 (file)
@@ -59,7 +59,7 @@ TheoryStrings::TheoryStrings(Env& env, OutputChannel& out, Valuation valuation)
       d_termReg(env, d_state, d_statistics, d_pnm),
       d_extTheoryCb(),
       d_im(env, *this, d_state, d_termReg, d_extTheory, d_statistics, d_pnm),
-      d_extTheory(d_extTheoryCb, context(), userContext(), d_im),
+      d_extTheory(env, d_extTheoryCb, d_im),
       d_rewriter(env.getRewriter(), &d_statistics.d_rewrites),
       d_bsolver(env, d_state, d_im),
       d_csolver(env, d_state, d_im, d_termReg, d_bsolver),
index 073accdaed4c2d76c79f42b7242235fb7d14df8e..eaa9a17461ec277dfd9420010670c22222e52e6f 100644 (file)
@@ -24,8 +24,8 @@ using namespace cvc5::kind;
 namespace cvc5 {
 
 TheoryEngineProofGenerator::TheoryEngineProofGenerator(ProofNodeManager* pnm,
-                                                       context::UserContext* u)
-    : d_pnm(pnm), d_proofs(u)
+                                                       context::Context* c)
+    : d_pnm(pnm), d_proofs(c)
 {
   d_false = NodeManager::currentNM()->mkConst(false);
 }
index 68f7dea32db50f6df7d5058147021d0513a91b59..1cb99b0397a0057e60a5fa03fdabe97562f84a04 100644 (file)
@@ -42,7 +42,7 @@ class TheoryEngineProofGenerator : public ProofGenerator
       NodeLazyCDProofMap;
 
  public:
-  TheoryEngineProofGenerator(ProofNodeManager* pnm, context::UserContext* u);
+  TheoryEngineProofGenerator(ProofNodeManager* pnm, context::Context* c);
   ~TheoryEngineProofGenerator() {}
   /**
    * Make trust explanation. Called when lpf has a proof of lit from free
index ca8b3f74042eb99b4c6f9a726660a4660cb6809a..b6e44533407ea063851741b0bef6a97852935ca8 100644 (file)
@@ -30,10 +30,10 @@ namespace theory {
 namespace eq {
 
 ProofEqEngine::ProofEqEngine(context::Context* c,
-                             context::UserContext* u,
+                             context::Context* lc,
                              EqualityEngine& ee,
                              ProofNodeManager* pnm)
-    : EagerProofGenerator(pnm, u, "pfee::" + ee.identify()),
+    : EagerProofGenerator(pnm, lc, "pfee::" + ee.identify()),
       d_ee(ee),
       d_factPg(c, pnm),
       d_assumpPg(pnm),
index baf155dac9fd24eaea0305c978e08346b2d46e50..9ebdd03e5cc1da5cfe4303f272e58bb13c3702d5 100644 (file)
@@ -85,8 +85,14 @@ class ProofEqEngine : public EagerProofGenerator
   typedef context::CDHashMap<Node, std::shared_ptr<ProofNode>> NodeProofMap;
 
  public:
+  /**
+   * @param c The SAT context
+   * @param lc The context lemmas live in
+   * @param ee The equality engine this is layered on
+   * @param pnm The proof node manager for producing proof nodes.
+   */
   ProofEqEngine(context::Context* c,
-                context::UserContext* u,
+                context::Context* lc,
                 EqualityEngine& ee,
                 ProofNodeManager* pnm);
   ~ProofEqEngine() {}