Changeset a585396 for src


Ignore:
Timestamp:
Oct 5, 2017, 1:36:59 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
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
Message:

Fix missing environment/open vars update in iterative resolver

Location:
src/ResolvExpr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    re472d54 ra585396  
    579579                          tupleEls() {}
    580580               
    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
    584586                        actuals.emplace_back( actual, this->env, cost );
     587                        // count tuple elements, if applicable
     588                        if ( ! tupleEls.empty() ) ++tupleEls.back();
    585589                }
    586590               
    587591                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)
    589593                        : 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),
    591595                          tupleEls(old.tupleEls) {
    592596                        // add new actual
     
    713717                                        for ( const Alternative& actual : args[result.nextArg] ) {
    714718                                                addExplodedActual( result, actual.expr, actual.cost, nextResults,
    715                                                         []( ArgPack& result, Expression* expr, Cost cost,
     719                                                        [&actual]( ArgPack& result, Expression* expr, Cost cost,
    716720                                                                        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 );
    718726                                                        } );
    719727                                        }
     
    741749                                                        nextResults.emplace_back( result, cnstExpr->clone(),
    742750                                                                std::move(resultEnv), std::move(resultNeed),
    743                                                                 std::move(resultHave) );
     751                                                                std::move(resultHave), OpenVarSet{ result.openVars } );
    744752                                                }
    745753                                        }
     
    751759                        for ( const Alternative& actual : args[result.nextArg] ) {
    752760                                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,
    754762                                                        std::vector<ArgPack>& nextResults ) {
    755763                                                // attempt to unify actual with parameter
    756764                                                TypeEnvironment resultEnv = result.env;
    757765                                                AssertionSet resultNeed = result.need, resultHave = result.have;
     766                                                OpenVarSet resultOpenVars = result.openVars;
     767                                                resultEnv.addActual( actual.env, resultOpenVars );
    758768                                                Type* actualType = expr->get_result();
     769
    759770
    760771                                                PRINT(
     
    767778
    768779                                                if ( unify( formalType, actualType, resultEnv, resultNeed, resultHave,
    769                                                                 result.openVars, indexer ) ) {
     780                                                                resultOpenVars, indexer ) ) {
    770781                                                        nextResults.emplace_back( result, expr->clone(),
    771782                                                                std::move(resultEnv), std::move(resultNeed), std::move(resultHave),
    772                                                                 cost );
     783                                                                std::move(resultOpenVars), cost );
    773784                                                }
    774785                                        } );
     
    829840                                        // add each possible next argument
    830841                                        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 );
    832847                                        }
    833848                                }
     
    13681383                findSubExprs( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end(), back_inserter( subExprAlternatives ) );
    13691384                std::list< AltList > possibilities;
     1385                // TODO re-write to use iterative method
    13701386                combos( subExprAlternatives.begin(), subExprAlternatives.end(), back_inserter( possibilities ) );
    13711387                for ( std::list< AltList >::const_iterator i = possibilities.begin(); i != possibilities.end(); ++i ) {
  • src/ResolvExpr/TypeEnvironment.cc

    re472d54 ra585396  
    201201        }
    202202
     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
    203214} // namespace ResolvExpr
    204215
  • src/ResolvExpr/TypeEnvironment.h

    re472d54 ra585396  
    8686                TypeEnvironment *clone() const { return new TypeEnvironment( *this ); }
    8787
     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
    8892                typedef std::list< EqvClass >::iterator iterator;
    8993                iterator begin() { return env.begin(); }
Note: See TracChangeset for help on using the changeset viewer.