GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/preprocessing/passes/sort_infer.cpp Lines: 31 31 100.0 %
Date: 2021-11-07 Branches: 44 78 56.4 %

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