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