In some use cases (unit tests, old proofs infrastructure), we use a Theory with no associated TheoryEngine. This PR makes the Valuation class more robust to this case.
This includes making the "unevaluated kinds" a no-op in this case (this is necessary for Theory::finishInit with no TheoryEngine) and adding some assertions to cases that the Theory should never call without TheoryEngine.
This is required for a new policy for dynamically configuring equality engine infrastructure in Theory.
void TheoryArith::finishInit()
{
- TheoryModel* tm = d_valuation.getModel();
- Assert(tm != nullptr);
if (getLogicInfo().isTheoryEnabled(THEORY_ARITH)
&& getLogicInfo().areTranscendentalsUsed())
{
// witness is used to eliminate square root
- tm->setUnevaluatedKind(kind::WITNESS);
+ d_valuation.setUnevaluatedKind(kind::WITNESS);
// we only need to add the operators that are not syntax sugar
- tm->setUnevaluatedKind(kind::EXPONENTIAL);
- tm->setUnevaluatedKind(kind::SINE);
- tm->setUnevaluatedKind(kind::PI);
+ d_valuation.setUnevaluatedKind(kind::EXPONENTIAL);
+ d_valuation.setUnevaluatedKind(kind::SINE);
+ d_valuation.setUnevaluatedKind(kind::PI);
}
}
void TheoryQuantifiers::finishInit()
{
// quantifiers are not evaluated in getModelValue
- TheoryModel* tm = d_valuation.getModel();
- Assert(tm != nullptr);
- tm->setUnevaluatedKind(EXISTS);
- tm->setUnevaluatedKind(FORALL);
+ d_valuation.setUnevaluatedKind(EXISTS);
+ d_valuation.setUnevaluatedKind(FORALL);
// witness is used in several instantiation strategies
- tm->setUnevaluatedKind(WITNESS);
+ d_valuation.setUnevaluatedKind(WITNESS);
}
void TheoryQuantifiers::preRegisterTerm(TNode n) {
void TheorySets::finishInit()
{
- TheoryModel* tm = d_valuation.getModel();
- Assert(tm != nullptr);
- tm->setUnevaluatedKind(COMPREHENSION);
+ d_valuation.setUnevaluatedKind(COMPREHENSION);
// choice is used to eliminate witness
- tm->setUnevaluatedKind(WITNESS);
+ d_valuation.setUnevaluatedKind(WITNESS);
}
void TheorySets::addSharedTerm(TNode n) {
}
void TheoryStrings::finishInit()
{
- TheoryModel* tm = d_valuation.getModel();
// witness is used to eliminate str.from_code
- tm->setUnevaluatedKind(WITNESS);
+ d_valuation.setUnevaluatedKind(WITNESS);
}
bool TheoryStrings::areCareDisequal( TNode x, TNode y ) {
void TheoryUF::finishInit() {
// combined cardinality constraints are not evaluated in getModelValue
- TheoryModel* tm = d_valuation.getModel();
- Assert(tm != nullptr);
- tm->setUnevaluatedKind(kind::COMBINED_CARDINALITY_CONSTRAINT);
+ d_valuation.setUnevaluatedKind(kind::COMBINED_CARDINALITY_CONSTRAINT);
// Initialize the cardinality constraints solver if the logic includes UF,
// finite model finding is enabled, and it is not disabled by
// options::ufssMode().
#include "options/theory_options.h"
#include "theory/rewriter.h"
#include "theory/theory_engine.h"
+#include "theory/theory_model.h"
namespace CVC4 {
namespace theory {
}
bool Valuation::isSatLiteral(TNode n) const {
+ Assert(d_engine != nullptr);
return d_engine->getPropEngine()->isSatLiteral(n);
}
Node Valuation::getSatValue(TNode n) const {
+ Assert(d_engine != nullptr);
if(n.getKind() == kind::NOT) {
Node atomRes = d_engine->getPropEngine()->getValue(n[0]);
if(atomRes.getKind() == kind::CONST_BOOLEAN) {
}
bool Valuation::hasSatValue(TNode n, bool& value) const {
+ Assert(d_engine != nullptr);
if (d_engine->getPropEngine()->isSatLiteral(n)) {
return d_engine->getPropEngine()->hasValue(n, value);
} else {
}
EqualityStatus Valuation::getEqualityStatus(TNode a, TNode b) {
+ Assert(d_engine != nullptr);
return d_engine->getEqualityStatus(a, b);
}
Node Valuation::getModelValue(TNode var) {
+ Assert(d_engine != nullptr);
return d_engine->getModelValue(var);
}
TheoryModel* Valuation::getModel() {
+ if (d_engine == nullptr)
+ {
+ // no theory engine, thus we don't have a model object
+ return nullptr;
+ }
return d_engine->getModel();
}
+void Valuation::setUnevaluatedKind(Kind k)
+{
+ TheoryModel* m = getModel();
+ if (m != nullptr)
+ {
+ m->setUnevaluatedKind(k);
+ }
+ // If no model is available, this command has no effect. This is the case
+ // when e.g. calling Theory::finishInit for theories that are using a
+ // Valuation with no model.
+}
+
+void Valuation::setSemiEvaluatedKind(Kind k)
+{
+ TheoryModel* m = getModel();
+ if (m != nullptr)
+ {
+ m->setSemiEvaluatedKind(k);
+ }
+}
+
Node Valuation::ensureLiteral(TNode n) {
+ Assert(d_engine != nullptr);
return d_engine->ensureLiteral(n);
}
bool Valuation::isDecision(Node lit) const {
+ Assert(d_engine != nullptr);
return d_engine->getPropEngine()->isDecision(lit);
}
unsigned Valuation::getAssertionLevel() const{
+ Assert(d_engine != nullptr);
return d_engine->getPropEngine()->getAssertionLevel();
}
std::pair<bool, Node> Valuation::entailmentCheck(options::TheoryOfMode mode,
TNode lit)
{
+ Assert(d_engine != nullptr);
return d_engine->entailmentCheck(mode, lit);
}
bool Valuation::needCheck() const{
+ Assert(d_engine != nullptr);
return d_engine->needCheck();
}
* Returns pointer to model.
*/
TheoryModel* getModel();
-
+
+ //-------------------------------------- static configuration of the model
+ /**
+ * Set that k is an unevaluated kind in the TheoryModel, if it exists.
+ * See TheoryModel::setUnevaluatedKind for details.
+ */
+ void setUnevaluatedKind(Kind k);
+ /**
+ * Set that k is an unevaluated kind in the TheoryModel, if it exists.
+ * See TheoryModel::setSemiEvaluatedKind for details.
+ */
+ void setSemiEvaluatedKind(Kind k);
+ //-------------------------------------- end static configuration of the model
+
/**
* Ensure that the given node will have a designated SAT literal
* that is definitionally equal to it. The result of this function