GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/engine_output_channel.cpp Lines: 79 110 71.8 %
Date: 2021-08-03 Branches: 89 296 30.1 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Tim King, Morgan Deters
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
 * The theory engine output channel.
14
 */
15
16
#include "theory/engine_output_channel.h"
17
18
#include "expr/skolem_manager.h"
19
#include "prop/prop_engine.h"
20
#include "smt/smt_statistics_registry.h"
21
#include "theory/theory_engine.h"
22
23
using namespace cvc5::kind;
24
25
namespace cvc5 {
26
namespace theory {
27
28
127969
EngineOutputChannel::Statistics::Statistics(theory::TheoryId theory)
29
255938
    : conflicts(smtStatisticsRegistry().registerInt(getStatsPrefix(theory)
30
255938
                                                    + "conflicts")),
31
255938
      propagations(smtStatisticsRegistry().registerInt(getStatsPrefix(theory)
32
255938
                                                       + "propagations")),
33
255938
      lemmas(smtStatisticsRegistry().registerInt(getStatsPrefix(theory)
34
255938
                                                 + "lemmas")),
35
255938
      requirePhase(smtStatisticsRegistry().registerInt(getStatsPrefix(theory)
36
255938
                                                       + "requirePhase")),
37
255938
      restartDemands(smtStatisticsRegistry().registerInt(getStatsPrefix(theory)
38
255938
                                                         + "restartDemands")),
39
127969
      trustedConflicts(smtStatisticsRegistry().registerInt(
40
255938
          getStatsPrefix(theory) + "trustedConflicts")),
41
255938
      trustedLemmas(smtStatisticsRegistry().registerInt(getStatsPrefix(theory)
42
895783
                                                        + "trustedLemmas"))
43
{
44
127969
}
45
46
127969
EngineOutputChannel::EngineOutputChannel(TheoryEngine* engine,
47
127969
                                         theory::TheoryId theory)
48
127969
    : d_engine(engine), d_statistics(theory), d_theory(theory)
49
{
50
127969
}
51
52
160526
void EngineOutputChannel::safePoint(Resource r)
53
{
54
160526
  spendResource(r);
55
160526
  if (d_engine->d_interrupted)
56
  {
57
    throw theory::Interrupted();
58
  }
59
160526
}
60
61
1222
void EngineOutputChannel::lemma(TNode lemma, LemmaProperty p)
62
{
63
2444
  Trace("theory::lemma") << "EngineOutputChannel<" << d_theory << ">::lemma("
64
1222
                         << lemma << ")"
65
1222
                         << ", properties = " << p << std::endl;
66
1222
  ++d_statistics.lemmas;
67
1222
  d_engine->d_outputChannelUsed = true;
68
69
2444
  TrustNode tlem = TrustNode::mkTrustLemma(lemma);
70
2444
  d_engine->lemma(tlem,
71
                  p,
72
1222
                  isLemmaPropertySendAtoms(p) ? d_theory : theory::THEORY_LAST,
73
                  d_theory);
74
1222
}
75
76
void EngineOutputChannel::splitLemma(TNode lemma, bool removable)
77
{
78
  Trace("theory::lemma") << "EngineOutputChannel<" << d_theory << ">::lemma("
79
                         << lemma << ")" << std::endl;
80
  ++d_statistics.lemmas;
81
  d_engine->d_outputChannelUsed = true;
82
83
  Trace("pf::explain") << "EngineOutputChannel::splitLemma( " << lemma << " )"
84
                       << std::endl;
85
  TrustNode tlem = TrustNode::mkTrustLemma(lemma);
86
  LemmaProperty p = removable ? LemmaProperty::REMOVABLE : LemmaProperty::NONE;
87
  d_engine->lemma(tlem, p, d_theory);
88
}
89
90
9071394
bool EngineOutputChannel::propagate(TNode literal)
91
{
92
18142788
  Trace("theory::propagate") << "EngineOutputChannel<" << d_theory
93
9071394
                             << ">::propagate(" << literal << ")" << std::endl;
94
9071394
  ++d_statistics.propagations;
95
9071394
  d_engine->d_outputChannelUsed = true;
96
9071394
  return d_engine->propagate(literal, d_theory);
97
}
98
99
void EngineOutputChannel::conflict(TNode conflictNode)
100
{
101
  Trace("theory::conflict")
102
      << "EngineOutputChannel<" << d_theory << ">::conflict(" << conflictNode
103
      << ")" << std::endl;
104
  ++d_statistics.conflicts;
105
  d_engine->d_outputChannelUsed = true;
106
  TrustNode tConf = TrustNode::mkTrustConflict(conflictNode);
107
  d_engine->conflict(tConf, d_theory);
108
}
109
110
void EngineOutputChannel::demandRestart()
111
{
112
  NodeManager* nm = NodeManager::currentNM();
113
  SkolemManager* sm = nm->getSkolemManager();
114
  Node restartVar = sm->mkDummySkolem(
115
      "restartVar",
116
      nm->booleanType(),
117
      "A boolean variable asserted to be true to force a restart");
118
  Trace("theory::restart") << "EngineOutputChannel<" << d_theory
119
                           << ">::restart(" << restartVar << ")" << std::endl;
120
  ++d_statistics.restartDemands;
121
  lemma(restartVar, LemmaProperty::REMOVABLE);
122
}
123
124
36153
void EngineOutputChannel::requirePhase(TNode n, bool phase)
125
{
126
72306
  Trace("theory") << "EngineOutputChannel::requirePhase(" << n << ", " << phase
127
36153
                  << ")" << std::endl;
128
36153
  ++d_statistics.requirePhase;
129
36153
  d_engine->getPropEngine()->requirePhase(n, phase);
130
36153
}
131
132
2178
void EngineOutputChannel::setIncomplete(IncompleteId id)
133
{
134
2178
  Trace("theory") << "setIncomplete(" << id << ")" << std::endl;
135
2178
  d_engine->setIncomplete(d_theory, id);
136
2178
}
137
138
5142382
void EngineOutputChannel::spendResource(Resource r)
139
{
140
5142382
  d_engine->spendResource(r);
141
5142382
}
142
143
49205
void EngineOutputChannel::handleUserAttribute(const char* attr,
144
                                              theory::Theory* t)
145
{
146
49205
  d_engine->handleUserAttribute(attr, t);
147
49205
}
148
149
102669
void EngineOutputChannel::trustedConflict(TrustNode pconf)
150
{
151
102669
  Assert(pconf.getKind() == TrustNodeKind::CONFLICT);
152
205338
  Trace("theory::conflict")
153
102669
      << "EngineOutputChannel<" << d_theory << ">::trustedConflict("
154
102669
      << pconf.getNode() << ")" << std::endl;
155
102669
  if (pconf.getGenerator() != nullptr)
156
  {
157
13898
    ++d_statistics.trustedConflicts;
158
  }
159
102669
  ++d_statistics.conflicts;
160
102669
  d_engine->d_outputChannelUsed = true;
161
102669
  d_engine->conflict(pconf, d_theory);
162
102669
}
163
164
298337
void EngineOutputChannel::trustedLemma(TrustNode plem, LemmaProperty p)
165
{
166
596674
  Trace("theory::lemma") << "EngineOutputChannel<" << d_theory
167
298337
                         << ">::trustedLemma(" << plem << ")" << std::endl;
168
298337
  Assert(plem.getKind() == TrustNodeKind::LEMMA);
169
298337
  if (plem.getGenerator() != nullptr)
170
  {
171
39231
    ++d_statistics.trustedLemmas;
172
  }
173
298337
  ++d_statistics.lemmas;
174
298337
  d_engine->d_outputChannelUsed = true;
175
  // now, call the normal interface for lemma
176
596676
  d_engine->lemma(plem,
177
                  p,
178
298337
                  isLemmaPropertySendAtoms(p) ? d_theory : theory::THEORY_LAST,
179
                  d_theory);
180
298335
}
181
182
}  // namespace theory
183
29286
}  // namespace cvc5