Changeset dd33c1f for src/GenPoly
- Timestamp:
- Jul 26, 2022, 2:17:49 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- 1b97cc87
- Parents:
- 4c48be0 (diff), 3992098 (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. - Location:
- src/GenPoly
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Specialize.h
r4c48be0 rdd33c1f 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Specialize.h -- 7 // Specialize.h -- Generate thunks to specialize polymorphic functions. 8 8 // 9 9 // Author : Richard C. Bilson … … 17 17 18 18 #include <list> // for list 19 #include "AST/TranslationUnit.hpp"20 19 21 20 class Declaration; 21 namespace ast { 22 class TranslationUnit; 23 } 22 24 23 25 namespace GenPoly { -
src/GenPoly/SpecializeNew.cpp
r4c48be0 rdd33c1f 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // SpecializeNew.cpp -- 7 // SpecializeNew.cpp -- Generate thunks to specialize polymorphic functions. 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 //}208 203 return mut; 209 204 } … … 227 222 } 228 223 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 224 // Restructures arguments to match the structure of the formal parameters 225 // of the actual function. Returns the next structured argument. 247 226 template<typename Iterator> 248 227 const ast::Expr * structureArg( 249 228 const CodeLocation& location, const ast::ptr<ast::Type> & type, 250 229 Iterator & begin, const Iterator & end ) { 251 if ( auto tuple = type ->as<ast::TupleType>() ) {230 if ( auto tuple = type.as<ast::TupleType>() ) { 252 231 std::vector<ast::ptr<ast::Expr>> exprs; 253 232 for ( const ast::Type * t : *tuple ) { … … 260 239 } 261 240 } 262 #endif263 241 264 242 namespace { … … 291 269 // Must replace only occurrences of type variables 292 270 // that occure free in the thunk's type. 293 //ast::TypeSubstitution::ApplyResult<ast::FunctionType>294 // typeSubs->applyFree( newType );295 271 auto result = typeSubs->applyFree( newType ); 296 272 newType = result.node.release(); … … 300 276 using DeclVector = std::vector<ast::ptr<ast::TypeDecl>>; 301 277 302 //const std::string & thunkName = thunkNamer.newName();303 //UniqueName paramNamer(thunkName + "Param");304 278 UniqueName paramNamer( paramPrefix ); 305 279 306 //auto toParamDecl = [&location, ¶mNamer]( const ast::Type * type ) {307 // return new ast::ObjectDecl(308 // location, paramNamer.newName(), ast::deepCopy( type ) );309 //};310 311 280 // Create new thunk with same signature as formal type. 312 313 // std::map<const ast::TypeDecl *, std::pair<int, int>> typeMap;314 281 ast::Pass<TypeInstFixer> fixer; 315 282 for (const auto & kv : newType->forall) { 316 283 if (fixer.core.typeMap.count(kv->base)) { 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; 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; 319 288 assertf(false, "multiple formals in specialize"); 320 289 } … … 322 291 fixer.core.typeMap[kv->base] = std::make_pair(kv->expr_id, kv->formal_usage); 323 292 } 324 } 293 } 325 294 326 295 ast::CompoundStmt * thunkBody = new ast::CompoundStmt( location ); … … 345 314 ); 346 315 347 // thunkFunc->accept(fixer);348 316 thunkFunc->fixUniqueId(); 349 350 351 317 352 318 // Thunks may be generated and not used, avoid them. … … 375 341 // Name each thunk parameter and explode it. 376 342 // These are then threaded back into the actual function call. 377 //param->name = paramNamer.newName();378 343 ast::DeclWithType * mutParam = ast::mutate( param.get() ); 379 // - Should be renamed earlier. -380 //mutParam->name = paramNamer.newName();381 344 explodeSimple( location, new ast::VariableExpr( location, mutParam ), 382 345 std::back_inserter( args ) ); … … 388 351 argBegin = args.begin(), argEnd = args.end(); 389 352 for ( const auto & actualArg : actualType->params ) { 390 structureArg( location, actualArg.get(), argBegin, argEnd,391 st d::back_inserter( app->args) );353 app->args.push_back( 354 structureArg( location, actualArg.get(), argBegin, argEnd ) ); 392 355 } 393 356 assertf( argBegin == argEnd, "Did not structure all arguments." ); … … 469 432 // Create thunks for the inferred parameters. 470 433 // This is not needed for intrinsic calls, because they aren't 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. 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. 477 439 ast::ApplicationExpr * mut = handleExplicitParams( expr ); 478 440 if ( !mut->inferred.hasParams() ) {
Note: See TracChangeset
for help on using the changeset viewer.