- Timestamp:
- Jul 24, 2019, 10:40:28 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:
- 77d2432, 96ac72c0
- Parents:
- 6130304 (diff), 8fc15cf (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:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
r6130304 r83b52f1 9 9 // Author : Rob Schluntz 10 10 // Created On : Fri May 13 11:26:36 2016 11 // Last Modified By : A aron B. Moss12 // Last Modified On : Mon Jun 10 13:30:00 201913 // Update Count : 511 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jun 19 14:34:00 2019 13 // Update Count : 6 14 14 // 15 15 … … 633 633 return nullptr; 634 634 } 635 636 DeclarationWithType * getFunctionCore( const Expression * expr ) { 637 if ( const auto * appExpr = dynamic_cast< const ApplicationExpr * >( expr ) ) { 638 return getCalledFunction( appExpr->function ); 639 } else if ( const auto * untyped = dynamic_cast< const UntypedExpr * >( expr ) ) { 640 return getCalledFunction( untyped->function ); 641 } 642 assertf( false, "getFunction with unknown expression: %s", toString( expr ).c_str() ); 643 } 635 644 } 636 645 637 646 DeclarationWithType * getFunction( Expression * expr ) { 638 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr ) ) { 639 return getCalledFunction( appExpr->get_function() ); 640 } else if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * > ( expr ) ) { 641 return getCalledFunction( untyped->get_function() ); 642 } 643 assertf( false, "getFunction received unknown expression: %s", toString( expr ).c_str() ); 647 return getFunctionCore( expr ); 648 } 649 650 const DeclarationWithType * getFunction( const Expression * expr ) { 651 return getFunctionCore( expr ); 644 652 } 645 653 -
src/InitTweak/InitTweak.h
r6130304 r83b52f1 9 9 // Author : Rob Schluntz 10 10 // Created On : Fri May 13 11:26:36 2016 11 // Last Modified By : A aron B. Moss12 // Last Modified On : Mon Jun 10 13:30:00 201913 // Update Count : 511 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jul 19 14:18:00 2019 13 // Update Count : 6 14 14 // 15 15 … … 61 61 /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr) 62 62 DeclarationWithType * getFunction( Expression * expr ); 63 const DeclarationWithType * getFunction( const Expression * expr ); 63 64 const ast::DeclWithType * getFunction( const ast::Expr * expr ); 64 65 -
src/ResolvExpr/Alternative.h
r6130304 r83b52f1 29 29 /// One assertion to resolve 30 30 struct AssertionItem { 31 DeclarationWithType* decl;31 const DeclarationWithType* decl; 32 32 AssertionSetValue info; 33 33 34 34 AssertionItem() = default; 35 AssertionItem( DeclarationWithType* decl, const AssertionSetValue& info )35 AssertionItem( const DeclarationWithType* decl, const AssertionSetValue& info ) 36 36 : decl(decl), info(info) {} 37 37 AssertionItem( const AssertionSet::value_type& e ) : decl(e.first), info(e.second) {} -
src/ResolvExpr/FindOpenVars.cc
r6130304 r83b52f1 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 09:42:48 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun May 17 09:45:25 201513 // Update Count : 311 // Last Modified By : Andrew 12 // Last Modified On : Fri Jul 12 14:18:00 2019 13 // Update Count : 4 14 14 // 15 15 … … 29 29 FindOpenVars_old( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ); 30 30 31 void previsit( PointerType * pointerType );32 void previsit( ArrayType * arrayType );33 void previsit( FunctionType * functionType );34 void previsit( TupleType * tupleType );31 void previsit( const PointerType * pointerType ); 32 void previsit( const ArrayType * arrayType ); 33 void previsit( const FunctionType * functionType ); 34 void previsit( const TupleType * tupleType ); 35 35 36 void common_action( Type *type );36 void common_action( const Type *type ); 37 37 38 38 OpenVarSet &openVars, &closedVars; … … 41 41 }; 42 42 43 void findOpenVars( Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) {43 void findOpenVars( const Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) { 44 44 PassVisitor<FindOpenVars_old> finder( openVars, closedVars, needAssertions, haveAssertions, firstIsOpen ); 45 45 type->accept( finder ); … … 50 50 } 51 51 52 void FindOpenVars_old::common_action( Type *type ) {52 void FindOpenVars_old::common_action( const Type * type ) { 53 53 if ( nextIsOpen ) { 54 for ( Type::ForallList::const_iterator i = type-> get_forall().begin(); i != type->get_forall().end(); ++i ) {54 for ( Type::ForallList::const_iterator i = type->forall.begin(); i != type->forall.end(); ++i ) { 55 55 openVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) }; 56 56 for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) { … … 61 61 } 62 62 } else { 63 for ( Type::ForallList::const_iterator i = type-> get_forall().begin(); i != type->get_forall().end(); ++i ) {63 for ( Type::ForallList::const_iterator i = type->forall.begin(); i != type->forall.end(); ++i ) { 64 64 closedVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) }; 65 65 for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) { … … 78 78 } 79 79 80 void FindOpenVars_old::previsit( PointerType *pointerType) {80 void FindOpenVars_old::previsit(const PointerType * pointerType) { 81 81 common_action( pointerType ); 82 82 } 83 83 84 void FindOpenVars_old::previsit( ArrayType *arrayType) {84 void FindOpenVars_old::previsit(const ArrayType * arrayType) { 85 85 common_action( arrayType ); 86 86 } 87 87 88 void FindOpenVars_old::previsit( FunctionType *functionType) {88 void FindOpenVars_old::previsit(const FunctionType * functionType) { 89 89 common_action( functionType ); 90 90 nextIsOpen = ! nextIsOpen; … … 92 92 } 93 93 94 void FindOpenVars_old::previsit( TupleType *tupleType) {94 void FindOpenVars_old::previsit(const TupleType * tupleType) { 95 95 common_action( tupleType ); 96 96 } … … 104 104 bool nextIsOpen; 105 105 106 FindOpenVars_new( 107 ast::OpenVarSet & o, ast::OpenVarSet & c, ast::AssertionSet & n, 106 FindOpenVars_new( 107 ast::OpenVarSet & o, ast::OpenVarSet & c, ast::AssertionSet & n, 108 108 ast::AssertionSet & h, FirstMode firstIsOpen ) 109 109 : open( o ), closed( c ), need( n ), have( h ), nextIsOpen( firstIsOpen ) {} … … 135 135 } 136 136 137 void findOpenVars( 138 const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed, 137 void findOpenVars( 138 const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed, 139 139 ast::AssertionSet & need, ast::AssertionSet & have, FirstMode firstIsOpen ) { 140 140 ast::Pass< FindOpenVars_new > finder{ open, closed, need, have, firstIsOpen }; -
src/ResolvExpr/FindOpenVars.h
r6130304 r83b52f1 26 26 namespace ResolvExpr { 27 27 // Updates open and closed variables and their associated assertions 28 void findOpenVars( Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen );28 void findOpenVars( const Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ); 29 29 30 30 enum FirstMode { FirstClosed, FirstOpen }; -
src/ResolvExpr/Occurs.cc
r6130304 r83b52f1 24 24 struct Occurs : public WithVisitorRef<Occurs> { 25 25 Occurs( std::string varName, const TypeEnvironment &env ); 26 void previsit( TypeInstType * typeInst );26 void previsit( const TypeInstType * typeInst ); 27 27 28 28 bool result; … … 31 31 }; 32 32 33 bool occurs( Type *type, std::stringvarName, const TypeEnvironment &env ) {33 bool occurs( const Type *type, const std::string & varName, const TypeEnvironment &env ) { 34 34 PassVisitor<Occurs> occur( varName, env ); 35 35 type->accept( occur ); … … 45 45 } 46 46 47 void Occurs::previsit( TypeInstType * typeInst ) {47 void Occurs::previsit( const TypeInstType * typeInst ) { 48 48 /// std::cerr << "searching for vars: "; 49 49 /// std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cerr, " " ) ); -
src/ResolvExpr/ResolveAssertions.cc
r6130304 r83b52f1 73 73 CandidateList matches; 74 74 75 DeferItem( DeclarationWithType* decl, const AssertionSetValue& info, CandidateList&& matches )75 DeferItem( const DeclarationWithType* decl, const AssertionSetValue& info, CandidateList&& matches ) 76 76 : decl(decl), info(info), matches(std::move(matches)) {} 77 77 -
src/ResolvExpr/TypeEnvironment.cc
r6130304 r83b52f1 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:19:47 2015 11 // Last Modified By : A aron B. Moss12 // Last Modified On : Mon Jun 18 11:58:00 201813 // Update Count : 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jun 18 14:27:00 2019 13 // Update Count : 5 14 14 // 15 15 … … 315 315 } 316 316 317 bool isFtype( Type *type ) {318 if ( dynamic_cast< FunctionType* >( type ) ) {317 bool isFtype( const Type * type ) { 318 if ( dynamic_cast< const FunctionType * >( type ) ) { 319 319 return true; 320 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) {320 } else if ( const TypeInstType *typeInst = dynamic_cast< const TypeInstType * >( type ) ) { 321 321 return typeInst->get_isFtype(); 322 322 } // if … … 324 324 } 325 325 326 bool tyVarCompatible( const TypeDecl::Data & data, Type *type ) {326 bool tyVarCompatible( const TypeDecl::Data & data, const Type * type ) { 327 327 switch ( data.kind ) { 328 328 case TypeDecl::Dtype: … … 336 336 case TypeDecl::Ttype: 337 337 // ttype unifies with any tuple type 338 return dynamic_cast< TupleType * >( type ) || Tuples::isTtype( type );338 return dynamic_cast< const TupleType * >( type ) || Tuples::isTtype( type ); 339 339 default: 340 340 assertf(false, "Unhandled tyvar kind: %d", data.kind); … … 343 343 } 344 344 345 bool TypeEnvironment::bindVar( TypeInstType *typeInst, Type *bindTo, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer ) {345 bool TypeEnvironment::bindVar( const TypeInstType *typeInst, Type *bindTo, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer ) { 346 346 347 347 // remove references from other, so that type variables can only bind to value types … … 361 361 // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to 362 362 std::unique_ptr< Type > newType( curClass->type->clone() ); 363 newType-> get_qualifiers() = typeInst->get_qualifiers();363 newType->tq = typeInst->tq; 364 364 if ( unifyInexact( newType.get(), bindTo, *this, need, have, openVars, widen & WidenMode( curClass->allowWidening, true ), indexer, common ) ) { 365 365 if ( common ) { … … 386 386 } 387 387 388 bool TypeEnvironment::bindVarToVar( TypeInstType *var1, TypeInstType *var2,389 TypeDecl::Data && data, AssertionSet &need, AssertionSet &have, 388 bool TypeEnvironment::bindVarToVar( const TypeInstType * var1, const TypeInstType * var2, 389 TypeDecl::Data && data, AssertionSet &need, AssertionSet &have, 390 390 const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer ) { 391 391 -
src/ResolvExpr/TypeEnvironment.h
r6130304 r83b52f1 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:24:58 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Apr 30 23:04:10 201913 // Update Count : 911 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jul 19 17:00:10 2019 13 // Update Count : 10 14 14 // 15 15 … … 40 40 // declarations. 41 41 // 42 // I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this 42 // I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this 43 43 // comparator. 44 44 // … … 46 46 // memory layout can alter compilation time in unpredictable ways. For example, the placement 47 47 // of a line directive can reorder type pointers with respect to each other so that assertions 48 // are seen in different orders, causing a potentially different number of unification calls 49 // when resolving assertions. I've seen a TU go from 36 seconds to 27 seconds by reordering 50 // line directives alone, so it would be nice to fix this comparison so that assertions compare 51 // more consistently. I've tried to modify this to compare on mangle name instead of type as 52 // the second comparator, but this causes some assertions to never be recorded. More 48 // are seen in different orders, causing a potentially different number of unification calls 49 // when resolving assertions. I've seen a TU go from 36 seconds to 27 seconds by reordering 50 // line directives alone, so it would be nice to fix this comparison so that assertions compare 51 // more consistently. I've tried to modify this to compare on mangle name instead of type as 52 // the second comparator, but this causes some assertions to never be recorded. More 53 53 // investigation is needed. 54 54 struct AssertCompare { 55 bool operator()( DeclarationWithType * d1,DeclarationWithType * d2 ) const {55 bool operator()( const DeclarationWithType * d1, const DeclarationWithType * d2 ) const { 56 56 int cmp = d1->get_name().compare( d2->get_name() ); 57 57 return cmp < 0 || … … 65 65 AssertionSetValue() : isUsed(false), resnSlot(0) {} 66 66 }; 67 typedef std::map< DeclarationWithType *, AssertionSetValue, AssertCompare > AssertionSet;67 typedef std::map< const DeclarationWithType *, AssertionSetValue, AssertCompare > AssertionSet; 68 68 typedef std::unordered_map< std::string, TypeDecl::Data > OpenVarSet; 69 69 … … 78 78 struct EqvClass { 79 79 std::set< std::string > vars; 80 Type * type;80 Type * type; 81 81 bool allowWidening; 82 82 TypeDecl::Data data; … … 111 111 bool isEmpty() const { return env.empty(); } 112 112 void print( std::ostream &os, Indenter indent = {} ) const; 113 113 114 114 /// Simply concatenate the second environment onto this one; no safety checks performed 115 115 void simpleCombine( const TypeEnvironment &second ); … … 126 126 /// Returns false if fails, but does NOT roll back partial changes. 127 127 bool combine( const TypeEnvironment& second, OpenVarSet& openVars, const SymTab::Indexer& indexer ); 128 128 129 129 void extractOpenVars( OpenVarSet &openVars ) const; 130 130 TypeEnvironment *clone() const { return new TypeEnvironment( *this ); } … … 134 134 void addActual( const TypeEnvironment& actualEnv, OpenVarSet& openVars ); 135 135 136 /// Binds the type class represented by `typeInst` to the type `bindTo`; will add 136 /// Binds the type class represented by `typeInst` to the type `bindTo`; will add 137 137 /// the class if needed. Returns false on failure. 138 bool bindVar( TypeInstType *typeInst, Type *bindTo, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer );139 140 /// Binds the type classes represented by `var1` and `var2` together; will add 138 bool bindVar( const TypeInstType * typeInst, Type * bindTo, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer ); 139 140 /// Binds the type classes represented by `var1` and `var2` together; will add 141 141 /// one or both classes if needed. Returns false on failure. 142 bool bindVarToVar( TypeInstType *var1, TypeInstType *var2, TypeDecl::Data && data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer );142 bool bindVarToVar( const TypeInstType * var1, const TypeInstType * var2, TypeDecl::Data && data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer ); 143 143 144 144 /// Disallows widening for all bindings in the environment … … 151 151 private: 152 152 ClassList env; 153 153 154 154 ClassList::iterator internal_lookup( const std::string &var ); 155 155 }; -
src/ResolvExpr/typeops.h
r6130304 r83b52f1 149 149 150 150 // in Occurs.cc 151 bool occurs( Type * type, std::stringvarName, const TypeEnvironment & env );151 bool occurs( const Type * type, const std::string & varName, const TypeEnvironment & env ); 152 152 // new AST version in TypeEnvironment.cpp (only place it was used in old AST) 153 153 … … 200 200 201 201 // in TypeEnvironment.cc 202 bool isFtype( Type * type );202 bool isFtype( const Type * type ); 203 203 } // namespace ResolvExpr 204 204 -
src/SynTree/Type.cc
r6130304 r83b52f1 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Jan 31 21:54:16201913 // Update Count : 4 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jul 12 15:48:00 2019 13 // Update Count : 44 14 14 // 15 15 #include "Type.h" … … 141 141 } 142 142 143 const Type * Type::stripReferences() const { 144 const Type * type; 145 const ReferenceType * ref; 146 for ( type = this; (ref = dynamic_cast<const ReferenceType *>( type )); type = ref->base ); 147 return type; 148 } 149 143 150 int Type::referenceDepth() const { return 0; } 144 151 -
src/SynTree/Type.h
r6130304 r83b52f1 172 172 /// return type without outer references 173 173 Type * stripReferences(); 174 const Type * stripReferences() const; 174 175 175 176 /// return the number of references occuring consecutively on the outermost layer of this type (i.e. do not count references nested within other types) … … 256 257 BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 257 258 258 Kind get_kind() { return kind; }259 Kind get_kind() const { return kind; } 259 260 void set_kind( Kind newValue ) { kind = newValue; } 260 261 -
src/Tuples/TupleExpansion.cc
r6130304 r83b52f1 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Feb 13 18:14:12201913 // Update Count : 2 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jul 19 14:39:00 2019 13 // Update Count : 22 14 14 // 15 15 … … 350 350 } 351 351 352 const TypeInstType * isTtype( const Type * type ) { 353 if ( const TypeInstType * inst = dynamic_cast< const TypeInstType * >( type ) ) { 354 if ( inst->baseType && inst->baseType->kind == TypeDecl::Ttype ) { 355 return inst; 356 } 357 } 358 return nullptr; 359 } 360 352 361 const ast::TypeInstType * isTtype( const ast::Type * type ) { 353 362 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( type ) ) { … … 364 373 ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {} 365 374 366 void previsit( ApplicationExpr * appExpr ) {375 void previsit( const ApplicationExpr * appExpr ) { 367 376 visit_children = false; 368 if ( DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {369 if ( function-> get_linkage()== LinkageSpec::Intrinsic ) {370 if ( function-> get_name() == "*?" || function->get_name()== "?[?]" ) {377 if ( const DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) { 378 if ( function->linkage == LinkageSpec::Intrinsic ) { 379 if ( function->name == "*?" || function->name == "?[?]" ) { 371 380 // intrinsic dereference, subscript are pure, but need to recursively look for impurity 372 381 visit_children = true; … … 377 386 maybeImpure = true; 378 387 } 379 void previsit( UntypedExpr * ) { maybeImpure = true; visit_children = false; }380 void previsit( UniqueExpr * ) {388 void previsit( const UntypedExpr * ) { maybeImpure = true; visit_children = false; } 389 void previsit( const UniqueExpr * ) { 381 390 if ( ignoreUnique ) { 382 391 // bottom out at unique expression. … … 393 402 } // namespace 394 403 395 bool maybeImpure( Expression * expr ) {404 bool maybeImpure( const Expression * expr ) { 396 405 PassVisitor<ImpurityDetector> detector( false ); 397 406 expr->accept( detector ); … … 399 408 } 400 409 401 bool maybeImpureIgnoreUnique( Expression * expr ) {410 bool maybeImpureIgnoreUnique( const Expression * expr ) { 402 411 PassVisitor<ImpurityDetector> detector( true ); 403 412 expr->accept( detector ); -
src/Tuples/Tuples.h
r6130304 r83b52f1 52 52 /// returns a TypeInstType if `type` is a ttype, nullptr otherwise 53 53 TypeInstType * isTtype( Type * type ); 54 const TypeInstType * isTtype( const Type * type ); 54 55 const ast::TypeInstType * isTtype( const ast::Type * type ); 55 56 56 57 /// returns true if the expression may contain side-effects. 57 bool maybeImpure( Expression * expr );58 bool maybeImpure( const Expression * expr ); 58 59 bool maybeImpure( const ast::Expr * expr ); 59 60 60 61 /// Returns true if the expression may contain side-effect, 61 62 /// ignoring the presence of unique expressions. 62 bool maybeImpureIgnoreUnique( Expression * expr );63 bool maybeImpureIgnoreUnique( const Expression * expr ); 63 64 bool maybeImpureIgnoreUnique( const ast::Expr * expr ); 64 65 } // namespace Tuples
Note:
See TracChangeset
for help on using the changeset viewer.