GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/prop/theory_proxy.cpp Lines: 97 103 94.2 %
Date: 2021-09-29 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
6328
TheoryProxy::TheoryProxy(PropEngine* propEngine,
37
                         TheoryEngine* theoryEngine,
38
                         decision::DecisionEngine* decisionEngine,
39
                         SkolemDefManager* skdm,
40
6328
                         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
6328
      d_env(env)
49
{
50
6328
}
51
52
12650
TheoryProxy::~TheoryProxy() {
53
  /* nothing to do for now */
54
12650
}
55
56
6328
void TheoryProxy::finishInit(CnfStream* cnfStream) { d_cnfStream = cnfStream; }
57
58
245317
void TheoryProxy::notifyAssertion(Node a, TNode skolem)
59
{
60
245317
  if (skolem.isNull())
61
  {
62
230512
    d_decisionEngine->addAssertion(a);
63
  }
64
  else
65
  {
66
14805
    d_skdm->notifySkolemDefinition(skolem, a);
67
14805
    d_decisionEngine->addSkolemDefinition(a, skolem);
68
  }
69
245317
}
70
71
197430
void TheoryProxy::variableNotify(SatVariable var) {
72
197430
  d_theoryEngine->preRegister(getNode(SatLiteral(var)));
73
197430
}
74
75
9960645
void TheoryProxy::theoryCheck(theory::Theory::Effort effort) {
76
17265394
  while (!d_queue.empty()) {
77
14609498
    TNode assertion = d_queue.front();
78
7304749
    d_queue.pop();
79
7304749
    d_theoryEngine->assertFact(assertion);
80
7304749
    d_decisionEngine->notifyAsserted(assertion);
81
  }
82
2655896
  d_theoryEngine->check(effort);
83
2655882
}
84
85
2655882
void TheoryProxy::theoryPropagate(std::vector<SatLiteral>& output) {
86
  // Get the propagated literals
87
5311764
  std::vector<TNode> outputNodes;
88
2655882
  d_theoryEngine->getPropagatedLiterals(outputNodes);
89
7623554
  for (unsigned i = 0, i_end = outputNodes.size(); i < i_end; ++ i) {
90
4967672
    Debug("prop-explain") << "theoryPropagate() => " << outputNodes[i] << std::endl;
91
4967672
    output.push_back(d_cnfStream->getLiteral(outputNodes[i]));
92
  }
93
2655882
}
94
95
73435
void TheoryProxy::explainPropagation(SatLiteral l, SatClause& explanation) {
96
146870
  TNode lNode = d_cnfStream->getNode(l);
97
73435
  Debug("prop-explain") << "explainPropagation(" << lNode << ")" << std::endl;
98
99
146870
  TrustNode tte = d_theoryEngine->getExplanation(lNode);
100
146870
  Node theoryExplanation = tte.getNode();
101
73435
  if (d_env.isSatProofProducing())
102
  {
103
229
    Assert(options::unsatCoresMode() != options::UnsatCoresMode::FULL_PROOF
104
           || tte.getGenerator());
105
229
    d_propEngine->getProofCnfStream()->convertPropagation(tte);
106
  }
107
146870
  Debug("prop-explain") << "explainPropagation() => " << theoryExplanation
108
73435
                        << std::endl;
109
73435
  explanation.push_back(l);
110
73435
  if (theoryExplanation.getKind() == kind::AND)
111
  {
112
518586
    for (const Node& n : theoryExplanation)
113
    {
114
448415
      explanation.push_back(~d_cnfStream->getLiteral(n));
115
    }
116
  }
117
  else
118
  {
119
3264
    explanation.push_back(~d_cnfStream->getLiteral(theoryExplanation));
120
  }
121
73435
  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
73435
}
133
134
8711944
void TheoryProxy::enqueueTheoryLiteral(const SatLiteral& l) {
135
17423888
  Node literalNode = d_cnfStream->getNode(l);
136
8711944
  Debug("prop") << "enqueueing theory literal " << l << " " << literalNode << std::endl;
137
8711944
  Assert(!literalNode.isNull());
138
8711944
  d_queue.push(literalNode);
139
8711944
}
140
141
1911621
SatLiteral TheoryProxy::getNextTheoryDecisionRequest() {
142
3823240
  TNode n = d_theoryEngine->getNextDecisionRequest();
143
3823238
  return n.isNull() ? undefSatLiteral : d_cnfStream->getLiteral(n);
144
}
145
146
1867215
SatLiteral TheoryProxy::getNextDecisionEngineRequest(bool &stopSearch) {
147
1867215
  Assert(d_decisionEngine != NULL);
148
1867215
  Assert(stopSearch != true);
149
1867215
  SatLiteral ret = d_decisionEngine->getNext(stopSearch);
150
1867215
  if(stopSearch) {
151
36734
    Trace("decision") << "  ***  Decision Engine stopped search *** " << std::endl;
152
  }
153
1867215
  return ret;
154
}
155
156
11996
bool TheoryProxy::theoryNeedCheck() const {
157
11996
  return d_theoryEngine->needCheck();
158
}
159
160
197430
TNode TheoryProxy::getNode(SatLiteral lit) {
161
197430
  return d_cnfStream->getNode(lit);
162
}
163
164
1312
void TheoryProxy::notifyRestart() {
165
1312
  d_propEngine->spendResource(Resource::RestartStep);
166
1312
  d_theoryEngine->notifyRestart();
167
1312
}
168
169
2085695
void TheoryProxy::spendResource(Resource r)
170
{
171
2085695
  d_theoryEngine->spendResource(r);
172
2085695
}
173
174
2972087
bool TheoryProxy::isDecisionRelevant(SatVariable var) { return true; }
175
176
46076
bool TheoryProxy::isDecisionEngineDone() {
177
46076
  return d_decisionEngine->isDone();
178
}
179
180
1041232
SatValue TheoryProxy::getDecisionPolarity(SatVariable var) {
181
1041232
  return SAT_VALUE_UNKNOWN;
182
}
183
184
64
CnfStream* TheoryProxy::getCnfStream() { return d_cnfStream; }
185
186
248867
TrustNode TheoryProxy::preprocessLemma(TrustNode trn,
187
                                       std::vector<TrustNode>& newLemmas,
188
                                       std::vector<Node>& newSkolems)
189
{
190
248867
  return d_tpp.preprocessLemma(trn, newLemmas, newSkolems);
191
}
192
193
190431
TrustNode TheoryProxy::preprocess(TNode node,
194
                                  std::vector<TrustNode>& newLemmas,
195
                                  std::vector<Node>& newSkolems)
196
{
197
190431
  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
1928
void TheoryProxy::getSkolems(TNode node,
209
                             std::vector<Node>& skAsserts,
210
                             std::vector<Node>& sks)
211
{
212
3856
  std::unordered_set<Node> skolems;
213
1928
  d_skdm->getSkolems(node, skolems);
214
3362
  for (const Node& k : skolems)
215
  {
216
1434
    sks.push_back(k);
217
1434
    skAsserts.push_back(d_skdm->getDefinitionForSkolem(k));
218
  }
219
1928
}
220
221
297729
void TheoryProxy::preRegister(Node n) { d_theoryEngine->preRegister(n); }
222
223
}  // namespace prop
224
22746
}  // namespace cvc5