Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rb0837e4 r954ef5b  
    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                                                 )
    128124                                        }
    129125                                } else {
     
    131127                                }
    132128                        }
     129
     130                        PRINT(
     131                                std::cerr << "there are " << selected.size() << " alternatives before elimination" << std::endl;
     132                        )
    133133
    134134                        // accept the alternatives that were unambiguous
     
    181181                }
    182182                if ( prune ) {
    183                         auto oldsize = alternatives.size();
    184183                        PRINT(
    185184                                std::cerr << "alternatives before prune:" << std::endl;
     
    199198                        }
    200199                        alternatives.erase( oldBegin, alternatives.end() );
    201                         PRINT(
    202                                 std::cerr << "there are " << oldsize << " alternatives before elimination" << std::endl;
    203                         )
    204200                        PRINT(
    205201                                std::cerr << "there are " << alternatives.size() << " alternatives after elimination" << std::endl;
     
    323319        Cost computeExpressionConversionCost( Expression *& actualExpr, Type * formalType, const SymTab::Indexer &indexer, const TypeEnvironment & env ) {
    324320                Cost convCost = computeConversionCost( actualExpr->result, formalType, indexer, env );
    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.
     321                // if ( convCost != Cost::zero ) {
     322
     323                // xxx - temporary -- ignore poly cost, since this causes some polymorphic functions to be cast, which causes the specialize
     324                // pass to try to specialize them, which currently does not work. Once that is fixed, remove the next 3 lines and uncomment the
     325                // previous line.
    329326                Cost tmpCost = convCost;
    330327                tmpCost.incPoly( -tmpCost.get_polyCost() );
    331328                if ( tmpCost != Cost::zero ) {
    332                 // if ( convCost != Cost::zero ) {
    333329                        Type *newType = formalType->clone();
    334330                        env.apply( newType );
     
    636632                                        std::cerr << std::endl;
    637633                                )
     634                                ApplicationExpr *appExpr = static_cast< ApplicationExpr* >( newerAlt.expr );
    638635                                // 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).
    639                                 InferredParams * inferParameters = &newerAlt.expr->get_inferParams();
     636                                InferredParams * inferParameters = &appExpr->get_inferParams();
    640637                                for ( UniqueId id : cur->second.idChain ) {
    641638                                        inferParameters = (*inferParameters)[ id ].inferParams.get();
     
    684681                OpenVarSet openVars;
    685682                AssertionSet resultNeed, resultHave;
    686                 TypeEnvironment resultEnv( func.env );
     683                TypeEnvironment resultEnv;
    687684                makeUnifiableVars( funcType, openVars, resultNeed );
    688685                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
     
    918915                                thisCost.incSafe( discardedValues );
    919916                                Alternative newAlt( restructureCast( i->expr->clone(), toType ), i->env, i->cost, thisCost );
    920                                 inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) );
     917                                // xxx - this doesn't work at the moment, since inferParameters requires an ApplicationExpr as the alternative.
     918                                // Once this works, it should be possible to infer parameters on a cast expression and specialize any function.
     919
     920                                // inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) );
     921                                candidates.emplace_back( std::move( newAlt ) );
    921922                        } // if
    922923                } // for
     
    12971298                                        // count one safe conversion for each value that is thrown away
    12981299                                        thisCost.incSafe( discardedValues );
    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 ) );
     1300                                        candidates.push_back( Alternative( new InitExpr( restructureCast( alt.expr->clone(), toType ), initAlt.designation->clone() ), newEnv, alt.cost, thisCost ) );
    13011301                                }
    13021302                        }
Note: See TracChangeset for help on using the changeset viewer.