GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/term_registry.cpp Lines: 53 59 89.8 %
Date: 2021-05-22 Branches: 71 166 42.8 %

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/quantifiers_options.h"
19
#include "options/smt_options.h"
20
#include "theory/quantifiers/first_order_model.h"
21
#include "theory/quantifiers/fmf/first_order_model_fmc.h"
22
#include "theory/quantifiers/quantifiers_attributes.h"
23
#include "theory/quantifiers/quantifiers_state.h"
24
#include "theory/quantifiers/term_util.h"
25
26
namespace cvc5 {
27
namespace theory {
28
namespace quantifiers {
29
30
9460
TermRegistry::TermRegistry(QuantifiersState& qs, QuantifiersRegistry& qr)
31
9460
    : d_presolve(qs.getUserContext(), true),
32
9460
      d_presolveCache(qs.getUserContext()),
33
9460
      d_termEnum(new TermEnumeration),
34
9460
      d_termPools(new TermPools(qs)),
35
9460
      d_termDb(new TermDb(qs, qr)),
36
      d_sygusTdb(nullptr),
37
56760
      d_qmodel(nullptr)
38
{
39
9460
  if (options::sygus() || options::sygusInst())
40
  {
41
    // must be constructed here since it is required for datatypes finistInit
42
1529
    d_sygusTdb.reset(new TermDbSygus(qs));
43
  }
44
9460
  Trace("quant-engine-debug") << "Initialize quantifiers engine." << std::endl;
45
18920
  Trace("quant-engine-debug")
46
9460
      << "Initialize model, mbqi : " << options::mbqiMode() << std::endl;
47
9460
}
48
49
9460
void TermRegistry::finishInit(FirstOrderModel* fm,
50
                              QuantifiersInferenceManager* qim)
51
{
52
9460
  d_qmodel = fm;
53
9460
  d_termDb->finishInit(qim);
54
9460
  if (d_sygusTdb.get())
55
  {
56
1529
    d_sygusTdb->finishInit(qim);
57
  }
58
9460
}
59
60
7331
void TermRegistry::presolve()
61
{
62
7331
  d_termDb->presolve();
63
7331
  d_presolve = false;
64
  // add all terms to database
65
7331
  if (options::incrementalSolving() && !options::termDbCd())
66
  {
67
    Trace("quant-engine-proc")
68
        << "Add presolve cache " << d_presolveCache.size() << std::endl;
69
    for (const Node& t : d_presolveCache)
70
    {
71
      addTerm(t);
72
    }
73
    Trace("quant-engine-proc") << "Done add presolve cache " << std::endl;
74
  }
75
7331
}
76
77
824678
void TermRegistry::addTerm(Node n, bool withinQuant)
78
{
79
  // don't add terms in quantifier bodies
80
900110
  if (withinQuant && !options::registerQuantBodyTerms())
81
  {
82
75432
    return;
83
  }
84
749246
  if (options::incrementalSolving() && !options::termDbCd())
85
  {
86
    d_presolveCache.insert(n);
87
  }
88
  // only wait if we are doing incremental solving
89
749246
  if (!d_presolve || !options::incrementalSolving() || options::termDbCd())
90
  {
91
749246
    d_termDb->addTerm(n);
92
749246
    if (d_sygusTdb.get() && options::sygusEvalUnfold())
93
    {
94
175022
      d_sygusTdb->getEvalUnfold()->registerEvalTerm(n);
95
    }
96
  }
97
}
98
99
2279
Node TermRegistry::getTermForType(TypeNode tn)
100
{
101
2279
  if (tn.isClosedEnumerable())
102
  {
103
99
    return d_termEnum->getEnumerateTerm(tn, 0);
104
  }
105
2180
  return d_termDb->getOrMakeTypeGroundTerm(tn);
106
}
107
108
5
void TermRegistry::declarePool(Node p, const std::vector<Node>& initValue)
109
{
110
5
  d_termPools->registerPool(p, initValue);
111
5
}
112
113
36917
void TermRegistry::processInstantiation(Node q, const std::vector<Node>& terms)
114
{
115
36917
  d_termPools->processInstantiation(q, terms);
116
36917
}
117
2501
void TermRegistry::processSkolemization(Node q,
118
                                        const std::vector<Node>& skolems)
119
{
120
2501
  d_termPools->processSkolemization(q, skolems);
121
2501
}
122
123
17850137
TermDb* TermRegistry::getTermDatabase() const { return d_termDb.get(); }
124
125
5052
TermDbSygus* TermRegistry::getTermDatabaseSygus() const
126
{
127
5052
  return d_sygusTdb.get();
128
}
129
130
474
TermEnumeration* TermRegistry::getTermEnumeration() const
131
{
132
474
  return d_termEnum.get();
133
}
134
135
9464
TermPools* TermRegistry::getTermPools() const { return d_termPools.get(); }
136
137
252507
FirstOrderModel* TermRegistry::getModel() const { return d_qmodel; }
138
139
}  // namespace quantifiers
140
}  // namespace theory
141
103626
}  // namespace cvc5