1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/******************************************************************************
* Top contributors (to current version):
* Andrew Reynolds
*
* This file is part of the cvc5 project.
*
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
* in the top-level source directory and their institutional affiliations.
* All rights reserved. See the file COPYING in the top-level source
* directory for licensing information.
* ****************************************************************************
*
* Management of a distributed approach for equality sharing.
*/
#include "theory/ee_manager_distributed.h"
#include "theory/quantifiers_engine.h"
#include "theory/shared_solver.h"
#include "theory/theory_engine.h"
#include "theory/uf/equality_engine.h"
namespace cvc5 {
namespace theory {
EqEngineManagerDistributed::EqEngineManagerDistributed(Env& env,
TheoryEngine& te,
SharedSolver& shs)
: EqEngineManager(env, te, shs), d_masterEENotify(nullptr)
{
}
EqEngineManagerDistributed::~EqEngineManagerDistributed()
{
}
void EqEngineManagerDistributed::initializeTheories()
{
context::Context* c = context();
// initialize the shared solver
EeSetupInfo esis;
if (d_sharedSolver.needsEqualityEngine(esis))
{
// allocate an equality engine for the shared terms database
d_stbEqualityEngine.reset(allocateEqualityEngine(esis, c));
d_sharedSolver.setEqualityEngine(d_stbEqualityEngine.get());
}
else
{
Unhandled() << "Expected shared solver to use equality engine";
}
const LogicInfo& logicInfo = d_env.getLogicInfo();
if (logicInfo.isQuantified())
{
// construct the master equality engine
Assert(d_masterEqualityEngine == nullptr);
QuantifiersEngine* qe = d_te.getQuantifiersEngine();
Assert(qe != nullptr);
d_masterEENotify.reset(new quantifiers::MasterNotifyClass(qe));
d_masterEqualityEngine = std::make_unique<eq::EqualityEngine>(
d_env, c, *d_masterEENotify.get(), "theory::master", false);
}
// allocate equality engines per theory
for (TheoryId theoryId = theory::THEORY_FIRST;
theoryId != theory::THEORY_LAST;
++theoryId)
{
Theory* t = d_te.theoryOf(theoryId);
if (t == nullptr)
{
// theory not active, skip
continue;
}
// always allocate an object in d_einfo here
EeTheoryInfo& eet = d_einfo[theoryId];
EeSetupInfo esi;
if (!t->needsEqualityEngine(esi))
{
// the theory said it doesn't need an equality engine, skip
continue;
}
if (esi.d_useMaster)
{
// the theory said it wants to use the master equality engine
eet.d_usedEe = d_masterEqualityEngine.get();
continue;
}
// allocate the equality engine
eet.d_allocEe.reset(allocateEqualityEngine(esi, c));
// the theory uses the equality engine
eet.d_usedEe = eet.d_allocEe.get();
// if there is a master equality engine
if (d_masterEqualityEngine != nullptr)
{
// set the master equality engine of the theory's equality engine
eet.d_allocEe->setMasterEqualityEngine(d_masterEqualityEngine.get());
}
}
}
void EqEngineManagerDistributed::notifyModel(bool incomplete)
{
// should have a consistent master equality engine
if (d_masterEqualityEngine.get() != nullptr)
{
AlwaysAssert(d_masterEqualityEngine->consistent());
}
}
} // namespace theory
} // namespace cvc5
|