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