Ignore:
Timestamp:
Oct 3, 2018, 5:08:14 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
59cf83b
Parents:
588c2b0
Message:

TypeEnvironment::combine -- compiles, untested

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/TypeEnvironment.h

    r588c2b0 r9ad2f9f  
    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 {
     
    5860        struct AssertionSetValue {
    5961                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.
     62                // chain of Unique IDs of the assertion declarations. The first ID in the chain is the ID
     63                // of an assertion on the current type, with each successive ID being the ID of an
     64                // assertion pulled in by the previous ID. The last ID in the chain is the ID of the
     65                // assertion that pulled in the current assertion.
    6366                std::list< UniqueId > idChain;
    6467        };
     
    9194
    9295        class TypeEnvironment {
     96                using ClassList = std::list< EqvClass >;
    9397          public:
    9498                const EqvClass* lookup( const std::string &var ) const;
     
    103107                bool isEmpty() const { return env.empty(); }
    104108                void print( std::ostream &os, Indenter indent = {} ) const;
    105                 // void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) );
     109               
     110                /// Simply concatenate the second environment onto this one; no safety checks performed
    106111                void simpleCombine( const TypeEnvironment &second );
     112
     113          private:
     114                /// Unifies the type bound of to with the type bound of from, returning false if fails
     115                bool mergeBound( EqvClass& to, const EqvClass& from, OpenVarSet& openVars, const SymTab::Indexer& indexer );
     116
     117                /// Merges two type classes from local environment, returning false if fails
     118                bool mergeClasses( ClassList::iterator to, ClassList::iterator from, OpenVarSet& openVars, const SymTab::Indexer& indexer );
     119
     120          public:
     121                /// Merges the second environment with this one, checking compatibility.
     122                /// Returns false if fails, but does NOT roll back partial changes.
     123                bool combine( const TypeEnvironment& second, OpenVarSet& openVars, const SymTab::Indexer& indexer );
     124               
    107125                void extractOpenVars( OpenVarSet &openVars ) const;
    108126                TypeEnvironment *clone() const { return new TypeEnvironment( *this ); }
     
    123141                void forbidWidening();
    124142
    125                 using iterator = std::list< EqvClass >::const_iterator;
     143                using iterator = ClassList::const_iterator;
    126144                iterator begin() const { return env.begin(); }
    127145                iterator end() const { return env.end(); }
    128146
    129147          private:
    130                 std::list< EqvClass > env;
     148                ClassList env;
    131149               
    132                 std::list< EqvClass >::iterator internal_lookup( const std::string &var );
     150                ClassList::iterator internal_lookup( const std::string &var );
    133151        };
    134152
Note: See TracChangeset for help on using the changeset viewer.