1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Dejan Jovanovic, Gereon Kremer |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Base class for shared solver. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__SHARED_SOLVER__H |
19 |
|
#define CVC5__THEORY__SHARED_SOLVER__H |
20 |
|
|
21 |
|
#include "expr/node.h" |
22 |
|
#include "theory/inference_id.h" |
23 |
|
#include "theory/shared_terms_database.h" |
24 |
|
#include "theory/term_registration_visitor.h" |
25 |
|
#include "theory/valuation.h" |
26 |
|
|
27 |
|
namespace cvc5 { |
28 |
|
|
29 |
|
class LogicInfo; |
30 |
|
class ProofNodeManager; |
31 |
|
class TheoryEngine; |
32 |
|
|
33 |
|
namespace theory { |
34 |
|
|
35 |
|
struct EeSetupInfo; |
36 |
|
class TheoryInferenceManager; |
37 |
|
|
38 |
|
/** |
39 |
|
* A base class for shared solver. The shared solver is the component of theory |
40 |
|
* engine that behaves like a theory solver, and whose purpose is to ensure the |
41 |
|
* main theory combination method can be performed in CombinationEngine. |
42 |
|
* Its role is to: |
43 |
|
* (1) Notify the individual theories of shared terms via addSharedTerms, |
44 |
|
* (2) Be the official interface for equality statuses, |
45 |
|
* (3) Propagate equalities to TheoryEngine when necessary and explain them. |
46 |
|
*/ |
47 |
|
class SharedSolver |
48 |
|
{ |
49 |
|
public: |
50 |
|
SharedSolver(TheoryEngine& te, ProofNodeManager* pnm); |
51 |
9925 |
virtual ~SharedSolver() {} |
52 |
|
//------------------------------------- initialization |
53 |
|
/** |
54 |
|
* Returns true if we need an equality engine, this has the same contract |
55 |
|
* as Theory::needsEqualityEngine. |
56 |
|
*/ |
57 |
|
virtual bool needsEqualityEngine(theory::EeSetupInfo& esi); |
58 |
|
/** |
59 |
|
* Set the equality engine. This should be called by equality engine manager |
60 |
|
* during EqEngineManager::initializeTheories. |
61 |
|
*/ |
62 |
|
virtual void setEqualityEngine(eq::EqualityEngine* ee) = 0; |
63 |
|
//------------------------------------- end initialization |
64 |
|
/** |
65 |
|
* Called when the given atom is pre-registered in TheoryEngine. |
66 |
|
* |
67 |
|
* This calls Theory::preRegisterTerm on all subterms of atom for the |
68 |
|
* appropriate theories. |
69 |
|
* |
70 |
|
* Also, if sharing is enabled, this adds atom as an equality to propagate in |
71 |
|
* the shared terms database if it is an equality, and adds its shared terms |
72 |
|
* to the appropariate theories. |
73 |
|
* |
74 |
|
* @param atom The atom to preregister |
75 |
|
*/ |
76 |
|
void preRegister(TNode atom); |
77 |
|
/** |
78 |
|
* Pre-notify assertion fact with the given atom. This is called when any |
79 |
|
* fact is asserted in TheoryEngine, just before it is dispatched to the |
80 |
|
* appropriate theory. |
81 |
|
* |
82 |
|
* This calls Theory::notifySharedTerm for the shared terms of the atom. |
83 |
|
*/ |
84 |
|
void preNotifySharedFact(TNode atom); |
85 |
|
/** |
86 |
|
* Get the equality status of a and b. |
87 |
|
* |
88 |
|
* This method is used by theories via Valuation mostly for determining their |
89 |
|
* care graph. |
90 |
|
*/ |
91 |
|
virtual EqualityStatus getEqualityStatus(TNode a, TNode b); |
92 |
|
/** |
93 |
|
* Explain literal, which returns a conjunction of literals that entail |
94 |
|
* the given one. |
95 |
|
*/ |
96 |
|
virtual TrustNode explain(TNode literal, TheoryId id) = 0; |
97 |
|
/** |
98 |
|
* Assert n to the shared terms database. |
99 |
|
* |
100 |
|
* This method is called by TheoryEngine when a fact has been marked to |
101 |
|
* send to THEORY_BUILTIN, meaning that shared terms database should |
102 |
|
* maintain this fact. In the distributed equality engine architecture, |
103 |
|
* this is the case when either an equality is asserted from the SAT solver |
104 |
|
* or a theory propagates an equality between shared terms. |
105 |
|
*/ |
106 |
|
virtual void assertShared(TNode n, bool polarity, TNode reason) = 0; |
107 |
|
/** Is term t a shared term? */ |
108 |
|
virtual bool isShared(TNode t) const; |
109 |
|
|
110 |
|
/** |
111 |
|
* Propagate the predicate with polarity value on the output channel of this |
112 |
|
* solver. |
113 |
|
*/ |
114 |
|
bool propagateLit(TNode predicate, bool value); |
115 |
|
/** |
116 |
|
* Method called by equalityEngine when a becomes (dis-)equal to b and a and b |
117 |
|
* are shared with the theory. Returns false if there is a direct conflict |
118 |
|
* (via rewrite for example). |
119 |
|
*/ |
120 |
|
bool propagateSharedEquality(theory::TheoryId theory, |
121 |
|
TNode a, |
122 |
|
TNode b, |
123 |
|
bool value); |
124 |
|
/** Send lemma to the theory engine, atomsTo is the theory to send atoms to */ |
125 |
|
void sendLemma(TrustNode trn, TheoryId atomsTo, InferenceId id); |
126 |
|
/** Send conflict to the theory engine */ |
127 |
|
void sendConflict(TrustNode trn, InferenceId id); |
128 |
|
|
129 |
|
protected: |
130 |
|
/** Solver-specific pre-register shared */ |
131 |
|
virtual void preRegisterSharedInternal(TNode t) = 0; |
132 |
|
/** Reference to the theory engine */ |
133 |
|
TheoryEngine& d_te; |
134 |
|
/** Logic info of theory engine (cached) */ |
135 |
|
const LogicInfo& d_logicInfo; |
136 |
|
/** The database of shared terms.*/ |
137 |
|
SharedTermsDatabase d_sharedTerms; |
138 |
|
/** Default visitor for pre-registration */ |
139 |
|
PreRegisterVisitor d_preRegistrationVisitor; |
140 |
|
/** Visitor for collecting shared terms */ |
141 |
|
SharedTermsVisitor d_sharedTermsVisitor; |
142 |
|
/** Theory inference manager of theory builtin */ |
143 |
|
TheoryInferenceManager* d_im; |
144 |
|
}; |
145 |
|
|
146 |
|
} // namespace theory |
147 |
|
} // namespace cvc5 |
148 |
|
|
149 |
|
#endif /* CVC5__THEORY__SHARED_SOLVER__H */ |