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