Changeset 90152a4 for src/ResolvExpr/TypeEnvironment.h
- Timestamp:
- Aug 27, 2018, 4:40:34 PM (7 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:
- b7c89aa
- Parents:
- f9feab8 (diff), 305581d (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/TypeEnvironment.h
rf9feab8 r90152a4 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 : Sat Jul 22 09:35:45 201713 // Update Count : 311 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 18 11:58:00 2018 13 // Update Count : 4 14 14 // 15 15 … … 21 21 #include <set> // for set 22 22 #include <string> // for string 23 #include <utility> // for move, swap 24 25 #include "WidenMode.h" // for WidenMode 23 26 24 27 #include "SynTree/Declaration.h" // for TypeDecl::Data, DeclarationWit... … … 37 40 // 38 41 // I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this comparator. 42 // 43 // Note: since this compares pointers for position, minor changes in the source file that affect 44 // memory layout can alter compilation time in unpredictable ways. For example, the placement 45 // of a line directive can reorder type pointers with respect to each other so that assertions 46 // are seen in different orders, causing a potentially different number of unification calls when 47 // resolving assertions. I've seen a TU go from 36 seconds to 27 seconds by reordering line directives 48 // alone, so it would be nice to fix this comparison so that assertions compare more consistently. 49 // I've tried to modify this to compare on mangle name instead of type as the second comparator, but 50 // this causes some assertions to never be recorded. More investigation is needed. 39 51 struct AssertCompare { 40 52 bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) const { … … 64 76 65 77 void initialize( const EqvClass &src, EqvClass &dest ); 78 void initialize( const EqvClass &src, EqvClass &dest, const Type *ty ); 66 79 EqvClass(); 67 80 EqvClass( const EqvClass &other ); 81 EqvClass( const EqvClass &other, const Type *ty ); 82 EqvClass( EqvClass &&other ); 68 83 EqvClass &operator=( const EqvClass &other ); 84 EqvClass &operator=( EqvClass &&other ); 69 85 ~EqvClass(); 70 86 void print( std::ostream &os, Indenter indent = {} ) const; 87 88 /// Takes ownership of `ty`, freeing old `type` 89 void set_type(Type* ty); 71 90 }; 72 91 73 92 class TypeEnvironment { 74 93 public: 75 bool lookup( const std::string &var, EqvClass &eqvClass ) const; 76 void add( const EqvClass &eqvClass ); 94 const EqvClass* lookup( const std::string &var ) const; 95 private: 96 void add( EqvClass &&eqvClass ); 97 public: 77 98 void add( const Type::ForallList &tyDecls ); 99 void add( const TypeSubstitution & sub ); 78 100 template< typename SynTreeClass > int apply( SynTreeClass *&type ) const; 79 101 template< typename SynTreeClass > int applyFree( SynTreeClass *&type ) const; … … 81 103 bool isEmpty() const { return env.empty(); } 82 104 void print( std::ostream &os, Indenter indent = {} ) const; 83 void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) );105 // void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) ); 84 106 void simpleCombine( const TypeEnvironment &second ); 85 107 void extractOpenVars( OpenVarSet &openVars ) const; … … 90 112 void addActual( const TypeEnvironment& actualEnv, OpenVarSet& openVars ); 91 113 92 typedef std::list< EqvClass >::iterator iterator; 93 iterator begin() { return env.begin(); } 94 iterator end() { return env.end(); } 95 typedef std::list< EqvClass >::const_iterator const_iterator; 96 const_iterator begin() const { return env.begin(); } 97 const_iterator end() const { return env.end(); } 114 /// Binds the type class represented by `typeInst` to the type `bindTo`; will add 115 /// the class if needed. Returns false on failure. 116 bool bindVar( TypeInstType *typeInst, Type *bindTo, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ); 117 118 /// Binds the type classes represented by `var1` and `var2` together; will add 119 /// one or both classes if needed. Returns false on failure. 120 bool bindVarToVar( TypeInstType *var1, TypeInstType *var2, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ); 121 122 /// Disallows widening for all bindings in the environment 123 void forbidWidening(); 124 125 using iterator = std::list< EqvClass >::const_iterator; 126 iterator begin() const { return env.begin(); } 127 iterator end() const { return env.end(); } 128 98 129 private: 99 130 std::list< EqvClass > env; 131 100 132 std::list< EqvClass >::iterator internal_lookup( const std::string &var ); 101 133 };
Note:
See TracChangeset
for help on using the changeset viewer.