Changeset e497c1d for src/GenPoly/Box.cc


Ignore:
Timestamp:
Jul 30, 2015, 4:07:23 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
5aa708c
Parents:
e01559c
Message:

fix adapter passing in function application when two types unify to the same type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    re01559c re497c1d  
    527527
    528528                void Pass1::passAdapters( ApplicationExpr *appExpr, FunctionType *functionType, const TyVarMap &exprTyVars ) {
     529                        // collect a list of function types passed as parameters or implicit parameters (assertions)
    529530                        std::list< DeclarationWithType *> &paramList = functionType->get_parameters();
    530531                        std::list< FunctionType *> functions;
     
    537538                                findFunction( (*arg)->get_type(), functions, exprTyVars, needsAdapter );
    538539                        } // for
     540
     541                        // parameter function types for which an appropriate adapter has been generated.
     542                        // we cannot use the types after applying substitutions, since two different
     543                        // parameter types may be unified to the same type
    539544                        std::set< std::string > adaptersDone;
     545
    540546                        for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    541547                                FunctionType *realFunction = (*funType)->clone();
    542                                 assert( env );
    543                                 env->apply( realFunction );
    544 
    545548                                std::string mangleName = SymTab::Mangler::mangle( realFunction );
     549
     550                                // only attempt to create an adapter or pass one as a parameter if we haven't
     551                                // already done so for this pre-substitution parameter function type.
    546552                                if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) {
     553                                        std::string mangleName = SymTab::Mangler::mangle( realFunction );
     554                                        adaptersDone.insert( adaptersDone.begin(), mangleName );
     555                                       
     556                                        // apply substitution to type variables to figure out what the
     557                                        // adapter's type should look like
     558                                        assert( env );
     559                                        env->apply( realFunction );
     560                                        mangleName = SymTab::Mangler::mangle( realFunction );
    547561                                        AdapterMap & adapters = Pass1::adapters.top();
    548562                                        AdapterMap::iterator adapter = adapters.find( mangleName );
     
    555569                                                continue;
    556570                                        } else if ( adapter == adapters.end() ) {
     571                                                // adapter has not been created yet in the current scope, so define it
    557572                                                FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars );
    558573                                                adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) );
     
    560575                                        } // if
    561576                                        assert( adapter != adapters.end() );
     577
     578                                        // add the appropriate adapter as a parameter
    562579                                        appExpr->get_args().push_front( new VariableExpr( adapter->second ) );
    563                                         // appExpr->get_args().push_front( new NameExpr( makeAdapterName ( mangleName ) ) );
    564                                         adaptersDone.insert( adaptersDone.begin(), mangleName );
    565580                                } // if
    566581                        } // for
     
    880895
    881896                void Pass1::doBeginScope() {
     897                        // actually, maybe this could (should?) push
     898                        // a copy of the current map
    882899                        adapters.push(AdapterMap());
    883900                }
Note: See TracChangeset for help on using the changeset viewer.