GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/ee_manager_distributed.cpp Lines: 46 47 97.9 %
Date: 2021-05-24 Branches: 42 116 36.2 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds
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
 * Management of a distributed approach for equality sharing.
14
 */
15
16
#include "theory/ee_manager_distributed.h"
17
18
#include "theory/quantifiers_engine.h"
19
#include "theory/shared_solver.h"
20
#include "theory/theory_engine.h"
21
#include "theory/uf/equality_engine.h"
22
23
namespace cvc5 {
24
namespace theory {
25
26
9459
EqEngineManagerDistributed::EqEngineManagerDistributed(TheoryEngine& te,
27
9459
                                                       SharedSolver& shs)
28
9459
    : EqEngineManager(te, shs), d_masterEENotify(nullptr)
29
{
30
9459
}
31
32
18918
EqEngineManagerDistributed::~EqEngineManagerDistributed()
33
{
34
18918
}
35
36
9459
void EqEngineManagerDistributed::initializeTheories()
37
{
38
9459
  context::Context* c = d_te.getSatContext();
39
  // initialize the shared solver
40
18918
  EeSetupInfo esis;
41
9459
  if (d_sharedSolver.needsEqualityEngine(esis))
42
  {
43
    // allocate an equality engine for the shared terms database
44
9459
    d_stbEqualityEngine.reset(allocateEqualityEngine(esis, c));
45
9459
    d_sharedSolver.setEqualityEngine(d_stbEqualityEngine.get());
46
  }
47
  else
48
  {
49
    Unhandled() << "Expected shared solver to use equality engine";
50
  }
51
52
9459
  const LogicInfo& logicInfo = d_te.getLogicInfo();
53
9459
  if (logicInfo.isQuantified())
54
  {
55
    // construct the master equality engine
56
6413
    Assert(d_masterEqualityEngine == nullptr);
57
6413
    QuantifiersEngine* qe = d_te.getQuantifiersEngine();
58
6413
    Assert(qe != nullptr);
59
6413
    d_masterEENotify.reset(new MasterNotifyClass(qe));
60
19239
    d_masterEqualityEngine.reset(new eq::EqualityEngine(*d_masterEENotify.get(),
61
6413
                                                        d_te.getSatContext(),
62
                                                        "theory::master",
63
6413
                                                        false));
64
  }
65
  // allocate equality engines per theory
66
132426
  for (TheoryId theoryId = theory::THEORY_FIRST;
67
132426
       theoryId != theory::THEORY_LAST;
68
       ++theoryId)
69
  {
70
122967
    Theory* t = d_te.theoryOf(theoryId);
71
122967
    if (t == nullptr)
72
    {
73
      // theory not active, skip
74
28433
      continue;
75
    }
76
    // always allocate an object in d_einfo here
77
122967
    EeTheoryInfo& eet = d_einfo[theoryId];
78
217501
    EeSetupInfo esi;
79
122967
    if (!t->needsEqualityEngine(esi))
80
    {
81
      // the theory said it doesn't need an equality engine, skip
82
18974
      continue;
83
    }
84
113452
    if (esi.d_useMaster)
85
    {
86
      // the theory said it wants to use the master equality engine
87
9459
      eet.d_usedEe = d_masterEqualityEngine.get();
88
9459
      continue;
89
    }
90
    // allocate the equality engine
91
94534
    eet.d_allocEe.reset(allocateEqualityEngine(esi, c));
92
    // the theory uses the equality engine
93
94534
    eet.d_usedEe = eet.d_allocEe.get();
94
    // if there is a master equality engine
95
94534
    if (d_masterEqualityEngine != nullptr)
96
    {
97
      // set the master equality engine of the theory's equality engine
98
64126
      eet.d_allocEe->setMasterEqualityEngine(d_masterEqualityEngine.get());
99
    }
100
  }
101
9459
}
102
103
6994
void EqEngineManagerDistributed::notifyModel(bool incomplete)
104
{
105
  // should have a consistent master equality engine
106
6994
  if (d_masterEqualityEngine.get() != nullptr)
107
  {
108
2802
    AlwaysAssert(d_masterEqualityEngine->consistent());
109
  }
110
6994
}
111
112
739262
void EqEngineManagerDistributed::MasterNotifyClass::eqNotifyNewClass(TNode t)
113
{
114
  // adds t to the quantifiers term database
115
739262
  d_quantEngine->eqNotifyNewClass(t);
116
739262
}
117
118
}  // namespace theory
119
28191
}  // namespace cvc5