Changeset 6c3a988f for src/GenPoly
- Timestamp:
- Jan 5, 2017, 3:47:36 PM (9 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:
- f831177
- Parents:
- 1e3d5b6
- Location:
- src/GenPoly
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r1e3d5b6 r6c3a988f 783 783 void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) { 784 784 for ( std::list< DeclarationWithType *>::const_iterator param = function->get_parameters().begin(); param != function->get_parameters().end(); ++param, ++arg ) { 785 assert ( arg != appExpr->get_args().end() );785 assertf( arg != appExpr->get_args().end(), "boxParams: missing argument for param %s to %s in %s", toString( *param ).c_str(), toString( function ).c_str(), toString( appExpr ).c_str() ); 786 786 addCast( *arg, (*param)->get_type(), exprTyVars ); 787 787 boxParam( (*param)->get_type(), *arg, exprTyVars ); -
src/GenPoly/Specialize.cc
r1e3d5b6 r6c3a988f 112 112 FunctionType *newType = funType->clone(); 113 113 if ( env ) { 114 TypeSubstitution newEnv( *env );115 114 // it is important to replace only occurrences of type variables that occur free in the 116 115 // thunk's type 117 newEnv.applyFree( newType );116 env->applyFree( newType ); 118 117 } // if 119 118 // create new thunk with same signature as formal type (C linkage, empty body) … … 167 166 assertf( actual->has_result(), "attempting to specialize an untyped expression" ); 168 167 if ( needsSpecialization( formalType, actual->get_result(), env ) ) { 169 FunctionType *funType; 170 if ( ( funType = getFunctionType( formalType ) ) ) { 168 if ( FunctionType *funType = getFunctionType( formalType ) ) { 171 169 ApplicationExpr *appExpr; 172 170 VariableExpr *varExpr; … … 188 186 189 187 bool TupleSpecializer::needsSpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) { 190 // std::cerr << "asking if type needs tuple spec: " << formalType << std::endl;191 188 if ( FunctionType * ftype = getFunctionType( formalType ) ) { 192 189 return ftype->isTtype(); … … 215 212 void fixLastArg( Expression * last, Iterator begin, Iterator end, OutIterator out ) { 216 213 // safe_dynamic_cast for the assertion 217 safe_dynamic_cast< TupleType * >( last->get_result() ); // xxx - it's quite possible this will trigger for the unary case...214 safe_dynamic_cast< TupleType * >( last->get_result() ); 218 215 unsigned idx = 0; 219 216 for ( ; begin != end; ++begin ) { … … 227 224 Expression * TupleSpecializer::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) { 228 225 static UniqueName thunkNamer( "_tupleThunk" ); 229 // std::cerr << "creating tuple thunk for " << funType << std::endl;230 226 231 227 FunctionType *newType = funType->clone(); 232 228 if ( env ) { 233 TypeSubstitution newEnv( *env );234 229 // it is important to replace only occurrences of type variables that occur free in the 235 230 // thunk's type 236 newEnv.applyFree( newType );231 env->applyFree( newType ); 237 232 } // if 238 233 // create new thunk with same signature as formal type (C linkage, empty body) … … 246 241 UniqueName paramNamer( paramPrefix ); 247 242 ApplicationExpr *appExpr = new ApplicationExpr( actual ); 248 // std::cerr << actual << std::endl; 249 250 FunctionType * actualType = getFunctionType( actual->get_result() ); 243 244 FunctionType * actualType = getFunctionType( actual->get_result() )->clone(); 245 if ( env ) { 246 // need to apply the environment to the actual function's type, since it may itself be polymorphic 247 env->apply( actualType ); 248 } 249 std::unique_ptr< FunctionType > actualTypeManager( actualType ); // for RAII 251 250 std::list< DeclarationWithType * >::iterator actualBegin = actualType->get_parameters().begin(); 252 251 std::list< DeclarationWithType * >::iterator actualEnd = actualType->get_parameters().end(); … … 282 281 std::list< Statement* > oldStmts; 283 282 oldStmts.splice( oldStmts.end(), stmtsToAdd ); 284 spec. handleExplicitParams( appExpr );283 spec.mutate( appExpr ); 285 284 paramPrefix = oldParamPrefix; 286 285 // write any statements added for recursive specializations into the thunk body … … 297 296 } // if 298 297 thunkFunc->get_statements()->get_kids().push_back( appStmt ); 299 300 // std::cerr << "thunkFunc is: " << thunkFunc << std::endl;301 298 302 299 // add thunk definition to queue of statements to add … … 326 323 // don't need to do this for intrinsic calls, because they aren't actually passed 327 324 for ( InferredParams::iterator inferParam = appExpr->get_inferParams().begin(); inferParam != appExpr->get_inferParams().end(); ++inferParam ) { 328 inferParam->second.expr = specializer->doSpecialization( inferParam->second.formalType, inferParam->second.expr, &appExpr->get_inferParams() );325 inferParam->second.expr = specializer->doSpecialization( inferParam->second.formalType, inferParam->second.expr, inferParam->second.inferParams.get() ); 329 326 } 330 327 handleExplicitParams( appExpr );
Note:
See TracChangeset
for help on using the changeset viewer.