GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/ee_manager_distributed.cpp Lines: 42 43 97.7 %
Date: 2021-11-07 Branches: 39 108 36.1 %

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