diff options
author | Andrew Reynolds <andrew.j.reynolds@gmail.com> | 2020-06-06 09:45:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-06 09:45:46 -0500 |
commit | a694c7cbb69a71988896784bd755ca883e3fabdf (patch) | |
tree | 2b140c841480267e5b06fdfd8ba3ceacd6dee14b /src/smt/smt_engine.cpp | |
parent | 74fdb2e4daee739bb6351b3d5005d011641def1d (diff) | |
parent | fd60da4a22f02f6f5b82cef3585240c1b33595e9 (diff) |
Merge branch 'master' into issue4576issue4576
Diffstat (limited to 'src/smt/smt_engine.cpp')
-rw-r--r-- | src/smt/smt_engine.cpp | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/src/smt/smt_engine.cpp b/src/smt/smt_engine.cpp index 9e382cdcf..e7ef23c16 100644 --- a/src/smt/smt_engine.cpp +++ b/src/smt/smt_engine.cpp @@ -759,6 +759,7 @@ void SmtEngine::finishInit() // In the case of incremental solving, we appear to need these to // ensure the relevant Nodes remain live. d_assertionList = new (true) AssertionList(getUserContext()); + d_globalDefineFunRecLemmas.reset(new std::vector<Node>()); } // dump out a set-logic command only when raw-benchmark is disabled to avoid @@ -847,6 +848,8 @@ SmtEngine::~SmtEngine() d_assignments->deleteSelf(); } + d_globalDefineFunRecLemmas.reset(); + if(d_assertionList != NULL) { d_assertionList->deleteSelf(); } @@ -1179,7 +1182,8 @@ void SmtEngine::debugCheckFunctionBody(Expr formula, void SmtEngine::defineFunction(Expr func, const std::vector<Expr>& formals, - Expr formula) + Expr formula, + bool global) { SmtScope smts(this); finalOptionsAreSet(); @@ -1191,7 +1195,7 @@ void SmtEngine::defineFunction(Expr func, ss << language::SetLanguage( language::SetLanguage::getLanguage(Dump.getStream())) << func; - DefineFunctionCommand c(ss.str(), func, formals, formula); + DefineFunctionCommand c(ss.str(), func, formals, formula, global); addToModelCommandAndDump( c, ExprManager::VAR_FLAG_DEFINED, true, "declarations"); @@ -1220,13 +1224,22 @@ void SmtEngine::defineFunction(Expr func, // Otherwise, (check-sat) (get-value ((! foo :named bar))) breaks // d_haveAdditions = true; Debug("smt") << "definedFunctions insert " << funcNode << " " << formNode << endl; - d_definedFunctions->insert(funcNode, def); + + if (global) + { + d_definedFunctions->insertAtContextLevelZero(funcNode, def); + } + else + { + d_definedFunctions->insert(funcNode, def); + } } void SmtEngine::defineFunctionsRec( const std::vector<Expr>& funcs, - const std::vector<std::vector<Expr> >& formals, - const std::vector<Expr>& formulas) + const std::vector<std::vector<Expr>>& formals, + const std::vector<Expr>& formulas, + bool global) { SmtScope smts(this); finalOptionsAreSet(); @@ -1254,7 +1267,8 @@ void SmtEngine::defineFunctionsRec( if (Dump.isOn("raw-benchmark")) { - Dump("raw-benchmark") << DefineFunctionRecCommand(funcs, formals, formulas); + Dump("raw-benchmark") << DefineFunctionRecCommand( + funcs, formals, formulas, global); } ExprManager* em = getExprManager(); @@ -1294,17 +1308,28 @@ void SmtEngine::defineFunctionsRec( // notice we don't call assertFormula directly, since this would // duplicate the output on raw-benchmark. Expr e = d_private->substituteAbstractValues(Node::fromExpr(lem)).toExpr(); - if (d_assertionList != NULL) + if (d_assertionList != nullptr) { d_assertionList->push_back(e); } - d_private->addFormula(e.getNode(), false, true, false, maybeHasFv); + if (global && d_globalDefineFunRecLemmas != nullptr) + { + // Global definitions are asserted at check-sat-time because we have to + // make sure that they are always present + Assert(!language::isInputLangSygus(options::inputLanguage())); + d_globalDefineFunRecLemmas->emplace_back(Node::fromExpr(e)); + } + else + { + d_private->addFormula(e.getNode(), false, true, false, maybeHasFv); + } } } void SmtEngine::defineFunctionRec(Expr func, const std::vector<Expr>& formals, - Expr formula) + Expr formula, + bool global) { std::vector<Expr> funcs; funcs.push_back(func); @@ -1312,7 +1337,7 @@ void SmtEngine::defineFunctionRec(Expr func, formals_multi.push_back(formals); std::vector<Expr> formulas; formulas.push_back(formula); - defineFunctionsRec(funcs, formals_multi, formulas); + defineFunctionsRec(funcs, formals_multi, formulas, global); } bool SmtEngine::isDefinedFunction( Expr func ){ @@ -1652,6 +1677,17 @@ Result SmtEngine::checkSatisfiability(const vector<Expr>& assumptions, d_private->addFormula(e.getNode(), inUnsatCore, true, true); } + if (d_globalDefineFunRecLemmas != nullptr) + { + // Global definitions are asserted at check-sat-time because we have to + // make sure that they are always present (they are essentially level + // zero assertions) + for (const Node& lemma : *d_globalDefineFunRecLemmas) + { + d_private->addFormula(lemma, false, true, false, false); + } + } + r = check(); if ((options::solveRealAsInt() || options::solveIntAsBV() > 0) |