GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arrays/inference_manager.cpp Lines: 20 59 33.9 %
Date: 2021-09-29 Branches: 49 202 24.3 %

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
6271
InferenceManager::InferenceManager(Env& env,
31
                                   Theory& t,
32
                                   TheoryState& state,
33
6271
                                   ProofNodeManager* pnm)
34
    : TheoryInferenceManager(env, t, state, pnm, "theory::arrays::", false),
35
      d_lemmaPg(pnm ? new EagerProofGenerator(
36
120
                    pnm, userContext(), "ArrayLemmaProofGenerator")
37
6391
                    : nullptr)
38
{
39
6271
}
40
41
12349
bool InferenceManager::assertInference(TNode atom,
42
                                       bool polarity,
43
                                       InferenceId id,
44
                                       TNode reason,
45
                                       PfRule pfr)
46
{
47
24698
  Trace("arrays-infer") << "TheoryArrays::assertInference: "
48
24698
                        << (polarity ? Node(atom) : atom.notNode()) << " by "
49
12349
                        << reason << "; " << id << std::endl;
50
12349
  Assert(atom.getKind() == EQUAL);
51
  // if proofs are enabled, we determine which proof rule to add, otherwise
52
  // we simply assert the internal fact
53
12349
  if (isProofEnabled())
54
  {
55
    Node fact = polarity ? Node(atom) : atom.notNode();
56
    std::vector<Node> children;
57
    std::vector<Node> args;
58
    // convert to proof rule application
59
    convert(pfr, fact, reason, children, args);
60
    return assertInternalFact(atom, polarity, id, pfr, children, args);
61
  }
62
12349
  return assertInternalFact(atom, polarity, id, reason);
63
}
64
65
4739
bool InferenceManager::arrayLemma(
66
    Node conc, InferenceId id, Node exp, PfRule pfr, LemmaProperty p)
67
{
68
9478
  Trace("arrays-infer") << "TheoryArrays::arrayLemma: " << conc << " by " << exp
69
4739
                        << "; " << id << std::endl;
70
4739
  NodeManager* nm = NodeManager::currentNM();
71
4739
  if (isProofEnabled())
72
  {
73
    std::vector<Node> children;
74
    std::vector<Node> args;
75
    // convert to proof rule application
76
    convert(pfr, conc, exp, children, args);
77
    // make the trusted lemma based on the eager proof generator and send
78
    TrustNode tlem = d_lemmaPg->mkTrustNode(conc, pfr, children, args);
79
    return trustedLemma(tlem, id, p);
80
  }
81
  // send lemma without proofs
82
9478
  Node lem = nm->mkNode(IMPLIES, exp, conc);
83
4739
  return lemma(lem, id, p);
84
}
85
86
void InferenceManager::convert(PfRule& id,
87
                               Node conc,
88
                               Node exp,
89
                               std::vector<Node>& children,
90
                               std::vector<Node>& args)
91
{
92
  // note that children must contain something equivalent to exp,
93
  // regardless of the PfRule.
94
  switch (id)
95
  {
96
    case PfRule::MACRO_SR_PRED_INTRO:
97
      Assert(exp.isConst());
98
      args.push_back(conc);
99
      break;
100
    case PfRule::ARRAYS_READ_OVER_WRITE:
101
      if (exp.isConst())
102
      {
103
        // Premise can be shown by rewriting, use standard predicate intro rule.
104
        // This is the case where we have 2 constant indices.
105
        id = PfRule::MACRO_SR_PRED_INTRO;
106
        args.push_back(conc);
107
      }
108
      else
109
      {
110
        children.push_back(exp);
111
        args.push_back(conc[0]);
112
      }
113
      break;
114
    case PfRule::ARRAYS_READ_OVER_WRITE_CONTRA: children.push_back(exp); break;
115
    case PfRule::ARRAYS_READ_OVER_WRITE_1:
116
      Assert(exp.isConst());
117
      args.push_back(conc[0]);
118
      break;
119
    case PfRule::ARRAYS_EXT: children.push_back(exp); break;
120
    default:
121
      if (id != PfRule::THEORY_INFERENCE)
122
      {
123
        Assert(false) << "Unknown rule " << id << "\n";
124
      }
125
      children.push_back(exp);
126
      args.push_back(conc);
127
      args.push_back(
128
          builtin::BuiltinProofRuleChecker::mkTheoryIdNode(THEORY_ARRAYS));
129
      id = PfRule::THEORY_INFERENCE;
130
      break;
131
  }
132
}
133
134
}  // namespace arrays
135
}  // namespace theory
136
22746
}  // namespace cvc5