In preparation for refactoring E-matching to not pass QuantifiersEngine pointer to its utilities.
namespace theory {
namespace inst {
+IMGenerator::IMGenerator(quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim)
+ : d_qstate(qs), d_qim(qim)
+{
+}
+
bool IMGenerator::sendInstantiation(Trigger* tparent, InstMatch& m)
{
return tparent->sendInstantiation(m);
}
-InstMatchGenerator::InstMatchGenerator( Node pat ){
+InstMatchGenerator::InstMatchGenerator(
+ Node pat,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim)
+ : IMGenerator(qs, qim)
+{
d_cg = nullptr;
d_needsReset = true;
d_active_add = true;
- Assert(quantifiers::TermUtil::hasInstConstAttr(pat));
+ Assert(pat.isNull() || quantifiers::TermUtil::hasInstConstAttr(pat));
d_pattern = pat;
d_match_pattern = pat;
- d_match_pattern_type = pat.getType();
- d_next = nullptr;
- d_independent_gen = false;
-}
-
-InstMatchGenerator::InstMatchGenerator() {
- d_cg = nullptr;
- d_needsReset = true;
- d_active_add = true;
+ if (!pat.isNull())
+ {
+ d_match_pattern_type = pat.getType();
+ }
d_next = nullptr;
d_independent_gen = false;
}
}
else
{
- InstMatchGenerator* cimg = getInstMatchGenerator(q, pat);
+ InstMatchGenerator* cimg =
+ getInstMatchGenerator(q, pat, d_qstate, d_qim);
if (cimg)
{
d_children.push_back(cimg);
Trace("matching-fail") << "Internal error for match generator." << std::endl;
return -2;
}
- quantifiers::QuantifiersState& qs = qe->getState();
bool success = true;
std::vector<int> prev;
// if t is null
Trace("matching-debug2")
<< "Setting " << ct << " to " << t[i] << "..." << std::endl;
bool addToPrev = m.get(ct).isNull();
- if (!m.set(qs, ct, t[i]))
+ if (!m.set(d_qstate, ct, t[i]))
{
// match is in conflict
Trace("matching-fail")
}
else if (ct == -1)
{
- if (!qs.areEqual(d_match_pattern[i], t[i]))
+ if (!d_qstate.areEqual(d_match_pattern[i], t[i]))
{
Trace("matching-fail") << "Match fail arg: " << d_match_pattern[i]
<< " and " << t[i] << std::endl;
if (d_match_pattern.getKind() == INST_CONSTANT)
{
bool addToPrev = m.get(d_children_types[0]).isNull();
- if (!m.set(qs, d_children_types[0], t))
+ if (!m.set(d_qstate, d_children_types[0], t))
{
success = false;
}
{
if (t.getType().isBoolean())
{
- t_match = nm->mkConst(!qs.areEqual(nm->mkConst(true), t));
+ t_match = nm->mkConst(!d_qstate.areEqual(nm->mkConst(true), t));
}
else
{
if (!t_match.isNull())
{
bool addToPrev = m.get(v).isNull();
- if (!m.set(qs, v, t_match))
+ if (!m.set(d_qstate, v, t_match))
{
success = false;
}
// we did not properly initialize the candidate generator, thus we fail
return false;
}
- eqc = qe->getState().getRepresentative(eqc);
+ eqc = d_qstate.getRepresentative(eqc);
Trace("matching-debug2") << this << " reset " << eqc << "." << std::endl;
if( !d_eq_class_rel.isNull() && d_eq_class_rel.getKind()!=INST_CONSTANT ){
d_eq_class = d_eq_class_rel;
Node t = d_curr_first_candidate;
do{
Trace("matching-debug2") << "Matching candidate : " << t << std::endl;
- Assert(!qe->getState().isInConflict());
+ Assert(!d_qstate.isInConflict());
//if t not null, try to fit it into match m
if( !t.isNull() ){
if( d_curr_exclude_match.find( t )==d_curr_exclude_match.end() ){
}
//get the next candidate term t
if( success<0 ){
- t = qe->getState().isInConflict() ? Node::null()
- : d_cg->getNextCandidate();
+ t = d_qstate.isInConflict() ? Node::null() : d_cg->getNextCandidate();
}else{
d_curr_first_candidate = d_cg->getNextCandidate();
}
if (sendInstantiation(tparent, m))
{
addedLemmas++;
- if (qe->getState().isInConflict())
+ if (d_qstate.isInConflict())
{
break;
}
}
}else{
addedLemmas++;
- if (qe->getState().isInConflict())
+ if (d_qstate.isInConflict())
{
break;
}
return addedLemmas;
}
-
-InstMatchGenerator* InstMatchGenerator::mkInstMatchGenerator( Node q, Node pat, QuantifiersEngine* qe ) {
+InstMatchGenerator* InstMatchGenerator::mkInstMatchGenerator(
+ Node q,
+ Node pat,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim,
+ QuantifiersEngine* qe)
+{
std::vector< Node > pats;
pats.push_back( pat );
std::map< Node, InstMatchGenerator * > pat_map_init;
- return mkInstMatchGenerator( q, pats, qe, pat_map_init );
+ return mkInstMatchGenerator(q, pats, qs, qim, qe, pat_map_init);
}
-InstMatchGenerator* InstMatchGenerator::mkInstMatchGeneratorMulti( Node q, std::vector< Node >& pats, QuantifiersEngine* qe ) {
+InstMatchGenerator* InstMatchGenerator::mkInstMatchGeneratorMulti(
+ Node q,
+ std::vector<Node>& pats,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim,
+ QuantifiersEngine* qe)
+{
Assert(pats.size() > 1);
- InstMatchGeneratorMultiLinear * imgm = new InstMatchGeneratorMultiLinear( q, pats, qe );
+ InstMatchGeneratorMultiLinear* imgm =
+ new InstMatchGeneratorMultiLinear(q, pats, qs, qim);
std::vector< InstMatchGenerator* > gens;
imgm->initialize(q, qe, gens);
Assert(gens.size() == pats.size());
pat_map_init[pn] = g;
}
//return mkInstMatchGenerator( q, patsn, qe, pat_map_init );
- imgm->d_next = mkInstMatchGenerator( q, patsn, qe, pat_map_init );
+ imgm->d_next = mkInstMatchGenerator(q, patsn, qs, qim, qe, pat_map_init);
return imgm;
}
-InstMatchGenerator* InstMatchGenerator::mkInstMatchGenerator( Node q, std::vector< Node >& pats, QuantifiersEngine* qe,
- std::map< Node, InstMatchGenerator * >& pat_map_init ) {
+InstMatchGenerator* InstMatchGenerator::mkInstMatchGenerator(
+ Node q,
+ std::vector<Node>& pats,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim,
+ QuantifiersEngine* qe,
+ std::map<Node, InstMatchGenerator*>& pat_map_init)
+{
size_t pCounter = 0;
InstMatchGenerator* prev = NULL;
InstMatchGenerator* oinit = NULL;
InstMatchGenerator* init;
std::map< Node, InstMatchGenerator * >::iterator iti = pat_map_init.find( pats[pCounter] );
if( iti==pat_map_init.end() ){
- init = new InstMatchGenerator(pats[pCounter]);
+ init = new InstMatchGenerator(pats[pCounter], qs, qim);
}else{
init = iti->second;
}
return oinit;
}
-InstMatchGenerator* InstMatchGenerator::getInstMatchGenerator(Node q, Node n)
+InstMatchGenerator* InstMatchGenerator::getInstMatchGenerator(
+ Node q,
+ Node n,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim)
{
if (n.getKind() != INST_CONSTANT)
{
if (!x.isNull())
{
Node s = PatternTermSelector::getInversion(n, x);
- VarMatchGeneratorTermSubs* vmg = new VarMatchGeneratorTermSubs(x, s);
+ VarMatchGeneratorTermSubs* vmg =
+ new VarMatchGeneratorTermSubs(x, s, qs, qim);
Trace("var-trigger") << "Term substitution trigger : " << n
<< ", var = " << x << ", subs = " << s << std::endl;
return vmg;
}
}
- return new InstMatchGenerator(n);
+ return new InstMatchGenerator(n, qs, qim);
}
}/* CVC4::theory::inst namespace */
class QuantifiersEngine;
+namespace quantifiers {
+class QuantifiersState;
+class QuantifiersInferenceManager;
+} // namespace quantifiers
+
namespace inst {
class Trigger;
*/
class IMGenerator {
public:
- virtual ~IMGenerator() {}
- /** Reset instantiation round.
+ IMGenerator(quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim);
+ virtual ~IMGenerator() {}
+ /** Reset instantiation round.
*
* Called once at beginning of an instantiation round.
*/
- virtual void resetInstantiationRound(QuantifiersEngine* qe) {}
- /** Reset.
+ virtual void resetInstantiationRound(QuantifiersEngine* qe) {}
+ /** Reset.
*
* eqc is the equivalence class to search in (any if eqc=null).
* Returns true if this generator can produce instantiations, and false
* otherwise. An example of when it returns false is if it can be determined
* that no appropriate matchable terms occur based on eqc.
*/
- virtual bool reset(Node eqc, QuantifiersEngine* qe) { return true; }
- /** Get the next match.
+ virtual bool reset(Node eqc, QuantifiersEngine* qe) { return true; }
+ /** Get the next match.
*
* Must call reset( eqc ) before this function. This constructs an
* instantiation, which it populates in data structure m,
*
* Returns a value >0 if an instantiation was successfully generated
*/
- virtual int getNextMatch(Node q,
- InstMatch& m,
- QuantifiersEngine* qe,
- Trigger* tparent)
- {
- return 0;
+ virtual int getNextMatch(Node q,
+ InstMatch& m,
+ QuantifiersEngine* qe,
+ Trigger* tparent)
+ {
+ return 0;
}
/** add instantiations
*
* lemma cache.
*/
bool sendInstantiation(Trigger* tparent, InstMatch& m);
+ /** The state of the quantifiers engine */
+ quantifiers::QuantifiersState& d_qstate;
+ /** The quantifiers inference manager */
+ quantifiers::QuantifiersInferenceManager& d_qim;
};/* class IMGenerator */
class CandidateGenerator;
void setIndependent() { d_independent_gen = true; }
//-------------------------------construction of inst match generators
/** mkInstMatchGenerator for single triggers, calls the method below */
- static InstMatchGenerator* mkInstMatchGenerator(Node q,
- Node pat,
- QuantifiersEngine* qe);
+ static InstMatchGenerator* mkInstMatchGenerator(
+ Node q,
+ Node pat,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim,
+ QuantifiersEngine* qe);
/** mkInstMatchGenerator for the multi trigger case
*
* This linked list of InstMatchGenerator classes with one
* InstMatchGenerators corresponding to each unique subterm of pats with
* free variables.
*/
- static InstMatchGenerator* mkInstMatchGeneratorMulti(Node q,
- std::vector<Node>& pats,
- QuantifiersEngine* qe);
+ static InstMatchGenerator* mkInstMatchGeneratorMulti(
+ Node q,
+ std::vector<Node>& pats,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim,
+ QuantifiersEngine* qe);
/** mkInstMatchGenerator
*
* This generates a linked list of InstMatchGenerators for each unique
static InstMatchGenerator* mkInstMatchGenerator(
Node q,
std::vector<Node>& pats,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim,
QuantifiersEngine* qe,
std::map<Node, InstMatchGenerator*>& pat_map_init);
//-------------------------------end construction of inst match generators
* These are intentionally private, and are called during linked list
* construction in mkInstMatchGenerator.
*/
- InstMatchGenerator(Node pat);
- InstMatchGenerator();
+ InstMatchGenerator(Node pat,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim);
/** The pattern we are producing matches for.
*
* This term and d_match_pattern can be different since this
* appropriate matching algorithm for n within q
* within a linked list of InstMatchGenerators.
*/
- static InstMatchGenerator* getInstMatchGenerator(Node q, Node n);
+ static InstMatchGenerator* getInstMatchGenerator(
+ Node q,
+ Node n,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim);
};/* class InstMatchGenerator */
}
namespace theory {
namespace inst {
-InstMatchGeneratorMulti::InstMatchGeneratorMulti(Node q,
- std::vector<Node>& pats,
- QuantifiersEngine* qe)
- : d_quant(q)
+InstMatchGeneratorMulti::InstMatchGeneratorMulti(
+ Node q,
+ std::vector<Node>& pats,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim,
+ QuantifiersEngine* qe)
+ : IMGenerator(qs, qim), d_quant(q)
{
Trace("multi-trigger-cache")
<< "Making smart multi-trigger for " << q << std::endl;
Node n = pats[i];
// make the match generator
InstMatchGenerator* img =
- InstMatchGenerator::mkInstMatchGenerator(q, n, qe);
+ InstMatchGenerator::mkInstMatchGenerator(q, n, qs, qim, qe);
img->setActiveAdd(false);
d_children.push_back(img);
// compute unique/shared variables
/** constructors */
InstMatchGeneratorMulti(Node q,
std::vector<Node>& pats,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim,
QuantifiersEngine* qe);
/** destructor */
~InstMatchGeneratorMulti() override;
namespace inst {
InstMatchGeneratorMultiLinear::InstMatchGeneratorMultiLinear(
- Node q, std::vector<Node>& pats, QuantifiersEngine* qe)
+ Node q,
+ std::vector<Node>& pats,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim)
+ : InstMatchGenerator(Node::null(), qs, qim)
{
// order patterns to maximize eager matching failures
std::map<Node, std::vector<Node> > var_contains;
{
Node po = pats_ordered[i];
Trace("multi-trigger-linear") << "...make for " << po << std::endl;
- InstMatchGenerator* cimg = getInstMatchGenerator(q, po);
+ InstMatchGenerator* cimg = getInstMatchGenerator(q, po, qs, qim);
Assert(cimg != nullptr);
d_children.push_back(cimg);
// this could be improved
/** constructor */
InstMatchGeneratorMultiLinear(Node q,
std::vector<Node>& pats,
- QuantifiersEngine* qe);
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim);
};
} // namespace inst
namespace theory {
namespace inst {
-InstMatchGeneratorSimple::InstMatchGeneratorSimple(Node q,
- Node pat,
- QuantifiersEngine* qe)
- : d_quant(q), d_match_pattern(pat)
+InstMatchGeneratorSimple::InstMatchGeneratorSimple(
+ Node q,
+ Node pat,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim,
+ QuantifiersEngine* qe)
+ : IMGenerator(qs, qim), d_quant(q), d_match_pattern(pat)
{
if (d_match_pattern.getKind() == NOT)
{
{
public:
/** constructors */
- InstMatchGeneratorSimple(Node q, Node pat, QuantifiersEngine* qe);
+ InstMatchGeneratorSimple(Node q,
+ Node pat,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim,
+ QuantifiersEngine* qe);
/** Reset instantiation round. */
void resetInstantiationRound(QuantifiersEngine* qe) override;
if( d_nodes.size()==1 ){
if (TriggerTermInfo::isSimpleTrigger(d_nodes[0]))
{
- d_mg = new InstMatchGeneratorSimple(q, d_nodes[0], qe);
+ d_mg = new InstMatchGeneratorSimple(q, d_nodes[0], qs, qim, qe);
++(qe->d_statistics.d_triggers);
}else{
- d_mg = InstMatchGenerator::mkInstMatchGenerator(q, d_nodes[0], qe);
+ d_mg =
+ InstMatchGenerator::mkInstMatchGenerator(q, d_nodes[0], qs, qim, qe);
++(qe->d_statistics.d_simple_triggers);
}
}else{
if( options::multiTriggerCache() ){
- d_mg = new InstMatchGeneratorMulti(q, d_nodes, qe);
+ d_mg = new InstMatchGeneratorMulti(q, d_nodes, qs, qim, qe);
}else{
- d_mg = InstMatchGenerator::mkInstMatchGeneratorMulti(q, d_nodes, qe);
+ d_mg = InstMatchGenerator::mkInstMatchGeneratorMulti(
+ q, d_nodes, qs, qim, qe);
}
if (Trace.isOn("multi-trigger"))
{
namespace theory {
namespace inst {
-VarMatchGeneratorTermSubs::VarMatchGeneratorTermSubs(Node var, Node subs)
- : InstMatchGenerator(), d_var(var), d_subs(subs), d_rm_prev(false)
+VarMatchGeneratorTermSubs::VarMatchGeneratorTermSubs(
+ Node var,
+ Node subs,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim)
+ : InstMatchGenerator(Node::null(), qs, qim),
+ d_var(var),
+ d_subs(subs),
+ d_rm_prev(false)
{
d_children_types.push_back(d_var.getAttribute(InstVarNumAttribute()));
d_var_type = d_var.getType();
class VarMatchGeneratorTermSubs : public InstMatchGenerator
{
public:
- VarMatchGeneratorTermSubs(Node var, Node subs);
+ VarMatchGeneratorTermSubs(Node var,
+ Node subs,
+ quantifiers::QuantifiersState& qs,
+ quantifiers::QuantifiersInferenceManager& qim);
/** Reset */
bool reset(Node eqc, QuantifiersEngine* qe) override;