GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/env.cpp Lines: 80 87 92.0 %
Date: 2021-09-29 Branches: 59 140 42.1 %

Line Exec Source
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
9528
Env::Env(NodeManager* nm, const Options* opts)
38
9528
    : d_context(new context::Context()),
39
9528
      d_userContext(new context::UserContext()),
40
      d_nodeManager(nm),
41
      d_proofNodeManager(nullptr),
42
9528
      d_rewriter(new theory::Rewriter()),
43
9528
      d_evalRew(new theory::Evaluator(d_rewriter.get())),
44
9528
      d_eval(new theory::Evaluator(nullptr)),
45
19056
      d_topLevelSubs(new theory::TrustSubstitutionMap(d_userContext.get())),
46
9528
      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
85752
      d_resourceManager()
52
{
53
9528
  if (opts != nullptr)
54
  {
55
8642
    d_options.copyValues(*opts);
56
  }
57
9528
  d_statisticsRegistry->registerTimer("global::totalTime").start();
58
9528
  d_resourceManager = std::make_unique<ResourceManager>(*d_statisticsRegistry, d_options);
59
9528
}
60
61
6882
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
6868
void Env::shutdown()
73
{
74
6868
  d_rewriter.reset(nullptr);
75
6868
  d_dumpManager.reset(nullptr);
76
  // d_resourceManager must be destroyed before d_statisticsRegistry
77
6868
  d_resourceManager.reset(nullptr);
78
6868
}
79
80
623055
context::UserContext* Env::getUserContext() { return d_userContext.get(); }
81
82
22985964
context::Context* Env::getContext() { return d_context.get(); }
83
84
1032730
NodeManager* Env::getNodeManager() const { return d_nodeManager; }
85
86
38030
ProofNodeManager* Env::getProofNodeManager() { return d_proofNodeManager; }
87
88
79806
bool Env::isSatProofProducing() const
89
{
90
79806
  return d_proofNodeManager != nullptr
91
80142
         && (!d_options.smt.unsatCores
92
737
             || (d_options.smt.unsatCoresMode
93
                     != options::UnsatCoresMode::ASSUMPTIONS
94
340
                 && d_options.smt.unsatCoresMode
95
79806
                        != options::UnsatCoresMode::PP_ONLY));
96
}
97
98
117535
bool Env::isTheoryProofProducing() const
99
{
100
117535
  return d_proofNodeManager != nullptr
101
118510
         && (!d_options.smt.unsatCores
102
2603
             || d_options.smt.unsatCoresMode
103
117535
                    == options::UnsatCoresMode::FULL_PROOF);
104
}
105
106
25092912
theory::Rewriter* Env::getRewriter() { return d_rewriter.get(); }
107
108
278904
theory::TrustSubstitutionMap& Env::getTopLevelSubstitutions()
109
{
110
278904
  return *d_topLevelSubs.get();
111
}
112
113
17258
DumpManager* Env::getDumpManager() { return d_dumpManager.get(); }
114
115
3718330
const LogicInfo& Env::getLogicInfo() const { return d_logic; }
116
117
2530362
StatisticsRegistry& Env::getStatisticsRegistry()
118
{
119
2530362
  return *d_statisticsRegistry;
120
}
121
122
23102034
const Options& Env::getOptions() const { return d_options; }
123
124
const Options& Env::getOriginalOptions() const { return *d_originalOptions; }
125
126
10839938
ResourceManager* Env::getResourceManager() const
127
{
128
10839938
  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
265383
bool Env::isOutputOn(options::OutputTag tag) const
139
{
140
265383
  return d_options.base.outputTagHolder[static_cast<size_t>(tag)];
141
}
142
212691
bool Env::isOutputOn(const std::string& tag) const
143
{
144
212691
  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
22746
}  // namespace cvc5