Changeset f6aa89c
- Timestamp:
- Nov 3, 2022, 10:27:45 AM (2 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 7ed7b4a
- Parents:
- 7cf8006
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r7cf8006 rf6aa89c 100 100 /// wraps a function application with a new temporary for the out-parameter return value 101 101 Expression *addRetParam( ApplicationExpr *appExpr, Type *retType, std::list< Expression *>::iterator &arg ); 102 /// Replaces all the type parameters of a generic type with their concrete equivalents under the current environment103 void replaceParametersWithConcrete( ApplicationExpr *appExpr, std::list< Expression* >& params );104 /// Replaces a polymorphic type with its concrete equivalant under the current environment (returns itself if concrete).105 /// If `doClone` is set to false, will not clone interior types106 Type *replaceWithConcrete( ApplicationExpr *appExpr, Type *type, bool doClone = true );107 102 /// wraps a function application returning a polymorphic type with a new temporary for the out-parameter return value 108 103 Expression *addDynRetParam( ApplicationExpr *appExpr, Type *polyType, std::list< Expression *>::iterator &arg ); … … 450 445 } 451 446 447 /// Replaces a polymorphic type with its concrete equivalant under the current environment (returns itself if concrete). 448 /// If `doClone` is set to false, will not clone interior types 449 Type *replaceWithConcrete( Type *type, TypeSubstitution const * env, bool doClone = true ); 450 452 451 Pass1::Pass1() : tempNamer( "_temp" ) {} 453 452 … … 572 571 // a polymorphic return type may need to be added to the argument list 573 572 if ( polyRetType ) { 574 Type *concRetType = replaceWithConcrete( appExpr, polyRetType);573 Type *concRetType = replaceWithConcrete( polyRetType, env ); 575 574 passArgTypeVars( appExpr, polyRetType, concRetType, arg, exprTyVars, seenTypes ); 576 575 ++fnArg; // skip the return parameter in the argument list … … 620 619 } 621 620 622 void Pass1::replaceParametersWithConcrete( ApplicationExpr *appExpr, std::list< Expression* >& params ) { 621 /// Replaces all the type parameters of a generic type with their concrete equivalents under the current environment 622 void replaceParametersWithConcrete( std::list< Expression* >& params, TypeSubstitution const * env ) { 623 623 for ( Expression * const param : params ) { 624 624 TypeExpr *paramType = dynamic_cast< TypeExpr* >( param ); 625 625 assertf(paramType, "Aggregate parameters should be type expressions"); 626 paramType->set_type( replaceWithConcrete( appExpr, paramType->get_type(), false ) ); 627 } 628 } 629 630 Type *Pass1::replaceWithConcrete( ApplicationExpr *appExpr, Type *type, bool doClone ) { 626 paramType->set_type( replaceWithConcrete( paramType->get_type(), env, false ) ); 627 } 628 } 629 630 // See forward definition. 631 Type *replaceWithConcrete( Type *type, TypeSubstitution const * env, bool doClone ) { 631 632 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) { 632 633 Type *concrete = env->lookup( typeInst->get_name() ); … … 639 640 structType = structType->clone(); 640 641 } 641 replaceParametersWithConcrete( appExpr, structType->get_parameters());642 replaceParametersWithConcrete( structType->get_parameters(), env ); 642 643 return structType; 643 644 } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) { … … 645 646 unionType = unionType->clone(); 646 647 } 647 replaceParametersWithConcrete( appExpr, unionType->get_parameters());648 replaceParametersWithConcrete( unionType->get_parameters(), env ); 648 649 return unionType; 649 650 } … … 653 654 Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, Type *dynType, std::list< Expression *>::iterator &arg ) { 654 655 assert( env ); 655 Type *concrete = replaceWithConcrete( appExpr, dynType);656 Type *concrete = replaceWithConcrete( dynType, env ); 656 657 // add out-parameter for return value 657 658 return addRetParam( appExpr, concrete, arg ); … … 1115 1116 arg = appExpr->get_args().begin(); 1116 1117 1117 Type *concRetType = replaceWithConcrete( appExpr, dynRetType);1118 Type *concRetType = replaceWithConcrete( dynRetType, env ); 1118 1119 passTypeVars( appExpr, concRetType, arg, exprTyVars ); // xxx - used to use dynRetType instead of concRetType; this changed so that the correct type paramaters are passed for return types (it should be the concrete type's parameters, not the formal type's) 1119 1120 addInferredParams( appExpr, function, arg, exprTyVars );
Note: See TracChangeset
for help on using the changeset viewer.