Ignore:
Timestamp:
Nov 6, 2017, 10:28:17 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
bbeb908
Parents:
59a0bde (diff), 9f4524b (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Specialize.cc

    r59a0bde r121ac13  
    4545        struct Specialize final : public WithTypeSubstitution, public WithStmtsToAdd, public WithVisitorRef<Specialize> {
    4646                Expression * postmutate( ApplicationExpr *applicationExpr );
    47                 Expression * postmutate( AddressExpr *castExpr );
    4847                Expression * postmutate( CastExpr *castExpr );
    4948
    5049                void handleExplicitParams( ApplicationExpr *appExpr );
    5150                Expression * createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams );
    52                 Expression * doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams = nullptr );
     51                Expression * doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams );
    5352
    5453                std::string paramPrefix = "_p";
     
    6766                                if ( ! boundType ) continue;
    6867                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( boundType ) ) {
     68                                        // bound to another type variable
    6969                                        if ( closedVars.find( typeInst->get_name() ) == closedVars.end() ) {
     70                                                // bound to a closed variable => must specialize
    7071                                                return true;
    7172                                        } // if
    7273                                } else {
     74                                        // variable is bound to a concrete type => must specialize
    7375                                        return true;
    7476                                } // if
    7577                        } // for
     78                        // none of the type variables are bound
    7679                        return false;
    7780                } else {
     81                        // no env
    7882                        return false;
    7983                } // if
     
    131135                        if ( functionParameterSize( fftype ) != functionParameterSize( aftype ) ) return false;
    132136                        // tuple-parameter sizes are the same, but actual parameter sizes differ - must tuple specialize
    133                         if ( fftype->get_parameters().size() != aftype->get_parameters().size() ) return true;
     137                        if ( fftype->parameters.size() != aftype->parameters.size() ) return true;
    134138                        // total parameter size can be the same, while individual parameters can have different structure
    135                         for ( auto params : group_iterate( fftype->get_parameters(), aftype->get_parameters() ) ) {
     139                        for ( auto params : group_iterate( fftype->parameters, aftype->parameters ) ) {
    136140                                DeclarationWithType * formal = std::get<0>(params);
    137141                                DeclarationWithType * actual = std::get<1>(params);
     
    150154                if ( needsSpecialization( formalType, actual->get_result(), env ) ) {
    151155                        if ( FunctionType *funType = getFunctionType( formalType ) ) {
    152                                 ApplicationExpr *appExpr;
    153                                 VariableExpr *varExpr;
    154                                 if ( ( appExpr = dynamic_cast<ApplicationExpr*>( actual ) ) ) {
     156                                if ( ApplicationExpr * appExpr = dynamic_cast<ApplicationExpr*>( actual ) ) {
    155157                                        return createThunkFunction( funType, appExpr->get_function(), inferParams );
    156                                 } else if ( ( varExpr = dynamic_cast<VariableExpr*>( actual ) ) ) {
     158                                } else if ( VariableExpr * varExpr = dynamic_cast<VariableExpr*>( actual ) ) {
    157159                                        return createThunkFunction( funType, varExpr, inferParams );
    158160                                } else {
     
    323325        }
    324326
    325         Expression * Specialize::postmutate( AddressExpr *addrExpr ) {
    326                 assert( addrExpr->result );
    327                 addrExpr->set_arg( doSpecialization( addrExpr->result, addrExpr->arg ) );
    328                 return addrExpr;
    329         }
    330 
    331327        Expression * Specialize::postmutate( CastExpr *castExpr ) {
    332328                if ( castExpr->result->isVoid() ) {
     
    334330                        return castExpr;
    335331                }
    336                 Expression *specialized = doSpecialization( castExpr->result, castExpr->arg );
     332                Expression *specialized = doSpecialization( castExpr->result, castExpr->arg, &castExpr->inferParams );
    337333                if ( specialized != castExpr->arg ) {
    338334                        // assume here that the specialization incorporates the cast
Note: See TracChangeset for help on using the changeset viewer.