Changeset a585396
- Timestamp:
- Oct 5, 2017, 1:36:59 PM (7 years ago)
- 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:
- c43c171
- Parents:
- e472d54
- Location:
- src/ResolvExpr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
re472d54 ra585396 579 579 tupleEls() {} 580 580 581 ArgPack(const ArgPack& old, Expression* actual, const Cost& cost = Cost::zero) 582 : actuals(old.actuals), env(old.env), need(old.need), have(old.have), 583 openVars(old.openVars), nextArg(old.nextArg + 1), tupleEls(old.tupleEls) { 581 ArgPack(const ArgPack& old, Expression* actual, TypeEnvironment&& env, 582 OpenVarSet&& openVars, const Cost& cost = Cost::zero) 583 : actuals(old.actuals), env(std::move(env)), need(old.need), have(old.have), 584 openVars(std::move(openVars)), nextArg(old.nextArg + 1), tupleEls(old.tupleEls) { 585 // add new actual 584 586 actuals.emplace_back( actual, this->env, cost ); 587 // count tuple elements, if applicable 588 if ( ! tupleEls.empty() ) ++tupleEls.back(); 585 589 } 586 590 587 591 ArgPack(const ArgPack& old, Expression* actual, TypeEnvironment&& env, AssertionSet&& need, 588 AssertionSet&& have, const Cost& cost = Cost::zero)592 AssertionSet&& have, OpenVarSet&& openVars, const Cost& cost = Cost::zero) 589 593 : actuals(old.actuals), env(std::move(env)), need(std::move(need)), 590 have(std::move(have)), openVars( old.openVars), nextArg(old.nextArg + 1),594 have(std::move(have)), openVars(std::move(openVars)), nextArg(old.nextArg + 1), 591 595 tupleEls(old.tupleEls) { 592 596 // add new actual … … 713 717 for ( const Alternative& actual : args[result.nextArg] ) { 714 718 addExplodedActual( result, actual.expr, actual.cost, nextResults, 715 [ ]( ArgPack& result, Expression* expr, Cost cost,719 [&actual]( ArgPack& result, Expression* expr, Cost cost, 716 720 std::vector<ArgPack>& nextResults ) { 717 nextResults.emplace_back( result, expr, cost ); 721 TypeEnvironment env{ result.env }; 722 OpenVarSet openVars{ result.openVars }; 723 env.addActual( actual.env, openVars ); 724 nextResults.emplace_back( result, expr, std::move(env), 725 std::move(openVars), cost ); 718 726 } ); 719 727 } … … 741 749 nextResults.emplace_back( result, cnstExpr->clone(), 742 750 std::move(resultEnv), std::move(resultNeed), 743 std::move(resultHave) );751 std::move(resultHave), OpenVarSet{ result.openVars } ); 744 752 } 745 753 } … … 751 759 for ( const Alternative& actual : args[result.nextArg] ) { 752 760 addExplodedActual( result, actual.expr, actual.cost, nextResults, 753 [formalType,&indexer ]( ArgPack& result, Expression* expr, Cost cost,761 [formalType,&indexer,&actual]( ArgPack& result, Expression* expr, Cost cost, 754 762 std::vector<ArgPack>& nextResults ) { 755 763 // attempt to unify actual with parameter 756 764 TypeEnvironment resultEnv = result.env; 757 765 AssertionSet resultNeed = result.need, resultHave = result.have; 766 OpenVarSet resultOpenVars = result.openVars; 767 resultEnv.addActual( actual.env, resultOpenVars ); 758 768 Type* actualType = expr->get_result(); 769 759 770 760 771 PRINT( … … 767 778 768 779 if ( unify( formalType, actualType, resultEnv, resultNeed, resultHave, 769 result .openVars, indexer ) ) {780 resultOpenVars, indexer ) ) { 770 781 nextResults.emplace_back( result, expr->clone(), 771 782 std::move(resultEnv), std::move(resultNeed), std::move(resultHave), 772 cost );783 std::move(resultOpenVars), cost ); 773 784 } 774 785 } ); … … 829 840 // add each possible next argument 830 841 for ( const Alternative& actual : args[result.nextArg] ) { 831 nextResults.emplace_back( result, actual.expr, actual.cost ); 842 TypeEnvironment env{ result.env }; 843 OpenVarSet openVars{ result.openVars }; 844 env.addActual( actual.env, openVars ); 845 nextResults.emplace_back( result, actual.expr, std::move(env), 846 std::move(openVars), actual.cost ); 832 847 } 833 848 } … … 1368 1383 findSubExprs( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end(), back_inserter( subExprAlternatives ) ); 1369 1384 std::list< AltList > possibilities; 1385 // TODO re-write to use iterative method 1370 1386 combos( subExprAlternatives.begin(), subExprAlternatives.end(), back_inserter( possibilities ) ); 1371 1387 for ( std::list< AltList >::const_iterator i = possibilities.begin(); i != possibilities.end(); ++i ) { -
src/ResolvExpr/TypeEnvironment.cc
re472d54 ra585396 201 201 } 202 202 203 void TypeEnvironment::addActual( const TypeEnvironment& actualEnv, OpenVarSet& openVars ) { 204 for ( const EqvClass& c : actualEnv ) { 205 EqvClass c2 = c; 206 c2.allowWidening = false; 207 for ( const std::string& var : c2.vars ) { 208 openVars[ var ] = c2.data; 209 } 210 env.push_back( std::move(c2) ); 211 } 212 } 213 203 214 } // namespace ResolvExpr 204 215 -
src/ResolvExpr/TypeEnvironment.h
re472d54 ra585396 86 86 TypeEnvironment *clone() const { return new TypeEnvironment( *this ); } 87 87 88 /// Iteratively adds the environment of a new actual (with allowWidening = false), 89 /// and extracts open variables. 90 void addActual( const TypeEnvironment& actualEnv, OpenVarSet& openVars ); 91 88 92 typedef std::list< EqvClass >::iterator iterator; 89 93 iterator begin() { return env.begin(); }
Note: See TracChangeset
for help on using the changeset viewer.