GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/preprocessing/passes/sort_infer.cpp Lines: 35 35 100.0 %
Date: 2021-09-10 Branches: 51 90 56.7 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Andres Noetzli
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
 * Sort inference preprocessing pass.
14
 */
15
16
#include "preprocessing/passes/sort_infer.h"
17
18
#include "options/smt_options.h"
19
#include "options/uf_options.h"
20
#include "preprocessing/assertion_pipeline.h"
21
#include "preprocessing/preprocessing_pass_context.h"
22
#include "smt/dump_manager.h"
23
#include "theory/rewriter.h"
24
#include "theory/sort_inference.h"
25
#include "theory/theory_engine.h"
26
27
using namespace std;
28
29
namespace cvc5 {
30
namespace preprocessing {
31
namespace passes {
32
33
9913
SortInferencePass::SortInferencePass(PreprocessingPassContext* preprocContext)
34
9913
    : PreprocessingPass(preprocContext, "sort-inference")
35
{
36
9913
}
37
38
24
PreprocessingPassResult SortInferencePass::applyInternal(
39
    AssertionPipeline* assertionsToPreprocess)
40
{
41
  theory::SortInference* si =
42
24
      d_preprocContext->getTheoryEngine()->getSortInference();
43
44
24
  if (options().smt.sortInference)
45
  {
46
20
    si->initialize(assertionsToPreprocess->ref());
47
40
    std::map<Node, Node> model_replace_f;
48
40
    std::map<Node, std::map<TypeNode, Node> > visited;
49
98
    for (unsigned i = 0, size = assertionsToPreprocess->size(); i < size; i++)
50
    {
51
156
      Node prev = (*assertionsToPreprocess)[i];
52
156
      Node next = si->simplify(prev, model_replace_f, visited);
53
78
      if (next != prev)
54
      {
55
30
        next = rewrite(next);
56
30
        assertionsToPreprocess->replace(i, next);
57
60
        Trace("sort-infer-preprocess")
58
30
            << "*** Preprocess SortInferencePass " << prev << endl;
59
60
        Trace("sort-infer-preprocess")
60
30
            << "   ...got " << (*assertionsToPreprocess)[i] << endl;
61
      }
62
    }
63
40
    std::vector<Node> newAsserts;
64
20
    si->getNewAssertions(newAsserts);
65
22
    for (const Node& na : newAsserts)
66
    {
67
4
      Node nar = rewrite(na);
68
4
      Trace("sort-infer-preprocess")
69
2
          << "*** Preprocess SortInferencePass : new constraint " << nar
70
2
          << endl;
71
2
      assertionsToPreprocess->push_back(nar);
72
    }
73
    // indicate correspondence between the functions
74
20
    smt::DumpManager* dm = d_env.getDumpManager();
75
30
    for (const std::pair<const Node, Node>& mrf : model_replace_f)
76
    {
77
10
      dm->setPrintFuncInModel(mrf.first, false);
78
10
      dm->setPrintFuncInModel(mrf.second, true);
79
    }
80
  }
81
  // only need to compute monotonicity on the resulting formula if we are
82
  // using this option
83
24
  if (options().uf.ufssFairnessMonotone)
84
  {
85
4
    si->computeMonotonicity(assertionsToPreprocess->ref());
86
  }
87
24
  return PreprocessingPassResult::NO_CONFLICT;
88
}
89
90
91
}  // namespace passes
92
}  // namespace preprocessing
93
29502
}  // namespace cvc5