LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/prop - proof_post_processor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 48 53 90.6 %
Date: 2026-03-28 10:41:09 Functions: 10 10 100.0 %
Branches: 19 44 43.2 %

           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 the module for processing proof nodes in the prop engine.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "prop/proof_post_processor.h"
      14                 :            : 
      15                 :            : #include "proof/proof.h"
      16                 :            : #include "theory/builtin/proof_checker.h"
      17                 :            : 
      18                 :            : namespace cvc5::internal {
      19                 :            : namespace prop {
      20                 :            : 
      21                 :      20037 : ProofPostprocessCallback::ProofPostprocessCallback(
      22                 :      20037 :     Env& env, ProofGenerator* proofCnfStream)
      23                 :      20037 :     : EnvObj(env), d_pg(proofCnfStream), d_blocked(userContext())
      24                 :            : {
      25                 :      20037 : }
      26                 :            : 
      27                 :       8518 : void ProofPostprocessCallback::initializeUpdate() { d_assumpToProof.clear(); }
      28                 :            : 
      29                 :     588989 : bool ProofPostprocessCallback::shouldUpdate(
      30                 :            :     std::shared_ptr<ProofNode> pn,
      31                 :            :     CVC5_UNUSED const std::vector<Node>& fa,
      32                 :            :     bool& continueUpdate)
      33                 :            : {
      34                 :            :   bool result =
      35 [ +  + ][ +  - ]:     588989 :       pn->getRule() == ProofRule::ASSUME && d_pg->hasProofFor(pn->getResult());
         [ +  + ][ -  - ]
      36                 :    1177978 :   if (TraceIsOn("prop-proof-pp") && !result
      37 [ -  + ][ -  - ]:    1177978 :       && pn->getRule() == ProofRule::ASSUME)
                 [ +  - ]
      38                 :            :   {
      39         [ -  - ]:          0 :     Trace("prop-proof-pp") << "- Ignoring no-proof assumption "
      40                 :          0 :                            << pn->getResult() << "\n";
      41                 :            :   }
      42                 :            :   // check if should continue traversing
      43         [ +  + ]:     588989 :   if (isBlocked(pn))
      44                 :            :   {
      45                 :          2 :     continueUpdate = false;
      46                 :          2 :     result = false;
      47                 :            :   }
      48                 :     588989 :   return result;
      49                 :            : }
      50                 :            : 
      51                 :     352159 : bool ProofPostprocessCallback::update(Node res,
      52                 :            :                                       ProofRule id,
      53                 :            :                                       const std::vector<Node>& children,
      54                 :            :                                       const std::vector<Node>& args,
      55                 :            :                                       CDProof* cdp,
      56                 :            :                                       bool& continueUpdate)
      57                 :            : {
      58         [ +  - ]:     704318 :   Trace("prop-proof-pp") << "- Post process " << id << " " << res << " : "
      59                 :          0 :                          << children << " / " << args << "\n"
      60                 :     352159 :                          << push;
      61 [ -  + ][ -  + ]:     352159 :   Assert(id == ProofRule::ASSUME);
                 [ -  - ]
      62                 :            :   // we cache based on the assumption node, not the proof node, since there
      63                 :            :   // may be multiple occurrences of the same node.
      64                 :     352159 :   Node f = args[0];
      65                 :     352159 :   std::shared_ptr<ProofNode> pfn;
      66                 :            :   std::map<Node, std::shared_ptr<ProofNode>>::iterator it =
      67                 :     352159 :       d_assumpToProof.find(f);
      68         [ +  + ]:     352159 :   if (it != d_assumpToProof.end())
      69                 :            :   {
      70         [ +  - ]:        157 :     Trace("prop-proof-pp") << "...already computed" << std::endl;
      71                 :        157 :     pfn = it->second;
      72                 :            :   }
      73                 :            :   else
      74                 :            :   {
      75 [ -  + ][ -  + ]:     352002 :     Assert(d_pg != nullptr);
                 [ -  - ]
      76                 :            :     // get proof from proof cnf stream
      77                 :     352002 :     pfn = d_pg->getProofFor(f);
      78                 :     352002 :     Assert(pfn != nullptr && pfn->getResult() == f);
      79         [ -  + ]:     352002 :     if (TraceIsOn("prop-proof-pp"))
      80                 :            :     {
      81         [ -  - ]:          0 :       Trace("prop-proof-pp") << "=== Connect CNF proof for: " << f << "\n";
      82         [ -  - ]:          0 :       Trace("prop-proof-pp") << *pfn.get() << "\n";
      83                 :            :     }
      84                 :     352002 :     d_assumpToProof[f] = pfn;
      85                 :            :   }
      86         [ +  - ]:     352159 :   Trace("prop-proof-pp") << pop;
      87                 :            :   // connect the proof
      88                 :     352159 :   cdp->addProof(pfn);
      89                 :            :   // do not recursively process the result
      90                 :     352159 :   continueUpdate = false;
      91                 :            :   // moreover block the fact f so that its proof node is not traversed if we run
      92                 :            :   // this post processor again (which can happen in incremental benchmarks)
      93                 :     352159 :   addBlocked(pfn);
      94                 :     352159 :   return true;
      95                 :     352159 : }
      96                 :            : 
      97                 :     352159 : void ProofPostprocessCallback::addBlocked(std::shared_ptr<ProofNode> pfn)
      98                 :            : {
      99                 :     352159 :   d_blocked.insert(pfn);
     100                 :     352159 : }
     101                 :            : 
     102                 :     588989 : bool ProofPostprocessCallback::isBlocked(std::shared_ptr<ProofNode> pfn)
     103                 :            : {
     104                 :     588989 :   return d_blocked.contains(pfn);
     105                 :            : }
     106                 :            : 
     107                 :      20037 : ProofPostprocess::ProofPostprocess(Env& env, ProofGenerator* pg)
     108                 :      20037 :     : EnvObj(env), d_cb(env, pg)
     109                 :            : {
     110                 :      20037 : }
     111                 :            : 
     112                 :      40046 : ProofPostprocess::~ProofPostprocess() {}
     113                 :            : 
     114                 :       8518 : void ProofPostprocess::process(std::shared_ptr<ProofNode> pf)
     115                 :            : {
     116                 :            :   // Initialize the callback, which computes necessary static information about
     117                 :            :   // how to process, including how to process assumptions in pf.
     118                 :       8518 :   d_cb.initializeUpdate();
     119                 :            :   // now, process
     120                 :       8518 :   ProofNodeUpdater updater(d_env, d_cb);
     121                 :       8518 :   updater.process(pf);
     122                 :       8518 : }
     123                 :            : 
     124                 :            : }  // namespace prop
     125                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14