From: Andrew Reynolds Date: Thu, 17 Apr 2014 09:24:11 +0000 (-0500) Subject: Minor refactoring and optimizing. X-Git-Tag: cvc5-1.0.0~6965 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=78fa095e7cac7a59062a0bbf8cc862d0bbaa1e0a;p=cvc5.git Minor refactoring and optimizing. --- diff --git a/src/theory/datatypes/datatypes_rewriter.h b/src/theory/datatypes/datatypes_rewriter.h index 99245ef69..e884248e7 100644 --- a/src/theory/datatypes/datatypes_rewriter.h +++ b/src/theory/datatypes/datatypes_rewriter.h @@ -248,6 +248,58 @@ public: } return false; } + /** get instantiate cons */ + static Node getInstCons( Node n, const Datatype& dt, int index, bool mkVar = false ) { + Type tspec; + if( dt.isParametric() ){ + tspec = dt[index].getSpecializedConstructorType(n.getType().toType()); + } + std::vector< Node > children; + children.push_back( Node::fromExpr( dt[index].getConstructor() ) ); + for( int i=0; i<(int)dt[index].getNumArgs(); i++ ){ + Node nc = NodeManager::currentNM()->mkNode( kind::APPLY_SELECTOR_TOTAL, Node::fromExpr( dt[index][i].getSelector() ), n ); + if( mkVar ){ + TypeNode tn = nc.getType(); + if( dt.isParametric() ){ + tn = TypeNode::fromType( tspec )[i]; + } + nc = NodeManager::currentNM()->mkSkolem( "m_$$", tn, "created for inst cons" ); + } + children.push_back( nc ); + } + Node n_ic = NodeManager::currentNM()->mkNode( kind::APPLY_CONSTRUCTOR, children ); + //add type ascription for ambiguous constructor types + if(!n_ic.getType().isComparableTo(n.getType())) { + Assert( dt.isParametric() ); + Debug("datatypes-parametric") << "DtInstantiate: ambiguous type for " << n_ic << ", ascribe to " << n.getType() << std::endl; + Debug("datatypes-parametric") << "Constructor is " << dt[index] << std::endl; + Type tspec = dt[index].getSpecializedConstructorType(n.getType().toType()); + Debug("datatypes-parametric") << "Type specification is " << tspec << std::endl; + children[0] = NodeManager::currentNM()->mkNode(kind::APPLY_TYPE_ASCRIPTION, + NodeManager::currentNM()->mkConst(AscriptionType(tspec)), children[0] ); + n_ic = NodeManager::currentNM()->mkNode( kind::APPLY_CONSTRUCTOR, children ); + Assert( n_ic.getType()==n.getType() ); + } + Assert( isInstCons( n_ic, dt, index ) ); + //n_ic = Rewriter::rewrite( n_ic ); + return n_ic; + } + static bool isInstCons( Node n, const Datatype& dt, int index ){ + if( n.getKind()==kind::APPLY_CONSTRUCTOR ){ + const DatatypeConstructor& c = dt[index]; + if( n.getOperator()==Node::fromExpr( c.getConstructor() ) ){ + for( unsigned i=0; i::iterator it = d_inst_map[n].find( index ); + if( it!=d_inst_map[n].end() ){ + return it->second; + }else{ //add constructor to equivalence class - Type tspec; - if( dt.isParametric() ){ - tspec = dt[index].getSpecializedConstructorType(n.getType().toType()); - } - std::vector< Node > children; - children.push_back( Node::fromExpr( dt[index].getConstructor() ) ); - for( int i=0; i<(int)dt[index].getNumArgs(); i++ ){ - Node nc = NodeManager::currentNM()->mkNode( APPLY_SELECTOR_TOTAL, Node::fromExpr( dt[index][i].getSelector() ), n ); - if( mkVar ){ - TypeNode tn = nc.getType(); - if( dt.isParametric() ){ - tn = TypeNode::fromType( tspec )[i]; - } - nc = NodeManager::currentNM()->mkSkolem( "m_$$", tn, "created during model gen" ); - } - children.push_back( nc ); - if( isActive ){ - processNewTerm( nc ); - } - } - Node n_ic = NodeManager::currentNM()->mkNode( APPLY_CONSTRUCTOR, children ); + Node n_ic = DatatypesRewriter::getInstCons( n, dt, index, mkVar ); if( isActive ){ + for( unsigned i = 0; imkNode(kind::APPLY_TYPE_ASCRIPTION, - NodeManager::currentNM()->mkConst(AscriptionType(tspec)), children[0] ); - n_ic = NodeManager::currentNM()->mkNode( APPLY_CONSTRUCTOR, children ); - Assert( n_ic.getType()==n.getType() ); - } n_ic = Rewriter::rewrite( n_ic ); Debug("dt-enum") << "Made instantiate cons " << n_ic << std::endl; - //d_inst_map[n][index] = n_ic; + d_inst_map[n][index] = n_ic; return n_ic; - //} + } } void TheoryDatatypes::instantiate( EqcInfo* eqc, Node n ){ @@ -1238,7 +1210,7 @@ void TheoryDatatypes::instantiate( EqcInfo* eqc, Node n ){ //if( eqc->d_selectors || dt[ index ].isFinite() ){ // || mustSpecifyAssignment() //instantiate this equivalence class eqc->d_inst = true; - Node tt_cons = getInstantiateCons( tt, dt, index ); + Node tt_cons = getInstantiateCons( tt, dt, index, false, true ); Node eq; if( tt!=tt_cons ){ eq = tt.eqNode( tt_cons ); diff --git a/src/theory/datatypes/theory_datatypes.h b/src/theory/datatypes/theory_datatypes.h index eb8d792cf..307e90e91 100644 --- a/src/theory/datatypes/theory_datatypes.h +++ b/src/theory/datatypes/theory_datatypes.h @@ -247,7 +247,7 @@ private: /** collect terms */ void collectTerms( Node n ); /** get instantiate cons */ - Node getInstantiateCons( Node n, const Datatype& dt, int index, bool mkVar = false, bool isActive = true ); + Node getInstantiateCons( Node n, const Datatype& dt, int index, bool mkVar, bool isActive ); /** process new term that was created internally */ void processNewTerm( Node n ); /** check instantiate */