GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/term_registry.cpp Lines: 54 60 90.0 %
Date: 2021-09-15 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
9942
TermRegistry::TermRegistry(Env& env,
33
                           QuantifiersState& qs,
34
9942
                           QuantifiersRegistry& qr)
35
    : EnvObj(env),
36
9942
      d_presolve(userContext(), true),
37
9942
      d_presolveCache(userContext()),
38
9942
      d_termEnum(new TermEnumeration),
39
9942
      d_termPools(new TermPools(env, qs)),
40
10133
      d_termDb(logicInfo().isHigherOrder() ? new HoTermDb(env, qs, qr)
41
9751
                                           : new TermDb(env, qs, qr)),
42
      d_sygusTdb(nullptr),
43
69594
      d_qmodel(nullptr)
44
{
45
9942
  if (options::sygus() || options::sygusInst())
46
  {
47
    // must be constructed here since it is required for datatypes finistInit
48
1233
    d_sygusTdb.reset(new TermDbSygus(env, qs));
49
  }
50
9942
  Trace("quant-engine-debug") << "Initialize quantifiers engine." << std::endl;
51
19884
  Trace("quant-engine-debug")
52
9942
      << "Initialize model, mbqi : " << options::mbqiMode() << std::endl;
53
9942
}
54
55
9942
void TermRegistry::finishInit(FirstOrderModel* fm,
56
                              QuantifiersInferenceManager* qim)
57
{
58
9942
  d_qmodel = fm;
59
9942
  d_termDb->finishInit(qim);
60
9942
  if (d_sygusTdb.get())
61
  {
62
1233
    d_sygusTdb->finishInit(qim);
63
  }
64
9942
}
65
66
8211
void TermRegistry::presolve()
67
{
68
8211
  d_presolve = false;
69
  // add all terms to database
70
8211
  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
8211
}
81
82
966730
void TermRegistry::addTerm(Node n, bool withinQuant)
83
{
84
  // don't add terms in quantifier bodies
85
966730
  if (withinQuant && !options::registerQuantBodyTerms())
86
  {
87
68180
    return;
88
  }
89
898550
  if (options::incrementalSolving() && !options::termDbCd())
90
  {
91
    d_presolveCache.insert(n);
92
  }
93
  // only wait if we are doing incremental solving
94
898550
  if (!d_presolve || !options::incrementalSolving() || options::termDbCd())
95
  {
96
898550
    d_termDb->addTerm(n);
97
898550
    if (d_sygusTdb.get() && options::sygusEvalUnfold())
98
    {
99
188865
      d_sygusTdb->getEvalUnfold()->registerEvalTerm(n);
100
    }
101
  }
102
}
103
104
2070
Node TermRegistry::getTermForType(TypeNode tn)
105
{
106
2070
  if (tn.isClosedEnumerable())
107
  {
108
102
    return d_termEnum->getEnumerateTerm(tn, 0);
109
  }
110
1968
  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
38080
void TermRegistry::processInstantiation(Node q, const std::vector<Node>& terms)
119
{
120
38080
  d_termPools->processInstantiation(q, terms);
121
38080
}
122
2398
void TermRegistry::processSkolemization(Node q,
123
                                        const std::vector<Node>& skolems)
124
{
125
2398
  d_termPools->processSkolemization(q, skolems);
126
2398
}
127
128
16233254
TermDb* TermRegistry::getTermDatabase() const { return d_termDb.get(); }
129
130
4306
TermDbSygus* TermRegistry::getTermDatabaseSygus() const
131
{
132
4306
  return d_sygusTdb.get();
133
}
134
135
601
TermEnumeration* TermRegistry::getTermEnumeration() const
136
{
137
601
  return d_termEnum.get();
138
}
139
140
9946
TermPools* TermRegistry::getTermPools() const { return d_termPools.get(); }
141
142
326597
FirstOrderModel* TermRegistry::getModel() const { return d_qmodel; }
143
144
}  // namespace quantifiers
145
}  // namespace theory
146
29577
}  // namespace cvc5