GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/prop/theory_proxy.cpp Lines: 98 104 94.2 %
Date: 2021-08-14 Branches: 133 310 42.9 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Haniel Barbosa, Dejan Jovanovic
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
 * [[ Add one-line brief description here ]]
14
 *
15
 * [[ Add lengthier description here ]]
16
 * \todo document this file
17
 */
18
#include "prop/theory_proxy.h"
19
20
#include "context/context.h"
21
#include "decision/decision_engine.h"
22
#include "options/decision_options.h"
23
#include "options/smt_options.h"
24
#include "prop/cnf_stream.h"
25
#include "prop/prop_engine.h"
26
#include "prop/skolem_def_manager.h"
27
#include "smt/smt_statistics_registry.h"
28
#include "theory/rewriter.h"
29
#include "theory/theory_engine.h"
30
#include "util/statistics_stats.h"
31
32
namespace cvc5 {
33
namespace prop {
34
35
9920
TheoryProxy::TheoryProxy(PropEngine* propEngine,
36
                         TheoryEngine* theoryEngine,
37
                         decision::DecisionEngine* decisionEngine,
38
                         SkolemDefManager* skdm,
39
                         context::Context* context,
40
                         context::UserContext* userContext,
41
9920
                         ProofNodeManager* pnm)
42
    : d_propEngine(propEngine),
43
      d_cnfStream(nullptr),
44
      d_decisionEngine(decisionEngine),
45
      d_theoryEngine(theoryEngine),
46
      d_queue(context),
47
      d_tpp(*theoryEngine, userContext, pnm),
48
9920
      d_skdm(skdm)
49
{
50
9920
}
51
52
19840
TheoryProxy::~TheoryProxy() {
53
  /* nothing to do for now */
54
19840
}
55
56
9920
void TheoryProxy::finishInit(CnfStream* cnfStream) { d_cnfStream = cnfStream; }
57
58
444494
void TheoryProxy::notifyAssertion(Node a, TNode skolem)
59
{
60
444494
  if (skolem.isNull())
61
  {
62
414804
    d_decisionEngine->addAssertion(a);
63
  }
64
  else
65
  {
66
29690
    d_skdm->notifySkolemDefinition(skolem, a);
67
29690
    d_decisionEngine->addSkolemDefinition(a, skolem);
68
  }
69
444494
}
70
71
435608
void TheoryProxy::variableNotify(SatVariable var) {
72
435608
  d_theoryEngine->preRegister(getNode(SatLiteral(var)));
73
435608
}
74
75
16419477
void TheoryProxy::theoryCheck(theory::Theory::Effort effort) {
76
28652735
  while (!d_queue.empty()) {
77
24466516
    TNode assertion = d_queue.front();
78
12233258
    d_queue.pop();
79
12233258
    d_theoryEngine->assertFact(assertion);
80
12233258
    d_decisionEngine->notifyAsserted(assertion);
81
  }
82
4186219
  d_theoryEngine->check(effort);
83
4186205
}
84
85
4186205
void TheoryProxy::theoryPropagate(std::vector<SatLiteral>& output) {
86
  // Get the propagated literals
87
8372410
  std::vector<TNode> outputNodes;
88
4186205
  d_theoryEngine->getPropagatedLiterals(outputNodes);
89
10963395
  for (unsigned i = 0, i_end = outputNodes.size(); i < i_end; ++ i) {
90
6777190
    Debug("prop-explain") << "theoryPropagate() => " << outputNodes[i] << std::endl;
91
6777190
    output.push_back(d_cnfStream->getLiteral(outputNodes[i]));
92
  }
93
4186205
}
94
95
111031
void TheoryProxy::explainPropagation(SatLiteral l, SatClause& explanation) {
96
222062
  TNode lNode = d_cnfStream->getNode(l);
97
111031
  Debug("prop-explain") << "explainPropagation(" << lNode << ")" << std::endl;
98
99
222062
  TrustNode tte = d_theoryEngine->getExplanation(lNode);
100
222062
  Node theoryExplanation = tte.getNode();
101
222062
  if (options::produceProofs()
102
111031
      && options::unsatCoresMode() != options::UnsatCoresMode::ASSUMPTIONS)
103
  {
104
18299
    Assert(options::unsatCoresMode() != options::UnsatCoresMode::FULL_PROOF
105
           || tte.getGenerator());
106
18299
    d_propEngine->getProofCnfStream()->convertPropagation(tte);
107
  }
108
222062
  Debug("prop-explain") << "explainPropagation() => " << theoryExplanation
109
111031
                        << std::endl;
110
111031
  explanation.push_back(l);
111
111031
  if (theoryExplanation.getKind() == kind::AND)
112
  {
113
890646
    for (const Node& n : theoryExplanation)
114
    {
115
784962
      explanation.push_back(~d_cnfStream->getLiteral(n));
116
    }
117
  }
118
  else
119
  {
120
5347
    explanation.push_back(~d_cnfStream->getLiteral(theoryExplanation));
121
  }
122
111031
  if (Trace.isOn("sat-proof"))
123
  {
124
    std::stringstream ss;
125
    ss << "TheoryProxy::explainPropagation: clause for lit is ";
126
    for (unsigned i = 0, size = explanation.size(); i < size; ++i)
127
    {
128
      ss << explanation[i] << " [" << d_cnfStream->getNode(explanation[i])
129
         << "] ";
130
    }
131
    Trace("sat-proof") << ss.str() << "\n";
132
  }
133
111031
}
134
135
17382470
void TheoryProxy::enqueueTheoryLiteral(const SatLiteral& l) {
136
34764940
  Node literalNode = d_cnfStream->getNode(l);
137
17382470
  Debug("prop") << "enqueueing theory literal " << l << " " << literalNode << std::endl;
138
17382470
  Assert(!literalNode.isNull());
139
17382470
  d_queue.push(literalNode);
140
17382470
}
141
142
2827073
SatLiteral TheoryProxy::getNextTheoryDecisionRequest() {
143
5654144
  TNode n = d_theoryEngine->getNextDecisionRequest();
144
5654142
  return n.isNull() ? undefSatLiteral : d_cnfStream->getLiteral(n);
145
}
146
147
2766602
SatLiteral TheoryProxy::getNextDecisionEngineRequest(bool &stopSearch) {
148
2766602
  Assert(d_decisionEngine != NULL);
149
2766602
  Assert(stopSearch != true);
150
2766602
  SatLiteral ret = d_decisionEngine->getNext(stopSearch);
151
2766602
  if(stopSearch) {
152
51470
    Trace("decision") << "  ***  Decision Engine stopped search *** " << std::endl;
153
  }
154
2766602
  return ret;
155
}
156
157
16278
bool TheoryProxy::theoryNeedCheck() const {
158
16278
  return d_theoryEngine->needCheck();
159
}
160
161
435608
TNode TheoryProxy::getNode(SatLiteral lit) {
162
435608
  return d_cnfStream->getNode(lit);
163
}
164
165
2700
void TheoryProxy::notifyRestart() {
166
2700
  d_propEngine->spendResource(Resource::RestartStep);
167
2700
  d_theoryEngine->notifyRestart();
168
2700
}
169
170
3423612
void TheoryProxy::spendResource(Resource r)
171
{
172
3423612
  d_theoryEngine->spendResource(r);
173
3423612
}
174
175
5139698
bool TheoryProxy::isDecisionRelevant(SatVariable var) { return true; }
176
177
61579
bool TheoryProxy::isDecisionEngineDone() {
178
61579
  return d_decisionEngine->isDone();
179
}
180
181
1563290
SatValue TheoryProxy::getDecisionPolarity(SatVariable var) {
182
1563290
  return SAT_VALUE_UNKNOWN;
183
}
184
185
1254
CnfStream* TheoryProxy::getCnfStream() { return d_cnfStream; }
186
187
430308
TrustNode TheoryProxy::preprocessLemma(TrustNode trn,
188
                                       std::vector<TrustNode>& newLemmas,
189
                                       std::vector<Node>& newSkolems)
190
{
191
430308
  return d_tpp.preprocessLemma(trn, newLemmas, newSkolems);
192
}
193
194
312348
TrustNode TheoryProxy::preprocess(TNode node,
195
                                  std::vector<TrustNode>& newLemmas,
196
                                  std::vector<Node>& newSkolems)
197
{
198
312348
  return d_tpp.preprocess(node, newLemmas, newSkolems);
199
}
200
201
4
TrustNode TheoryProxy::removeItes(TNode node,
202
                                  std::vector<TrustNode>& newLemmas,
203
                                  std::vector<Node>& newSkolems)
204
{
205
4
  RemoveTermFormulas& rtf = d_tpp.getRemoveTermFormulas();
206
4
  return rtf.run(node, newLemmas, newSkolems, true);
207
}
208
209
2734
void TheoryProxy::getSkolems(TNode node,
210
                             std::vector<Node>& skAsserts,
211
                             std::vector<Node>& sks)
212
{
213
5468
  std::unordered_set<Node> skolems;
214
2734
  d_skdm->getSkolems(node, skolems);
215
5142
  for (const Node& k : skolems)
216
  {
217
2408
    sks.push_back(k);
218
2408
    skAsserts.push_back(d_skdm->getDefinitionForSkolem(k));
219
  }
220
2734
}
221
222
616186
void TheoryProxy::preRegister(Node n) { d_theoryEngine->preRegister(n); }
223
224
}  // namespace prop
225
29340
}  // namespace cvc5