GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/prop/theory_proxy.cpp Lines: 97 103 94.2 %
Date: 2021-09-18 Branches: 131 310 42.3 %

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/env.h"
28
#include "smt/smt_statistics_registry.h"
29
#include "theory/rewriter.h"
30
#include "theory/theory_engine.h"
31
#include "util/statistics_stats.h"
32
33
namespace cvc5 {
34
namespace prop {
35
36
10007
TheoryProxy::TheoryProxy(PropEngine* propEngine,
37
                         TheoryEngine* theoryEngine,
38
                         decision::DecisionEngine* decisionEngine,
39
                         SkolemDefManager* skdm,
40
10007
                         Env& env)
41
    : d_propEngine(propEngine),
42
      d_cnfStream(nullptr),
43
      d_decisionEngine(decisionEngine),
44
      d_theoryEngine(theoryEngine),
45
      d_queue(env.getContext()),
46
      d_tpp(*theoryEngine, env.getUserContext(), env.getProofNodeManager()),
47
      d_skdm(skdm),
48
10007
      d_env(env)
49
{
50
10007
}
51
52
20008
TheoryProxy::~TheoryProxy() {
53
  /* nothing to do for now */
54
20008
}
55
56
10007
void TheoryProxy::finishInit(CnfStream* cnfStream) { d_cnfStream = cnfStream; }
57
58
451386
void TheoryProxy::notifyAssertion(Node a, TNode skolem)
59
{
60
451386
  if (skolem.isNull())
61
  {
62
422942
    d_decisionEngine->addAssertion(a);
63
  }
64
  else
65
  {
66
28444
    d_skdm->notifySkolemDefinition(skolem, a);
67
28444
    d_decisionEngine->addSkolemDefinition(a, skolem);
68
  }
69
451386
}
70
71
458371
void TheoryProxy::variableNotify(SatVariable var) {
72
458371
  d_theoryEngine->preRegister(getNode(SatLiteral(var)));
73
458371
}
74
75
16682400
void TheoryProxy::theoryCheck(theory::Theory::Effort effort) {
76
29174601
  while (!d_queue.empty()) {
77
24984402
    TNode assertion = d_queue.front();
78
12492201
    d_queue.pop();
79
12492201
    d_theoryEngine->assertFact(assertion);
80
12492201
    d_decisionEngine->notifyAsserted(assertion);
81
  }
82
4190199
  d_theoryEngine->check(effort);
83
4190185
}
84
85
4190185
void TheoryProxy::theoryPropagate(std::vector<SatLiteral>& output) {
86
  // Get the propagated literals
87
8380370
  std::vector<TNode> outputNodes;
88
4190185
  d_theoryEngine->getPropagatedLiterals(outputNodes);
89
11400530
  for (unsigned i = 0, i_end = outputNodes.size(); i < i_end; ++ i) {
90
7210345
    Debug("prop-explain") << "theoryPropagate() => " << outputNodes[i] << std::endl;
91
7210345
    output.push_back(d_cnfStream->getLiteral(outputNodes[i]));
92
  }
93
4190185
}
94
95
120578
void TheoryProxy::explainPropagation(SatLiteral l, SatClause& explanation) {
96
241156
  TNode lNode = d_cnfStream->getNode(l);
97
120578
  Debug("prop-explain") << "explainPropagation(" << lNode << ")" << std::endl;
98
99
241156
  TrustNode tte = d_theoryEngine->getExplanation(lNode);
100
241156
  Node theoryExplanation = tte.getNode();
101
120578
  if (d_env.isSatProofProducing())
102
  {
103
18535
    Assert(options::unsatCoresMode() != options::UnsatCoresMode::FULL_PROOF
104
           || tte.getGenerator());
105
18535
    d_propEngine->getProofCnfStream()->convertPropagation(tte);
106
  }
107
241156
  Debug("prop-explain") << "explainPropagation() => " << theoryExplanation
108
120578
                        << std::endl;
109
120578
  explanation.push_back(l);
110
120578
  if (theoryExplanation.getKind() == kind::AND)
111
  {
112
942821
    for (const Node& n : theoryExplanation)
113
    {
114
828180
      explanation.push_back(~d_cnfStream->getLiteral(n));
115
    }
116
  }
117
  else
118
  {
119
5937
    explanation.push_back(~d_cnfStream->getLiteral(theoryExplanation));
120
  }
121
120578
  if (Trace.isOn("sat-proof"))
122
  {
123
    std::stringstream ss;
124
    ss << "TheoryProxy::explainPropagation: clause for lit is ";
125
    for (unsigned i = 0, size = explanation.size(); i < size; ++i)
126
    {
127
      ss << explanation[i] << " [" << d_cnfStream->getNode(explanation[i])
128
         << "] ";
129
    }
130
    Trace("sat-proof") << ss.str() << "\n";
131
  }
132
120578
}
133
134
17368048
void TheoryProxy::enqueueTheoryLiteral(const SatLiteral& l) {
135
34736096
  Node literalNode = d_cnfStream->getNode(l);
136
17368048
  Debug("prop") << "enqueueing theory literal " << l << " " << literalNode << std::endl;
137
17368048
  Assert(!literalNode.isNull());
138
17368048
  d_queue.push(literalNode);
139
17368048
}
140
141
2796232
SatLiteral TheoryProxy::getNextTheoryDecisionRequest() {
142
5592462
  TNode n = d_theoryEngine->getNextDecisionRequest();
143
5592460
  return n.isNull() ? undefSatLiteral : d_cnfStream->getLiteral(n);
144
}
145
146
2733866
SatLiteral TheoryProxy::getNextDecisionEngineRequest(bool &stopSearch) {
147
2733866
  Assert(d_decisionEngine != NULL);
148
2733866
  Assert(stopSearch != true);
149
2733866
  SatLiteral ret = d_decisionEngine->getNext(stopSearch);
150
2733866
  if(stopSearch) {
151
53268
    Trace("decision") << "  ***  Decision Engine stopped search *** " << std::endl;
152
  }
153
2733866
  return ret;
154
}
155
156
16598
bool TheoryProxy::theoryNeedCheck() const {
157
16598
  return d_theoryEngine->needCheck();
158
}
159
160
458371
TNode TheoryProxy::getNode(SatLiteral lit) {
161
458371
  return d_cnfStream->getNode(lit);
162
}
163
164
2655
void TheoryProxy::notifyRestart() {
165
2655
  d_propEngine->spendResource(Resource::RestartStep);
166
2655
  d_theoryEngine->notifyRestart();
167
2655
}
168
169
3401992
void TheoryProxy::spendResource(Resource r)
170
{
171
3401992
  d_theoryEngine->spendResource(r);
172
3401992
}
173
174
4722422
bool TheoryProxy::isDecisionRelevant(SatVariable var) { return true; }
175
176
62273
bool TheoryProxy::isDecisionEngineDone() {
177
62273
  return d_decisionEngine->isDone();
178
}
179
180
1486264
SatValue TheoryProxy::getDecisionPolarity(SatVariable var) {
181
1486264
  return SAT_VALUE_UNKNOWN;
182
}
183
184
1252
CnfStream* TheoryProxy::getCnfStream() { return d_cnfStream; }
185
186
445843
TrustNode TheoryProxy::preprocessLemma(TrustNode trn,
187
                                       std::vector<TrustNode>& newLemmas,
188
                                       std::vector<Node>& newSkolems)
189
{
190
445843
  return d_tpp.preprocessLemma(trn, newLemmas, newSkolems);
191
}
192
193
309996
TrustNode TheoryProxy::preprocess(TNode node,
194
                                  std::vector<TrustNode>& newLemmas,
195
                                  std::vector<Node>& newSkolems)
196
{
197
309996
  return d_tpp.preprocess(node, newLemmas, newSkolems);
198
}
199
200
2
TrustNode TheoryProxy::removeItes(TNode node,
201
                                  std::vector<TrustNode>& newLemmas,
202
                                  std::vector<Node>& newSkolems)
203
{
204
2
  RemoveTermFormulas& rtf = d_tpp.getRemoveTermFormulas();
205
2
  return rtf.run(node, newLemmas, newSkolems, true);
206
}
207
208
3317
void TheoryProxy::getSkolems(TNode node,
209
                             std::vector<Node>& skAsserts,
210
                             std::vector<Node>& sks)
211
{
212
6634
  std::unordered_set<Node> skolems;
213
3317
  d_skdm->getSkolems(node, skolems);
214
5748
  for (const Node& k : skolems)
215
  {
216
2431
    sks.push_back(k);
217
2431
    skAsserts.push_back(d_skdm->getDefinitionForSkolem(k));
218
  }
219
3317
}
220
221
622225
void TheoryProxy::preRegister(Node n) { d_theoryEngine->preRegister(n); }
222
223
}  // namespace prop
224
29574
}  // namespace cvc5