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