summaryrefslogtreecommitdiff
path: root/src/smt/preprocessor.cpp
blob: 7406b922efa280fe11a23586db3323443c327157 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/******************************************************************************
 * Top contributors (to current version):
 *   Andrew Reynolds, Morgan Deters, Aina Niemetz
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * The preprocessor of the SMT engine.
 */

#include "smt/preprocessor.h"

#include "options/expr_options.h"
#include "options/smt_options.h"
#include "preprocessing/preprocessing_pass_context.h"
#include "printer/printer.h"
#include "smt/abstract_values.h"
#include "smt/assertions.h"
#include "smt/dump.h"
#include "smt/env.h"
#include "smt/preprocess_proof_generator.h"
#include "smt/smt_engine.h"
#include "theory/rewriter.h"

using namespace std;
using namespace cvc5::theory;
using namespace cvc5::kind;

namespace cvc5 {
namespace smt {

Preprocessor::Preprocessor(SmtEngine& smt,
                           Env& env,
                           AbstractValues& abs,
                           SmtEngineStatistics& stats)
    : d_smt(smt),
      d_env(env),
      d_absValues(abs),
      d_propagator(true, true),
      d_assertionsProcessed(env.getUserContext(), false),
      d_exDefs(env, stats),
      d_processor(smt, *env.getResourceManager(), stats),
      d_pnm(nullptr)
{
}

Preprocessor::~Preprocessor()
{
  if (d_propagator.getNeedsFinish())
  {
    d_propagator.finish();
    d_propagator.setNeedsFinish(false);
  }
}

void Preprocessor::finishInit()
{
  d_ppContext.reset(new preprocessing::PreprocessingPassContext(
      &d_smt, d_env, &d_propagator));

  // initialize the preprocessing passes
  d_processor.finishInit(d_ppContext.get());
}

bool Preprocessor::process(Assertions& as)
{
  preprocessing::AssertionPipeline& ap = as.getAssertionPipeline();

  // should not be called if empty
  Assert(ap.size() != 0)
      << "Can only preprocess a non-empty list of assertions";

  if (d_assertionsProcessed && options::incrementalSolving())
  {
    // TODO(b/1255): Substitutions in incremental mode should be managed with a
    // proper data structure.
    ap.enableStoreSubstsInAsserts();
  }
  else
  {
    ap.disableStoreSubstsInAsserts();
  }

  // process the assertions, return true if no conflict is discovered
  bool noConflict = d_processor.apply(as);

  // now, post-process the assertions

  // if incremental, compute which variables are assigned
  if (options::incrementalSolving())
  {
    d_ppContext->recordSymbolsInAssertions(ap.ref());
  }

  // mark that we've processed assertions
  d_assertionsProcessed = true;

  return noConflict;
}

void Preprocessor::clearLearnedLiterals()
{
  d_propagator.getLearnedLiterals().clear();
}

void Preprocessor::cleanup() { d_processor.cleanup(); }

Node Preprocessor::expandDefinitions(const Node& n)
{
  std::unordered_map<Node, Node> cache;
  return expandDefinitions(n, cache);
}

Node Preprocessor::expandDefinitions(const Node& node,
                                     std::unordered_map<Node, Node>& cache)
{
  Trace("smt") << "SMT expandDefinitions(" << node << ")" << endl;
  // Substitute out any abstract values in node.
  Node n = d_absValues.substituteAbstractValues(node);
  if (options::typeChecking())
  {
    // Ensure node is type-checked at this point.
    n.getType(true);
  }
  // we apply substitutions here, before expanding definitions
  n = d_env.getTopLevelSubstitutions().apply(n, false);
  // now call expand definitions
  n = d_exDefs.expandDefinitions(n, cache);
  return n;
}

Node Preprocessor::simplify(const Node& node)
{
  Trace("smt") << "SMT simplify(" << node << ")" << endl;
  if (Dump.isOn("benchmark"))
  {
    d_smt.getOutputManager().getPrinter().toStreamCmdSimplify(
        d_smt.getOutputManager().getDumpOut(), node);
  }
  Node ret = expandDefinitions(node);
  ret = theory::Rewriter::rewrite(ret);
  return ret;
}

void Preprocessor::setProofGenerator(PreprocessProofGenerator* pppg)
{
  Assert(pppg != nullptr);
  d_pnm = pppg->getManager();
  d_exDefs.setProofNodeManager(d_pnm);
  d_propagator.setProof(d_pnm, d_env.getUserContext(), pppg);
}

}  // namespace smt
}  // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback