Changeset 43e0949 for src/ResolvExpr/ResolveAssertions.cc
- Timestamp:
- Feb 19, 2019, 1:19:47 PM (7 years ago)
- Branches:
- no_list
- Children:
- 2f42718
- Parents:
- 99614c2
- File:
-
- 1 edited
-
src/ResolvExpr/ResolveAssertions.cc (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ResolveAssertions.cc
r99614c2 r43e0949 47 47 UniqueId resnSlot; ///< Slot for any recursive assertion IDs 48 48 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)), 52 52 need(std::move(need)), openVars(std::move(openVars)), resnSlot(resnSlot) {} 53 53 }; … … 86 86 const AssnCache* cache; ///< Cache storing assertion item 87 87 std::string key; ///< Key into cache 88 88 89 89 DeferItem( const AssnCache& cache, const std::string& key ) : cache(&cache), key(key) {} 90 90 … … 99 99 100 100 // 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 102 102 // of matches in candidate) 103 103 bool operator< ( const DeferItem& o ) const { return key < o.key; } … … 108 108 using DeferList = std::vector<DeferItem>; 109 109 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. 111 111 /// Rejects an appended candidate if the environments cannot be merged. 112 112 class CandidateEnvMerger { … … 119 119 /// Indexer to use for merges 120 120 const SymTab::Indexer& indexer; 121 121 122 122 public: 123 123 /// The merged environment/open variables and the list of candidates … … 127 127 std::vector<DeferRef> assns; 128 128 129 OutType( const TypeEnvironment& env, const OpenVarSet& openVars, 129 OutType( const TypeEnvironment& env, const OpenVarSet& openVars, 130 130 const std::vector<DeferRef>& assns ) 131 131 : env(env), openVars(openVars), assns(assns) {} 132 132 }; 133 133 134 CandidateEnvMerger( const TypeEnvironment& env, const OpenVarSet& openVars, 134 CandidateEnvMerger( const TypeEnvironment& env, const OpenVarSet& openVars, 135 135 const SymTab::Indexer& indexer ) 136 136 : crnt(), envs{ env }, varSets{ openVars }, indexer(indexer) {} … … 158 158 }; 159 159 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 161 161 /// sums 162 162 struct CandidateCost { … … 176 176 Cost k = Cost::zero; 177 177 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, 180 180 x.env ); 181 181 } … … 184 184 return it->second; 185 185 } 186 186 187 187 /// compares elements by cost 188 188 bool operator() ( const Element& a, const Element& b ) const { … … 214 214 /// Updated resolution state with new need-list 215 215 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(), 217 217 inferred(std::move(o.inferred)), indexer(o.indexer) {} 218 218 }; 219 219 220 220 /// 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, 222 222 AssnCandidate& match, InferCache& inferred ) { 223 223 224 224 DeclarationWithType* candidate = match.cdata.id; 225 225 assertf( candidate->get_uniqueId(), "Assertion candidate does not have a unique ID: %s", toString( candidate ).c_str() ); … … 232 232 // place newly-inferred assertion in proper place in cache 233 233 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(), 235 235 varExpr }; 236 236 } … … 260 260 if ( it == cache.end() ) { 261 261 // lookup candidates for this assertion 262 std:: list< SymTab::Indexer::IdData > candidates;262 std::vector< SymTab::Indexer::IdData > candidates; 263 263 resn.indexer.lookupId( assn.decl->name, candidates ); 264 264 … … 277 277 278 278 // 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, 280 280 resn.indexer ) ) { 281 281 // set up binding slot for recursive assertions … … 288 288 } 289 289 290 matches.emplace_back( cdata, adjType, std::move(newEnv), std::move(have), 290 matches.emplace_back( cdata, adjType, std::move(newEnv), std::move(have), 291 291 std::move(newNeed), std::move(newOpenVars), crntResnSlot ); 292 292 } else { … … 339 339 } 340 340 InferredParams& inferParams = it->second; 341 341 342 342 // place inferred parameters into proper place in expression 343 343 for ( auto& entry : inferParams ) { … … 402 402 // resolve deferred assertions by mutual compatibility 403 403 std::vector<CandidateEnvMerger::OutType> compatible = filterCombos( 404 resn.deferred, 404 resn.deferred, 405 405 CandidateEnvMerger{ resn.alt.env, resn.alt.openVars, resn.indexer } ); 406 406 // sort by cost … … 431 431 // for each deferred assertion with the same form 432 432 for ( AssnId id : r.item.deferIds ) { 433 bindAssertion( 433 bindAssertion( 434 434 id.decl, id.info, new_resn.alt, match, new_resn.inferred ); 435 435 } … … 455 455 new_resns.clear(); 456 456 } 457 457 458 458 // exceeded recursion limit if reaches here 459 459 if ( out.empty() ) {
Note:
See TracChangeset
for help on using the changeset viewer.