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