LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory - shared_solver.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2026-07-03 10:34:34 Functions: 1 2 50.0 %
Branches: 0 0 -

           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                 :            :  * Base class for shared solver.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "cvc5_private.h"
      14                 :            : 
      15                 :            : #ifndef CVC5__THEORY__SHARED_SOLVER__H
      16                 :            : #define CVC5__THEORY__SHARED_SOLVER__H
      17                 :            : 
      18                 :            : #include "expr/node.h"
      19                 :            : #include "smt/env_obj.h"
      20                 :            : #include "theory/inference_id.h"
      21                 :            : #include "theory/shared_terms_database.h"
      22                 :            : #include "theory/term_registration_visitor.h"
      23                 :            : #include "theory/valuation.h"
      24                 :            : 
      25                 :            : namespace cvc5::internal {
      26                 :            : 
      27                 :            : class LogicInfo;
      28                 :            : class ProofNodeManager;
      29                 :            : class TheoryEngine;
      30                 :            : 
      31                 :            : namespace theory {
      32                 :            : 
      33                 :            : struct EeSetupInfo;
      34                 :            : class TheoryInferenceManager;
      35                 :            : 
      36                 :            : /**
      37                 :            :  * A base class for shared solver. The shared solver is the component of theory
      38                 :            :  * engine that behaves like a theory solver, and whose purpose is to ensure the
      39                 :            :  * main theory combination method can be performed in CombinationEngine.
      40                 :            :  * Its role is to:
      41                 :            :  * (1) Notify the individual theories of shared terms via addSharedTerms,
      42                 :            :  * (2) Be the official interface for equality statuses,
      43                 :            :  * (3) Propagate equalities to TheoryEngine when necessary and explain them.
      44                 :            :  */
      45                 :            : class SharedSolver : protected EnvObj
      46                 :            : {
      47                 :            :  public:
      48                 :            :   SharedSolver(Env& env, TheoryEngine& te);
      49                 :      50981 :   virtual ~SharedSolver() {}
      50                 :            :   //------------------------------------- initialization
      51                 :            :   /**
      52                 :            :    * Returns true if we need an equality engine, this has the same contract
      53                 :            :    * as Theory::needsEqualityEngine.
      54                 :            :    */
      55                 :            :   virtual bool needsEqualityEngine(theory::EeSetupInfo& esi);
      56                 :            :   /**
      57                 :            :    * Set the equality engine. This should be called by equality engine manager
      58                 :            :    * during EqEngineManager::initializeTheories.
      59                 :            :    */
      60                 :            :   virtual void setEqualityEngine(eq::EqualityEngine* ee) = 0;
      61                 :            :   //------------------------------------- end initialization
      62                 :            :   /**
      63                 :            :    * Called when the given atom is pre-registered in TheoryEngine.
      64                 :            :    *
      65                 :            :    * This calls Theory::preRegisterTerm on all subterms of atom for the
      66                 :            :    * appropriate theories.
      67                 :            :    *
      68                 :            :    * Also, if sharing is enabled, this adds atom as an equality to propagate in
      69                 :            :    * the shared terms database if it is an equality, and adds its shared terms
      70                 :            :    * to the appropariate theories.
      71                 :            :    *
      72                 :            :    * @param atom The atom to preregister
      73                 :            :    */
      74                 :            :   void preRegister(TNode atom);
      75                 :            :   /**
      76                 :            :    * Pre-notify assertion fact with the given atom. This is called when any
      77                 :            :    * fact is asserted in TheoryEngine, just before it is dispatched to the
      78                 :            :    * appropriate theory.
      79                 :            :    *
      80                 :            :    * This calls Theory::notifySharedTerm for the shared terms of the atom.
      81                 :            :    */
      82                 :            :   void preNotifySharedFact(TNode atom);
      83                 :            :   /**
      84                 :            :    * Get the equality status of a and b.
      85                 :            :    *
      86                 :            :    * This method is used by theories via Valuation mostly for determining their
      87                 :            :    * care graph.
      88                 :            :    */
      89                 :            :   virtual EqualityStatus getEqualityStatus(TNode a, TNode b);
      90                 :            :   /**
      91                 :            :    * Explain literal, which returns a conjunction of literals that entail
      92                 :            :    * the given one.
      93                 :            :    */
      94                 :            :   virtual TrustNode explain(TNode literal, TheoryId id) = 0;
      95                 :            :   /**
      96                 :            :    * Assert n to the shared terms database.
      97                 :            :    *
      98                 :            :    * This method is called by TheoryEngine when a fact has been marked to
      99                 :            :    * send to THEORY_BUILTIN, meaning that shared terms database should
     100                 :            :    * maintain this fact. In the distributed equality engine architecture,
     101                 :            :    * this is the case when either an equality is asserted from the SAT solver
     102                 :            :    * or a theory propagates an equality between shared terms.
     103                 :            :    */
     104                 :            :   virtual void assertShared(TNode n, bool polarity, TNode reason) = 0;
     105                 :            :   /** Is term t a shared term? */
     106                 :            :   virtual bool isShared(TNode t) const;
     107                 :            : 
     108                 :            :   /**
     109                 :            :    * Propagate the predicate with polarity value on the output channel of this
     110                 :            :    * solver.
     111                 :            :    */
     112                 :            :   bool propagateLit(TNode predicate, bool value);
     113                 :            :   /**
     114                 :            :    * Method called by equalityEngine when a becomes (dis-)equal to b and a and b
     115                 :            :    * are shared with the theory. Returns false if there is a direct conflict
     116                 :            :    * (via rewrite for example).
     117                 :            :    */
     118                 :            :   bool propagateSharedEquality(theory::TheoryId theory,
     119                 :            :                                TNode a,
     120                 :            :                                TNode b,
     121                 :            :                                bool value);
     122                 :            :   /** Send lemma to the theory engine, atomsTo is the theory to send atoms to */
     123                 :            :   void sendLemma(TrustNode trn, TheoryId atomsTo, InferenceId id);
     124                 :            :   /** Send conflict to the theory engine */
     125                 :            :   void sendConflict(TrustNode trn, InferenceId id);
     126                 :            : 
     127                 :            :  protected:
     128                 :            :   /** Solver-specific pre-register shared */
     129                 :            :   virtual void preRegisterSharedInternal(TNode t) = 0;
     130                 :            :   /** Reference to the theory engine */
     131                 :            :   TheoryEngine& d_te;
     132                 :            :   /** Logic info of theory engine (cached) */
     133                 :            :   const LogicInfo& d_logicInfo;
     134                 :            :   /** The database of shared terms.*/
     135                 :            :   SharedTermsDatabase d_sharedTerms;
     136                 :            :   /** Default visitor for pre-registration */
     137                 :            :   PreRegisterVisitor d_preRegistrationVisitor;
     138                 :            :   /** Visitor for collecting shared terms */
     139                 :            :   SharedTermsVisitor d_sharedTermsVisitor;
     140                 :            :   /** Theory inference manager of theory builtin */
     141                 :            :   TheoryInferenceManager* d_im;
     142                 :            : };
     143                 :            : 
     144                 :            : }  // namespace theory
     145                 :            : }  // namespace cvc5::internal
     146                 :            : 
     147                 :            : #endif /* CVC5__THEORY__SHARED_SOLVER__H */

Generated by: LCOV version 1.14