Changeset c4187df
- Timestamp:
- Mar 22, 2017, 5:17:08 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, 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:
- 22854f8, 37f9860, ccd8bc3
- Parents:
- 06ccbc7 (diff), c2bfb31 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 40 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r06ccbc7 rc4187df 1298 1298 FunctionType * ftype = functionDecl->get_functionType(); 1299 1299 if ( ! ftype->get_returnVals().empty() && functionDecl->get_statements() ) { 1300 if ( functionDecl->get_name() != "?=?" && ! isPrefix( functionDecl->get_name(), "_thunk" ) ) { // xxx - remove check for ?=? once reference types are in; remove check for prefix once thunks properly use ctor/dtors1300 if ( functionDecl->get_name() != "?=?" && ! isPrefix( functionDecl->get_name(), "_thunk" ) && ! isPrefix( functionDecl->get_name(), "_adapter" ) ) { // xxx - remove check for ?=? once reference types are in; remove check for prefix once thunks properly use ctor/dtors 1301 1301 assert( ftype->get_returnVals().size() == 1 ); 1302 1302 DeclarationWithType * retval = ftype->get_returnVals().front(); -
src/GenPoly/Specialize.cc
r06ccbc7 rc4187df 168 168 } 169 169 170 struct EnvTrimmer : public Visitor { 171 TypeSubstitution * env, * newEnv; 172 EnvTrimmer( TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){} 173 virtual void visit( TypeDecl * tyDecl ) { 174 // transfer known bindings for seen type variables 175 if ( Type * t = env->lookup( tyDecl->get_name() ) ) { 176 newEnv->add( tyDecl->get_name(), t ); 177 } 178 } 179 }; 180 181 /// reduce environment to just the parts that are referenced in a given expression 182 TypeSubstitution * trimEnv( ApplicationExpr * expr, TypeSubstitution * env ) { 183 if ( env ) { 184 TypeSubstitution * newEnv = new TypeSubstitution(); 185 EnvTrimmer trimmer( env, newEnv ); 186 expr->accept( trimmer ); 187 return newEnv; 188 } 189 return nullptr; 190 } 191 170 192 /// Generates a thunk that calls `actual` with type `funType` and returns its address 171 193 Expression * Specialize::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) { … … 211 233 } 212 234 213 appExpr->set_env( maybeClone(env ) );235 appExpr->set_env( trimEnv( appExpr, env ) ); 214 236 if ( inferParams ) { 215 237 appExpr->get_inferParams() = *inferParams; -
src/InitTweak/FixInit.cc
r06ccbc7 rc4187df 52 52 namespace { 53 53 typedef std::unordered_map< Expression *, TypeSubstitution * > EnvMap; 54 typedef std::unordered_map< int, int > UnqCount; 54 55 55 56 class InsertImplicitCalls final : public GenPoly::PolyMutator { … … 74 75 /// generate/resolve copy construction expressions for each, and generate/resolve destructors for both 75 76 /// arguments and return value temporaries 76 static void resolveImplicitCalls( std::list< Declaration * > & translationUnit, const EnvMap & envMap );77 static void resolveImplicitCalls( std::list< Declaration * > & translationUnit, const EnvMap & envMap, UnqCount & unqCount ); 77 78 78 79 typedef SymTab::Indexer Parent; 79 80 using Parent::visit; 80 81 81 ResolveCopyCtors( const EnvMap & envMap ) : envMap( envMap) {}82 ResolveCopyCtors( const EnvMap & envMap, UnqCount & unqCount ) : envMap( envMap ), unqCount( unqCount ) {} 82 83 83 84 virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr ) override; … … 94 95 TypeSubstitution * env; 95 96 const EnvMap & envMap; 97 UnqCount & unqCount; // count the number of times each unique expr ID appears 96 98 }; 97 99 … … 202 204 class FixCopyCtors final : public GenPoly::PolyMutator { 203 205 public: 206 FixCopyCtors( UnqCount & unqCount ) : unqCount( unqCount ){} 204 207 /// expand ImplicitCopyCtorExpr nodes into the temporary declarations, copy constructors, call expression, 205 208 /// and destructors 206 static void fixCopyCtors( std::list< Declaration * > &translationUnit );209 static void fixCopyCtors( std::list< Declaration * > &translationUnit, UnqCount & unqCount ); 207 210 208 211 typedef GenPoly::PolyMutator Parent; … … 211 214 virtual Expression * mutate( UniqueExpr * unqExpr ) override; 212 215 virtual Expression * mutate( StmtExpr * stmtExpr ) override; 216 217 UnqCount & unqCount; 213 218 }; 214 219 … … 272 277 273 278 EnvMap envMap; 279 UnqCount unqCount; 274 280 275 281 InsertImplicitCalls::insert( translationUnit, envMap ); 276 ResolveCopyCtors::resolveImplicitCalls( translationUnit, envMap );282 ResolveCopyCtors::resolveImplicitCalls( translationUnit, envMap, unqCount ); 277 283 InsertDtors::insert( translationUnit ); 278 284 FixInit::fixInitializers( translationUnit ); 279 285 280 286 // FixCopyCtors must happen after FixInit, so that destructors are placed correctly 281 FixCopyCtors::fixCopyCtors( translationUnit );287 FixCopyCtors::fixCopyCtors( translationUnit, unqCount ); 282 288 283 289 GenStructMemberCalls::generate( translationUnit ); … … 298 304 } 299 305 300 void ResolveCopyCtors::resolveImplicitCalls( std::list< Declaration * > & translationUnit, const EnvMap & envMap ) {301 ResolveCopyCtors resolver( envMap );306 void ResolveCopyCtors::resolveImplicitCalls( std::list< Declaration * > & translationUnit, const EnvMap & envMap, UnqCount & unqCount ) { 307 ResolveCopyCtors resolver( envMap, unqCount ); 302 308 acceptAll( translationUnit, resolver ); 303 309 } … … 329 335 } 330 336 331 void FixCopyCtors::fixCopyCtors( std::list< Declaration * > & translationUnit ) {332 FixCopyCtors fixer ;337 void FixCopyCtors::fixCopyCtors( std::list< Declaration * > & translationUnit, UnqCount & unqCount ) { 338 FixCopyCtors fixer( unqCount ); 333 339 mutateAll( translationUnit, fixer ); 334 340 } … … 520 526 void ResolveCopyCtors::visit( UniqueExpr * unqExpr ) { 521 527 static std::unordered_set< int > vars; 528 unqCount[ unqExpr->get_id() ]++; // count the number of unique expressions for each ID 522 529 if ( vars.count( unqExpr->get_id() ) ) { 523 530 // xxx - hack to prevent double-handling of unique exprs, otherwise too many temporary variables and destructors are generated … … 636 643 637 644 Expression * FixCopyCtors::mutate( UniqueExpr * unqExpr ) { 645 unqCount[ unqExpr->get_id() ]--; 646 static std::unordered_map< int, std::list< Statement * > > dtors; 638 647 static std::unordered_map< int, UniqueExpr * > unqMap; 639 648 static std::unordered_set< int > addDeref; … … 645 654 delete unqExpr->get_result(); 646 655 unqExpr->set_result( maybeClone( unqExpr->get_expr()->get_result() ) ); 656 if ( unqCount[ unqExpr->get_id() ] == 0 ) { // insert destructor after the last use of the unique expression 657 stmtsToAdd.splice( stmtsToAddAfter.end(), dtors[ unqExpr->get_id() ] ); 658 } 647 659 if ( addDeref.count( unqExpr->get_id() ) ) { 648 660 // other UniqueExpr was dereferenced because it was an lvalue return, so this one should be too … … 651 663 return unqExpr; 652 664 } 653 unqExpr = safe_dynamic_cast< UniqueExpr * >( Parent::mutate( unqExpr ) ); // stmtexprs contained should not be separately fixed, so this must occur after the lookup 665 FixCopyCtors fixer( unqCount ); 666 unqExpr->set_expr( unqExpr->get_expr()->acceptMutator( fixer ) ); // stmtexprs contained should not be separately fixed, so this must occur after the lookup 667 stmtsToAdd.splice( stmtsToAdd.end(), fixer.stmtsToAdd ); 654 668 unqMap[unqExpr->get_id()] = unqExpr; 655 669 if ( UntypedExpr * deref = dynamic_cast< UntypedExpr * >( unqExpr->get_expr() ) ) { … … 661 675 getCallArg( deref, 0 ) = unqExpr; 662 676 addDeref.insert( unqExpr->get_id() ); 677 if ( unqCount[ unqExpr->get_id() ] == 0 ) { // insert destructor after the last use of the unique expression 678 stmtsToAdd.splice( stmtsToAddAfter.end(), dtors[ unqExpr->get_id() ] ); 679 } else { // remember dtors for last instance of unique expr 680 dtors[ unqExpr->get_id() ] = fixer.stmtsToAddAfter; 681 } 663 682 return deref; 664 683 }
Note: See TracChangeset
for help on using the changeset viewer.