Skip to content

Commit

Permalink
Do not print internally generated datatypes in external outputs with…
Browse files Browse the repository at this point in the history
… sygus (cvc5#2234)
  • Loading branch information
ajreynol authored Aug 24, 2018
1 parent 907cc0a commit 33fe4c2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
19 changes: 13 additions & 6 deletions src/expr/expr_manager_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,22 +640,29 @@ SetType ExprManager::mkSetType(Type elementType) const {
return SetType(Type(d_nodeManager, new TypeNode(d_nodeManager->mkSetType(*elementType.d_typeNode))));
}

DatatypeType ExprManager::mkDatatypeType(Datatype& datatype) {
DatatypeType ExprManager::mkDatatypeType(Datatype& datatype, uint32_t flags)
{
// Not worth a special implementation; this doesn't need to be fast
// code anyway.
vector<Datatype> datatypes;
datatypes.push_back(datatype);
std::vector<DatatypeType> result = mkMutualDatatypeTypes(datatypes);
std::vector<DatatypeType> result = mkMutualDatatypeTypes(datatypes, flags);
Assert(result.size() == 1);
return result.front();
}

std::vector<DatatypeType> ExprManager::mkMutualDatatypeTypes(std::vector<Datatype>& datatypes) {
std::vector<DatatypeType> ExprManager::mkMutualDatatypeTypes(
std::vector<Datatype>& datatypes, uint32_t flags)
{
std::set<Type> unresolvedTypes;
return mkMutualDatatypeTypes(datatypes, unresolvedTypes);
return mkMutualDatatypeTypes(datatypes, unresolvedTypes, flags);
}

std::vector<DatatypeType> ExprManager::mkMutualDatatypeTypes(std::vector<Datatype>& datatypes, std::set<Type>& unresolvedTypes) {
std::vector<DatatypeType> ExprManager::mkMutualDatatypeTypes(
std::vector<Datatype>& datatypes,
std::set<Type>& unresolvedTypes,
uint32_t flags)
{
NodeManagerScope nms(d_nodeManager);
std::map<std::string, DatatypeType> nameResolutions;
std::vector<DatatypeType> dtts;
Expand Down Expand Up @@ -764,7 +771,7 @@ std::vector<DatatypeType> ExprManager::mkMutualDatatypeTypes(std::vector<Datatyp
}

for(std::vector<NodeManagerListener*>::iterator i = d_nodeManager->d_listeners.begin(); i != d_nodeManager->d_listeners.end(); ++i) {
(*i)->nmNotifyNewDatatypes(dtts);
(*i)->nmNotifyNewDatatypes(dtts, flags);
}

return dtts;
Expand Down
22 changes: 19 additions & 3 deletions src/expr/expr_manager_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,27 @@ class CVC4_PUBLIC ExprManager {
/** Make the type of set with the given parameterization. */
SetType mkSetType(Type elementType) const;

/** Bits for use in mkDatatypeType() flags.
*
* DATATYPE_FLAG_PLACEHOLDER indicates that the type should not be printed
* out as a definition, for example, in models or during dumping.
*/
enum
{
DATATYPE_FLAG_NONE = 0,
DATATYPE_FLAG_PLACEHOLDER = 1
}; /* enum */

/** Make a type representing the given datatype. */
DatatypeType mkDatatypeType(Datatype& datatype);
DatatypeType mkDatatypeType(Datatype& datatype,
uint32_t flags = DATATYPE_FLAG_NONE);

/**
* Make a set of types representing the given datatypes, which may be
* mutually recursive.
*/
std::vector<DatatypeType> mkMutualDatatypeTypes(std::vector<Datatype>& datatypes);
std::vector<DatatypeType> mkMutualDatatypeTypes(
std::vector<Datatype>& datatypes, uint32_t flags = DATATYPE_FLAG_NONE);

/**
* Make a set of types representing the given datatypes, which may
Expand Down Expand Up @@ -410,7 +423,10 @@ class CVC4_PUBLIC ExprManager {
* then no complicated Type needs to be created, and the above,
* simpler form of mkMutualDatatypeTypes() is enough.
*/
std::vector<DatatypeType> mkMutualDatatypeTypes(std::vector<Datatype>& datatypes, std::set<Type>& unresolvedTypes);
std::vector<DatatypeType> mkMutualDatatypeTypes(
std::vector<Datatype>& datatypes,
std::set<Type>& unresolvedTypes,
uint32_t flags = DATATYPE_FLAG_NONE);

/**
* Make a type representing a constructor with the given parameterization.
Expand Down
9 changes: 6 additions & 3 deletions src/expr/node_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ class NodeManagerListener {
virtual void nmNotifyNewSortConstructor(TypeNode tn, uint32_t flags) {}
virtual void nmNotifyInstantiateSortConstructor(TypeNode ctor, TypeNode sort,
uint32_t flags) {}
virtual void nmNotifyNewDatatypes(
const std::vector<DatatypeType>& datatypes) {}
virtual void nmNotifyNewDatatypes(const std::vector<DatatypeType>& datatypes,
uint32_t flags)
{
}
virtual void nmNotifyNewVar(TNode n, uint32_t flags) {}
virtual void nmNotifyNewSkolem(TNode n, const std::string& comment,
uint32_t flags) {}
Expand All @@ -86,7 +88,8 @@ class NodeManager {
friend Expr ExprManager::mkVar(Type, uint32_t flags);

// friend so it can access NodeManager's d_listeners and notify clients
friend std::vector<DatatypeType> ExprManager::mkMutualDatatypeTypes(std::vector<Datatype>&, std::set<Type>&);
friend std::vector<DatatypeType> ExprManager::mkMutualDatatypeTypes(
std::vector<Datatype>&, std::set<Type>&, uint32_t);

/** Predicate for use with STL algorithms */
struct NodeValueReferenceCountNonZero {
Expand Down
10 changes: 7 additions & 3 deletions src/smt/smt_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,14 @@ class SmtEnginePrivate : public NodeManagerListener {
}
}

void nmNotifyNewDatatypes(const std::vector<DatatypeType>& dtts) override
void nmNotifyNewDatatypes(const std::vector<DatatypeType>& dtts,
uint32_t flags) override
{
DatatypeDeclarationCommand c(dtts);
d_smt.addToModelCommandAndDump(c);
if ((flags & ExprManager::DATATYPE_FLAG_PLACEHOLDER) == 0)
{
DatatypeDeclarationCommand c(dtts);
d_smt.addToModelCommandAndDump(c);
}
}

void nmNotifyNewVar(TNode n, uint32_t flags) override
Expand Down
8 changes: 6 additions & 2 deletions src/theory/quantifiers/sygus/sygus_grammar_cons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,9 @@ TypeNode CegGrammarConstructor::mkSygusDefaultType(
unres);
Trace("sygus-grammar-def") << "...made " << datatypes.size() << " datatypes, now make mutual datatype types..." << std::endl;
Assert( !datatypes.empty() );
std::vector<DatatypeType> types = NodeManager::currentNM()->toExprManager()->mkMutualDatatypeTypes(datatypes, unres);
std::vector<DatatypeType> types =
NodeManager::currentNM()->toExprManager()->mkMutualDatatypeTypes(
datatypes, unres, ExprManager::DATATYPE_FLAG_PLACEHOLDER);
Assert( types.size()==datatypes.size() );
return TypeNode::fromType( types[0] );
}
Expand Down Expand Up @@ -882,7 +884,9 @@ TypeNode CegGrammarConstructor::mkSygusTemplateTypeRec( Node templ, Node templ_a
// we have a single sygus constructor that encodes the template
datatypes.back().addSygusConstructor( op.toExpr(), cname, argTypes );
datatypes.back().setSygus( templ.getType().toType(), bvl.toExpr(), true, true );
std::vector<DatatypeType> types = NodeManager::currentNM()->toExprManager()->mkMutualDatatypeTypes(datatypes, unres);
std::vector<DatatypeType> types =
NodeManager::currentNM()->toExprManager()->mkMutualDatatypeTypes(
datatypes, unres, ExprManager::DATATYPE_FLAG_PLACEHOLDER);
Assert( types.size()==1 );
return TypeNode::fromType( types[0] );
}
Expand Down
2 changes: 1 addition & 1 deletion src/theory/quantifiers/sygus/sygus_grammar_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ TypeNode SygusGrammarNorm::normalizeSygusType(TypeNode tn, Node sygus_vars)
Assert(d_dt_all.size() == d_unres_t_all.size());
std::vector<DatatypeType> types =
NodeManager::currentNM()->toExprManager()->mkMutualDatatypeTypes(
d_dt_all, d_unres_t_all);
d_dt_all, d_unres_t_all, ExprManager::DATATYPE_FLAG_PLACEHOLDER);
Assert(types.size() == d_dt_all.size());
/* Clear accumulators */
d_dt_all.clear();
Expand Down

0 comments on commit 33fe4c2

Please sign in to comment.