Ignore:
Timestamp:
Nov 6, 2017, 11:11:56 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:
a2ea829
Parents:
e706bfd (diff), 121ac13 (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/ResolvExpr/AlternativeFinder.cc

    re706bfd rbbeb908  
    122122                                                )
    123123                                                mapPlace->second.isAmbiguous = true;
     124                                        } else {
     125                                                PRINT(
     126                                                        std::cerr << "cost " << candidate->cost << " loses to " << mapPlace->second.candidate->cost << std::endl;
     127                                                )
    124128                                        }
    125129                                } else {
     
    127131                                }
    128132                        }
    129 
    130                         PRINT(
    131                                 std::cerr << "there are " << selected.size() << " alternatives before elimination" << std::endl;
    132                         )
    133133
    134134                        // accept the alternatives that were unambiguous
     
    180180                        throw SemanticError( "No reasonable alternatives for expression ", expr );
    181181                }
    182                 for ( AltList::iterator i = alternatives.begin(); i != alternatives.end(); ++i ) {
    183                         if ( adjust ) {
    184                                 adjustExprType( i->expr->get_result(), i->env, indexer );
    185                         }
    186                 }
    187182                if ( prune ) {
     183                        auto oldsize = alternatives.size();
    188184                        PRINT(
    189185                                std::cerr << "alternatives before prune:" << std::endl;
     
    204200                        alternatives.erase( oldBegin, alternatives.end() );
    205201                        PRINT(
     202                                std::cerr << "there are " << oldsize << " alternatives before elimination" << std::endl;
     203                        )
     204                        PRINT(
    206205                                std::cerr << "there are " << alternatives.size() << " alternatives after elimination" << std::endl;
    207206                        )
     207                }
     208                // adjust types after pruning so that types substituted by pruneAlternatives are correctly adjusted
     209                for ( AltList::iterator i = alternatives.begin(); i != alternatives.end(); ++i ) {
     210                        if ( adjust ) {
     211                                adjustExprType( i->expr->get_result(), i->env, indexer );
     212                        }
    208213                }
    209214
     
    318323        Cost computeExpressionConversionCost( Expression *& actualExpr, Type * formalType, const SymTab::Indexer &indexer, const TypeEnvironment & env ) {
    319324                Cost convCost = computeConversionCost( actualExpr->result, formalType, indexer, env );
    320                 // if ( convCost != Cost::zero ) {
    321 
    322                 // xxx - temporary -- ignore poly cost, since this causes some polymorphic functions to be cast, which causes the specialize
    323                 // pass to try to specialize them, which currently does not work. Once that is fixed, remove the next 3 lines and uncomment the
    324                 // previous line.
     325
     326                // if there is a non-zero conversion cost, ignoring poly cost, then the expression requires conversion.
     327                // ignore poly cost for now, since this requires resolution of the cast to infer parameters and this
     328                // does not currently work for the reason stated below.
    325329                Cost tmpCost = convCost;
    326330                tmpCost.incPoly( -tmpCost.get_polyCost() );
    327331                if ( tmpCost != Cost::zero ) {
     332                // if ( convCost != Cost::zero ) {
    328333                        Type *newType = formalType->clone();
    329334                        env.apply( newType );
     
    631636                                        std::cerr << std::endl;
    632637                                )
    633                                 ApplicationExpr *appExpr = static_cast< ApplicationExpr* >( newerAlt.expr );
    634638                                // follow the current assertion's ID chain to find the correct set of inferred parameters to add the candidate to (i.e. the set of inferred parameters belonging to the entity which requested the assertion parameter).
    635                                 InferredParams * inferParameters = &appExpr->get_inferParams();
     639                                InferredParams * inferParameters = &newerAlt.expr->get_inferParams();
    636640                                for ( UniqueId id : cur->second.idChain ) {
    637641                                        inferParameters = (*inferParameters)[ id ].inferParams.get();
     
    680684                OpenVarSet openVars;
    681685                AssertionSet resultNeed, resultHave;
    682                 TypeEnvironment resultEnv;
     686                TypeEnvironment resultEnv( func.env );
    683687                makeUnifiableVars( funcType, openVars, resultNeed );
    684688                resultEnv.add( funcType->get_forall() ); // add all type variables as open variables now so that those not used in the parameter list are still considered open
     
    914918                                thisCost.incSafe( discardedValues );
    915919                                Alternative newAlt( restructureCast( i->expr->clone(), toType ), i->env, i->cost, thisCost );
    916                                 // xxx - this doesn't work at the moment, since inferParameters requires an ApplicationExpr as the alternative.
    917                                 // Once this works, it should be possible to infer parameters on a cast expression and specialize any function.
    918 
    919                                 // inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) );
    920                                 candidates.emplace_back( std::move( newAlt ) );
     920                                inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) );
    921921                        } // if
    922922                } // for
     
    12971297                                        // count one safe conversion for each value that is thrown away
    12981298                                        thisCost.incSafe( discardedValues );
    1299                                         candidates.push_back( Alternative( new InitExpr( restructureCast( alt.expr->clone(), toType ), initAlt.designation->clone() ), newEnv, alt.cost, thisCost ) );
     1299                                        Alternative newAlt( new InitExpr( restructureCast( alt.expr->clone(), toType ), initAlt.designation->clone() ), newEnv, alt.cost, thisCost );
     1300                                        inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) );
    13001301                                }
    13011302                        }
Note: See TracChangeset for help on using the changeset viewer.