Changeset 452747a


Ignore:
Timestamp:
Nov 22, 2017, 3:43:50 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:
5fe35d6
Parents:
7e4c4f4 (diff), c2c6177 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

Location:
src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r7e4c4f4 r452747a  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep 23 18:16:48 2017
    13 // Update Count     : 1024
     12// Last Modified On : Mon Nov 20 09:21:52 2017
     13// Update Count     : 1031
    1414//
    1515
     
    509509
    510510DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) {
    511         if ( ! q ) { delete q; return this; }
     511        if ( ! q ) { delete q; return this; }                           // empty qualifier
    512512
    513513        checkSpecifiers( q );
    514514        copySpecifiers( q );
    515515
    516         if ( ! q->type ) {
    517                 delete q;
    518                 return this;
    519         } // if
     516        if ( ! q->type ) { delete q; return this; }
    520517
    521518        if ( ! type ) {
    522                 type = q->type;                                                                 // reuse this structure
     519                type = q->type;                                                                 // reuse structure
    523520                q->type = nullptr;
    524521                delete q;
     
    526523        } // if
    527524
    528         if ( q->type->forall ) {
    529                 if ( type->forall ) {
    530                         type->forall->appendList( q->type->forall );
     525        if ( q->type->forall ) {                                                        // forall qualifier ?
     526                if ( type->forall ) {                                                   // polymorphic routine ?
     527                        type->forall->appendList( q->type->forall ); // augment forall qualifier
    531528                } else {
    532                         if ( type->kind == TypeData::Aggregate ) {
    533                                 type->aggregate.params = q->type->forall;
    534                                 // change implicit typedef from TYPEDEFname to TYPEGENname
    535                                 typedefTable.changeKind( *type->aggregate.name, TypedefTable::TG );
    536                         } else {
    537                                 type->forall = q->type->forall;
     529                        if ( type->kind == TypeData::Aggregate ) {      // struct/union ?
     530                                if ( type->aggregate.params ) {                 // polymorphic ?
     531                                        type->aggregate.params->appendList( q->type->forall ); // augment forall qualifier
     532                                } else {                                                                // not polymorphic
     533                                        type->aggregate.params = q->type->forall; // make polymorphic type
     534                                        // change implicit typedef from TYPEDEFname to TYPEGENname
     535                                        typedefTable.changeKind( *type->aggregate.name, TypedefTable::TG );
     536                                } // if
     537                        } else {                                                                        // not polymorphic
     538                                type->forall = q->type->forall;                 // make polymorphic routine
    538539                        } // if
    539540                } // if
    540                 q->type->forall = nullptr;
     541                q->type->forall = nullptr;                                              // forall qualifier moved
    541542        } // if
    542543
  • src/Parser/parser.yy

    r7e4c4f4 r452747a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 17 11:38:57 2017
    13 // Update Count     : 2914
     12// Last Modified On : Mon Nov 20 09:45:36 2017
     13// Update Count     : 2945
    1414//
    1515
     
    114114        } // for
    115115} // distExt
     116
     117// There is an ambiguity for inline generic-routine return-types and generic routines.
     118//   forall( otype T ) struct S { int i; } bar( T ) {}
     119// Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding.
     120//   forall( otype T ) struct S { int T; } forall( otype W ) bar( W ) {}
     121
     122void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) {
     123        if ( declSpec->type->kind == TypeData::Aggregate ) { // return is aggregate definition
     124                funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type
     125                declSpec->type->aggregate.params = nullptr;
     126        } // if
     127} // rebindForall
    116128
    117129bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
     
    24012413        | declaration_specifier function_declarator with_clause_opt compound_statement
    24022414                {
     2415                        rebindForall( $1, $2 );
    24032416                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24042417                        typedefTable.leaveScope();
     
    24272440        | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24282441                {
     2442                        rebindForall( $1, $2 );
    24292443                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24302444                        typedefTable.leaveScope();
  • src/ResolvExpr/Alternative.cc

    r7e4c4f4 r452747a  
    1818#include <ostream>                       // for operator<<, ostream, basic_o...
    1919#include <string>                        // for operator<<, char_traits, string
     20#include <utility>                       // for move
    2021
    2122#include "Common/utility.h"              // for maybeClone
     
    8182                os << std::endl;
    8283        }
     84
     85        void splice( AltList& dst, AltList& src ) {
     86                dst.reserve( dst.size() + src.size() );
     87                for ( Alternative& alt : src ) {
     88                        dst.push_back( std::move(alt) );
     89                }
     90                src.clear();
     91        }
     92
     93        void spliceBegin( AltList& dst, AltList& src ) {
     94                splice( src, dst );
     95                dst.swap( src );
     96        }
     97
    8398} // namespace ResolvExpr
    8499
  • src/ResolvExpr/Alternative.h

    r7e4c4f4 r452747a  
    1717
    1818#include <iosfwd>             // for ostream
    19 #include <list>               // for list
     19#include <vector>             // for vector
    2020
    2121#include "Cost.h"             // for Cost
     
    2525
    2626namespace ResolvExpr {
    27         struct Alternative;
    28 
    29         typedef std::list< Alternative > AltList;
    30 
    3127        struct Alternative {
    3228                Alternative();
     
    4642                TypeEnvironment env;
    4743        };
     44
     45        typedef std::vector< Alternative > AltList;
     46
     47        /// Moves all elements from src to the end of dst
     48        void splice( AltList& dst, AltList& src );
     49
     50        /// Moves all elements from src to the beginning of dst
     51        void spliceBegin( AltList& dst, AltList& src );
    4852} // namespace ResolvExpr
    4953
  • src/ResolvExpr/AlternativeFinder.cc

    r7e4c4f4 r452747a  
    1616#include <algorithm>               // for copy
    1717#include <cassert>                 // for strict_dynamic_cast, assert, assertf
     18#include <cstddef>                 // for size_t
    1819#include <iostream>                // for operator<<, cerr, ostream, endl
    1920#include <iterator>                // for back_insert_iterator, back_inserter
    2021#include <list>                    // for _List_iterator, list, _List_const_...
    2122#include <map>                     // for _Rb_tree_iterator, map, _Rb_tree_c...
    22 #include <memory>                  // for allocator_traits<>::value_type
     23#include <memory>                  // for allocator_traits<>::value_type, unique_ptr
    2324#include <utility>                 // for pair
    2425#include <vector>                  // for vector
     
    5051#define PRINT( text ) if ( resolvep ) { text }
    5152//#define DEBUG_COST
     53
     54using std::move;
     55
     56/// copies any copyable type
     57template<typename T>
     58T copy(const T& x) { return x; }
    5259
    5360namespace ResolvExpr {
     
    187194                                printAlts( alternatives, std::cerr );
    188195                        )
    189                         AltList::iterator oldBegin = alternatives.begin();
    190                         pruneAlternatives( alternatives.begin(), alternatives.end(), front_inserter( alternatives ) );
    191                         if ( failFast && alternatives.begin() == oldBegin ) {
     196                        AltList pruned;
     197                        pruneAlternatives( alternatives.begin(), alternatives.end(), back_inserter( pruned ) );
     198                        if ( failFast && pruned.empty() ) {
    192199                                std::ostringstream stream;
    193200                                AltList winners;
     
    199206                                throw SemanticError( stream.str() );
    200207                        }
    201                         alternatives.erase( oldBegin, alternatives.end() );
     208                        alternatives = move(pruned);
    202209                        PRINT(
    203210                                std::cerr << "there are " << oldsize << " alternatives before elimination" << std::endl;
     
    571578        /// State to iteratively build a match of parameter expressions to arguments
    572579        struct ArgPack {
    573                 AltList actuals;                 ///< Arguments included in this pack
    574                 TypeEnvironment env;             ///< Environment for this pack
    575                 AssertionSet need;               ///< Assertions outstanding for this pack
    576                 AssertionSet have;               ///< Assertions found for this pack
    577                 OpenVarSet openVars;             ///< Open variables for this pack
    578                 unsigned nextArg;                ///< Index of next argument in arguments list
    579                 std::vector<Alternative> expls;  ///< Exploded actuals left over from last match
    580                 unsigned nextExpl;               ///< Index of next exploded alternative to use
    581                 std::vector<unsigned> tupleEls;  /// Number of elements in current tuple element(s)
     580                std::size_t parent;                ///< Index of parent pack
     581                std::unique_ptr<Expression> expr;  ///< The argument stored here
     582                Cost cost;                         ///< The cost of this argument
     583                TypeEnvironment env;               ///< Environment for this pack
     584                AssertionSet need;                 ///< Assertions outstanding for this pack
     585                AssertionSet have;                 ///< Assertions found for this pack
     586                OpenVarSet openVars;               ///< Open variables for this pack
     587                unsigned nextArg;                  ///< Index of next argument in arguments list
     588                unsigned tupleStart;               ///< Number of tuples that start at this index
     589                // TODO fix this somehow
     590                std::vector<Alternative> expls;    ///< Exploded actuals left over from last match
     591
     592                ArgPack()
     593                        : parent(0), expr(), cost(Cost::zero), env(), need(), have(), openVars(), nextArg(0),
     594                          tupleStart(0), expls() {}
    582595
    583596                ArgPack(const TypeEnvironment& env, const AssertionSet& need, const AssertionSet& have,
    584597                                const OpenVarSet& openVars)
    585                         : actuals(), env(env), need(need), have(have), openVars(openVars), nextArg(0),
    586                           expls(), nextExpl(0), tupleEls() {}
    587 
    588                 /// Starts a new tuple expression
    589                 void beginTuple() {
    590                         if ( ! tupleEls.empty() ) ++tupleEls.back();
    591                         tupleEls.push_back(0);
    592                 }
     598                        : parent(0), expr(), cost(Cost::zero), env(env), need(need), have(have),
     599                          openVars(openVars), nextArg(0), tupleStart(0), expls() {}
     600
     601                ArgPack(std::size_t parent, Expression* expr, TypeEnvironment&& env, AssertionSet&& need,
     602                                AssertionSet&& have, OpenVarSet&& openVars, unsigned nextArg,
     603                                unsigned tupleStart = 0, Cost cost = Cost::zero,
     604                                std::vector<Alternative>&& expls = std::vector<Alternative>{} )
     605                        : parent(parent), expr(expr->clone()), cost(cost), env(move(env)), need(move(need)),
     606                          have(move(have)), openVars(move(openVars)), nextArg(nextArg), tupleStart(tupleStart),
     607                          expls(move(expls)) {}
     608
     609                ArgPack(const ArgPack& o, TypeEnvironment&& env, AssertionSet&& need, AssertionSet&& have,
     610                                OpenVarSet&& openVars, unsigned nextArg, Cost added )
     611                        : parent(o.parent), expr(o.expr ? o.expr->clone() : nullptr), cost(o.cost + added),
     612                          env(move(env)), need(move(need)), have(move(have)), openVars(move(openVars)),
     613                          nextArg(nextArg), tupleStart(o.tupleStart), expls() {}
     614
     615
     616                // ArgPack(const ArgPack& o)
     617                //      : parent(o.parent), expr(o.expr ? o.expr->clone() : nullptr), env(o.env),
     618                //        need(o.need), have(o.have), openVars(o.openVars), nextArg(o.nextArg),
     619                //        tupleStart(o.tupleStart), expls(o.expls) {}
     620
     621                // ArgPack(ArgPack&&) = default;
    593622
    594623                /// Ends a tuple expression, consolidating the appropriate actuals
    595                 void endTuple() {
    596                         // set up new Tuple alternative
     624                void endTuple( const std::vector<ArgPack>& packs ) {
     625                        // add all expressions in tuple to list, summing cost
    597626                        std::list<Expression*> exprs;
    598                         Cost cost = Cost::zero;
    599 
    600                         // transfer elements into alternative
    601                         for (unsigned i = 0; i < tupleEls.back(); ++i) {
    602                                 exprs.push_front( actuals.back().expr );
    603                                 actuals.back().expr = nullptr;
    604                                 cost += actuals.back().cost;
    605                                 actuals.pop_back();
    606                         }
    607                         tupleEls.pop_back();
    608 
    609                         // build new alternative
    610                         actuals.emplace_back( new TupleExpr( exprs ), this->env, cost );
    611                 }
    612 
    613                 /// Clones and adds an actual, returns this
    614                 ArgPack& withArg( Expression* expr, Cost cost = Cost::zero ) {
    615                         actuals.emplace_back( expr->clone(), this->env, cost );
    616                         if ( ! tupleEls.empty() ) ++tupleEls.back();
    617                         return *this;
     627                        const ArgPack* pack = this;
     628                        if ( expr ) { exprs.push_front( expr.release() ); }
     629                        while ( pack->tupleStart == 0 ) {
     630                                pack = &packs[pack->parent];
     631                                exprs.push_front( pack->expr->clone() );
     632                                cost += pack->cost;
     633                        }
     634                        // reset pack to appropriate tuple
     635                        expr.reset( new TupleExpr( exprs ) );
     636                        tupleStart = pack->tupleStart - 1;
     637                        parent = pack->parent;
    618638                }
    619639        };
     
    621641        /// Instantiates an argument to match a formal, returns false if no results left
    622642        bool instantiateArgument( Type* formalType, Initializer* initializer,
    623                         const std::vector< AlternativeFinder >& args,
    624                         std::vector<ArgPack>& results, std::vector<ArgPack>& nextResults,
    625                         const SymTab::Indexer& indexer ) {
     643                        const std::vector< AlternativeFinder >& args, std::vector<ArgPack>& results,
     644                        std::size_t& genStart, const SymTab::Indexer& indexer, unsigned nTuples = 0 ) {
    626645                if ( TupleType* tupleType = dynamic_cast<TupleType*>( formalType ) ) {
    627646                        // formalType is a TupleType - group actuals into a TupleExpr
    628                         for ( ArgPack& result : results ) { result.beginTuple(); }
     647                        ++nTuples;
    629648                        for ( Type* type : *tupleType ) {
    630649                                // xxx - dropping initializer changes behaviour from previous, but seems correct
    631                                 if ( ! instantiateArgument( type, nullptr, args, results, nextResults, indexer ) )
     650                                if ( ! instantiateArgument(
     651                                                type, nullptr, args, results, genStart, indexer, nTuples ) )
    632652                                        return false;
    633                         }
    634                         for ( ArgPack& result : results ) { result.endTuple(); }
     653                                nTuples = 0;
     654                        }
     655                        // re-consititute tuples for final generation
     656                        for ( auto i = genStart; i < results.size(); ++i ) {
     657                                results[i].endTuple( results );
     658                        }
    635659                        return true;
    636660                } else if ( TypeInstType* ttype = Tuples::isTtype( formalType ) ) {
    637661                        // formalType is a ttype, consumes all remaining arguments
    638662                        // xxx - mixing default arguments with variadic??
    639                         std::vector<ArgPack> finalResults{};  /// list of completed tuples
    640                         // start tuples
    641                         for ( ArgPack& result : results ) {
    642                                 result.beginTuple();
    643 
    644                                 // use rest of exploded tuple if present
    645                                 while ( result.nextExpl < result.expls.size() ) {
    646                                         const Alternative& actual = result.expls[result.nextExpl];
    647                                         result.env.addActual( actual.env, result.openVars );
    648                                         result.withArg( actual.expr );
    649                                         ++result.nextExpl;
    650                                 }
    651                         }
     663
     664                        // completed tuples; will be spliced to end of results to finish
     665                        std::vector<ArgPack> finalResults{};
     666
    652667                        // iterate until all results completed
    653                         while ( ! results.empty() ) {
     668                        std::size_t genEnd;
     669                        ++nTuples;
     670                        do {
     671                                genEnd = results.size();
     672
    654673                                // add another argument to results
    655                                 for ( ArgPack& result : results ) {
    656                                         // finish result when out of arguments
    657                                         if ( result.nextArg >= args.size() ) {
    658                                                 Type* argType = result.actuals.back().expr->get_result();
    659                                                 if ( result.tupleEls.back() == 1 && Tuples::isTtype( argType ) ) {
    660                                                         // the case where a ttype value is passed directly is special, e.g. for
    661                                                         // argument forwarding purposes
    662                                                         // xxx - what if passing multiple arguments, last of which is ttype?
    663                                                         // xxx - what would happen if unify was changed so that unifying tuple
    664                                                         // types flattened both before unifying lists? then pass in TupleType
    665                                                         // (ttype) below.
    666                                                         result.tupleEls.pop_back();
    667                                                 } else {
    668                                                         // collapse leftover arguments into tuple
    669                                                         result.endTuple();
    670                                                         argType = result.actuals.back().expr->get_result();
    671                                                 }
    672                                                 // check unification for ttype before adding to final
    673                                                 if ( unify( ttype, argType, result.env, result.need, result.have,
    674                                                                 result.openVars, indexer ) ) {
    675                                                         finalResults.push_back( std::move(result) );
    676                                                 }
     674                                for ( std::size_t i = genStart; i < genEnd; ++i ) {
     675                                        // use remainder of exploded tuple if present
     676                                        if ( ! results[i].expls.empty() ) {
     677                                                const Alternative& actual = results[i].expls.front();
     678
     679                                                TypeEnvironment env = results[i].env;
     680                                                OpenVarSet openVars = results[i].openVars;
     681
     682                                                env.addActual( actual.env, openVars );
     683
     684                                                std::vector<Alternative> newExpls(
     685                                                        std::next( results[i].expls.begin() ), results[i].expls.end() );
     686                                                results.emplace_back(
     687                                                        i, actual.expr, move(env), copy(results[i].need),
     688                                                        copy(results[i].have), move(openVars), results[i].nextArg, nTuples,
     689                                                        Cost::zero, move(newExpls) );
     690
    677691                                                continue;
    678692                                        }
    679693
     694                                        // finish result when out of arguments
     695                                        if ( results[i].nextArg >= args.size() ) {
     696                                                ArgPack newResult{
     697                                                        results[i].env, results[i].need, results[i].have,
     698                                                        results[i].openVars };
     699                                                newResult.nextArg = results[i].nextArg;
     700                                                Type* argType;
     701
     702                                                if ( nTuples > 0 ) {
     703                                                        // first iteration, push empty tuple expression
     704                                                        newResult.parent = i;
     705                                                        std::list<Expression*> emptyList;
     706                                                        newResult.expr.reset( new TupleExpr( emptyList ) );
     707                                                        argType = newResult.expr->get_result();
     708                                                } else {
     709                                                        // clone result to collect tuple
     710                                                        newResult.parent = results[i].parent;
     711                                                        newResult.cost = results[i].cost;
     712                                                        newResult.tupleStart = results[i].tupleStart;
     713                                                        newResult.expr.reset( results[i].expr->clone() );
     714                                                        argType = newResult.expr->get_result();
     715
     716                                                        if ( results[i].tupleStart > 0 && Tuples::isTtype( argType ) ) {
     717                                                                // the case where a ttype value is passed directly is special,
     718                                                                // e.g. for argument forwarding purposes
     719                                                                // xxx - what if passing multiple arguments, last of which is
     720                                                                //       ttype?
     721                                                                // xxx - what would happen if unify was changed so that unifying
     722                                                                //       tuple
     723                                                                // types flattened both before unifying lists? then pass in
     724                                                                // TupleType (ttype) below.
     725                                                                --newResult.tupleStart;
     726                                                        } else {
     727                                                                // collapse leftover arguments into tuple
     728                                                                newResult.endTuple( results );
     729                                                                argType = newResult.expr->get_result();
     730                                                        }
     731                                                }
     732
     733                                                // check unification for ttype before adding to final
     734                                                if ( unify( ttype, argType, newResult.env, newResult.need, newResult.have,
     735                                                                newResult.openVars, indexer ) ) {
     736                                                        finalResults.push_back( move(newResult) );
     737                                                }
     738
     739                                                continue;
     740                                        }
     741
    680742                                        // add each possible next argument
    681                                         for ( const Alternative& actual : args[result.nextArg] ) {
    682                                                 ArgPack aResult = result;  // copy to clone everything
    683                                                 // add details of actual to result
    684                                                 aResult.env.addActual( actual.env, aResult.openVars );
    685                                                 Cost cost = actual.cost;
     743                                        auto j = results[i].nextArg;
     744                                        for ( const Alternative& actual : args[j] ) {
     745                                                // fresh copies of parent parameters for this iteration
     746                                                TypeEnvironment env = results[i].env;
     747                                                OpenVarSet openVars = results[i].openVars;
     748
     749                                                env.addActual( actual.env, openVars );
    686750
    687751                                                // explode argument
    688752                                                std::vector<Alternative> exploded;
    689753                                                Tuples::explode( actual, indexer, back_inserter( exploded ) );
    690 
    691                                                 // add exploded argument to tuple
    692                                                 for ( Alternative& aActual : exploded ) {
    693                                                         aResult.withArg( aActual.expr, cost );
    694                                                         cost = Cost::zero;
     754                                                if ( exploded.empty() ) {
     755                                                        // skip empty tuple arguments by (near-)cloning parent into next gen
     756                                                        results.emplace_back(
     757                                                                results[i], move(env), copy(results[i].need),
     758                                                                copy(results[i].have), move(openVars), j + 1, actual.cost );
     759
     760                                                        continue;
    695761                                                }
    696                                                 ++aResult.nextArg;
    697                                                 nextResults.push_back( std::move(aResult) );
     762
     763                                                // trim first element from exploded
     764                                                std::vector<Alternative> newExpls;
     765                                                newExpls.reserve( exploded.size() - 1 );
     766                                                for ( std::size_t i = 1; i < exploded.size(); ++i ) {
     767                                                        newExpls.push_back( move(exploded[i]) );
     768                                                }
     769                                                // add new result
     770                                                results.emplace_back(
     771                                                        i, exploded.front().expr, move(env), copy(results[i].need),
     772                                                        copy(results[i].have), move(openVars), results[i].nextArg + 1,
     773                                                        nTuples, actual.cost, move(newExpls) );
    698774                                        }
    699775                                }
    700776
    701777                                // reset for next round
    702                                 results.swap( nextResults );
    703                                 nextResults.clear();
    704                         }
    705                         results.swap( finalResults );
    706                         return ! results.empty();
     778                                genStart = genEnd;
     779                                nTuples = 0;
     780                        } while ( genEnd != results.size() );
     781
     782                        // splice final results onto results
     783                        for ( std::size_t i = 0; i < finalResults.size(); ++i ) {
     784                                results.push_back( move(finalResults[i]) );
     785                        }
     786                        return ! finalResults.empty();
    707787                }
    708788
    709789                // iterate each current subresult
    710                 for ( unsigned iResult = 0; iResult < results.size(); ++iResult ) {
    711                         ArgPack& result = results[iResult];
    712 
    713                         if ( result.nextExpl < result.expls.size() ) {
    714                                 // use remainder of exploded tuple if present
    715                                 const Alternative& actual = result.expls[result.nextExpl];
    716                                 result.env.addActual( actual.env, result.openVars );
     790                std::size_t genEnd = results.size();
     791                for ( std::size_t i = genStart; i < genEnd; ++i ) {
     792                        // use remainder of exploded tuple if present
     793                        if ( ! results[i].expls.empty() ) {
     794                                const Alternative& actual = results[i].expls.front();
     795
     796                                TypeEnvironment env = results[i].env;
     797                                AssertionSet need = results[i].need, have = results[i].have;
     798                                OpenVarSet openVars = results[i].openVars;
     799
     800                                env.addActual( actual.env, openVars );
    717801                                Type* actualType = actual.expr->get_result();
    718802
     
    725809                                )
    726810
    727                                 if ( unify( formalType, actualType, result.env, result.need, result.have,
    728                                                 result.openVars, indexer ) ) {
    729                                         ++result.nextExpl;
    730                                         nextResults.push_back( std::move(result.withArg( actual.expr )) );
     811                                if ( unify( formalType, actualType, env, need, have, openVars, indexer ) ) {
     812                                        std::vector<Alternative> newExpls(
     813                                                std::next( results[i].expls.begin() ), results[i].expls.end() );
     814                                        results.emplace_back(
     815                                                i, actual.expr, move(env), move(need), move(have), move(openVars),
     816                                                results[i].nextArg, nTuples, Cost::zero, move(newExpls) );;
    731817                                }
    732818
    733819                                continue;
    734                         } else if ( result.nextArg >= args.size() ) {
    735                                 // use default initializers if out of arguments
     820                        }
     821
     822                        // use default initializers if out of arguments
     823                        if ( results[i].nextArg >= args.size() ) {
    736824                                if ( ConstantExpr* cnstExpr = getDefaultValue( initializer ) ) {
    737825                                        if ( Constant* cnst = dynamic_cast<Constant*>( cnstExpr->get_constant() ) ) {
    738                                                 if ( unify( formalType, cnst->get_type(), result.env, result.need,
    739                                                                 result.have, result.openVars, indexer ) ) {
    740                                                         nextResults.push_back( std::move(result.withArg( cnstExpr )) );
     826                                                TypeEnvironment env = results[i].env;
     827                                                AssertionSet need = results[i].need, have = results[i].have;
     828                                                OpenVarSet openVars = results[i].openVars;
     829
     830                                                if ( unify( formalType, cnst->get_type(), env, need, have, openVars,
     831                                                                indexer ) ) {
     832                                                        results.emplace_back(
     833                                                                i, cnstExpr, move(env), move(need), move(have),
     834                                                                move(openVars), results[i].nextArg, nTuples );
    741835                                                }
    742836                                        }
    743837                                }
     838
    744839                                continue;
    745840                        }
    746841
    747842                        // Check each possible next argument
    748                         for ( const Alternative& actual : args[result.nextArg] ) {
    749                                 ArgPack aResult = result;  // copy to clone everything
    750                                 // add details of actual to result
    751                                 aResult.env.addActual( actual.env, aResult.openVars );
     843                        auto j = results[i].nextArg;
     844                        for ( const Alternative& actual : args[j] ) {
     845                                // fresh copies of parent parameters for this iteration
     846                                TypeEnvironment env = results[i].env;
     847                                AssertionSet need = results[i].need, have = results[i].have;
     848                                OpenVarSet openVars = results[i].openVars;
     849
     850                                env.addActual( actual.env, openVars );
    752851
    753852                                // explode argument
     
    755854                                Tuples::explode( actual, indexer, back_inserter( exploded ) );
    756855                                if ( exploded.empty() ) {
    757                                         // skip empty tuple arguments
    758                                         ++aResult.nextArg;
    759                                         results.push_back( std::move(aResult) );
     856                                        // skip empty tuple arguments by (near-)cloning parent into next gen
     857                                        results.emplace_back(
     858                                                results[i], move(env), move(need), move(have), move(openVars), j + 1,
     859                                                actual.cost );
     860
    760861                                        continue;
    761862                                }
     
    774875
    775876                                // attempt to unify types
    776                                 if ( unify( formalType, actualType, aResult.env, aResult.need, aResult.have, aResult.openVars, indexer ) ) {
    777                                         // add argument
    778                                         aResult.withArg( aActual.expr, actual.cost );
    779                                         ++aResult.nextArg;
    780                                         if ( exploded.size() > 1 ) {
    781                                                 // other parts of tuple left over
    782                                                 aResult.expls = std::move( exploded );
    783                                                 aResult.nextExpl = 1;
     877                                if ( unify( formalType, actualType, env, need, have, openVars, indexer ) ) {
     878                                        // trim first element from exploded
     879                                        std::vector<Alternative> newExpls;
     880                                        newExpls.reserve( exploded.size() - 1 );
     881                                        for ( std::size_t i = 1; i < exploded.size(); ++i ) {
     882                                                newExpls.push_back( move(exploded[i]) );
    784883                                        }
    785                                         nextResults.push_back( std::move(aResult) );
     884                                        // add new result
     885                                        results.emplace_back(
     886                                                i, aActual.expr, move(env), move(need), move(have), move(openVars),
     887                                                j + 1, nTuples, actual.cost, move(newExpls) );
    786888                                }
    787889                        }
     
    789891
    790892                // reset for next parameter
    791                 results.swap( nextResults );
    792                 nextResults.clear();
    793 
    794                 return ! results.empty();
     893                genStart = genEnd;
     894
     895                return genEnd != results.size();
     896        }
     897
     898        template<typename OutputIterator>
     899        void AlternativeFinder::validateFunctionAlternative( const Alternative &func, ArgPack& result,
     900                        const std::vector<ArgPack>& results, OutputIterator out ) {
     901                ApplicationExpr *appExpr = new ApplicationExpr( func.expr->clone() );
     902                // sum cost and accumulate actuals
     903                std::list<Expression*>& args = appExpr->get_args();
     904                Cost cost = Cost::zero;
     905                const ArgPack* pack = &result;
     906                while ( pack->expr ) {
     907                        args.push_front( pack->expr->clone() );
     908                        cost += pack->cost;
     909                        pack = &results[pack->parent];
     910                }
     911                // build and validate new alternative
     912                Alternative newAlt( appExpr, result.env, cost );
     913                PRINT(
     914                        std::cerr << "instantiate function success: " << appExpr << std::endl;
     915                        std::cerr << "need assertions:" << std::endl;
     916                        printAssertionSet( result.need, std::cerr, 8 );
     917                )
     918                inferParameters( result.need, result.have, newAlt, result.openVars, out );
    795919        }
    796920
     
    818942
    819943                // iteratively build matches, one parameter at a time
    820                 std::vector<ArgPack> results{ ArgPack{ funcEnv, funcNeed, funcHave, funcOpenVars } };
    821                 std::vector<ArgPack> nextResults{};
     944                std::vector<ArgPack> results;
     945                results.push_back( ArgPack{ funcEnv, funcNeed, funcHave, funcOpenVars } );
     946                std::size_t genStart = 0;
     947
    822948                for ( DeclarationWithType* formal : funcType->get_parameters() ) {
    823949                        ObjectDecl* obj = strict_dynamic_cast< ObjectDecl* >( formal );
    824950                        if ( ! instantiateArgument(
    825                                         obj->get_type(), obj->get_init(), args, results, nextResults, indexer ) )
     951                                        obj->get_type(), obj->get_init(), args, results, genStart, indexer ) )
    826952                                return;
    827953                }
    828954
    829                 // filter out results that don't use all the arguments, and aren't variadic
    830                 std::vector<ArgPack> finalResults{};
    831955                if ( funcType->get_isVarArgs() ) {
    832                         for ( ArgPack& result : results ) {
    833                                 // use rest of exploded tuple if present
    834                                 while ( result.nextExpl < result.expls.size() ) {
    835                                         const Alternative& actual = result.expls[result.nextExpl];
    836                                         result.env.addActual( actual.env, result.openVars );
    837                                         result.withArg( actual.expr );
    838                                         ++result.nextExpl;
    839                                 }
    840                         }
    841 
    842                         while ( ! results.empty() ) {
    843                                 // build combinations for all remaining arguments
    844                                 for ( ArgPack& result : results ) {
    845                                         // keep if used all arguments
    846                                         if ( result.nextArg >= args.size() ) {
    847                                                 finalResults.push_back( std::move(result) );
     956                        // append any unused arguments to vararg pack
     957                        std::size_t genEnd;
     958                        do {
     959                                genEnd = results.size();
     960
     961                                // iterate results
     962                                for ( std::size_t i = genStart; i < genEnd; ++i ) {
     963                                        // use remainder of exploded tuple if present
     964                                        if ( ! results[i].expls.empty() ) {
     965                                                const Alternative& actual = results[i].expls.front();
     966
     967                                                TypeEnvironment env = results[i].env;
     968                                                OpenVarSet openVars = results[i].openVars;
     969
     970                                                env.addActual( actual.env, openVars );
     971
     972                                                std::vector<Alternative> newExpls(
     973                                                        std::next( results[i].expls.begin() ), results[i].expls.end() );
     974                                                results.emplace_back(
     975                                                        i, actual.expr, move(env), copy(results[i].need),
     976                                                        copy(results[i].have), move(openVars), results[i].nextArg, 0,
     977                                                        Cost::zero, move(newExpls) );
     978
    848979                                                continue;
    849980                                        }
    850981
     982                                        // finish result when out of arguments
     983                                        if ( results[i].nextArg >= args.size() ) {
     984                                                validateFunctionAlternative( func, results[i], results, out );
     985
     986                                                continue;
     987                                        }
     988
    851989                                        // add each possible next argument
    852                                         for ( const Alternative& actual : args[result.nextArg] ) {
    853                                                 ArgPack aResult = result; // copy to clone everything
    854                                                 // add details of actual to result
    855                                                 aResult.env.addActual( actual.env, aResult.openVars );
    856                                                 Cost cost = actual.cost;
     990                                        auto j = results[i].nextArg;
     991                                        for ( const Alternative& actual : args[j] ) {
     992                                                // fresh copies of parent parameters for this iteration
     993                                                TypeEnvironment env = results[i].env;
     994                                                OpenVarSet openVars = results[i].openVars;
     995
     996                                                env.addActual( actual.env, openVars );
    857997
    858998                                                // explode argument
    859999                                                std::vector<Alternative> exploded;
    8601000                                                Tuples::explode( actual, indexer, back_inserter( exploded ) );
    861 
    862                                                 // add exploded argument to arg list
    863                                                 for ( Alternative& aActual : exploded ) {
    864                                                         aResult.withArg( aActual.expr, cost );
    865                                                         cost = Cost::zero;
     1001                                                if ( exploded.empty() ) {
     1002                                                        // skip empty tuple arguments by (near-)cloning parent into next gen
     1003                                                        results.emplace_back(
     1004                                                                results[i], move(env), copy(results[i].need),
     1005                                                                copy(results[i].have), move(openVars), j + 1, actual.cost );
     1006                                                        continue;
    8661007                                                }
    867                                                 ++aResult.nextArg;
    868                                                 nextResults.push_back( std::move(aResult) );
     1008
     1009                                                // trim first element from exploded
     1010                                                std::vector<Alternative> newExpls;
     1011                                                newExpls.reserve( exploded.size() - 1 );
     1012                                                for ( std::size_t i = 1; i < exploded.size(); ++i ) {
     1013                                                        newExpls.push_back( move(exploded[i]) );
     1014                                                }
     1015                                                // add new result
     1016                                                results.emplace_back(
     1017                                                        i, exploded.front().expr, move(env), copy(results[i].need),
     1018                                                        copy(results[i].have), move(openVars), j + 1, 0,
     1019                                                        actual.cost, move(newExpls) );
    8691020                                        }
    8701021                                }
    8711022
    872                                 // reset for next round
    873                                 results.swap( nextResults );
    874                                 nextResults.clear();
    875                         }
     1023                                genStart = genEnd;
     1024                        } while ( genEnd != results.size() );
    8761025                } else {
    8771026                        // filter out results that don't use all the arguments
    878                         for ( ArgPack& result : results ) {
    879                                 if ( result.nextExpl >= result.expls.size() && result.nextArg >= args.size() ) {
    880                                         finalResults.push_back( std::move(result) );
     1027                        for ( std::size_t i = genStart; i < results.size(); ++i ) {
     1028                                ArgPack& result = results[i];
     1029                                if ( result.expls.empty() && result.nextArg >= args.size() ) {
     1030                                        validateFunctionAlternative( func, result, results, out );
    8811031                                }
    8821032                        }
    883                 }
    884 
    885                 // validate matching combos, add to final result list
    886                 for ( ArgPack& result : finalResults ) {
    887                         ApplicationExpr *appExpr = new ApplicationExpr( func.expr->clone() );
    888                         Alternative newAlt( appExpr, result.env, sumCost( result.actuals ) );
    889                         makeExprList( result.actuals, appExpr->get_args() );
    890                         PRINT(
    891                                 std::cerr << "instantiate function success: " << appExpr << std::endl;
    892                                 std::cerr << "need assertions:" << std::endl;
    893                                 printAssertionSet( result.need, std::cerr, 8 );
    894                         )
    895                         inferParameters( result.need, result.have, newAlt, result.openVars, out );
    8961033                }
    8971034        }
     
    9561093                if ( ! funcOpFinder.alternatives.empty() ) {
    9571094                        // add function alternatives to front of argument list
    958                         argAlternatives.insert( argAlternatives.begin(), std::move(funcFinder) );
     1095                        argAlternatives.insert( argAlternatives.begin(), move(funcFinder) );
    9591096
    9601097                        for ( AltList::iterator funcOp = funcOpFinder.alternatives.begin();
     
    9821119
    9831120                // compute conversionsion costs
    984                 for ( AltList::iterator withFunc = candidates.begin(); withFunc != candidates.end(); ++withFunc ) {
    985                         Cost cvtCost = computeApplicationConversionCost( *withFunc, indexer );
     1121                for ( Alternative& withFunc : candidates ) {
     1122                        Cost cvtCost = computeApplicationConversionCost( withFunc, indexer );
    9861123
    9871124                        PRINT(
    988                                 ApplicationExpr *appExpr = strict_dynamic_cast< ApplicationExpr* >( withFunc->expr );
     1125                                ApplicationExpr *appExpr = strict_dynamic_cast< ApplicationExpr* >( withFunc.expr );
    9891126                                PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
    9901127                                FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->get_base() );
     
    9951132                                printAll( appExpr->get_args(), std::cerr, 8 );
    9961133                                std::cerr << "bindings are:" << std::endl;
    997                                 withFunc->env.print( std::cerr, 8 );
     1134                                withFunc.env.print( std::cerr, 8 );
    9981135                                std::cerr << "cost of conversion is:" << cvtCost << std::endl;
    9991136                        )
    10001137                        if ( cvtCost != Cost::infinity ) {
    1001                                 withFunc->cvtCost = cvtCost;
    1002                                 alternatives.push_back( *withFunc );
     1138                                withFunc.cvtCost = cvtCost;
     1139                                alternatives.push_back( withFunc );
    10031140                        } // if
    10041141                } // for
    10051142
    1006                 candidates.clear();
    1007                 candidates.splice( candidates.end(), alternatives );
     1143                candidates = move(alternatives);
    10081144
    10091145                // use a new list so that alternatives are not examined by addAnonConversions twice.
     
    10111147                findMinCost( candidates.begin(), candidates.end(), std::back_inserter( winners ) );
    10121148
    1013                 // function may return struct or union value, in which case we need to add alternatives for implicit
    1014                 // conversions to each of the anonymous members, must happen after findMinCost since anon conversions
    1015                 // are never the cheapest expression
     1149                // function may return struct or union value, in which case we need to add alternatives
     1150                // for implicitconversions to each of the anonymous members, must happen after findMinCost
     1151                // since anon conversions are never the cheapest expression
    10161152                for ( const Alternative & alt : winners ) {
    10171153                        addAnonConversions( alt );
    10181154                }
    1019                 alternatives.splice( alternatives.begin(), winners );
     1155                spliceBegin( alternatives, winners );
    10201156
    10211157                if ( alternatives.empty() && targetType && ! targetType->isVoid() ) {
     
    10411177                AlternativeFinder finder( indexer, env );
    10421178                finder.find( addressExpr->get_arg() );
    1043                 for ( std::list< Alternative >::iterator i = finder.alternatives.begin(); i != finder.alternatives.end(); ++i ) {
    1044                         if ( isLvalue( i->expr ) ) {
    1045                                 alternatives.push_back( Alternative( new AddressExpr( i->expr->clone() ), i->env, i->cost ) );
     1179                for ( Alternative& alt : finder.alternatives ) {
     1180                        if ( isLvalue( alt.expr ) ) {
     1181                                alternatives.push_back(
     1182                                        Alternative{ new AddressExpr( alt.expr->clone() ), alt.env, alt.cost } );
    10461183                        } // if
    10471184                } // for
     
    10491186
    10501187        void AlternativeFinder::visit( LabelAddressExpr * expr ) {
    1051                 alternatives.push_back( Alternative( expr->clone(), env, Cost::zero) );
     1188                alternatives.push_back( Alternative{ expr->clone(), env, Cost::zero } );
    10521189        }
    10531190
     
    10911228
    10921229                AltList candidates;
    1093                 for ( std::list< Alternative >::iterator i = finder.alternatives.begin(); i != finder.alternatives.end(); ++i ) {
     1230                for ( Alternative & alt : finder.alternatives ) {
    10941231                        AssertionSet needAssertions, haveAssertions;
    10951232                        OpenVarSet openVars;
     
    10991236                        // that are cast directly.  The candidate is invalid if it has fewer results than there are types to cast
    11001237                        // to.
    1101                         int discardedValues = i->expr->get_result()->size() - castExpr->get_result()->size();
     1238                        int discardedValues = alt.expr->get_result()->size() - castExpr->get_result()->size();
    11021239                        if ( discardedValues < 0 ) continue;
    11031240                        // xxx - may need to go into tuple types and extract relevant types and use unifyList. Note that currently, this does not
    11041241                        // allow casting a tuple to an atomic type (e.g. (int)([1, 2, 3]))
    11051242                        // unification run for side-effects
    1106                         unify( castExpr->get_result(), i->expr->get_result(), i->env, needAssertions, haveAssertions, openVars, indexer );
    1107                         Cost thisCost = castCost( i->expr->get_result(), castExpr->get_result(), indexer, i->env );
     1243                        unify( castExpr->get_result(), alt.expr->get_result(), alt.env, needAssertions,
     1244                                haveAssertions, openVars, indexer );
     1245                        Cost thisCost = castCost( alt.expr->get_result(), castExpr->get_result(), indexer,
     1246                                alt.env );
    11081247                        PRINT(
    11091248                                std::cerr << "working on cast with result: " << castExpr->result << std::endl;
    1110                                 std::cerr << "and expr type: " << i->expr->result << std::endl;
    1111                                 std::cerr << "env: " << i->env << std::endl;
     1249                                std::cerr << "and expr type: " << alt.expr->result << std::endl;
     1250                                std::cerr << "env: " << alt.env << std::endl;
    11121251                        )
    11131252                        if ( thisCost != Cost::infinity ) {
     
    11171256                                // count one safe conversion for each value that is thrown away
    11181257                                thisCost.incSafe( discardedValues );
    1119                                 Alternative newAlt( restructureCast( i->expr->clone(), toType ), i->env, i->cost, thisCost );
    1120                                 inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) );
     1258                                Alternative newAlt( restructureCast( alt.expr->clone(), toType ), alt.env,
     1259                                        alt.cost, thisCost );
     1260                                inferParameters( needAssertions, haveAssertions, newAlt, openVars,
     1261                                        back_inserter( candidates ) );
    11211262                        } // if
    11221263                } // for
     
    14051546
    14061547        void AlternativeFinder::visit( UntypedTupleExpr *tupleExpr ) {
    1407                 std::list< AlternativeFinder > subExprAlternatives;
    1408                 findSubExprs( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end(), back_inserter( subExprAlternatives ) );
    1409                 std::list< AltList > possibilities;
    1410                 combos( subExprAlternatives.begin(), subExprAlternatives.end(), back_inserter( possibilities ) );
    1411                 for ( std::list< AltList >::const_iterator i = possibilities.begin(); i != possibilities.end(); ++i ) {
     1548                std::vector< AlternativeFinder > subExprAlternatives;
     1549                findSubExprs( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end(),
     1550                        back_inserter( subExprAlternatives ) );
     1551                std::vector< AltList > possibilities;
     1552                combos( subExprAlternatives.begin(), subExprAlternatives.end(),
     1553                        back_inserter( possibilities ) );
     1554                for ( const AltList& alts : possibilities ) {
    14121555                        std::list< Expression * > exprs;
    1413                         makeExprList( *i, exprs );
     1556                        makeExprList( alts, exprs );
    14141557
    14151558                        TypeEnvironment compositeEnv;
    1416                         simpleCombineEnvironments( i->begin(), i->end(), compositeEnv );
    1417                         alternatives.push_back( Alternative( new TupleExpr( exprs ) , compositeEnv, sumCost( *i ) ) );
     1559                        simpleCombineEnvironments( alts.begin(), alts.end(), compositeEnv );
     1560                        alternatives.push_back(
     1561                                Alternative{ new TupleExpr( exprs ), compositeEnv, sumCost( alts ) } );
    14181562                } // for
    14191563        }
  • src/ResolvExpr/AlternativeFinder.h

    r7e4c4f4 r452747a  
    3131
    3232namespace ResolvExpr {
     33        struct ArgPack;
     34
    3335        class AlternativeFinder : public Visitor {
    3436          public:
     
    3638
    3739                AlternativeFinder( const AlternativeFinder& o )
    38                         : indexer(o.indexer), alternatives(o.alternatives), env(o.env), 
     40                        : indexer(o.indexer), alternatives(o.alternatives), env(o.env),
    3941                          targetType(o.targetType) {}
    40                
     42
    4143                AlternativeFinder( AlternativeFinder&& o )
    42                         : indexer(o.indexer), alternatives(std::move(o.alternatives)), env(o.env), 
     44                        : indexer(o.indexer), alternatives(std::move(o.alternatives)), env(o.env),
    4345                          targetType(o.targetType) {}
    44                
     46
    4547                AlternativeFinder& operator= ( const AlternativeFinder& o ) {
    4648                        if (&o == this) return *this;
    47                        
     49
    4850                        // horrific nasty hack to rebind references...
    4951                        alternatives.~AltList();
     
    5456                AlternativeFinder& operator= ( AlternativeFinder&& o ) {
    5557                        if (&o == this) return *this;
    56                        
     58
    5759                        // horrific nasty hack to rebind references...
    5860                        alternatives.~AltList();
     
    126128                /// Adds alternatives for offsetof expressions, given the base type and name of the member
    127129                template< typename StructOrUnionType > void addOffsetof( StructOrUnionType *aggInst, const std::string &name );
     130                /// Takes a final result and checks if its assertions can be satisfied
     131                template<typename OutputIterator>
     132                void validateFunctionAlternative( const Alternative &func, ArgPack& result, const std::vector<ArgPack>& results, OutputIterator out );
     133                /// Finds matching alternatives for a function, given a set of arguments
    128134                template<typename OutputIterator>
    129135                void makeFunctionAlternatives( const Alternative &func, FunctionType *funcType, const std::vector< AlternativeFinder >& args, OutputIterator out );
     136                /// Checks if assertion parameters match for a new alternative
    130137                template< typename OutputIterator >
    131138                void inferParameters( const AssertionSet &need, AssertionSet &have, const Alternative &newAlt, OpenVarSet &openVars, OutputIterator out );
  • src/ResolvExpr/Resolver.cc

    r7e4c4f4 r452747a  
    1818#include <memory>                        // for allocator, allocator_traits<...
    1919#include <tuple>                         // for get
     20#include <vector>
    2021
    2122#include "Alternative.h"                 // for Alternative, AltList
     
    411412
    412413                        // Find all alternatives for all arguments in canonical form
    413                         std::list< AlternativeFinder > argAlternatives;
     414                        std::vector< AlternativeFinder > argAlternatives;
    414415                        funcFinder.findSubExprs( clause.target.arguments.begin(), clause.target.arguments.end(), back_inserter( argAlternatives ) );
    415416
    416417                        // List all combinations of arguments
    417                         std::list< AltList > possibilities;
     418                        std::vector< AltList > possibilities;
    418419                        combos( argAlternatives.begin(), argAlternatives.end(), back_inserter( possibilities ) );
    419420
  • src/ResolvExpr/typeops.h

    r7e4c4f4 r452747a  
    1616#pragma once
    1717
     18#include <vector>
     19
    1820#include "SynTree/SynTree.h"
    1921#include "SynTree/Type.h"
     
    2830        void combos( InputIterator begin, InputIterator end, OutputIterator out ) {
    2931                typedef typename InputIterator::value_type SetType;
    30                 typedef typename std::list< typename SetType::value_type > ListType;
     32                typedef typename std::vector< typename SetType::value_type > ListType;
    3133
    3234                if ( begin == end )     {
     
    3840                begin++;
    3941
    40                 std::list< ListType > recursiveResult;
     42                std::vector< ListType > recursiveResult;
    4143                combos( begin, end, back_inserter( recursiveResult ) );
    4244
    43                 for ( typename std::list< ListType >::const_iterator i = recursiveResult.begin(); i != recursiveResult.end(); ++i ) {
    44                         for ( typename ListType::const_iterator j = current->begin(); j != current->end(); ++j ) {
    45                                 ListType result;
    46                                 std::back_insert_iterator< ListType > inserter = back_inserter( result );
    47                                 *inserter++ = *j;
    48                                 std::copy( i->begin(), i->end(), inserter );
    49                                 *out++ = result;
    50                         } // for
    51                 } // for
     45                for ( const auto& i : recursiveResult ) for ( const auto& j : *current ) {
     46                        ListType result;
     47                        std::back_insert_iterator< ListType > inserter = back_inserter( result );
     48                        *inserter++ = j;
     49                        std::copy( i.begin(), i.end(), inserter );
     50                        *out++ = result;
     51                }
    5252        }
    5353
  • src/Tuples/TupleAssignment.cc

    r7e4c4f4 r452747a  
    251251                // combine assignment environments into combined expression environment
    252252                simpleCombineEnvironments( current.begin(), current.end(), matcher->compositeEnv );
    253                 currentFinder.get_alternatives().push_front( ResolvExpr::Alternative(
     253                // xxx -- was push_front
     254                currentFinder.get_alternatives().push_back( ResolvExpr::Alternative(
    254255                        new TupleAssignExpr(solved_assigns, matcher->tmpDecls), matcher->compositeEnv,
    255256                        ResolvExpr::sumCost( current ) + matcher->baseCost ) );
  • src/tests/.expect/castError.txt

    r7e4c4f4 r452747a  
    55  charAlternatives are:
    66Cost ( 1, 0, 0, 0 ): Cast of:
    7      Variable Expression: f: signed int
     7     Variable Expression: f: function
     8       accepting unspecified arguments
     9     ... returning nothing
     10
    811   ... to:
    912     char
     
    2326
    2427Cost ( 1, 0, 0, 0 ): Cast of:
    25      Variable Expression: f: function
    26        accepting unspecified arguments
    27      ... returning nothing
    28 
     28     Variable Expression: f: signed int
    2929   ... to:
    3030     char
Note: See TracChangeset for help on using the changeset viewer.