1 /********************* */
2 /*! \file ee_manager_distributed.cpp
4 ** Top contributors (to current version):
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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.\endverbatim
12 ** \brief Management of a distributed approach for equality sharing.
15 #include "theory/ee_manager_distributed.h"
17 #include "theory/quantifiers_engine.h"
18 #include "theory/theory_engine.h"
23 EqEngineManagerDistributed::EqEngineManagerDistributed(TheoryEngine
& te
)
24 : d_te(te
), d_masterEENotify(nullptr)
28 EqEngineManagerDistributed::~EqEngineManagerDistributed()
30 // pop the model context which we pushed on initialization
31 d_modelEeContext
.pop();
34 void EqEngineManagerDistributed::initializeTheories()
36 context::Context
* c
= d_te
.getSatContext();
38 // allocate equality engines per theory
39 for (TheoryId theoryId
= theory::THEORY_FIRST
;
40 theoryId
!= theory::THEORY_LAST
;
43 Theory
* t
= d_te
.theoryOf(theoryId
);
46 // theory not active, skip
49 // always allocate an object in d_einfo here
50 EeTheoryInfo
& eet
= d_einfo
[theoryId
];
52 if (!t
->needsEqualityEngine(esi
))
54 // theory said it doesn't need an equality engine, skip
57 // allocate the equality engine
58 eet
.d_allocEe
.reset(allocateEqualityEngine(esi
, c
));
59 // the theory uses the equality engine
60 eet
.d_usedEe
= eet
.d_allocEe
.get();
63 const LogicInfo
& logicInfo
= d_te
.getLogicInfo();
64 if (logicInfo
.isQuantified())
66 // construct the master equality engine
67 Assert(d_masterEqualityEngine
== nullptr);
68 QuantifiersEngine
* qe
= d_te
.getQuantifiersEngine();
69 Assert(qe
!= nullptr);
70 d_masterEENotify
.reset(new MasterNotifyClass(qe
));
71 d_masterEqualityEngine
.reset(new eq::EqualityEngine(*d_masterEENotify
.get(),
76 for (TheoryId theoryId
= theory::THEORY_FIRST
;
77 theoryId
!= theory::THEORY_LAST
;
80 Theory
* t
= d_te
.theoryOf(theoryId
);
83 // theory not active, skip
86 EeTheoryInfo
& eet
= d_einfo
[theoryId
];
87 // Get the allocated equality engine, and connect it to the master
89 eq::EqualityEngine
* eeAlloc
= eet
.d_allocEe
.get();
90 if (eeAlloc
!= nullptr)
92 // set the master equality engine of the theory's equality engine
93 eeAlloc
->setMasterEqualityEngine(d_masterEqualityEngine
.get());
99 void EqEngineManagerDistributed::initializeModel(
100 TheoryModel
* m
, eq::EqualityEngineNotify
* notify
)
102 Assert(m
!= nullptr);
103 // initialize the model equality engine
105 if (m
->needsEqualityEngine(esim
))
107 // use the provided notification object
108 esim
.d_notify
= notify
;
109 d_modelEqualityEngine
.reset(
110 allocateEqualityEngine(esim
, &d_modelEeContext
));
111 m
->setEqualityEngine(d_modelEqualityEngine
.get());
115 AlwaysAssert(false) << "Expected model to use equality engine";
118 // We push a context during initialization since the model is cleared during
119 // collectModelInfo using pop/push.
120 d_modelEeContext
.push();
123 void EqEngineManagerDistributed::MasterNotifyClass::eqNotifyNewClass(TNode t
)
125 // adds t to the quantifiers term database
126 d_quantEngine
->eqNotifyNewClass(t
);
129 context::Context
* EqEngineManagerDistributed::getModelEqualityEngineContext()
131 return &d_modelEeContext
;
134 eq::EqualityEngine
* EqEngineManagerDistributed::getModelEqualityEngine()
136 return d_modelEqualityEngine
.get();
139 eq::EqualityEngine
* EqEngineManagerDistributed::getCoreEqualityEngine()
141 return d_masterEqualityEngine
.get();
144 eq::EqualityEngine
* EqEngineManagerDistributed::allocateEqualityEngine(
145 EeSetupInfo
& esi
, context::Context
* c
)
147 if (esi
.d_notify
!= nullptr)
149 return new eq::EqualityEngine(
150 *esi
.d_notify
, c
, esi
.d_name
, esi
.d_constantsAreTriggers
);
152 // the theory doesn't care about explicit notifications
153 return new eq::EqualityEngine(c
, esi
.d_name
, esi
.d_constantsAreTriggers
);
156 } // namespace theory