GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/preprocessing/passes/sort_infer.cpp Lines: 36 36 100.0 %
Date: 2021-05-22 Branches: 54 100 54.0 %

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