LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/sets - term_registry.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 70 70 100.0 %
Date: 2026-08-28 19:31:41 Functions: 6 6 100.0 %
Branches: 38 46 82.6 %

           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                 :            :  * Implementation of sets term registry object.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "theory/sets/term_registry.h"
      14                 :            : 
      15                 :            : #include "expr/emptyset.h"
      16                 :            : #include "expr/skolem_manager.h"
      17                 :            : 
      18                 :            : using namespace std;
      19                 :            : using namespace cvc5::internal::kind;
      20                 :            : 
      21                 :            : namespace cvc5::internal {
      22                 :            : namespace theory {
      23                 :            : namespace sets {
      24                 :            : 
      25                 :      28784 : TermRegistry::TermRegistry(Env& env, InferenceManager& im, SkolemCache& skc)
      26                 :            :     : EnvObj(env),
      27                 :      28784 :       d_im(im),
      28                 :      28784 :       d_skCache(skc),
      29                 :      28784 :       d_proxy(userContext()),
      30                 :      28784 :       d_proxy_to_term(userContext()),
      31                 :      37559 :       d_epg(
      32         [ +  + ]:      28784 :           env.isTheoryProofProducing()
      33                 :       8775 :               ? new EagerProofGenerator(env, nullptr, "sets::TermRegistry::epg")
      34                 :      57568 :               : nullptr)
      35                 :            : {
      36                 :      28784 : }
      37                 :            : 
      38                 :      39881 : Node TermRegistry::getProxy(Node n)
      39                 :            : {
      40                 :      39881 :   Kind nk = n.getKind();
      41 [ +  + ][ +  + ]:      39881 :   if (nk != Kind::SET_EMPTY && nk != Kind::SET_SINGLETON
      42 [ +  + ][ +  + ]:      17425 :       && nk != Kind::SET_INTER && nk != Kind::SET_MINUS && nk != Kind::SET_UNION
                 [ +  + ]
      43 [ +  + ][ +  + ]:       6813 :       && nk != Kind::SET_UNIVERSE && nk != Kind::SET_MAP)
      44                 :            :   {
      45                 :       5008 :     return n;
      46                 :            :   }
      47                 :      34873 :   NodeMap::const_iterator it = d_proxy.find(n);
      48         [ +  + ]:      34873 :   if (it != d_proxy.end())
      49                 :            :   {
      50                 :      28395 :     return (*it).second;
      51                 :            :   }
      52                 :       6478 :   NodeManager* nm = nodeManager();
      53                 :       6478 :   Node k = d_skCache.mkTypedSkolemCached(
      54                 :      12956 :       n.getType(), n, SkolemCache::SK_PURIFY, "sp");
      55                 :            : 
      56                 :       6478 :   d_proxy[n] = k;
      57                 :       6478 :   d_proxy_to_term[k] = n;
      58                 :       6478 :   Node eq = k.eqNode(n);
      59                 :       6478 :   sendSimpleLemmaInternal(eq, InferenceId::SETS_PROXY);
      60         [ +  + ]:       6478 :   if (nk == Kind::SET_SINGLETON)
      61                 :            :   {
      62                 :       5528 :     Node slem = nm->mkNode(Kind::SET_MEMBER, n[0], k);
      63                 :       2764 :     sendSimpleLemmaInternal(slem, InferenceId::SETS_PROXY_SINGLETON);
      64                 :       2764 :   }
      65                 :       6478 :   return k;
      66                 :       6478 : }
      67                 :            : 
      68                 :      19478 : Node TermRegistry::getEmptySet(TypeNode tn)
      69                 :            : {
      70                 :      19478 :   std::map<TypeNode, Node>::iterator it = d_emptyset.find(tn);
      71         [ +  + ]:      19478 :   if (it != d_emptyset.end())
      72                 :            :   {
      73                 :      19301 :     return it->second;
      74                 :            :   }
      75                 :        177 :   Node n = nodeManager()->mkConst(EmptySet(tn));
      76                 :        177 :   d_emptyset[tn] = n;
      77                 :        177 :   return n;
      78                 :        177 : }
      79                 :            : 
      80                 :       4905 : Node TermRegistry::getUnivSet(TypeNode tn)
      81                 :            : {
      82                 :       4905 :   std::map<TypeNode, Node>::iterator it = d_univset.find(tn);
      83         [ +  + ]:       4905 :   if (it != d_univset.end())
      84                 :            :   {
      85                 :       4661 :     return it->second;
      86                 :            :   }
      87                 :        244 :   NodeManager* nm = nodeManager();
      88                 :        244 :   Node n = nm->mkNullaryOperator(tn, Kind::SET_UNIVERSE);
      89                 :        244 :   d_univset[tn] = n;
      90                 :        244 :   return n;
      91                 :        244 : }
      92                 :            : 
      93                 :      21297 : void TermRegistry::debugPrintSet(Node s, const char* c) const
      94                 :            : {
      95         [ +  + ]:      21297 :   if (s.getNumChildren() == 0)
      96                 :            :   {
      97                 :      13749 :     NodeMap::const_iterator it = d_proxy_to_term.find(s);
      98         [ +  + ]:      13749 :     if (it != d_proxy_to_term.end())
      99                 :            :     {
     100                 :       3425 :       debugPrintSet((*it).second, c);
     101                 :            :     }
     102                 :            :     else
     103                 :            :     {
     104         [ +  - ]:      10324 :       Trace(c) << s;
     105                 :            :     }
     106                 :            :   }
     107                 :            :   else
     108                 :            :   {
     109 [ +  - ][ -  + ]:       7548 :     Trace(c) << "(" << s.getOperator();
                 [ -  - ]
     110         [ +  + ]:      21552 :     for (const Node& sc : s)
     111                 :            :     {
     112         [ +  - ]:      14004 :       Trace(c) << " ";
     113                 :      14004 :       debugPrintSet(sc, c);
     114                 :      14004 :     }
     115         [ +  - ]:       7548 :     Trace(c) << ")";
     116                 :            :   }
     117                 :      21297 : }
     118                 :            : 
     119                 :       9242 : void TermRegistry::sendSimpleLemmaInternal(Node n, InferenceId id)
     120                 :            : {
     121         [ +  - ]:       9242 :   Trace("sets-lemma") << "Sets::Lemma : " << n << " by " << id << std::endl;
     122         [ +  + ]:       9242 :   if (d_epg.get() != nullptr)
     123                 :            :   {
     124                 :            :     TrustNode teq =
     125                 :      11619 :         d_epg->mkTrustNode(n, ProofRule::MACRO_SR_PRED_INTRO, {}, {n});
     126                 :       3873 :     d_im.trustedLemma(teq, id);
     127                 :       3873 :   }
     128                 :            :   else
     129                 :            :   {
     130                 :       5369 :     d_im.lemma(n, id);
     131                 :            :   }
     132                 :       9242 : }
     133                 :            : 
     134                 :            : }  // namespace sets
     135                 :            : }  // namespace theory
     136                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14