1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Gereon Kremer, Aina Niemetz |
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 |
|
* Smt Environment, main access to global utilities available to |
14 |
|
* internal code. |
15 |
|
*/ |
16 |
|
|
17 |
|
#include "smt/env.h" |
18 |
|
|
19 |
|
#include "context/context.h" |
20 |
|
#include "expr/node.h" |
21 |
|
#include "options/base_options.h" |
22 |
|
#include "options/quantifiers_options.h" |
23 |
|
#include "options/smt_options.h" |
24 |
|
#include "options/strings_options.h" |
25 |
|
#include "printer/printer.h" |
26 |
|
#include "proof/conv_proof_generator.h" |
27 |
|
#include "smt/solver_engine_stats.h" |
28 |
|
#include "theory/evaluator.h" |
29 |
|
#include "theory/rewriter.h" |
30 |
|
#include "theory/trust_substitutions.h" |
31 |
|
#include "util/resource_manager.h" |
32 |
|
#include "util/statistics_registry.h" |
33 |
|
|
34 |
|
using namespace cvc5::smt; |
35 |
|
|
36 |
|
namespace cvc5 { |
37 |
|
|
38 |
18654 |
Env::Env(NodeManager* nm, const Options* opts) |
39 |
18654 |
: d_context(new context::Context()), |
40 |
18654 |
d_userContext(new context::UserContext()), |
41 |
|
d_nodeManager(nm), |
42 |
|
d_proofNodeManager(nullptr), |
43 |
18654 |
d_rewriter(new theory::Rewriter()), |
44 |
|
d_evalRew(nullptr), |
45 |
|
d_eval(nullptr), |
46 |
37308 |
d_topLevelSubs(new theory::TrustSubstitutionMap(d_userContext.get())), |
47 |
|
d_logic(), |
48 |
|
d_statisticsRegistry(std::make_unique<StatisticsRegistry>(*this)), |
49 |
|
d_options(), |
50 |
|
d_originalOptions(opts), |
51 |
111924 |
d_resourceManager() |
52 |
|
{ |
53 |
18654 |
if (opts != nullptr) |
54 |
|
{ |
55 |
17766 |
d_options.copyValues(*opts); |
56 |
|
} |
57 |
|
// make the evaluators, which depend on the alphabet of strings |
58 |
37308 |
d_evalRew.reset(new theory::Evaluator(d_rewriter.get(), |
59 |
18654 |
d_options.strings.stringsAlphaCard)); |
60 |
37308 |
d_eval.reset( |
61 |
18654 |
new theory::Evaluator(nullptr, d_options.strings.stringsAlphaCard)); |
62 |
18654 |
d_statisticsRegistry->registerTimer("global::totalTime").start(); |
63 |
18654 |
d_resourceManager = std::make_unique<ResourceManager>(*d_statisticsRegistry, d_options); |
64 |
18654 |
d_rewriter->d_resourceManager = d_resourceManager.get(); |
65 |
18654 |
} |
66 |
|
|
67 |
15905 |
Env::~Env() {} |
68 |
|
|
69 |
7987 |
void Env::setProofNodeManager(ProofNodeManager* pnm) |
70 |
|
{ |
71 |
7987 |
Assert(pnm != nullptr); |
72 |
7987 |
Assert(d_proofNodeManager == nullptr); |
73 |
7987 |
d_proofNodeManager = pnm; |
74 |
7987 |
d_rewriter->setProofNodeManager(pnm); |
75 |
7987 |
d_topLevelSubs->setProofNodeManager(pnm); |
76 |
7987 |
} |
77 |
|
|
78 |
15883 |
void Env::shutdown() |
79 |
|
{ |
80 |
15883 |
d_rewriter.reset(nullptr); |
81 |
|
// d_resourceManager must be destroyed before d_statisticsRegistry |
82 |
15883 |
d_resourceManager.reset(nullptr); |
83 |
15883 |
} |
84 |
|
|
85 |
47705431 |
context::Context* Env::getContext() { return d_context.get(); } |
86 |
|
|
87 |
1819438 |
context::UserContext* Env::getUserContext() { return d_userContext.get(); } |
88 |
|
|
89 |
1311317 |
NodeManager* Env::getNodeManager() const { return d_nodeManager; } |
90 |
|
|
91 |
749173 |
ProofNodeManager* Env::getProofNodeManager() { return d_proofNodeManager; } |
92 |
|
|
93 |
145852 |
bool Env::isSatProofProducing() const |
94 |
|
{ |
95 |
145852 |
return d_proofNodeManager != nullptr |
96 |
176531 |
&& (!d_options.smt.unsatCores |
97 |
62047 |
|| (d_options.smt.unsatCoresMode |
98 |
|
!= options::UnsatCoresMode::ASSUMPTIONS |
99 |
30683 |
&& d_options.smt.unsatCoresMode |
100 |
145852 |
!= options::UnsatCoresMode::PP_ONLY)); |
101 |
|
} |
102 |
|
|
103 |
1342300 |
bool Env::isTheoryProofProducing() const |
104 |
|
{ |
105 |
1342300 |
return d_proofNodeManager != nullptr |
106 |
1612321 |
&& (!d_options.smt.unsatCores |
107 |
524718 |
|| d_options.smt.unsatCoresMode |
108 |
1342300 |
== options::UnsatCoresMode::FULL_PROOF); |
109 |
|
} |
110 |
|
|
111 |
87727157 |
theory::Rewriter* Env::getRewriter() { return d_rewriter.get(); } |
112 |
|
|
113 |
15272 |
theory::Evaluator* Env::getEvaluator(bool useRewriter) |
114 |
|
{ |
115 |
15272 |
return useRewriter ? d_evalRew.get() : d_eval.get(); |
116 |
|
} |
117 |
|
|
118 |
400313 |
theory::TrustSubstitutionMap& Env::getTopLevelSubstitutions() |
119 |
|
{ |
120 |
400313 |
return *d_topLevelSubs.get(); |
121 |
|
} |
122 |
|
|
123 |
7727044 |
const LogicInfo& Env::getLogicInfo() const { return d_logic; } |
124 |
|
|
125 |
6121500 |
StatisticsRegistry& Env::getStatisticsRegistry() |
126 |
|
{ |
127 |
6121500 |
return *d_statisticsRegistry; |
128 |
|
} |
129 |
|
|
130 |
66650686 |
const Options& Env::getOptions() const { return d_options; } |
131 |
|
|
132 |
2 |
const Options& Env::getOriginalOptions() const { return *d_originalOptions; } |
133 |
|
|
134 |
16153954 |
ResourceManager* Env::getResourceManager() const |
135 |
|
{ |
136 |
16153954 |
return d_resourceManager.get(); |
137 |
|
} |
138 |
|
|
139 |
1 |
const Printer& Env::getPrinter() |
140 |
|
{ |
141 |
1 |
return *Printer::getPrinter(d_options.base.outputLanguage); |
142 |
|
} |
143 |
|
|
144 |
336075 |
bool Env::isOutputOn(OutputTag tag) const |
145 |
|
{ |
146 |
336075 |
return d_options.base.outputTagHolder[static_cast<size_t>(tag)]; |
147 |
|
} |
148 |
242437 |
bool Env::isOutputOn(const std::string& tag) const |
149 |
|
{ |
150 |
242437 |
return isOutputOn(options::stringToOutputTag(tag)); |
151 |
|
} |
152 |
27 |
std::ostream& Env::output(const std::string& tag) const |
153 |
|
{ |
154 |
27 |
return output(options::stringToOutputTag(tag)); |
155 |
|
} |
156 |
|
|
157 |
39 |
std::ostream& Env::output(OutputTag tag) const |
158 |
|
{ |
159 |
39 |
if (isOutputOn(tag)) |
160 |
|
{ |
161 |
37 |
return *d_options.base.out; |
162 |
|
} |
163 |
2 |
return cvc5::null_os; |
164 |
|
} |
165 |
|
|
166 |
407120 |
bool Env::isVerboseOn(int64_t level) const |
167 |
|
{ |
168 |
407120 |
return !Configuration::isMuzzledBuild() && d_options.base.verbosity >= level; |
169 |
|
} |
170 |
|
|
171 |
405683 |
std::ostream& Env::verbose(int64_t level) const |
172 |
|
{ |
173 |
405683 |
if (isVerboseOn(level)) |
174 |
|
{ |
175 |
49 |
return *d_options.base.err; |
176 |
|
} |
177 |
405634 |
return cvc5::null_os; |
178 |
|
} |
179 |
|
|
180 |
11 |
std::ostream& Env::warning() const |
181 |
|
{ |
182 |
11 |
return verbose(0); |
183 |
|
} |
184 |
|
|
185 |
986969 |
Node Env::evaluate(TNode n, |
186 |
|
const std::vector<Node>& args, |
187 |
|
const std::vector<Node>& vals, |
188 |
|
bool useRewriter) const |
189 |
|
{ |
190 |
1973938 |
std::unordered_map<Node, Node> visited; |
191 |
1973938 |
return evaluate(n, args, vals, visited, useRewriter); |
192 |
|
} |
193 |
|
|
194 |
1007730 |
Node Env::evaluate(TNode n, |
195 |
|
const std::vector<Node>& args, |
196 |
|
const std::vector<Node>& vals, |
197 |
|
const std::unordered_map<Node, Node>& visited, |
198 |
|
bool useRewriter) const |
199 |
|
{ |
200 |
1007730 |
if (useRewriter) |
201 |
|
{ |
202 |
974436 |
return d_evalRew->eval(n, args, vals, visited); |
203 |
|
} |
204 |
33294 |
return d_eval->eval(n, args, vals, visited); |
205 |
|
} |
206 |
|
|
207 |
1724108 |
Node Env::rewriteViaMethod(TNode n, MethodId idr) |
208 |
|
{ |
209 |
1724108 |
if (idr == MethodId::RW_REWRITE) |
210 |
|
{ |
211 |
1690535 |
return d_rewriter->rewrite(n); |
212 |
|
} |
213 |
33573 |
if (idr == MethodId::RW_EXT_REWRITE) |
214 |
|
{ |
215 |
42 |
return d_rewriter->extendedRewrite(n); |
216 |
|
} |
217 |
33531 |
if (idr == MethodId::RW_REWRITE_EQ_EXT) |
218 |
|
{ |
219 |
237 |
return d_rewriter->rewriteEqualityExt(n); |
220 |
|
} |
221 |
33294 |
if (idr == MethodId::RW_EVALUATE) |
222 |
|
{ |
223 |
33294 |
return evaluate(n, {}, {}, false); |
224 |
|
} |
225 |
|
if (idr == MethodId::RW_IDENTITY) |
226 |
|
{ |
227 |
|
// does nothing |
228 |
|
return n; |
229 |
|
} |
230 |
|
// unknown rewriter |
231 |
|
Unhandled() << "Env::rewriteViaMethod: no rewriter for " << idr |
232 |
|
<< std::endl; |
233 |
|
return n; |
234 |
|
} |
235 |
|
|
236 |
8400834 |
bool Env::isFiniteType(TypeNode tn) const |
237 |
|
{ |
238 |
8400834 |
return isCardinalityClassFinite(tn.getCardinalityClass(), |
239 |
16801668 |
d_options.quantifiers.finiteModelFind); |
240 |
|
} |
241 |
|
|
242 |
31137 |
} // namespace cvc5 |