GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/term_registry.cpp Lines: 59 65 90.8 %
Date: 2021-11-07 Branches: 75 156 48.1 %

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/entailment_check.h"
22
#include "theory/quantifiers/first_order_model.h"
23
#include "theory/quantifiers/fmf/first_order_model_fmc.h"
24
#include "theory/quantifiers/ho_term_database.h"
25
#include "theory/quantifiers/quantifiers_attributes.h"
26
#include "theory/quantifiers/quantifiers_state.h"
27
#include "theory/quantifiers/term_util.h"
28
29
namespace cvc5 {
30
namespace theory {
31
namespace quantifiers {
32
33
15273
TermRegistry::TermRegistry(Env& env,
34
                           QuantifiersState& qs,
35
15273
                           QuantifiersRegistry& qr)
36
    : EnvObj(env),
37
15273
      d_presolve(userContext(), true),
38
15273
      d_presolveCache(userContext()),
39
15273
      d_termEnum(new TermEnumeration),
40
15273
      d_termPools(new TermPools(env, qs)),
41
15511
      d_termDb(logicInfo().isHigherOrder() ? new HoTermDb(env, qs, qr)
42
15035
                                           : new TermDb(env, qs, qr)),
43
15273
      d_echeck(new EntailmentCheck(env, qs, *d_termDb.get())),
44
      d_sygusTdb(nullptr),
45
122184
      d_qmodel(nullptr)
46
{
47
15273
  if (options().quantifiers.sygus || options().quantifiers.sygusInst)
48
  {
49
    // must be constructed here since it is required for datatypes finistInit
50
1900
    d_sygusTdb.reset(new TermDbSygus(env, qs));
51
  }
52
15273
  Trace("quant-engine-debug") << "Initialize quantifiers engine." << std::endl;
53
30546
  Trace("quant-engine-debug")
54
15273
      << "Initialize model, mbqi : " << options().quantifiers.mbqiMode
55
15273
      << std::endl;
56
15273
}
57
58
15273
void TermRegistry::finishInit(FirstOrderModel* fm,
59
                              QuantifiersInferenceManager* qim)
60
{
61
15273
  d_qmodel = fm;
62
15273
  d_termDb->finishInit(qim);
63
15273
  if (d_sygusTdb.get())
64
  {
65
1900
    d_sygusTdb->finishInit(qim);
66
  }
67
15273
}
68
69
13467
void TermRegistry::presolve()
70
{
71
13467
  d_presolve = false;
72
  // add all terms to database
73
13467
  if (options().base.incrementalSolving && !options().quantifiers.termDbCd)
74
  {
75
    Trace("quant-engine-proc")
76
        << "Add presolve cache " << d_presolveCache.size() << std::endl;
77
    for (const Node& t : d_presolveCache)
78
    {
79
      addTerm(t);
80
    }
81
    Trace("quant-engine-proc") << "Done add presolve cache " << std::endl;
82
  }
83
13467
}
84
85
1145816
void TermRegistry::addTerm(Node n, bool withinQuant)
86
{
87
  // don't add terms in quantifier bodies
88
1145816
  if (withinQuant && !options().quantifiers.registerQuantBodyTerms)
89
  {
90
69328
    return;
91
  }
92
1076488
  if (options().base.incrementalSolving && !options().quantifiers.termDbCd)
93
  {
94
    d_presolveCache.insert(n);
95
  }
96
  // only wait if we are doing incremental solving
97
2276055
  if (!d_presolve || !options().base.incrementalSolving
98
1096735
      || options().quantifiers.termDbCd)
99
  {
100
1076488
    d_termDb->addTerm(n);
101
1076488
    if (d_sygusTdb.get() && options().quantifiers.sygusEvalUnfold)
102
    {
103
327019
      d_sygusTdb->getEvalUnfold()->registerEvalTerm(n);
104
    }
105
  }
106
}
107
108
2270
Node TermRegistry::getTermForType(TypeNode tn)
109
{
110
2270
  if (tn.isClosedEnumerable())
111
  {
112
150
    return d_termEnum->getEnumerateTerm(tn, 0);
113
  }
114
2120
  return d_termDb->getOrMakeTypeGroundTerm(tn);
115
}
116
117
5
void TermRegistry::declarePool(Node p, const std::vector<Node>& initValue)
118
{
119
5
  d_termPools->registerPool(p, initValue);
120
5
}
121
122
43500
void TermRegistry::processInstantiation(Node q, const std::vector<Node>& terms)
123
{
124
43500
  d_termPools->processInstantiation(q, terms);
125
43500
}
126
2681
void TermRegistry::processSkolemization(Node q,
127
                                        const std::vector<Node>& skolems)
128
{
129
2681
  d_termPools->processSkolemization(q, skolems);
130
2681
}
131
132
15459782
TermDb* TermRegistry::getTermDatabase() const { return d_termDb.get(); }
133
134
6446
TermDbSygus* TermRegistry::getTermDatabaseSygus() const
135
{
136
6446
  return d_sygusTdb.get();
137
}
138
139
1498782
EntailmentCheck* TermRegistry::getEntailmentCheck() const
140
{
141
1498782
  return d_echeck.get();
142
}
143
144
654
TermEnumeration* TermRegistry::getTermEnumeration() const
145
{
146
654
  return d_termEnum.get();
147
}
148
149
15277
TermPools* TermRegistry::getTermPools() const { return d_termPools.get(); }
150
151
349702
FirstOrderModel* TermRegistry::getModel() const { return d_qmodel; }
152
153
}  // namespace quantifiers
154
}  // namespace theory
155
31137
}  // namespace cvc5