Changeset aaeacf4 for src/ResolvExpr
- Timestamp:
- Jun 12, 2019, 4:06:32 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 21300d7
- Parents:
- 6e3e0717
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ResolveAssertions.cc
r6e3e0717 raaeacf4 50 50 UniqueId resnSlot; ///< Slot for any recursive assertion IDs 51 51 52 AssnCandidate( const SymTab::Indexer::IdData& cdata, Type* adjType, TypeEnvironment&& env, 53 AssertionSet&& have, AssertionSet&& need, OpenVarSet&& openVars, UniqueId resnSlot ) 54 : cdata(cdata), adjType(adjType), env(std::move(env)), have(std::move(have)), 52 AssnCandidate( const SymTab::Indexer::IdData& cdata, Type* adjType, TypeEnvironment&& env, 53 AssertionSet&& have, AssertionSet&& need, OpenVarSet&& openVars, UniqueId resnSlot ) 54 : cdata(cdata), adjType(adjType), env(std::move(env)), have(std::move(have)), 55 55 need(std::move(need)), openVars(std::move(openVars)), resnSlot(resnSlot) {} 56 56 }; … … 86 86 using DeferList = std::vector<DeferItem>; 87 87 88 /// Combo iterator that combines candidates into an output list, merging their environments. 88 /// Combo iterator that combines candidates into an output list, merging their environments. 89 89 /// Rejects an appended candidate if the environments cannot be merged. 90 90 class CandidateEnvMerger { … … 97 97 /// Indexer to use for merges 98 98 const SymTab::Indexer& indexer; 99 99 100 100 public: 101 101 /// The merged environment/open variables and the list of candidates … … 106 106 Cost cost; 107 107 108 OutType( const TypeEnvironment& env, const OpenVarSet& openVars, 108 OutType( const TypeEnvironment& env, const OpenVarSet& openVars, 109 109 const std::vector<DeferRef>& assns ) 110 110 : env(env), openVars(openVars), assns(assns), cost(Cost::infinity) {} 111 111 }; 112 112 113 CandidateEnvMerger( const TypeEnvironment& env, const OpenVarSet& openVars, 113 CandidateEnvMerger( const TypeEnvironment& env, const OpenVarSet& openVars, 114 114 const SymTab::Indexer& indexer ) 115 115 : crnt(), envs{ env }, varSets{ openVars }, indexer(indexer) {} … … 137 137 }; 138 138 139 /// Comparator for CandidateEnvMerger outputs that sums their costs and caches the stored 139 /// Comparator for CandidateEnvMerger outputs that sums their costs and caches the stored 140 140 /// sums 141 141 struct CandidateCost { … … 156 156 for ( const auto& assn : x.assns ) { 157 157 // compute conversion cost from satisfying decl to assertion 158 k += computeConversionCost( 158 k += computeConversionCost( 159 159 assn.match.adjType, assn.decl->get_type(), indexer, x.env ); 160 160 161 161 // mark vars+specialization cost on function-type assertions 162 162 FunctionType* func = GenPoly::getFunctionType( assn.match.cdata.id->get_type() ); 163 163 if ( ! func ) continue; 164 164 165 165 for ( DeclarationWithType* formal : func->parameters ) { 166 166 k.decSpec( specCost( formal->get_type() ) ); … … 176 176 return k; 177 177 } 178 178 179 179 /// compares elements by cost 180 180 bool operator() ( Element& a, Element& b ) const { … … 206 206 /// Updated resolution state with new need-list 207 207 ResnState( ResnState&& o, IterateFlag ) 208 : alt(std::move(o.alt)), need(o.newNeed.begin(), o.newNeed.end()), newNeed(), deferred(), 208 : alt(std::move(o.alt)), need(o.newNeed.begin(), o.newNeed.end()), newNeed(), deferred(), 209 209 inferred(std::move(o.inferred)), indexer(o.indexer) {} 210 210 }; 211 211 212 212 /// Binds a single assertion, updating resolution state 213 void bindAssertion( const DeclarationWithType* decl, AssertionSetValue info, Alternative& alt, 213 void bindAssertion( const DeclarationWithType* decl, AssertionSetValue info, Alternative& alt, 214 214 AssnCandidate& match, InferCache& inferred ) { 215 215 216 216 DeclarationWithType* candidate = match.cdata.id; 217 217 assertf( candidate->get_uniqueId(), "Assertion candidate does not have a unique ID: %s", toString( candidate ).c_str() ); … … 224 224 // place newly-inferred assertion in proper place in cache 225 225 inferred[ info.resnSlot ][ decl->get_uniqueId() ] = ParamEntry{ 226 candidate->get_uniqueId(), match.adjType->clone(), decl->get_type()->clone(),226 candidate->get_uniqueId(), candidate->clone(), match.adjType->clone(), decl->get_type()->clone(), 227 227 varExpr }; 228 228 } … … 263 263 264 264 // keep unifying candidates 265 if ( unify( assn.decl->get_type(), adjType, newEnv, newNeed, have, newOpenVars, 265 if ( unify( assn.decl->get_type(), adjType, newEnv, newNeed, have, newOpenVars, 266 266 resn.indexer ) ) { 267 267 // set up binding slot for recursive assertions … … 274 274 } 275 275 276 matches.emplace_back( cdata, adjType, std::move(newEnv), std::move(have), 276 matches.emplace_back( cdata, adjType, std::move(newEnv), std::move(have), 277 277 std::move(newNeed), std::move(newOpenVars), crntResnSlot ); 278 278 } else { … … 319 319 } 320 320 InferredParams& inferParams = it->second; 321 321 322 322 // place inferred parameters into proper place in expression 323 323 for ( auto& entry : inferParams ) { … … 373 373 ss << (tabs-1) << "Could not satisfy assertion:\n"; 374 374 assn.decl->print( ss, tabs ); 375 375 376 376 errors.emplace_back( ss.str() ); 377 377 goto nextResn; … … 403 403 // resolve deferred assertions by mutual compatibility 404 404 std::vector<CandidateEnvMerger::OutType> compatible = filterCombos( 405 resn.deferred, 405 resn.deferred, 406 406 CandidateEnvMerger{ resn.alt.env, resn.alt.openVars, resn.indexer } ); 407 407 // fail early if no mutually-compatible assertion satisfaction … … 466 466 new_resns.clear(); 467 467 } 468 468 469 469 // exceeded recursion limit if reaches here 470 470 if ( out.empty() ) {
Note: See TracChangeset
for help on using the changeset viewer.