GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/ee_manager_distributed.cpp Lines: 43 44 97.7 %
Date: 2021-09-10 Branches: 42 114 36.8 %

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
9878
EqEngineManagerDistributed::EqEngineManagerDistributed(TheoryEngine& te,
27
9878
                                                       SharedSolver& shs)
28
9878
    : EqEngineManager(te, shs), d_masterEENotify(nullptr)
29
{
30
9878
}
31
32
19750
EqEngineManagerDistributed::~EqEngineManagerDistributed()
33
{
34
19750
}
35
36
9878
void EqEngineManagerDistributed::initializeTheories()
37
{
38
9878
  context::Context* c = d_te.getSatContext();
39
  // initialize the shared solver
40
19756
  EeSetupInfo esis;
41
9878
  if (d_sharedSolver.needsEqualityEngine(esis))
42
  {
43
    // allocate an equality engine for the shared terms database
44
9878
    d_stbEqualityEngine.reset(allocateEqualityEngine(esis, c));
45
9878
    d_sharedSolver.setEqualityEngine(d_stbEqualityEngine.get());
46
  }
47
  else
48
  {
49
    Unhandled() << "Expected shared solver to use equality engine";
50
  }
51
52
9878
  const LogicInfo& logicInfo = d_te.getLogicInfo();
53
9878
  if (logicInfo.isQuantified())
54
  {
55
    // construct the master equality engine
56
6789
    Assert(d_masterEqualityEngine == nullptr);
57
6789
    QuantifiersEngine* qe = d_te.getQuantifiersEngine();
58
6789
    Assert(qe != nullptr);
59
6789
    d_masterEENotify.reset(new quantifiers::MasterNotifyClass(qe));
60
20367
    d_masterEqualityEngine.reset(new eq::EqualityEngine(*d_masterEENotify.get(),
61
6789
                                                        d_te.getSatContext(),
62
                                                        "theory::master",
63
6789
                                                        false));
64
  }
65
  // allocate equality engines per theory
66
138292
  for (TheoryId theoryId = theory::THEORY_FIRST;
67
138292
       theoryId != theory::THEORY_LAST;
68
       ++theoryId)
69
  {
70
128414
    Theory* t = d_te.theoryOf(theoryId);
71
128414
    if (t == nullptr)
72
    {
73
      // theory not active, skip
74
29636
      continue;
75
    }
76
    // always allocate an object in d_einfo here
77
128414
    EeTheoryInfo& eet = d_einfo[theoryId];
78
227192
    EeSetupInfo esi;
79
128414
    if (!t->needsEqualityEngine(esi))
80
    {
81
      // the theory said it doesn't need an equality engine, skip
82
19758
      continue;
83
    }
84
118534
    if (esi.d_useMaster)
85
    {
86
      // the theory said it wants to use the master equality engine
87
9878
      eet.d_usedEe = d_masterEqualityEngine.get();
88
9878
      continue;
89
    }
90
    // allocate the equality engine
91
98778
    eet.d_allocEe.reset(allocateEqualityEngine(esi, c));
92
    // the theory uses the equality engine
93
98778
    eet.d_usedEe = eet.d_allocEe.get();
94
    // if there is a master equality engine
95
98778
    if (d_masterEqualityEngine != nullptr)
96
    {
97
      // set the master equality engine of the theory's equality engine
98
67890
      eet.d_allocEe->setMasterEqualityEngine(d_masterEqualityEngine.get());
99
    }
100
  }
101
9878
}
102
103
7469
void EqEngineManagerDistributed::notifyModel(bool incomplete)
104
{
105
  // should have a consistent master equality engine
106
7469
  if (d_masterEqualityEngine.get() != nullptr)
107
  {
108
3238
    AlwaysAssert(d_masterEqualityEngine->consistent());
109
  }
110
7469
}
111
112
}  // namespace theory
113
29502
}  // namespace cvc5