Changeset 03da511 for src/ResolvExpr
- Timestamp:
- Aug 16, 2016, 3:07:21 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 04cdd9b
- Parents:
- 04273e9
- git-author:
- Rob Schluntz <rschlunt@…> (08/15/16 17:19:40)
- git-committer:
- Rob Schluntz <rschlunt@…> (08/16/16 15:07:21)
- Location:
- src/ResolvExpr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/TypeEnvironment.cc
r04273e9 r03da511 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // TypeEnvironment.cc -- 7 // TypeEnvironment.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 23 23 24 24 namespace ResolvExpr { 25 // adding this comparison operator significantly improves assertion resolution run time for 26 // some cases. The current resolution algorithm's speed partially depends on the order of 27 // assertions. Assertions which have fewer possible matches should appear before 28 // assertions which have more possible matches. This seems to imply that this could 29 // be further improved by providing an indexer as an additional argument and ordering based 30 // on the number of matches of the same kind (object, function) for the names of the 31 // declarations. 32 // 33 // I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this comparator. 34 bool AssertCompare::operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) { 35 // Objects are always less than functions 36 if ( ObjectDecl * objectDecl1 = dynamic_cast< ObjectDecl * >( d1 ) ) { 37 if ( ObjectDecl * objectDecl2 = dynamic_cast< ObjectDecl * >( d2 ) ) { 38 // objects are ordered by name then type pointer, in that order 39 int cmp = objectDecl1->get_name().compare( objectDecl2->get_name() ); 40 return cmp < 0 || 41 ( cmp == 0 && objectDecl1->get_type() < objectDecl2->get_type() ); 42 } else { 43 return true; 44 } 45 } else if ( FunctionDecl * funcDecl1 = dynamic_cast< FunctionDecl * >( d1 ) ) { 46 if ( FunctionDecl * funcDecl2 = dynamic_cast< FunctionDecl * >( d2 ) ) { 47 // functions are ordered by name, # parameters, # returnVals, type pointer in that order 48 FunctionType * ftype1 = funcDecl1->get_functionType(); 49 FunctionType * ftype2 = funcDecl2->get_functionType(); 50 int numThings1 = ftype1->get_parameters().size() + ftype1->get_returnVals().size(); 51 int numThings2 = ftype2->get_parameters().size() + ftype2->get_returnVals().size(); 52 if ( numThings1 < numThings2 ) return true; 53 if ( numThings1 > numThings2 ) return false; 54 55 // if ( ftype1->get_parameters().size() < ftype2->get_parameters().size() ) return true; 56 // else if ( ftype1->get_parameters().size() > ftype2->get_parameters().size() ) return false; 57 // // same number of parameters 58 // if ( ftype1->get_returnVals().size() < ftype2->get_returnVals().size() ) return true; 59 // else if ( ftype1->get_returnVals().size() > ftype2->get_returnVals().size() ) return false; 60 // same number of return vals 61 // int cmp = funcDecl1->get_name().compare( funcDecl2->get_name() ); 62 // if ( cmp < 0 ) return true; 63 // else if ( cmp > 0 ) return false; 64 // // same name 65 return ftype1 < ftype2; 66 } else { 67 return false; 68 } 69 } else { 70 assert( false ); 71 } 72 } 73 25 74 void printAssertionSet( const AssertionSet &assertions, std::ostream &os, int indent ) { 26 75 for ( AssertionSet::const_iterator i = assertions.begin(); i != assertions.end(); ++i ) { -
src/ResolvExpr/TypeEnvironment.h
r04273e9 r03da511 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // TypeEnvironment.h -- 7 // TypeEnvironment.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 28 28 29 29 namespace ResolvExpr { 30 typedef std::map< DeclarationWithType*, bool > AssertionSet; 30 struct AssertCompare { 31 bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 ); 32 }; 33 typedef std::map< DeclarationWithType*, bool, AssertCompare > AssertionSet; 31 34 typedef std::map< std::string, TypeDecl::Kind > OpenVarSet; 32 35 … … 39 42 bool allowWidening; 40 43 TypeDecl::Kind kind; 41 44 42 45 void initialize( const EqvClass &src, EqvClass &dest ); 43 46 EqvClass(); … … 62 65 void extractOpenVars( OpenVarSet &openVars ) const; 63 66 TypeEnvironment *clone() const { return new TypeEnvironment( *this ); } 64 67 65 68 typedef std::list< EqvClass >::iterator iterator; 66 69 iterator begin() { return env.begin(); } -
src/ResolvExpr/Unify.cc
r04273e9 r03da511 484 484 FunctionType *otherFunction = dynamic_cast< FunctionType* >( type2 ); 485 485 if ( otherFunction && functionType->get_isVarArgs() == otherFunction->get_isVarArgs() ) { 486 487 if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {488 489 if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 490 491 markAssertions( haveAssertions, needAssertions, functionType);492 markAssertions( haveAssertions, needAssertions, otherFunction ); 493 494 result = true;486 if ( functionType->get_parameters().size() == otherFunction->get_parameters().size() && functionType->get_returnVals().size() == otherFunction->get_returnVals().size() ) { 487 if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 488 if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 489 490 markAssertions( haveAssertions, needAssertions, functionType ); 491 markAssertions( haveAssertions, needAssertions, otherFunction ); 492 493 result = true; 494 } // if 495 495 } // if 496 496 } // if
Note: See TracChangeset
for help on using the changeset viewer.