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/smt_options.h" |
23 |
|
#include "printer/printer.h" |
24 |
|
#include "proof/conv_proof_generator.h" |
25 |
|
#include "smt/dump_manager.h" |
26 |
|
#include "smt/smt_engine_stats.h" |
27 |
|
#include "theory/evaluator.h" |
28 |
|
#include "theory/rewriter.h" |
29 |
|
#include "theory/trust_substitutions.h" |
30 |
|
#include "util/resource_manager.h" |
31 |
|
#include "util/statistics_registry.h" |
32 |
|
|
33 |
|
using namespace cvc5::smt; |
34 |
|
|
35 |
|
namespace cvc5 { |
36 |
|
|
37 |
9536 |
Env::Env(NodeManager* nm, const Options* opts) |
38 |
9536 |
: d_context(new context::Context()), |
39 |
9536 |
d_userContext(new context::UserContext()), |
40 |
|
d_nodeManager(nm), |
41 |
|
d_proofNodeManager(nullptr), |
42 |
9536 |
d_rewriter(new theory::Rewriter()), |
43 |
9536 |
d_evalRew(new theory::Evaluator(d_rewriter.get())), |
44 |
9536 |
d_eval(new theory::Evaluator(nullptr)), |
45 |
19072 |
d_topLevelSubs(new theory::TrustSubstitutionMap(d_userContext.get())), |
46 |
9536 |
d_dumpManager(new DumpManager(d_userContext.get())), |
47 |
|
d_logic(), |
48 |
|
d_statisticsRegistry(std::make_unique<StatisticsRegistry>(*this)), |
49 |
|
d_options(), |
50 |
|
d_originalOptions(opts), |
51 |
85824 |
d_resourceManager() |
52 |
|
{ |
53 |
9536 |
if (opts != nullptr) |
54 |
|
{ |
55 |
8650 |
d_options.copyValues(*opts); |
56 |
|
} |
57 |
9536 |
d_statisticsRegistry->registerTimer("global::totalTime").start(); |
58 |
9536 |
d_resourceManager = std::make_unique<ResourceManager>(*d_statisticsRegistry, d_options); |
59 |
9536 |
} |
60 |
|
|
61 |
6889 |
Env::~Env() {} |
62 |
|
|
63 |
143 |
void Env::setProofNodeManager(ProofNodeManager* pnm) |
64 |
|
{ |
65 |
143 |
Assert(pnm != nullptr); |
66 |
143 |
Assert(d_proofNodeManager == nullptr); |
67 |
143 |
d_proofNodeManager = pnm; |
68 |
143 |
d_rewriter->setProofNodeManager(pnm); |
69 |
143 |
d_topLevelSubs->setProofNodeManager(pnm); |
70 |
143 |
} |
71 |
|
|
72 |
6875 |
void Env::shutdown() |
73 |
|
{ |
74 |
6875 |
d_rewriter.reset(nullptr); |
75 |
6875 |
d_dumpManager.reset(nullptr); |
76 |
|
// d_resourceManager must be destroyed before d_statisticsRegistry |
77 |
6875 |
d_resourceManager.reset(nullptr); |
78 |
6875 |
} |
79 |
|
|
80 |
623890 |
context::UserContext* Env::getUserContext() { return d_userContext.get(); } |
81 |
|
|
82 |
23911161 |
context::Context* Env::getContext() { return d_context.get(); } |
83 |
|
|
84 |
1033868 |
NodeManager* Env::getNodeManager() const { return d_nodeManager; } |
85 |
|
|
86 |
38072 |
ProofNodeManager* Env::getProofNodeManager() { return d_proofNodeManager; } |
87 |
|
|
88 |
80132 |
bool Env::isSatProofProducing() const |
89 |
|
{ |
90 |
80132 |
return d_proofNodeManager != nullptr |
91 |
80468 |
&& (!d_options.smt.unsatCores |
92 |
737 |
|| (d_options.smt.unsatCoresMode |
93 |
|
!= options::UnsatCoresMode::ASSUMPTIONS |
94 |
340 |
&& d_options.smt.unsatCoresMode |
95 |
80132 |
!= options::UnsatCoresMode::PP_ONLY)); |
96 |
|
} |
97 |
|
|
98 |
117677 |
bool Env::isTheoryProofProducing() const |
99 |
|
{ |
100 |
117677 |
return d_proofNodeManager != nullptr |
101 |
118652 |
&& (!d_options.smt.unsatCores |
102 |
2603 |
|| d_options.smt.unsatCoresMode |
103 |
117677 |
== options::UnsatCoresMode::FULL_PROOF); |
104 |
|
} |
105 |
|
|
106 |
25926003 |
theory::Rewriter* Env::getRewriter() { return d_rewriter.get(); } |
107 |
|
|
108 |
280010 |
theory::TrustSubstitutionMap& Env::getTopLevelSubstitutions() |
109 |
|
{ |
110 |
280010 |
return *d_topLevelSubs.get(); |
111 |
|
} |
112 |
|
|
113 |
17273 |
DumpManager* Env::getDumpManager() { return d_dumpManager.get(); } |
114 |
|
|
115 |
3727433 |
const LogicInfo& Env::getLogicInfo() const { return d_logic; } |
116 |
|
|
117 |
2533178 |
StatisticsRegistry& Env::getStatisticsRegistry() |
118 |
|
{ |
119 |
2533178 |
return *d_statisticsRegistry; |
120 |
|
} |
121 |
|
|
122 |
24525121 |
const Options& Env::getOptions() const { return d_options; } |
123 |
|
|
124 |
|
const Options& Env::getOriginalOptions() const { return *d_originalOptions; } |
125 |
|
|
126 |
11087005 |
ResourceManager* Env::getResourceManager() const |
127 |
|
{ |
128 |
11087005 |
return d_resourceManager.get(); |
129 |
|
} |
130 |
|
|
131 |
27 |
const Printer& Env::getPrinter() |
132 |
|
{ |
133 |
27 |
return *Printer::getPrinter(d_options.base.outputLanguage); |
134 |
|
} |
135 |
|
|
136 |
27 |
std::ostream& Env::getDumpOut() { return *d_options.base.out; } |
137 |
|
|
138 |
265436 |
bool Env::isOutputOn(options::OutputTag tag) const |
139 |
|
{ |
140 |
265436 |
return d_options.base.outputTagHolder[static_cast<size_t>(tag)]; |
141 |
|
} |
142 |
212726 |
bool Env::isOutputOn(const std::string& tag) const |
143 |
|
{ |
144 |
212726 |
return isOutputOn(options::stringToOutputTag(tag)); |
145 |
|
} |
146 |
19 |
std::ostream& Env::getOutput(options::OutputTag tag) const |
147 |
|
{ |
148 |
19 |
if (isOutputOn(tag)) |
149 |
|
{ |
150 |
17 |
return *d_options.base.out; |
151 |
|
} |
152 |
2 |
return cvc5::null_os; |
153 |
|
} |
154 |
17 |
std::ostream& Env::getOutput(const std::string& tag) const |
155 |
|
{ |
156 |
17 |
return getOutput(options::stringToOutputTag(tag)); |
157 |
|
} |
158 |
|
|
159 |
824870 |
Node Env::evaluate(TNode n, |
160 |
|
const std::vector<Node>& args, |
161 |
|
const std::vector<Node>& vals, |
162 |
|
bool useRewriter) const |
163 |
|
{ |
164 |
1649740 |
std::unordered_map<Node, Node> visited; |
165 |
1649740 |
return evaluate(n, args, vals, visited, useRewriter); |
166 |
|
} |
167 |
|
|
168 |
841488 |
Node Env::evaluate(TNode n, |
169 |
|
const std::vector<Node>& args, |
170 |
|
const std::vector<Node>& vals, |
171 |
|
const std::unordered_map<Node, Node>& visited, |
172 |
|
bool useRewriter) const |
173 |
|
{ |
174 |
841488 |
if (useRewriter) |
175 |
|
{ |
176 |
841468 |
return d_evalRew->eval(n, args, vals, visited); |
177 |
|
} |
178 |
20 |
return d_eval->eval(n, args, vals, visited); |
179 |
|
} |
180 |
|
|
181 |
163283 |
Node Env::rewriteViaMethod(TNode n, MethodId idr) |
182 |
|
{ |
183 |
163283 |
if (idr == MethodId::RW_REWRITE) |
184 |
|
{ |
185 |
163263 |
return d_rewriter->rewrite(n); |
186 |
|
} |
187 |
20 |
if (idr == MethodId::RW_EXT_REWRITE) |
188 |
|
{ |
189 |
|
return d_rewriter->extendedRewrite(n); |
190 |
|
} |
191 |
20 |
if (idr == MethodId::RW_REWRITE_EQ_EXT) |
192 |
|
{ |
193 |
|
return d_rewriter->rewriteEqualityExt(n); |
194 |
|
} |
195 |
20 |
if (idr == MethodId::RW_EVALUATE) |
196 |
|
{ |
197 |
20 |
return evaluate(n, {}, {}, false); |
198 |
|
} |
199 |
|
if (idr == MethodId::RW_IDENTITY) |
200 |
|
{ |
201 |
|
// does nothing |
202 |
|
return n; |
203 |
|
} |
204 |
|
// unknown rewriter |
205 |
|
Unhandled() << "Env::rewriteViaMethod: no rewriter for " << idr |
206 |
|
<< std::endl; |
207 |
|
return n; |
208 |
|
} |
209 |
|
|
210 |
22755 |
} // namespace cvc5 |