GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/prop/proof_post_processor.cpp Lines: 40 44 90.9 %
Date: 2021-09-16 Branches: 51 152 33.6 %

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
1252
ProofPostprocessCallback::ProofPostprocessCallback(
24
1252
    ProofNodeManager* pnm, ProofCnfStream* proofCnfStream)
25
1252
    : d_pnm(pnm), d_proofCnfStream(proofCnfStream)
26
{
27
1252
}
28
29
2829
void ProofPostprocessCallback::initializeUpdate() { d_assumpToProof.clear(); }
30
31
860748
bool ProofPostprocessCallback::shouldUpdate(std::shared_ptr<ProofNode> pn,
32
                                            const std::vector<Node>& fa,
33
                                            bool& continueUpdate)
34
{
35
860748
  bool result = pn->getRule() == PfRule::ASSUME
36
1721496
                && d_proofCnfStream->hasProofFor(pn->getResult());
37
  // check if should continue traversing
38
860748
  if (d_proofCnfStream->isBlocked(pn))
39
  {
40
    continueUpdate = false;
41
    result = false;
42
  }
43
860748
  return result;
44
}
45
46
532720
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
1065440
  Trace("prop-proof-pp-debug")
54
532720
      << "- Post process " << id << " " << children << " / " << args << "\n";
55
532720
  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
1065440
  Node f = args[0];
59
1065440
  std::shared_ptr<ProofNode> pfn;
60
  std::map<Node, std::shared_ptr<ProofNode>>::iterator it =
61
532720
      d_assumpToProof.find(f);
62
532720
  if (it != d_assumpToProof.end())
63
  {
64
418354
    Trace("prop-proof-pp-debug") << "...already computed" << std::endl;
65
418354
    pfn = it->second;
66
  }
67
  else
68
  {
69
114366
    Assert(d_proofCnfStream != nullptr);
70
    // get proof from proof cnf stream
71
114366
    pfn = d_proofCnfStream->getProofFor(f);
72
114366
    Assert(pfn != nullptr && pfn->getResult() == f);
73
114366
    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
114366
    d_assumpToProof[f] = pfn;
79
  }
80
  // connect the proof
81
532720
  cdp->addProof(pfn);
82
  // do not recursively process the result
83
532720
  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
532720
  d_proofCnfStream->addBlocked(pfn);
87
1065440
  return true;
88
}
89
90
1252
ProofPostproccess::ProofPostproccess(ProofNodeManager* pnm,
91
1252
                                     ProofCnfStream* proofCnfStream)
92
1252
    : d_cb(pnm, proofCnfStream), d_pnm(pnm)
93
{
94
1252
}
95
96
1252
ProofPostproccess::~ProofPostproccess() {}
97
98
2829
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
2829
  d_cb.initializeUpdate();
103
  // now, process
104
5658
  ProofNodeUpdater updater(d_pnm, d_cb);
105
2829
  updater.process(pf);
106
2829
}
107
108
}  // namespace prop
109
29577
}  // namespace cvc5