Changes in src/GenPoly/SpecializeNew.cpp [5cf1228:4c48be0]
- File:
-
- 1 edited
-
src/GenPoly/SpecializeNew.cpp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/SpecializeNew.cpp
r5cf1228 r4c48be0 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // SpecializeNew.cpp -- Generate thunks to specialize polymorphic functions.7 // SpecializeNew.cpp -- 8 8 // 9 9 // Author : Andrew Beach … … 201 201 *formal, *actual, getInferredParams( expr ) ); 202 202 } 203 //for ( auto pair : group_iterate( formal->params, mut->args ) ) { 204 // const ast::ptr<ast::Type> & formal = std::get<0>( pair ); 205 // ast::ptr<ast::Expr> & actual = std::get<1>( pair ); 206 // *actual = doSpecialization( (*actual)->location, *formal, *actual, getInferredParams( expr ) ); 207 //} 203 208 return mut; 204 209 } … … 222 227 } 223 228 224 // Restructures arguments to match the structure of the formal parameters 225 // of the actual function. Returns the next structured argument. 229 // Restructures the arguments to match the structure of the formal parameters 230 // of the actual function. [begin, end) are the exploded arguments. 231 template<typename Iterator, typename OutIterator> 232 void structureArg( const CodeLocation & location, const ast::Type * type, 233 Iterator & begin, Iterator end, OutIterator out ) { 234 if ( auto tuple = dynamic_cast<const ast::TupleType *>( type ) ) { 235 std::vector<ast::ptr<ast::Expr>> exprs; 236 for ( const ast::Type * t : *tuple ) { 237 structureArg( location, t, begin, end, std::back_inserter( exprs ) ); 238 } 239 *out++ = new ast::TupleExpr( location, std::move( exprs ) ); 240 } else { 241 assertf( begin != end, "reached the end of the arguments while structuring" ); 242 *out++ = *begin++; 243 } 244 } 245 246 #if 0 226 247 template<typename Iterator> 227 248 const ast::Expr * structureArg( 228 249 const CodeLocation& location, const ast::ptr<ast::Type> & type, 229 250 Iterator & begin, const Iterator & end ) { 230 if ( auto tuple = type .as<ast::TupleType>() ) {251 if ( auto tuple = type->as<ast::TupleType>() ) { 231 252 std::vector<ast::ptr<ast::Expr>> exprs; 232 253 for ( const ast::Type * t : *tuple ) { … … 239 260 } 240 261 } 262 #endif 241 263 242 264 namespace { … … 269 291 // Must replace only occurrences of type variables 270 292 // that occure free in the thunk's type. 293 //ast::TypeSubstitution::ApplyResult<ast::FunctionType> 294 // typeSubs->applyFree( newType ); 271 295 auto result = typeSubs->applyFree( newType ); 272 296 newType = result.node.release(); … … 276 300 using DeclVector = std::vector<ast::ptr<ast::TypeDecl>>; 277 301 302 //const std::string & thunkName = thunkNamer.newName(); 303 //UniqueName paramNamer(thunkName + "Param"); 278 304 UniqueName paramNamer( paramPrefix ); 279 305 306 //auto toParamDecl = [&location, ¶mNamer]( const ast::Type * type ) { 307 // return new ast::ObjectDecl( 308 // location, paramNamer.newName(), ast::deepCopy( type ) ); 309 //}; 310 280 311 // Create new thunk with same signature as formal type. 312 313 // std::map<const ast::TypeDecl *, std::pair<int, int>> typeMap; 281 314 ast::Pass<TypeInstFixer> fixer; 282 315 for (const auto & kv : newType->forall) { 283 316 if (fixer.core.typeMap.count(kv->base)) { 284 std::cerr << location << ' ' << kv->base->name 285 << ' ' << kv->expr_id << '_' << kv->formal_usage 286 << ',' << fixer.core.typeMap[kv->base].first 287 << '_' << fixer.core.typeMap[kv->base].second << std::endl; 317 std::cerr << location << ' ' << kv->base->name << ' ' << kv->expr_id << '_' << kv->formal_usage << ',' 318 << fixer.core.typeMap[kv->base].first << '_' << fixer.core.typeMap[kv->base].second << std::endl; 288 319 assertf(false, "multiple formals in specialize"); 289 320 } … … 291 322 fixer.core.typeMap[kv->base] = std::make_pair(kv->expr_id, kv->formal_usage); 292 323 } 293 } 324 } 294 325 295 326 ast::CompoundStmt * thunkBody = new ast::CompoundStmt( location ); … … 314 345 ); 315 346 347 // thunkFunc->accept(fixer); 316 348 thunkFunc->fixUniqueId(); 349 350 317 351 318 352 // Thunks may be generated and not used, avoid them. … … 341 375 // Name each thunk parameter and explode it. 342 376 // These are then threaded back into the actual function call. 377 //param->name = paramNamer.newName(); 343 378 ast::DeclWithType * mutParam = ast::mutate( param.get() ); 379 // - Should be renamed earlier. - 380 //mutParam->name = paramNamer.newName(); 344 381 explodeSimple( location, new ast::VariableExpr( location, mutParam ), 345 382 std::back_inserter( args ) ); … … 351 388 argBegin = args.begin(), argEnd = args.end(); 352 389 for ( const auto & actualArg : actualType->params ) { 353 app->args.push_back(354 st ructureArg( location, actualArg.get(), argBegin, argEnd) );390 structureArg( location, actualArg.get(), argBegin, argEnd, 391 std::back_inserter( app->args ) ); 355 392 } 356 393 assertf( argBegin == argEnd, "Did not structure all arguments." ); … … 432 469 // Create thunks for the inferred parameters. 433 470 // This is not needed for intrinsic calls, because they aren't 434 // actually passed to the function. It needs to handle explicit params 435 // before inferred params so that explicit params do not recieve a 436 // changed set of inferParams (and change them again). 437 // Alternatively, if order starts to matter then copy expr's inferParams 438 // and pass them to handleExplicitParams. 471 // actually passed 472 // 473 // need to handle explicit params before inferred params so that 474 // explicit params do not recieve a changed set of inferParams (and 475 // change them again) alternatively, if order starts to matter then 476 // copy appExpr's inferParams and pass them to handleExplicitParams. 439 477 ast::ApplicationExpr * mut = handleExplicitParams( expr ); 440 478 if ( !mut->inferred.hasParams() ) { … … 462 500 if ( specialized != expr->arg ) { 463 501 // Assume that the specialization incorporates the cast. 464 std::cerr << expr <<std::endl;502 // std::cerr << expr <<std::endl; 465 503 return specialized; 466 504 } else {
Note:
See TracChangeset
for help on using the changeset viewer.