Changeset ebc0a85
- Timestamp:
- May 29, 2019, 10:22:31 AM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- f57dd25
- Parents:
- 1259c35 (diff), eba615c (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. - Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r1259c35 rebc0a85 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T hu May 23 16:59:00 201913 // Update Count : 612 // Last Modified On : Tue May 28 12:00:00 2019 13 // Update Count : 7 14 14 // 15 15 … … 1337 1337 if ( ! old ) return nullptr; 1338 1338 old->accept(*this); 1339 return strict_dynamic_cast< NewT * >( node ); 1339 ast::Node * ret = node; 1340 node = nullptr; 1341 return strict_dynamic_cast< NewT * >( ret ); 1340 1342 } 1341 1343 … … 1350 1352 a->accept( *this ); 1351 1353 ret.emplace_back( strict_dynamic_cast< NewT * >(node) ); 1354 node = nullptr; 1352 1355 } 1353 1356 return ret; … … 1873 1876 GET_LABELS_V(old->labels) 1874 1877 ); 1878 cache.emplace( old, stmt ); 1879 stmt->callStmt = GET_ACCEPT_1(callStmt, Stmt); 1875 1880 this->node = stmt; 1876 cache.emplace( old, this->node );1877 stmt->callStmt = GET_ACCEPT_1(callStmt, Stmt);1878 1881 } 1879 1882 -
src/ResolvExpr/ResolveAssertions.cc
r1259c35 rebc0a85 103 103 OpenVarSet openVars; 104 104 std::vector<DeferRef> assns; 105 Cost cost; 105 106 106 107 OutType( const TypeEnvironment& env, const OpenVarSet& openVars, 107 108 const std::vector<DeferRef>& assns ) 108 : env(env), openVars(openVars), assns(assns) {}109 : env(env), openVars(openVars), assns(assns), cost(Cost::infinity) {} 109 110 }; 110 111 … … 140 141 using Element = CandidateEnvMerger::OutType; 141 142 private: 142 using Memo = std::unordered_map<const Element*, Cost>;143 mutable Memo cache; ///< cache of element costs144 143 const SymTab::Indexer& indexer; ///< Indexer for costing 145 144 … … 148 147 149 148 /// reports the cost of an element 150 Cost get( const Element& x ) const { 151 Memo::const_iterator it = cache.find( &x ); 152 if ( it == cache.end() ) { 153 Cost k = Cost::zero; 154 for ( const auto& assn : x.assns ) { 155 k += computeConversionCost( 156 assn.match.adjType, assn.decl->get_type(), indexer, x.env ); 157 158 // mark vars+specialization cost on function-type assertions 159 PointerType* ptr = dynamic_cast< PointerType* >( assn.decl->get_type() ); 160 if ( ! ptr ) continue; 161 FunctionType* func = dynamic_cast< FunctionType* >( ptr->base ); 162 if ( ! func ) continue; 163 164 for ( DeclarationWithType* formal : func->parameters ) { 165 k.decSpec( specCost( formal->get_type() ) ); 166 } 167 k.incVar( func->forall.size() ); 168 for ( TypeDecl* td : func->forall ) { 169 k.decSpec( td->assertions.size() ); 170 } 171 } 172 it = cache.emplace_hint( it, &x, k ); 149 Cost get( Element& x ) const { 150 // check cached cost 151 if ( x.cost != Cost::infinity ) return x.cost; 152 153 // generate cost 154 Cost k = Cost::zero; 155 for ( const auto& assn : x.assns ) { 156 k += computeConversionCost( 157 assn.match.adjType, assn.decl->get_type(), indexer, x.env ); 158 159 // mark vars+specialization cost on function-type assertions 160 Type* assnType = assn.match.cdata.id->get_type(); 161 FunctionType* func; 162 if ( PointerType* ptr = dynamic_cast< PointerType* >( assnType ) ) { 163 func = dynamic_cast< FunctionType* >( ptr->base ); 164 } else { 165 func = dynamic_cast< FunctionType* >( assnType ); 166 } 167 if ( ! func ) continue; 168 169 for ( DeclarationWithType* formal : func->parameters ) { 170 k.decSpec( specCost( formal->get_type() ) ); 171 } 172 k.incVar( func->forall.size() ); 173 for ( TypeDecl* td : func->forall ) { 174 k.decSpec( td->assertions.size() ); 175 } 173 176 } 174 return it->second; 177 178 // cache and return 179 x.cost = k; 180 return k; 175 181 } 176 182 177 183 /// compares elements by cost 178 bool operator() ( const Element& a, constElement& b ) const {184 bool operator() ( Element& a, Element& b ) const { 179 185 return get( a ) < get( b ); 180 186 }
Note: See TracChangeset
for help on using the changeset viewer.