Ignore:
Timestamp:
Jan 14, 2019, 3:38:28 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
fd73248
Parents:
07ec1a2 (diff), 52ffa30 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/TypeEnvironment.h

    r07ec1a2 r276a55b2  
    3939        // declarations.
    4040        //
    41         // I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this comparator.
     41        // I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this
     42        // comparator.
    4243        //
    4344        // Note: since this compares pointers for position, minor changes in the source file that affect
    4445        // memory layout can alter compilation time in unpredictable ways. For example, the placement
    4546        // 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.
     47        // are seen in different orders, causing a potentially different number of unification calls
     48        // when resolving assertions. I've seen a TU go from 36 seconds to 27 seconds by reordering
     49        // line directives alone, so it would be nice to fix this comparison so that assertions compare
     50        // more consistently. I've tried to modify this to compare on mangle name instead of type as
     51        // the second comparator, but this causes some assertions to never be recorded. More
     52        // investigation is needed.
    5153        struct AssertCompare {
    5254                bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) const {
     
    5759        };
    5860        struct AssertionSetValue {
    59                 bool isUsed;
    60                 // chain of Unique IDs of the assertion declarations. The first ID in the chain is the ID of an assertion on the current type,
    61                 // with each successive ID being the ID of an assertion pulled in by the previous ID. The last ID in the chain is
    62                 // the ID of the assertion that pulled in the current assertion.
    63                 std::list< UniqueId > idChain;
     61                bool isUsed;        ///< True if assertion needs to be resolved
     62                UniqueId resnSlot;  ///< ID of slot assertion belongs to
     63
     64                AssertionSetValue() : isUsed(false), resnSlot(0) {}
    6465        };
    6566        typedef std::map< DeclarationWithType*, AssertionSetValue, AssertCompare > AssertionSet;
    6667        typedef std::map< std::string, TypeDecl::Data > OpenVarSet;
     68
     69        /// merges one set of open vars into another
     70        static inline void mergeOpenVars( OpenVarSet& dst, const OpenVarSet& src ) {
     71                for ( const auto& entry : src ) { dst[ entry.first ] = entry.second; }
     72        }
    6773
    6874        void printAssertionSet( const AssertionSet &, std::ostream &, int indent = 0 );
     
    9197
    9298        class TypeEnvironment {
     99                using ClassList = std::list< EqvClass >;
    93100          public:
    94101                const EqvClass* lookup( const std::string &var ) const;
     
    103110                bool isEmpty() const { return env.empty(); }
    104111                void print( std::ostream &os, Indenter indent = {} ) const;
    105                 // void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) );
     112               
     113                /// Simply concatenate the second environment onto this one; no safety checks performed
    106114                void simpleCombine( const TypeEnvironment &second );
     115
     116          private:
     117                /// Unifies the type bound of to with the type bound of from, returning false if fails
     118                bool mergeBound( EqvClass& to, const EqvClass& from, OpenVarSet& openVars, const SymTab::Indexer& indexer );
     119
     120                /// Merges two type classes from local environment, returning false if fails
     121                bool mergeClasses( ClassList::iterator to, ClassList::iterator from, OpenVarSet& openVars, const SymTab::Indexer& indexer );
     122
     123          public:
     124                /// Merges the second environment with this one, checking compatibility.
     125                /// Returns false if fails, but does NOT roll back partial changes.
     126                bool combine( const TypeEnvironment& second, OpenVarSet& openVars, const SymTab::Indexer& indexer );
     127               
    107128                void extractOpenVars( OpenVarSet &openVars ) const;
    108129                TypeEnvironment *clone() const { return new TypeEnvironment( *this ); }
     
    123144                void forbidWidening();
    124145
    125                 using iterator = std::list< EqvClass >::const_iterator;
     146                using iterator = ClassList::const_iterator;
    126147                iterator begin() const { return env.begin(); }
    127148                iterator end() const { return env.end(); }
    128149
    129150          private:
    130                 std::list< EqvClass > env;
     151                ClassList env;
    131152               
    132                 std::list< EqvClass >::iterator internal_lookup( const std::string &var );
     153                ClassList::iterator internal_lookup( const std::string &var );
    133154        };
    134155
Note: See TracChangeset for help on using the changeset viewer.