Changeset d60780c
- Timestamp:
- Jun 13, 2019, 8:28:13 AM (6 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:
- d76f32c, dc5072f
- Parents:
- d7a02ae (diff), 21300d7 (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:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rd7a02ae rd60780c 579 579 tgtInferParams[srcParam.first] = ParamEntry( 580 580 srcParam.second.decl, 581 get<Declaration>().accept1(srcParam.second.declptr), 581 582 get<Type>().accept1(srcParam.second.actualType), 582 583 get<Type>().accept1(srcParam.second.formalType), … … 2004 2005 tgt[old.first] = ast::ParamEntry( 2005 2006 old.second.decl, 2007 getAccept1<ast::Decl>(old.second.declptr), 2006 2008 getAccept1<ast::Type>(old.second.actualType), 2007 2009 getAccept1<ast::Type>(old.second.formalType), -
src/AST/Expr.hpp
rd7a02ae rd60780c 39 39 struct ParamEntry { 40 40 UniqueId decl; 41 ptr<Decl> declptr; 41 42 ptr<Type> actualType; 42 43 ptr<Type> formalType; 43 44 ptr<Expr> expr; 44 45 45 ParamEntry() : decl( 0 ), actualType( nullptr ), formalType( nullptr ), expr( nullptr ) {}46 ParamEntry( UniqueId id, Type* actual, Type* formal, Expr* e )47 : decl( id ), actualType( actual ), formalType( formal ), expr( e ) {}46 ParamEntry() : decl( 0 ), declptr( nullptr ), actualType( nullptr ), formalType( nullptr ), expr( nullptr ) {} 47 ParamEntry( UniqueId id, Decl * declptr, Type* actual, Type* formal, Expr* e ) 48 : decl( id ), declptr( declptr ), actualType( actual ), formalType( formal ), expr( e ) {} 48 49 }; 49 50 … … 137 138 } 138 139 139 /// splices other InferUnion into this one. Will fail if one union is in `Slots` mode 140 /// splices other InferUnion into this one. Will fail if one union is in `Slots` mode 140 141 /// and the other is in `Params`. 141 142 void splice( InferUnion && o ) { … … 145 146 146 147 if ( mode == Slots ){ 147 data.resnSlots.insert( 148 data.resnSlots.insert( 148 149 data.resnSlots.end(), o.data.resnSlots.begin(), o.data.resnSlots.end() ); 149 150 } else if ( mode == Params ) { -
src/GenPoly/Lvalue.cc
rd7a02ae rd60780c 200 200 if(i == end) { return appExpr; } 201 201 for ( auto p : unsafe_group_iterate( appExpr->args, ftype->parameters ) ) { 202 if (i == end) break;203 202 Expression *& arg = std::get<0>( p ); 204 203 Type * formal = std::get<1>( p )->get_type(); … … 245 244 } 246 245 ++i; 246 if (i == end) break; 247 247 } 248 248 } -
src/InitTweak/FixInit.cc
rd7a02ae rd60780c 995 995 ) 996 996 997 998 // std::set_difference requires that the inputs be sorted. 999 lvars.sort(); 1000 curVars.sort(); 1001 997 1002 ObjectSet diff; 998 1003 // S_L-S_G results in set of objects whose construction is skipped - it's an error if this set is non-empty -
src/ResolvExpr/ResolveAssertions.cc
rd7a02ae rd60780c 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() ) { -
src/SynTree/ApplicationExpr.cc
rd7a02ae rd60780c 29 29 30 30 ParamEntry::ParamEntry( const ParamEntry &other ) : 31 decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) )/*, inferParams( new InferredParams( *other.inferParams ) )*/ {31 decl( other.decl ), declptr( maybeClone( other.declptr ) ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) )/*, inferParams( new InferredParams( *other.inferParams ) )*/ { 32 32 } 33 33 34 34 ParamEntry &ParamEntry::operator=( const ParamEntry &other ) { 35 35 if ( &other == this ) return *this; 36 decl = other.decl; 36 const_cast<UniqueId &>(decl) = other.decl; 37 const_cast<Declaration * &>(declptr) = maybeClone( other.declptr ); 37 38 // xxx - this looks like a memory leak 38 actualType= maybeClone( other.actualType );39 formalType= maybeClone( other.formalType );39 const_cast<Type * &>(actualType) = maybeClone( other.actualType ); 40 const_cast<Type * &>(formalType) = maybeClone( other.formalType ); 40 41 expr = maybeClone( other.expr ); 41 42 // *inferParams = *other.inferParams; … … 44 45 45 46 ParamEntry::~ParamEntry() { 47 delete declptr; 46 48 delete actualType; 47 49 delete formalType; … … 50 52 51 53 ParamEntry::ParamEntry( ParamEntry && other ) : 52 decl( other.decl ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr )/*, inferParams( std::move( other.inferParams ) )*/ { 53 other.actualType = nullptr; 54 other.formalType = nullptr; 54 decl( other.decl ), declptr( other.declptr ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr )/*, inferParams( std::move( other.inferParams ) )*/ { 55 const_cast<Declaration * &>(other.declptr) = nullptr; 56 const_cast<Type * &>(other.actualType) = nullptr; 57 const_cast<Type * &>(other.formalType) = nullptr; 55 58 other.expr = nullptr; 56 59 } … … 58 61 ParamEntry & ParamEntry::operator=( ParamEntry && other ) { 59 62 if ( &other == this ) return *this; 63 delete declptr; 60 64 delete actualType; 61 65 delete formalType; 62 66 delete expr; 63 decl = other.decl; 64 actualType = other.actualType; 65 formalType = other.formalType; 67 const_cast<UniqueId &>(decl) = other.decl; 68 const_cast<Declaration * &>(declptr) = other.declptr; 69 const_cast<Type * &>(actualType) = other.actualType; 70 const_cast<Type * &>(formalType) = other.formalType; 66 71 expr = other.expr; 67 other.actualType = nullptr; 68 other.formalType = nullptr; 72 const_cast<Declaration * &>(other.declptr) = nullptr; 73 const_cast<Type * &>(other.actualType) = nullptr; 74 const_cast<Type * &>(other.formalType) = nullptr; 69 75 other.expr = nullptr; 70 76 // inferParams = std::move( other.inferParams ); -
src/SynTree/Declaration.cc
rd7a02ae rd60780c 27 27 28 28 static UniqueId lastUniqueId = 0; 29 typedef std::map< UniqueId, Declaration* > IdMapType;30 static IdMapType idMap;31 29 32 30 Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage ) … … 45 43 if ( uniqueId ) return; 46 44 uniqueId = ++lastUniqueId; 47 idMap[ uniqueId ] = this;48 45 } 49 50 Declaration *Declaration::declFromId( UniqueId id ) {51 IdMapType::const_iterator i = idMap.find( id );52 return i != idMap.end() ? i->second : 0;53 }54 55 void Declaration::dumpIds( std::ostream &os ) {56 for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) {57 os << i->first << " -> ";58 i->second->printShort( os );59 os << std::endl;60 } // for61 }62 63 46 64 47 AsmDecl::AsmDecl( AsmStmt *stmt ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), stmt( stmt ) { -
src/SynTree/Declaration.h
rd7a02ae rd60780c 68 68 virtual void printShort( std::ostream &os, Indenter indent = {} ) const = 0; 69 69 70 static void dumpIds( std::ostream &os );71 static Declaration *declFromId( UniqueId id );72 73 70 UniqueId uniqueId; 74 71 Type::StorageClasses storageClasses; -
src/SynTree/Expression.cc
rd7a02ae rd60780c 38 38 for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) { 39 39 os << indent+1; 40 Declaration::declFromId( i->second.decl )->printShort( os, indent+1 ); 40 assert(i->second.declptr); 41 i->second.declptr->printShort( os, indent+1 ); 41 42 os << std::endl; 42 43 printInferParams( i->second.expr->inferParams, os, indent+1, level+1 ); -
src/SynTree/Expression.h
rd7a02ae rd60780c 39 39 /// but subject to decay-to-pointer and type parameter renaming 40 40 struct ParamEntry { 41 ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 )/*, inferParams( new InferredParams )*/ {} 42 ParamEntry( UniqueId decl, Type * actualType, Type * formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr )/*, inferParams( new InferredParams )*/ {} 41 ParamEntry(): decl( 0 ), declptr(nullptr), actualType( 0 ), formalType( 0 ), expr( 0 )/*, inferParams( new InferredParams )*/ {} 42 ParamEntry( UniqueId decl, Declaration * declptr, Type * actualType, Type * formalType, Expression* expr ) 43 : decl( decl ), declptr( declptr ), actualType( actualType ), formalType( formalType ), expr( expr )/*, inferParams( new InferredParams )*/ { 44 } 43 45 ParamEntry( const ParamEntry & other ); 44 46 ParamEntry( ParamEntry && other ); … … 47 49 ParamEntry & operator=( ParamEntry && other ); 48 50 49 UniqueId decl; 50 Type * actualType; 51 Type * formalType; 51 UniqueId const decl; 52 Declaration * const declptr; 53 Type * const actualType; 54 Type * const formalType; 52 55 Expression * expr; 53 56 // std::unique_ptr< InferredParams > inferParams;
Note: See TracChangeset
for help on using the changeset viewer.