GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arrays/inference_manager.cpp Lines: 49 59 83.1 %
Date: 2021-09-07 Branches: 78 202 38.6 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Gereon Kremer, Aina Niemetz
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
 * Arrays inference manager.
14
 */
15
16
#include "theory/arrays/inference_manager.h"
17
18
#include "options/smt_options.h"
19
#include "theory/builtin/proof_checker.h"
20
#include "theory/theory.h"
21
#include "theory/theory_state.h"
22
#include "theory/uf/equality_engine.h"
23
24
using namespace cvc5::kind;
25
26
namespace cvc5 {
27
namespace theory {
28
namespace arrays {
29
30
9926
InferenceManager::InferenceManager(Theory& t,
31
                                   TheoryState& state,
32
9926
                                   ProofNodeManager* pnm)
33
    : TheoryInferenceManager(t, state, pnm, "theory::arrays::", false),
34
      d_lemmaPg(pnm ? new EagerProofGenerator(
35
2486
                    pnm, state.getUserContext(), "ArrayLemmaProofGenerator")
36
12412
                    : nullptr)
37
{
38
9926
}
39
40
15506
bool InferenceManager::assertInference(TNode atom,
41
                                       bool polarity,
42
                                       InferenceId id,
43
                                       TNode reason,
44
                                       PfRule pfr)
45
{
46
31012
  Trace("arrays-infer") << "TheoryArrays::assertInference: "
47
31012
                        << (polarity ? Node(atom) : atom.notNode()) << " by "
48
15506
                        << reason << "; " << id << std::endl;
49
15506
  Assert(atom.getKind() == EQUAL);
50
  // if proofs are enabled, we determine which proof rule to add, otherwise
51
  // we simply assert the internal fact
52
15506
  if (isProofEnabled())
53
  {
54
1796
    Node fact = polarity ? Node(atom) : atom.notNode();
55
1796
    std::vector<Node> children;
56
1796
    std::vector<Node> args;
57
    // convert to proof rule application
58
898
    convert(pfr, fact, reason, children, args);
59
898
    return assertInternalFact(atom, polarity, id, pfr, children, args);
60
  }
61
14608
  return assertInternalFact(atom, polarity, id, reason);
62
}
63
64
5905
bool InferenceManager::arrayLemma(
65
    Node conc, InferenceId id, Node exp, PfRule pfr, LemmaProperty p)
66
{
67
11810
  Trace("arrays-infer") << "TheoryArrays::arrayLemma: " << conc << " by " << exp
68
5905
                        << "; " << id << std::endl;
69
5905
  NodeManager* nm = NodeManager::currentNM();
70
5905
  if (isProofEnabled())
71
  {
72
662
    std::vector<Node> children;
73
662
    std::vector<Node> args;
74
    // convert to proof rule application
75
331
    convert(pfr, conc, exp, children, args);
76
    // make the trusted lemma based on the eager proof generator and send
77
662
    TrustNode tlem = d_lemmaPg->mkTrustNode(conc, pfr, children, args);
78
331
    return trustedLemma(tlem, id, p);
79
  }
80
  // send lemma without proofs
81
11148
  Node lem = nm->mkNode(IMPLIES, exp, conc);
82
5574
  return lemma(lem, id, p);
83
}
84
85
1229
void InferenceManager::convert(PfRule& id,
86
                               Node conc,
87
                               Node exp,
88
                               std::vector<Node>& children,
89
                               std::vector<Node>& args)
90
{
91
  // note that children must contain something equivalent to exp,
92
  // regardless of the PfRule.
93
1229
  switch (id)
94
  {
95
119
    case PfRule::MACRO_SR_PRED_INTRO:
96
119
      Assert(exp.isConst());
97
119
      args.push_back(conc);
98
119
      break;
99
818
    case PfRule::ARRAYS_READ_OVER_WRITE:
100
818
      if (exp.isConst())
101
      {
102
        // Premise can be shown by rewriting, use standard predicate intro rule.
103
        // This is the case where we have 2 constant indices.
104
51
        id = PfRule::MACRO_SR_PRED_INTRO;
105
51
        args.push_back(conc);
106
      }
107
      else
108
      {
109
767
        children.push_back(exp);
110
767
        args.push_back(conc[0]);
111
      }
112
818
      break;
113
    case PfRule::ARRAYS_READ_OVER_WRITE_CONTRA: children.push_back(exp); break;
114
120
    case PfRule::ARRAYS_READ_OVER_WRITE_1:
115
120
      Assert(exp.isConst());
116
120
      args.push_back(conc[0]);
117
120
      break;
118
172
    case PfRule::ARRAYS_EXT: children.push_back(exp); break;
119
    default:
120
      if (id != PfRule::THEORY_INFERENCE)
121
      {
122
        Assert(false) << "Unknown rule " << id << "\n";
123
      }
124
      children.push_back(exp);
125
      args.push_back(conc);
126
      args.push_back(
127
          builtin::BuiltinProofRuleChecker::mkTheoryIdNode(THEORY_ARRAYS));
128
      id = PfRule::THEORY_INFERENCE;
129
      break;
130
  }
131
1229
}
132
133
}  // namespace arrays
134
}  // namespace theory
135
29502
}  // namespace cvc5