Changeset fee651f


Ignore:
Timestamp:
Jan 29, 2018, 4:03:04 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:
5a73f0f
Parents:
ebcb7ba
Message:

Refactor AlternativeFinder? handling of LogicalExpr? and RangeExpr? to greatly reduce the number of unnecessary recursive calls

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rebcb7ba rfee651f  
    15441544                AlternativeFinder firstFinder( indexer, env );
    15451545                firstFinder.findWithAdjustment( logicalExpr->get_arg1() );
     1546                if ( firstFinder.alternatives.empty() ) return;
     1547                AlternativeFinder secondFinder( indexer, env );
     1548                secondFinder.findWithAdjustment( logicalExpr->get_arg2() );
     1549                if ( secondFinder.alternatives.empty() ) return;
    15461550                for ( AltList::const_iterator first = firstFinder.alternatives.begin(); first != firstFinder.alternatives.end(); ++first ) {
    1547                         AlternativeFinder secondFinder( indexer, first->env );
    1548                         secondFinder.findWithAdjustment( logicalExpr->get_arg2() );
    15491551                        for ( AltList::const_iterator second = secondFinder.alternatives.begin(); second != secondFinder.alternatives.end(); ++second ) {
     1552                                TypeEnvironment compositeEnv;
     1553                                compositeEnv.simpleCombine( first->env );
     1554                                compositeEnv.simpleCombine( second->env );
     1555
    15501556                                LogicalExpr *newExpr = new LogicalExpr( first->expr->clone(), second->expr->clone(), logicalExpr->get_isAnd() );
    1551                                 alternatives.push_back( Alternative( newExpr, second->env, first->cost + second->cost ) );
     1557                                alternatives.push_back( Alternative( newExpr, compositeEnv, first->cost + second->cost ) );
    15521558                        }
    15531559                }
     
    16091615                AlternativeFinder firstFinder( indexer, env );
    16101616                firstFinder.findWithAdjustment( rangeExpr->get_low() );
     1617                if ( firstFinder.alternatives.empty() ) return;
     1618                AlternativeFinder secondFinder( indexer, env );
     1619                secondFinder.findWithAdjustment( rangeExpr->get_high() );
     1620                if ( secondFinder.alternatives.empty() ) return;
    16111621                for ( AltList::const_iterator first = firstFinder.alternatives.begin(); first != firstFinder.alternatives.end(); ++first ) {
    1612                         AlternativeFinder secondFinder( indexer, first->env );
    1613                         secondFinder.findWithAdjustment( rangeExpr->get_high() );
    16141622                        for ( AltList::const_iterator second = secondFinder.alternatives.begin(); second != secondFinder.alternatives.end(); ++second ) {
     1623                                TypeEnvironment compositeEnv;
     1624                                compositeEnv.simpleCombine( first->env );
     1625                                compositeEnv.simpleCombine( second->env );
    16151626                                OpenVarSet openVars;
    16161627                                AssertionSet needAssertions, haveAssertions;
    1617                                 Alternative newAlt( 0, second->env, first->cost + second->cost );
     1628                                Alternative newAlt( 0, compositeEnv, first->cost + second->cost );
    16181629                                Type* commonType = nullptr;
    16191630                                if ( unify( first->expr->get_result(), second->expr->get_result(), newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
Note: See TracChangeset for help on using the changeset viewer.