GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/inference_manager_buffered.cpp Lines: 81 87 93.1 %
Date: 2021-09-29 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
43897
InferenceManagerBuffered::InferenceManagerBuffered(Env& env,
28
                                                   Theory& t,
29
                                                   TheoryState& state,
30
                                                   ProofNodeManager* pnm,
31
                                                   const std::string& statsName,
32
43897
                                                   bool cacheLemmas)
33
    : TheoryInferenceManager(env, t, state, pnm, statsName, cacheLemmas),
34
43897
      d_processingPendingLemmas(false)
35
{
36
43897
}
37
38
2957922
bool InferenceManagerBuffered::hasPending() const
39
{
40
2957922
  return hasPendingFact() || hasPendingLemma();
41
}
42
43
3500440
bool InferenceManagerBuffered::hasPendingFact() const
44
{
45
3500440
  return !d_pendingFact.empty();
46
}
47
48
3542007
bool InferenceManagerBuffered::hasPendingLemma() const
49
{
50
3542007
  return !d_pendingLem.empty();
51
}
52
53
56978
bool InferenceManagerBuffered::addPendingLemma(Node lem,
54
                                               InferenceId id,
55
                                               LemmaProperty p,
56
                                               ProofGenerator* pg,
57
                                               bool checkCache)
58
{
59
56978
  if (checkCache)
60
  {
61
    // check if it is unique up to rewriting
62
97407
    Node lemr = Rewriter::rewrite(lem);
63
56978
    if (hasCachedLemma(lemr, p))
64
    {
65
16549
      return false;
66
    }
67
  }
68
  // make the simple theory lemma
69
40429
  d_pendingLem.emplace_back(new SimpleTheoryLemma(id, lem, p, pg));
70
40429
  return true;
71
}
72
73
17635
void InferenceManagerBuffered::addPendingLemma(
74
    std::unique_ptr<TheoryInference> lemma)
75
{
76
17635
  d_pendingLem.emplace_back(std::move(lemma));
77
17635
}
78
79
void InferenceManagerBuffered::addPendingFact(Node conc,
80
                                              InferenceId id,
81
                                              Node exp,
82
                                              ProofGenerator* pg)
83
{
84
  // make a simple theory internal fact
85
  Assert(conc.getKind() != AND && conc.getKind() != OR);
86
  d_pendingFact.emplace_back(new SimpleTheoryInternalFact(id, conc, exp, pg));
87
}
88
89
24555
void InferenceManagerBuffered::addPendingFact(
90
    std::unique_ptr<TheoryInference> fact)
91
{
92
24555
  d_pendingFact.emplace_back(std::move(fact));
93
24555
}
94
95
3287
void InferenceManagerBuffered::addPendingPhaseRequirement(Node lit, bool pol)
96
{
97
  // it is the responsibility of the caller to ensure lit is rewritten
98
3287
  d_pendingReqPhase[lit] = pol;
99
3287
}
100
101
3265599
void InferenceManagerBuffered::doPendingFacts()
102
{
103
3265599
  size_t i = 0;
104
3826335
  while (!d_theoryState.isInConflict() && i < d_pendingFact.size())
105
  {
106
    // assert the internal fact, which notice may enqueue more pending facts in
107
    // this loop, or result in a conflict.
108
280368
    assertInternalFactTheoryInference(d_pendingFact[i].get());
109
280368
    i++;
110
  }
111
3265599
  d_pendingFact.clear();
112
3265599
}
113
114
3129854
void InferenceManagerBuffered::doPendingLemmas()
115
{
116
3129854
  if (d_processingPendingLemmas)
117
  {
118
    // already processing
119
4564
    return;
120
  }
121
3125290
  d_processingPendingLemmas = true;
122
3125290
  size_t i = 0;
123
3252888
  while (i < d_pendingLem.size())
124
  {
125
    // process this lemma, which notice may enqueue more pending lemmas in this
126
    // loop, or clear the lemmas.
127
63800
    lemmaTheoryInference(d_pendingLem[i].get());
128
63799
    i++;
129
  }
130
3125289
  d_pendingLem.clear();
131
3125289
  d_processingPendingLemmas = false;
132
}
133
134
154679
void InferenceManagerBuffered::doPendingPhaseRequirements()
135
{
136
  // process the pending require phase calls
137
157965
  for (const std::pair<const Node, bool>& prp : d_pendingReqPhase)
138
  {
139
3286
    requirePhase(prp.first, prp.second);
140
  }
141
154679
  d_pendingReqPhase.clear();
142
154679
}
143
901278
void InferenceManagerBuffered::clearPending()
144
{
145
901278
  d_pendingFact.clear();
146
901278
  d_pendingLem.clear();
147
901278
  d_pendingReqPhase.clear();
148
901278
}
149
1033
void InferenceManagerBuffered::clearPendingFacts() { d_pendingFact.clear(); }
150
15191
void InferenceManagerBuffered::clearPendingLemmas() { d_pendingLem.clear(); }
151
1804
void InferenceManagerBuffered::clearPendingPhaseRequirements()
152
{
153
1804
  d_pendingReqPhase.clear();
154
1804
}
155
156
179500
std::size_t InferenceManagerBuffered::numPendingLemmas() const
157
{
158
179500
  return d_pendingLem.size();
159
}
160
std::size_t InferenceManagerBuffered::numPendingFacts() const
161
{
162
  return d_pendingFact.size();
163
}
164
165
65657
void InferenceManagerBuffered::lemmaTheoryInference(TheoryInference* lem)
166
{
167
  // process this lemma
168
65657
  LemmaProperty p = LemmaProperty::NONE;
169
131314
  TrustNode tlem = lem->processLemma(p);
170
65657
  Assert(!tlem.isNull());
171
  // send the lemma
172
65657
  trustedLemma(tlem, lem->getId(), p);
173
65656
}
174
175
280368
void InferenceManagerBuffered::assertInternalFactTheoryInference(
176
    TheoryInference* fact)
177
{
178
  // process this fact
179
560736
  std::vector<Node> exp;
180
280368
  ProofGenerator* pg = nullptr;
181
560736
  Node lit = fact->processFact(exp, pg);
182
280368
  Assert(!lit.isNull());
183
280368
  bool pol = lit.getKind() != NOT;
184
560736
  TNode atom = pol ? lit : lit[0];
185
  // no double negation or conjunctive conclusions
186
280368
  Assert(atom.getKind() != NOT && atom.getKind() != AND);
187
  // assert the internal fact
188
280368
  assertInternalFact(atom, pol, fact->getId(), exp, pg);
189
280368
}
190
191
884450
void InferenceManagerBuffered::notifyInConflict()
192
{
193
884450
  d_theoryState.notifyInConflict();
194
  // also clear the pending facts, which will be stale after backtracking
195
884450
  clearPending();
196
884450
}
197
198
}  // namespace theory
199
22746
}  // namespace cvc5