GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/prop/proof_post_processor.cpp Lines: 38 44 86.4 %
Date: 2021-09-29 Branches: 46 152 30.3 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Haniel Barbosa
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 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 "theory/builtin/proof_checker.h"
19
20
namespace cvc5 {
21
namespace prop {
22
23
64
ProofPostprocessCallback::ProofPostprocessCallback(
24
64
    ProofNodeManager* pnm, ProofCnfStream* proofCnfStream)
25
64
    : d_pnm(pnm), d_proofCnfStream(proofCnfStream)
26
{
27
64
}
28
29
43
void ProofPostprocessCallback::initializeUpdate() { d_assumpToProof.clear(); }
30
31
143
bool ProofPostprocessCallback::shouldUpdate(std::shared_ptr<ProofNode> pn,
32
                                            const std::vector<Node>& fa,
33
                                            bool& continueUpdate)
34
{
35
143
  bool result = pn->getRule() == PfRule::ASSUME
36
286
                && d_proofCnfStream->hasProofFor(pn->getResult());
37
  // check if should continue traversing
38
143
  if (d_proofCnfStream->isBlocked(pn))
39
  {
40
    continueUpdate = false;
41
    result = false;
42
  }
43
143
  return result;
44
}
45
46
40
bool ProofPostprocessCallback::update(Node res,
47
                                      PfRule id,
48
                                      const std::vector<Node>& children,
49
                                      const std::vector<Node>& args,
50
                                      CDProof* cdp,
51
                                      bool& continueUpdate)
52
{
53
80
  Trace("prop-proof-pp-debug")
54
40
      << "- Post process " << id << " " << children << " / " << args << "\n";
55
40
  Assert(id == PfRule::ASSUME);
56
  // we cache based on the assumption node, not the proof node, since there
57
  // may be multiple occurrences of the same node.
58
80
  Node f = args[0];
59
80
  std::shared_ptr<ProofNode> pfn;
60
  std::map<Node, std::shared_ptr<ProofNode>>::iterator it =
61
40
      d_assumpToProof.find(f);
62
40
  if (it != d_assumpToProof.end())
63
  {
64
    Trace("prop-proof-pp-debug") << "...already computed" << std::endl;
65
    pfn = it->second;
66
  }
67
  else
68
  {
69
40
    Assert(d_proofCnfStream != nullptr);
70
    // get proof from proof cnf stream
71
40
    pfn = d_proofCnfStream->getProofFor(f);
72
40
    Assert(pfn != nullptr && pfn->getResult() == f);
73
40
    if (Trace.isOn("prop-proof-pp"))
74
    {
75
      Trace("prop-proof-pp") << "=== Connect CNF proof for: " << f << "\n";
76
      Trace("prop-proof-pp") << *pfn.get() << "\n";
77
    }
78
40
    d_assumpToProof[f] = pfn;
79
  }
80
  // connect the proof
81
40
  cdp->addProof(pfn);
82
  // do not recursively process the result
83
40
  continueUpdate = false;
84
  // moreover block the fact f so that its proof node is not traversed if we run
85
  // this post processor again (which can happen in incremental benchmarks)
86
40
  d_proofCnfStream->addBlocked(pfn);
87
80
  return true;
88
}
89
90
64
ProofPostproccess::ProofPostproccess(ProofNodeManager* pnm,
91
64
                                     ProofCnfStream* proofCnfStream)
92
64
    : d_cb(pnm, proofCnfStream), d_pnm(pnm)
93
{
94
64
}
95
96
64
ProofPostproccess::~ProofPostproccess() {}
97
98
43
void ProofPostproccess::process(std::shared_ptr<ProofNode> pf)
99
{
100
  // Initialize the callback, which computes necessary static information about
101
  // how to process, including how to process assumptions in pf.
102
43
  d_cb.initializeUpdate();
103
  // now, process
104
86
  ProofNodeUpdater updater(d_pnm, d_cb);
105
43
  updater.process(pf);
106
43
}
107
108
}  // namespace prop
109
22746
}  // namespace cvc5