Changeset 6c3a988f for src/GenPoly


Ignore:
Timestamp:
Jan 5, 2017, 3:47:36 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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
Message:

fix inferred parameter data structures to correctly associate parameters with the entity that requested them, modify tuple specialization and unification to work with self-recursive assertions

Location:
src/GenPoly
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r1e3d5b6 r6c3a988f  
    783783                void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
    784784                        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() );
    786786                                addCast( *arg, (*param)->get_type(), exprTyVars );
    787787                                boxParam( (*param)->get_type(), *arg, exprTyVars );
  • src/GenPoly/Specialize.cc

    r1e3d5b6 r6c3a988f  
    112112                FunctionType *newType = funType->clone();
    113113                if ( env ) {
    114                         TypeSubstitution newEnv( *env );
    115114                        // it is important to replace only occurrences of type variables that occur free in the
    116115                        // thunk's type
    117                         newEnv.applyFree( newType );
     116                        env->applyFree( newType );
    118117                } // if
    119118                // create new thunk with same signature as formal type (C linkage, empty body)
     
    167166                assertf( actual->has_result(), "attempting to specialize an untyped expression" );
    168167                if ( needsSpecialization( formalType, actual->get_result(), env ) ) {
    169                         FunctionType *funType;
    170                         if ( ( funType = getFunctionType( formalType ) ) ) {
     168                        if ( FunctionType *funType = getFunctionType( formalType ) ) {
    171169                                ApplicationExpr *appExpr;
    172170                                VariableExpr *varExpr;
     
    188186
    189187        bool TupleSpecializer::needsSpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) {
    190                 // std::cerr << "asking if type needs tuple spec: " << formalType << std::endl;
    191188                if ( FunctionType * ftype = getFunctionType( formalType ) ) {
    192189                        return ftype->isTtype();
     
    215212        void fixLastArg( Expression * last, Iterator begin, Iterator end, OutIterator out ) {
    216213                // 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() );
    218215                unsigned idx = 0;
    219216                for ( ; begin != end; ++begin ) {
     
    227224        Expression * TupleSpecializer::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) {
    228225                static UniqueName thunkNamer( "_tupleThunk" );
    229                 // std::cerr << "creating tuple thunk for " << funType << std::endl;
    230226
    231227                FunctionType *newType = funType->clone();
    232228                if ( env ) {
    233                         TypeSubstitution newEnv( *env );
    234229                        // it is important to replace only occurrences of type variables that occur free in the
    235230                        // thunk's type
    236                         newEnv.applyFree( newType );
     231                        env->applyFree( newType );
    237232                } // if
    238233                // create new thunk with same signature as formal type (C linkage, empty body)
     
    246241                UniqueName paramNamer( paramPrefix );
    247242                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
    251250                std::list< DeclarationWithType * >::iterator actualBegin = actualType->get_parameters().begin();
    252251                std::list< DeclarationWithType * >::iterator actualEnd = actualType->get_parameters().end();
     
    282281                std::list< Statement* > oldStmts;
    283282                oldStmts.splice( oldStmts.end(), stmtsToAdd );
    284                 spec.handleExplicitParams( appExpr );
     283                spec.mutate( appExpr );
    285284                paramPrefix = oldParamPrefix;
    286285                // write any statements added for recursive specializations into the thunk body
     
    297296                } // if
    298297                thunkFunc->get_statements()->get_kids().push_back( appStmt );
    299 
    300                 // std::cerr << "thunkFunc is: " << thunkFunc << std::endl;
    301298
    302299                // add thunk definition to queue of statements to add
     
    326323                        // don't need to do this for intrinsic calls, because they aren't actually passed
    327324                        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() );
    329326                        }
    330327                        handleExplicitParams( appExpr );
Note: See TracChangeset for help on using the changeset viewer.