GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/inference_manager_buffered.cpp Lines: 81 87 93.1 %
Date: 2021-11-06 Branches: 55 152 36.2 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Gereon Kremer, Aina Niemetz
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
 * A buffered inference manager.
14
 */
15
16
#include "theory/inference_manager_buffered.h"
17
18
#include "theory/rewriter.h"
19
#include "theory/theory.h"
20
#include "theory/theory_state.h"
21
22
using namespace cvc5::kind;
23
24
namespace cvc5 {
25
namespace theory {
26
27
106904
InferenceManagerBuffered::InferenceManagerBuffered(Env& env,
28
                                                   Theory& t,
29
                                                   TheoryState& state,
30
                                                   const std::string& statsName,
31
106904
                                                   bool cacheLemmas)
32
    : TheoryInferenceManager(env, t, state, statsName, cacheLemmas),
33
106904
      d_processingPendingLemmas(false)
34
{
35
106904
}
36
37
4297224
bool InferenceManagerBuffered::hasPending() const
38
{
39
4297224
  return hasPendingFact() || hasPendingLemma();
40
}
41
42
5201504
bool InferenceManagerBuffered::hasPendingFact() const
43
{
44
5201504
  return !d_pendingFact.empty();
45
}
46
47
5327672
bool InferenceManagerBuffered::hasPendingLemma() const
48
{
49
5327672
  return !d_pendingLem.empty();
50
}
51
52
160300
bool InferenceManagerBuffered::addPendingLemma(Node lem,
53
                                               InferenceId id,
54
                                               LemmaProperty p,
55
                                               ProofGenerator* pg,
56
                                               bool checkCache)
57
{
58
160300
  if (checkCache)
59
  {
60
    // check if it is unique up to rewriting
61
264305
    Node lemr = rewrite(lem);
62
160300
    if (hasCachedLemma(lemr, p))
63
    {
64
56295
      return false;
65
    }
66
  }
67
  // make the simple theory lemma
68
104005
  d_pendingLem.emplace_back(new SimpleTheoryLemma(id, lem, p, pg));
69
104005
  return true;
70
}
71
72
26404
void InferenceManagerBuffered::addPendingLemma(
73
    std::unique_ptr<TheoryInference> lemma)
74
{
75
26404
  d_pendingLem.emplace_back(std::move(lemma));
76
26404
}
77
78
void InferenceManagerBuffered::addPendingFact(Node conc,
79
                                              InferenceId id,
80
                                              Node exp,
81
                                              ProofGenerator* pg)
82
{
83
  // make a simple theory internal fact
84
  Assert(conc.getKind() != AND && conc.getKind() != OR);
85
  d_pendingFact.emplace_back(new SimpleTheoryInternalFact(id, conc, exp, pg));
86
}
87
88
41077
void InferenceManagerBuffered::addPendingFact(
89
    std::unique_ptr<TheoryInference> fact)
90
{
91
41077
  d_pendingFact.emplace_back(std::move(fact));
92
41077
}
93
94
4958
void InferenceManagerBuffered::addPendingPhaseRequirement(Node lit, bool pol)
95
{
96
  // it is the responsibility of the caller to ensure lit is rewritten
97
4958
  d_pendingReqPhase[lit] = pol;
98
4958
}
99
100
6662186
void InferenceManagerBuffered::doPendingFacts()
101
{
102
6662186
  size_t i = 0;
103
7774726
  while (!d_theoryState.isInConflict() && i < d_pendingFact.size())
104
  {
105
    // assert the internal fact, which notice may enqueue more pending facts in
106
    // this loop, or result in a conflict.
107
556270
    assertInternalFactTheoryInference(d_pendingFact[i].get());
108
556270
    i++;
109
  }
110
6662186
  d_pendingFact.clear();
111
6662186
}
112
113
6462857
void InferenceManagerBuffered::doPendingLemmas()
114
{
115
6462857
  if (d_processingPendingLemmas)
116
  {
117
    // already processing
118
12718
    return;
119
  }
120
6450139
  d_processingPendingLemmas = true;
121
6450139
  size_t i = 0;
122
6769679
  while (i < d_pendingLem.size())
123
  {
124
    // process this lemma, which notice may enqueue more pending lemmas in this
125
    // loop, or clear the lemmas.
126
159771
    lemmaTheoryInference(d_pendingLem[i].get());
127
159770
    i++;
128
  }
129
6450138
  d_pendingLem.clear();
130
6450138
  d_processingPendingLemmas = false;
131
}
132
133
278908
void InferenceManagerBuffered::doPendingPhaseRequirements()
134
{
135
  // process the pending require phase calls
136
283864
  for (const std::pair<const Node, bool>& prp : d_pendingReqPhase)
137
  {
138
4956
    requirePhase(prp.first, prp.second);
139
  }
140
278908
  d_pendingReqPhase.clear();
141
278908
}
142
1565374
void InferenceManagerBuffered::clearPending()
143
{
144
1565374
  d_pendingFact.clear();
145
1565374
  d_pendingLem.clear();
146
1565374
  d_pendingReqPhase.clear();
147
1565374
}
148
1690
void InferenceManagerBuffered::clearPendingFacts() { d_pendingFact.clear(); }
149
26957
void InferenceManagerBuffered::clearPendingLemmas() { d_pendingLem.clear(); }
150
2856
void InferenceManagerBuffered::clearPendingPhaseRequirements()
151
{
152
2856
  d_pendingReqPhase.clear();
153
2856
}
154
155
359237
std::size_t InferenceManagerBuffered::numPendingLemmas() const
156
{
157
359237
  return d_pendingLem.size();
158
}
159
std::size_t InferenceManagerBuffered::numPendingFacts() const
160
{
161
  return d_pendingFact.size();
162
}
163
164
164308
void InferenceManagerBuffered::lemmaTheoryInference(TheoryInference* lem)
165
{
166
  // process this lemma
167
164308
  LemmaProperty p = LemmaProperty::NONE;
168
328616
  TrustNode tlem = lem->processLemma(p);
169
164308
  Assert(!tlem.isNull());
170
  // send the lemma
171
164308
  trustedLemma(tlem, lem->getId(), p);
172
164307
}
173
174
556270
void InferenceManagerBuffered::assertInternalFactTheoryInference(
175
    TheoryInference* fact)
176
{
177
  // process this fact
178
1112540
  std::vector<Node> exp;
179
556270
  ProofGenerator* pg = nullptr;
180
1112540
  Node lit = fact->processFact(exp, pg);
181
556270
  Assert(!lit.isNull());
182
556270
  bool pol = lit.getKind() != NOT;
183
1112540
  TNode atom = pol ? lit : lit[0];
184
  // no double negation or conjunctive conclusions
185
556270
  Assert(atom.getKind() != NOT && atom.getKind() != AND);
186
  // assert the internal fact
187
556270
  assertInternalFact(atom, pol, fact->getId(), exp, pg);
188
556270
}
189
190
1532860
void InferenceManagerBuffered::notifyInConflict()
191
{
192
1532860
  d_theoryState.notifyInConflict();
193
  // also clear the pending facts, which will be stale after backtracking
194
1532860
  clearPending();
195
1532860
}
196
197
}  // namespace theory
198
31137
}  // namespace cvc5