GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/term_registry.cpp Lines: 55 61 90.2 %
Date: 2021-09-09 Branches: 73 152 48.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mathias Preiner
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
 * Term registry class.
14
 */
15
16
#include "theory/quantifiers/term_registry.h"
17
18
#include "options/base_options.h"
19
#include "options/quantifiers_options.h"
20
#include "options/smt_options.h"
21
#include "theory/quantifiers/first_order_model.h"
22
#include "theory/quantifiers/fmf/first_order_model_fmc.h"
23
#include "theory/quantifiers/ho_term_database.h"
24
#include "theory/quantifiers/quantifiers_attributes.h"
25
#include "theory/quantifiers/quantifiers_state.h"
26
#include "theory/quantifiers/term_util.h"
27
28
namespace cvc5 {
29
namespace theory {
30
namespace quantifiers {
31
32
9928
TermRegistry::TermRegistry(Env& env,
33
                           QuantifiersState& qs,
34
9928
                           QuantifiersRegistry& qr)
35
9928
    : d_presolve(qs.getUserContext(), true),
36
9928
      d_presolveCache(qs.getUserContext()),
37
9928
      d_termEnum(new TermEnumeration),
38
9928
      d_termPools(new TermPools(env, qs)),
39
9928
      d_termDb(qs.getEnv().getLogicInfo().isHigherOrder()
40
191
                   ? new HoTermDb(env, qs, qr)
41
9737
                   : new TermDb(env, qs, qr)),
42
      d_sygusTdb(nullptr),
43
69496
      d_qmodel(nullptr)
44
{
45
9928
  if (options::sygus() || options::sygusInst())
46
  {
47
    // must be constructed here since it is required for datatypes finistInit
48
1230
    d_sygusTdb.reset(new TermDbSygus(env, qs));
49
  }
50
9928
  Trace("quant-engine-debug") << "Initialize quantifiers engine." << std::endl;
51
19856
  Trace("quant-engine-debug")
52
9928
      << "Initialize model, mbqi : " << options::mbqiMode() << std::endl;
53
9928
}
54
55
9928
void TermRegistry::finishInit(FirstOrderModel* fm,
56
                              QuantifiersInferenceManager* qim)
57
{
58
9928
  d_qmodel = fm;
59
9928
  d_termDb->finishInit(qim);
60
9928
  if (d_sygusTdb.get())
61
  {
62
1230
    d_sygusTdb->finishInit(qim);
63
  }
64
9928
}
65
66
8213
void TermRegistry::presolve()
67
{
68
8213
  d_presolve = false;
69
  // add all terms to database
70
8213
  if (options::incrementalSolving() && !options::termDbCd())
71
  {
72
    Trace("quant-engine-proc")
73
        << "Add presolve cache " << d_presolveCache.size() << std::endl;
74
    for (const Node& t : d_presolveCache)
75
    {
76
      addTerm(t);
77
    }
78
    Trace("quant-engine-proc") << "Done add presolve cache " << std::endl;
79
  }
80
8213
}
81
82
967462
void TermRegistry::addTerm(Node n, bool withinQuant)
83
{
84
  // don't add terms in quantifier bodies
85
967462
  if (withinQuant && !options::registerQuantBodyTerms())
86
  {
87
69049
    return;
88
  }
89
898413
  if (options::incrementalSolving() && !options::termDbCd())
90
  {
91
    d_presolveCache.insert(n);
92
  }
93
  // only wait if we are doing incremental solving
94
898413
  if (!d_presolve || !options::incrementalSolving() || options::termDbCd())
95
  {
96
898413
    d_termDb->addTerm(n);
97
898413
    if (d_sygusTdb.get() && options::sygusEvalUnfold())
98
    {
99
190974
      d_sygusTdb->getEvalUnfold()->registerEvalTerm(n);
100
    }
101
  }
102
}
103
104
2072
Node TermRegistry::getTermForType(TypeNode tn)
105
{
106
2072
  if (tn.isClosedEnumerable())
107
  {
108
102
    return d_termEnum->getEnumerateTerm(tn, 0);
109
  }
110
1970
  return d_termDb->getOrMakeTypeGroundTerm(tn);
111
}
112
113
5
void TermRegistry::declarePool(Node p, const std::vector<Node>& initValue)
114
{
115
5
  d_termPools->registerPool(p, initValue);
116
5
}
117
118
37666
void TermRegistry::processInstantiation(Node q, const std::vector<Node>& terms)
119
{
120
37666
  d_termPools->processInstantiation(q, terms);
121
37666
}
122
2390
void TermRegistry::processSkolemization(Node q,
123
                                        const std::vector<Node>& skolems)
124
{
125
2390
  d_termPools->processSkolemization(q, skolems);
126
2390
}
127
128
17003014
TermDb* TermRegistry::getTermDatabase() const { return d_termDb.get(); }
129
130
4300
TermDbSygus* TermRegistry::getTermDatabaseSygus() const
131
{
132
4300
  return d_sygusTdb.get();
133
}
134
135
582
TermEnumeration* TermRegistry::getTermEnumeration() const
136
{
137
582
  return d_termEnum.get();
138
}
139
140
9932
TermPools* TermRegistry::getTermPools() const { return d_termPools.get(); }
141
142
326341
FirstOrderModel* TermRegistry::getModel() const { return d_qmodel; }
143
144
}  // namespace quantifiers
145
}  // namespace theory
146
29505
}  // namespace cvc5