1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Morgan Deters, Andrew Reynolds, Tim King |
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 |
|
* The theory output channel interface. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__OUTPUT_CHANNEL_H |
19 |
|
#define CVC5__THEORY__OUTPUT_CHANNEL_H |
20 |
|
|
21 |
|
#include "proof/trust_node.h" |
22 |
|
#include "theory/incomplete_id.h" |
23 |
|
#include "util/resource_manager.h" |
24 |
|
|
25 |
|
namespace cvc5 { |
26 |
|
namespace theory { |
27 |
|
|
28 |
|
/** Properties of lemmas */ |
29 |
|
enum class LemmaProperty : uint32_t |
30 |
|
{ |
31 |
|
// default |
32 |
|
NONE = 0, |
33 |
|
// whether the lemma is removable |
34 |
|
REMOVABLE = 1, |
35 |
|
// whether the processing of the lemma should send atoms to the caller |
36 |
|
SEND_ATOMS = 2, |
37 |
|
// whether the lemma is part of the justification for answering "sat" |
38 |
|
NEEDS_JUSTIFY = 4 |
39 |
|
}; |
40 |
|
/** Define operator lhs | rhs */ |
41 |
|
LemmaProperty operator|(LemmaProperty lhs, LemmaProperty rhs); |
42 |
|
/** Define operator lhs |= rhs */ |
43 |
|
LemmaProperty& operator|=(LemmaProperty& lhs, LemmaProperty rhs); |
44 |
|
/** Define operator lhs & rhs */ |
45 |
|
LemmaProperty operator&(LemmaProperty lhs, LemmaProperty rhs); |
46 |
|
/** Define operator lhs &= rhs */ |
47 |
|
LemmaProperty& operator&=(LemmaProperty& lhs, LemmaProperty rhs); |
48 |
|
/** is the removable bit set on p? */ |
49 |
|
bool isLemmaPropertyRemovable(LemmaProperty p); |
50 |
|
/** is the send atoms bit set on p? */ |
51 |
|
bool isLemmaPropertySendAtoms(LemmaProperty p); |
52 |
|
/** is the needs justify bit set on p? */ |
53 |
|
bool isLemmaPropertyNeedsJustify(LemmaProperty p); |
54 |
|
|
55 |
|
/** |
56 |
|
* Writes an lemma property name to a stream. |
57 |
|
* |
58 |
|
* @param out The stream to write to |
59 |
|
* @param p The lemma property to write to the stream |
60 |
|
* @return The stream |
61 |
|
*/ |
62 |
|
std::ostream& operator<<(std::ostream& out, LemmaProperty p); |
63 |
|
|
64 |
|
class Theory; |
65 |
|
|
66 |
|
/** |
67 |
|
* Generic "theory output channel" interface. |
68 |
|
* |
69 |
|
* All methods can throw unrecoverable cvc5::Exception's unless otherwise |
70 |
|
* documented. |
71 |
|
*/ |
72 |
|
class OutputChannel { |
73 |
|
public: |
74 |
|
/** Construct an OutputChannel. */ |
75 |
81656 |
OutputChannel() {} |
76 |
|
|
77 |
|
/** |
78 |
|
* Destructs an OutputChannel. This implementation does nothing, |
79 |
|
* but we need a virtual destructor for safety in case subclasses |
80 |
|
* have a destructor. |
81 |
|
*/ |
82 |
81617 |
virtual ~OutputChannel() {} |
83 |
|
|
84 |
|
OutputChannel(const OutputChannel&) = delete; |
85 |
|
OutputChannel& operator=(const OutputChannel&) = delete; |
86 |
|
|
87 |
|
/** |
88 |
|
* With safePoint(), the theory signals that it is at a safe point |
89 |
|
* and can be interrupted. |
90 |
|
* |
91 |
|
* @throws Interrupted if the theory can be safely interrupted. |
92 |
|
*/ |
93 |
|
virtual void safePoint(Resource r) {} |
94 |
|
|
95 |
|
/** |
96 |
|
* Indicate a theory conflict has arisen. |
97 |
|
* |
98 |
|
* @param n - a conflict at the current decision level. This should |
99 |
|
* be an AND-kinded node of literals that are TRUE in the current |
100 |
|
* assignment and are in conflict (i.e., at least one must be |
101 |
|
* assigned false), or else a literal by itself (in the case of a |
102 |
|
* unit conflict) which is assigned TRUE (and T-conflicting) in the |
103 |
|
* current assignment. |
104 |
|
*/ |
105 |
|
virtual void conflict(TNode n) = 0; |
106 |
|
|
107 |
|
/** |
108 |
|
* Propagate a theory literal. |
109 |
|
* |
110 |
|
* @param n - a theory consequence at the current decision level |
111 |
|
* @return false if an immediate conflict was encountered |
112 |
|
*/ |
113 |
|
virtual bool propagate(TNode n) = 0; |
114 |
|
|
115 |
|
/** |
116 |
|
* Tell the core that a valid theory lemma at decision level 0 has |
117 |
|
* been detected. (This requests a split.) |
118 |
|
* |
119 |
|
* @param n - a theory lemma valid at decision level 0 |
120 |
|
* @param p The properties of the lemma |
121 |
|
*/ |
122 |
|
virtual void lemma(TNode n, LemmaProperty p = LemmaProperty::NONE) = 0; |
123 |
|
|
124 |
|
/** |
125 |
|
* If a decision is made on n, it must be in the phase specified. |
126 |
|
* Note that this is enforced *globally*, i.e., it is completely |
127 |
|
* context-INdependent. If you ever requirePhase() on a literal, |
128 |
|
* it is phase-locked forever and ever. If it is to ever have the |
129 |
|
* other phase as its assignment, it will be because it has been |
130 |
|
* propagated that way (or it's a unit, at decision level 0). |
131 |
|
* |
132 |
|
* @param n - a theory atom with a SAT literal assigned; must have |
133 |
|
* been pre-registered |
134 |
|
* @param phase - the phase to decide on n |
135 |
|
*/ |
136 |
|
virtual void requirePhase(TNode n, bool phase) = 0; |
137 |
|
|
138 |
|
/** |
139 |
|
* Notification from a theory that it realizes it is incomplete at |
140 |
|
* this context level. If SAT is later determined by the |
141 |
|
* TheoryEngine, it should actually return an UNKNOWN result. |
142 |
|
*/ |
143 |
|
virtual void setIncomplete(IncompleteId id) = 0; |
144 |
|
|
145 |
|
/** |
146 |
|
* "Spend" a "resource." The meaning is specific to the context in |
147 |
|
* which the theory is operating, and may even be ignored. The |
148 |
|
* intended meaning is that if the user has set a limit on the "units |
149 |
|
* of resource" that can be expended in a search, and that limit is |
150 |
|
* exceeded, then the search is terminated. Note that the check for |
151 |
|
* termination occurs in the main search loop, so while theories |
152 |
|
* should call OutputChannel::spendResource() during particularly |
153 |
|
* long-running operations, they cannot rely on resource() to break |
154 |
|
* out of infinite or intractable computations. |
155 |
|
*/ |
156 |
2 |
virtual void spendResource(Resource r) {} |
157 |
|
|
158 |
|
/** |
159 |
|
* Handle user attribute. |
160 |
|
* Associates theory t with the attribute attr. Theory t will be |
161 |
|
* notified whenever an attribute of name attr is set on a node. |
162 |
|
* This can happen through, for example, the SMT-LIBv2 language. |
163 |
|
*/ |
164 |
|
virtual void handleUserAttribute(const char* attr, Theory* t) {} |
165 |
|
|
166 |
|
/** Demands that the search restart from sat search level 0. |
167 |
|
* Using this leads to non-termination issues. |
168 |
|
* It is appropriate for prototyping for theories. |
169 |
|
*/ |
170 |
|
virtual void demandRestart() {} |
171 |
|
|
172 |
|
//---------------------------- new proof |
173 |
|
/** |
174 |
|
* Let pconf be the pair (Node conf, ProofGenerator * pfg). This method |
175 |
|
* sends conf on the output channel of this class whose proof can be generated |
176 |
|
* by the generator pfg. Apart from pfg, the interface for this method is |
177 |
|
* the same as OutputChannel. |
178 |
|
*/ |
179 |
|
virtual void trustedConflict(TrustNode pconf); |
180 |
|
/** |
181 |
|
* Let plem be the pair (Node lem, ProofGenerator * pfg). |
182 |
|
* Send lem on the output channel of this class whose proof can be generated |
183 |
|
* by the generator pfg. Apart from pfg, the interface for this method is |
184 |
|
* the same as OutputChannel. |
185 |
|
*/ |
186 |
|
virtual void trustedLemma(TrustNode lem, |
187 |
|
LemmaProperty p = LemmaProperty::NONE); |
188 |
|
//---------------------------- end new proof |
189 |
|
}; /* class OutputChannel */ |
190 |
|
|
191 |
|
} // namespace theory |
192 |
|
} // namespace cvc5 |
193 |
|
|
194 |
|
#endif /* CVC5__THEORY__OUTPUT_CHANNEL_H */ |