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: 2024-09-28 11:33:24 Functions: 1 2 50.0 %
Branches: 0 0 -

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

Generated by: LCOV version 1.14