Changeset ebcb7ba


Ignore:
Timestamp:
Jan 29, 2018, 2:05:26 PM (7 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:
93967c8, fee651f
Parents:
ff39851
Message:

Refactor AlternativeFinder? handling of ConditionalExpr? to greatly reduce the number of unnecessary recursive calls

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rff39851 rebcb7ba  
    15581558                AlternativeFinder firstFinder( indexer, env );
    15591559                firstFinder.findWithAdjustment( conditionalExpr->get_arg1() );
     1560                if ( firstFinder.alternatives.empty() ) return;
     1561                // find alternatives for true expression
     1562                AlternativeFinder secondFinder( indexer, env );
     1563                secondFinder.findWithAdjustment( conditionalExpr->get_arg2() );
     1564                if ( secondFinder.alternatives.empty() ) return;
     1565                // find alterantives for false expression
     1566                AlternativeFinder thirdFinder( indexer, env );
     1567                thirdFinder.findWithAdjustment( conditionalExpr->get_arg3() );
     1568                if ( thirdFinder.alternatives.empty() ) return;
    15601569                for ( AltList::const_iterator first = firstFinder.alternatives.begin(); first != firstFinder.alternatives.end(); ++first ) {
    1561                         // find alternatives for true expression
    1562                         AlternativeFinder secondFinder( indexer, first->env );
    1563                         secondFinder.findWithAdjustment( conditionalExpr->get_arg2() );
    15641570                        for ( AltList::const_iterator second = secondFinder.alternatives.begin(); second != secondFinder.alternatives.end(); ++second ) {
    1565                                 // find alterantives for false expression
    1566                                 AlternativeFinder thirdFinder( indexer, second->env );
    1567                                 thirdFinder.findWithAdjustment( conditionalExpr->get_arg3() );
    15681571                                for ( AltList::const_iterator third = thirdFinder.alternatives.begin(); third != thirdFinder.alternatives.end(); ++third ) {
     1572                                        TypeEnvironment compositeEnv;
     1573                                        compositeEnv.simpleCombine( first->env );
     1574                                        compositeEnv.simpleCombine( second->env );
     1575                                        compositeEnv.simpleCombine( third->env );
     1576
    15691577                                        // unify true and false types, then infer parameters to produce new alternatives
    15701578                                        OpenVarSet openVars;
    15711579                                        AssertionSet needAssertions, haveAssertions;
    1572                                         Alternative newAlt( 0, third->env, first->cost + second->cost + third->cost );
     1580                                        Alternative newAlt( 0, compositeEnv, first->cost + second->cost + third->cost );
    15731581                                        Type* commonType = nullptr;
    15741582                                        if ( unify( second->expr->get_result(), third->expr->get_result(), newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
Note: See TracChangeset for help on using the changeset viewer.