Ignore:
Timestamp:
Feb 19, 2019, 1:19:47 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
no_list
Children:
2f42718
Parents:
99614c2
Message:

more lists converted to vectors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/ResolveAssertions.cc

    r99614c2 r43e0949  
    4747                UniqueId resnSlot;              ///< Slot for any recursive assertion IDs
    4848
    49                 AssnCandidate( const SymTab::Indexer::IdData& cdata, Type* adjType, TypeEnvironment&& env, 
    50                         AssertionSet&& have, AssertionSet&& need, OpenVarSet&& openVars, UniqueId resnSlot ) 
    51                 : cdata(cdata), adjType(adjType), env(std::move(env)), have(std::move(have)), 
     49                AssnCandidate( const SymTab::Indexer::IdData& cdata, Type* adjType, TypeEnvironment&& env,
     50                        AssertionSet&& have, AssertionSet&& need, OpenVarSet&& openVars, UniqueId resnSlot )
     51                : cdata(cdata), adjType(adjType), env(std::move(env)), have(std::move(have)),
    5252                        need(std::move(need)), openVars(std::move(openVars)), resnSlot(resnSlot) {}
    5353        };
     
    8686                const AssnCache* cache;     ///< Cache storing assertion item
    8787                std::string key;            ///< Key into cache
    88                
     88
    8989                DeferItem( const AssnCache& cache, const std::string& key ) : cache(&cache), key(key) {}
    9090
     
    9999
    100100                // sortable by key
    101                 // TODO look into optimizing combination process with other sort orders (e.g. by number 
     101                // TODO look into optimizing combination process with other sort orders (e.g. by number
    102102                // of matches in candidate)
    103103                bool operator< ( const DeferItem& o ) const { return key < o.key; }
     
    108108        using DeferList = std::vector<DeferItem>;
    109109
    110         /// Combo iterator that combines candidates into an output list, merging their environments. 
     110        /// Combo iterator that combines candidates into an output list, merging their environments.
    111111        /// Rejects an appended candidate if the environments cannot be merged.
    112112        class CandidateEnvMerger {
     
    119119                /// Indexer to use for merges
    120120                const SymTab::Indexer& indexer;
    121        
     121
    122122        public:
    123123                /// The merged environment/open variables and the list of candidates
     
    127127                        std::vector<DeferRef> assns;
    128128
    129                         OutType( const TypeEnvironment& env, const OpenVarSet& openVars, 
     129                        OutType( const TypeEnvironment& env, const OpenVarSet& openVars,
    130130                                const std::vector<DeferRef>& assns )
    131131                        : env(env), openVars(openVars), assns(assns) {}
    132132                };
    133133
    134                 CandidateEnvMerger( const TypeEnvironment& env, const OpenVarSet& openVars, 
     134                CandidateEnvMerger( const TypeEnvironment& env, const OpenVarSet& openVars,
    135135                        const SymTab::Indexer& indexer )
    136136                : crnt(), envs{ env }, varSets{ openVars }, indexer(indexer) {}
     
    158158        };
    159159
    160         /// Comparator for CandidateEnvMerger outputs that sums their costs and caches the stored 
     160        /// Comparator for CandidateEnvMerger outputs that sums their costs and caches the stored
    161161        /// sums
    162162        struct CandidateCost {
     
    176176                                Cost k = Cost::zero;
    177177                                for ( const auto& assn : x.assns ) {
    178                                         k += computeConversionCost( 
    179                                                 assn.match.adjType, assn.item.deferIds[0].decl->get_type(), indexer, 
     178                                        k += computeConversionCost(
     179                                                assn.match.adjType, assn.item.deferIds[0].decl->get_type(), indexer,
    180180                                                x.env );
    181181                                }
     
    184184                        return it->second;
    185185                }
    186                
     186
    187187                /// compares elements by cost
    188188                bool operator() ( const Element& a, const Element& b ) const {
     
    214214                /// Updated resolution state with new need-list
    215215                ResnState( ResnState&& o, IterateFlag )
    216                 : alt(std::move(o.alt)), need(o.newNeed.begin(), o.newNeed.end()), newNeed(), deferred(), 
     216                : alt(std::move(o.alt)), need(o.newNeed.begin(), o.newNeed.end()), newNeed(), deferred(),
    217217                  inferred(std::move(o.inferred)), indexer(o.indexer) {}
    218218        };
    219219
    220220        /// Binds a single assertion, updating resolution state
    221         void bindAssertion( const DeclarationWithType* decl, AssertionSetValue info, Alternative& alt, 
     221        void bindAssertion( const DeclarationWithType* decl, AssertionSetValue info, Alternative& alt,
    222222                        AssnCandidate& match, InferCache& inferred ) {
    223                
     223
    224224                DeclarationWithType* candidate = match.cdata.id;
    225225                assertf( candidate->get_uniqueId(), "Assertion candidate does not have a unique ID: %s", toString( candidate ).c_str() );
     
    232232                // place newly-inferred assertion in proper place in cache
    233233                inferred[ info.resnSlot ][ decl->get_uniqueId() ] = ParamEntry{
    234                                 candidate->get_uniqueId(), match.adjType->clone(), decl->get_type()->clone(), 
     234                                candidate->get_uniqueId(), match.adjType->clone(), decl->get_type()->clone(),
    235235                                varExpr };
    236236        }
     
    260260                if ( it == cache.end() ) {
    261261                        // lookup candidates for this assertion
    262                         std::list< SymTab::Indexer::IdData > candidates;
     262                        std::vector< SymTab::Indexer::IdData > candidates;
    263263                        resn.indexer.lookupId( assn.decl->name, candidates );
    264264
     
    277277
    278278                                // keep unifying candidates
    279                                 if ( unify( assn.decl->get_type(), adjType, newEnv, newNeed, have, newOpenVars, 
     279                                if ( unify( assn.decl->get_type(), adjType, newEnv, newNeed, have, newOpenVars,
    280280                                                resn.indexer ) ) {
    281281                                        // set up binding slot for recursive assertions
     
    288288                                        }
    289289
    290                                         matches.emplace_back( cdata, adjType, std::move(newEnv), std::move(have), 
     290                                        matches.emplace_back( cdata, adjType, std::move(newEnv), std::move(have),
    291291                                                std::move(newNeed), std::move(newOpenVars), crntResnSlot );
    292292                                } else {
     
    339339                                }
    340340                                InferredParams& inferParams = it->second;
    341                                
     341
    342342                                // place inferred parameters into proper place in expression
    343343                                for ( auto& entry : inferParams ) {
     
    402402                                        // resolve deferred assertions by mutual compatibility
    403403                                        std::vector<CandidateEnvMerger::OutType> compatible = filterCombos(
    404                                                 resn.deferred, 
     404                                                resn.deferred,
    405405                                                CandidateEnvMerger{ resn.alt.env, resn.alt.openVars, resn.indexer } );
    406406                                        // sort by cost
     
    431431                                                        // for each deferred assertion with the same form
    432432                                                        for ( AssnId id : r.item.deferIds ) {
    433                                                                 bindAssertion( 
     433                                                                bindAssertion(
    434434                                                                        id.decl, id.info, new_resn.alt, match, new_resn.inferred );
    435435                                                        }
     
    455455                        new_resns.clear();
    456456                }
    457                
     457
    458458                // exceeded recursion limit if reaches here
    459459                if ( out.empty() ) {
Note: See TracChangeset for help on using the changeset viewer.