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