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