Changeset 83b52f1 for src/ResolvExpr


Ignore:
Timestamp:
Jul 24, 2019, 10:40:28 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

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

Location:
src/ResolvExpr
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Alternative.h

    r6130304 r83b52f1  
    2929        /// One assertion to resolve
    3030        struct AssertionItem {
    31                 DeclarationWithType* decl;
     31                const DeclarationWithType* decl;
    3232                AssertionSetValue info;
    33                
     33
    3434                AssertionItem() = default;
    35                 AssertionItem( DeclarationWithType* decl, const AssertionSetValue& info )
     35                AssertionItem( const DeclarationWithType* decl, const AssertionSetValue& info )
    3636                : decl(decl), info(info) {}
    3737                AssertionItem( const AssertionSet::value_type& e ) : decl(e.first), info(e.second) {}
  • src/ResolvExpr/FindOpenVars.cc

    r6130304 r83b52f1  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 09:42:48 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 09:45:25 2015
    13 // Update Count     : 3
     11// Last Modified By : Andrew
     12// Last Modified On : Fri Jul 12 14:18:00 2019
     13// Update Count     : 4
    1414//
    1515
     
    2929                FindOpenVars_old( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen );
    3030
    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 );
    3535
    36                 void common_action( Type *type );
     36                void common_action( const Type *type );
    3737
    3838                OpenVarSet &openVars, &closedVars;
     
    4141        };
    4242
    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 ) {
    4444                PassVisitor<FindOpenVars_old> finder( openVars, closedVars, needAssertions, haveAssertions, firstIsOpen );
    4545                type->accept( finder );
     
    5050        }
    5151
    52         void FindOpenVars_old::common_action( Type *type ) {
     52        void FindOpenVars_old::common_action( const Type * type ) {
    5353                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 ) {
    5555                                openVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) };
    5656                                for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
     
    6161                        }
    6262                } 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 ) {
    6464                                closedVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) };
    6565                                for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
     
    7878        }
    7979
    80         void FindOpenVars_old::previsit(PointerType *pointerType) {
     80        void FindOpenVars_old::previsit(const PointerType * pointerType) {
    8181                common_action( pointerType );
    8282        }
    8383
    84         void FindOpenVars_old::previsit(ArrayType *arrayType) {
     84        void FindOpenVars_old::previsit(const ArrayType * arrayType) {
    8585                common_action( arrayType );
    8686        }
    8787
    88         void FindOpenVars_old::previsit(FunctionType *functionType) {
     88        void FindOpenVars_old::previsit(const FunctionType * functionType) {
    8989                common_action( functionType );
    9090                nextIsOpen = ! nextIsOpen;
     
    9292        }
    9393
    94         void FindOpenVars_old::previsit(TupleType *tupleType) {
     94        void FindOpenVars_old::previsit(const TupleType * tupleType) {
    9595                common_action( tupleType );
    9696        }
     
    104104                        bool nextIsOpen;
    105105
    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,
    108108                                ast::AssertionSet & h, FirstMode firstIsOpen )
    109109                        : open( o ), closed( c ), need( n ), have( h ), nextIsOpen( firstIsOpen ) {}
     
    135135        }
    136136
    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,
    139139                        ast::AssertionSet & need, ast::AssertionSet & have, FirstMode firstIsOpen ) {
    140140                ast::Pass< FindOpenVars_new > finder{ open, closed, need, have, firstIsOpen };
  • src/ResolvExpr/FindOpenVars.h

    r6130304 r83b52f1  
    2626namespace ResolvExpr {
    2727        // 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 );
    2929
    3030        enum FirstMode { FirstClosed, FirstOpen };
  • src/ResolvExpr/Occurs.cc

    r6130304 r83b52f1  
    2424        struct Occurs : public WithVisitorRef<Occurs> {
    2525                Occurs( std::string varName, const TypeEnvironment &env );
    26                 void previsit( TypeInstType * typeInst );
     26                void previsit( const TypeInstType * typeInst );
    2727
    2828                bool result;
     
    3131        };
    3232
    33         bool occurs( Type *type, std::string varName, const TypeEnvironment &env ) {
     33        bool occurs( const Type *type, const std::string & varName, const TypeEnvironment &env ) {
    3434                PassVisitor<Occurs> occur( varName, env );
    3535                type->accept( occur );
     
    4545        }
    4646
    47         void Occurs::previsit( TypeInstType * typeInst ) {
     47        void Occurs::previsit( const TypeInstType * typeInst ) {
    4848                ///   std::cerr << "searching for vars: ";
    4949///   std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cerr, " " ) );
  • src/ResolvExpr/ResolveAssertions.cc

    r6130304 r83b52f1  
    7373                CandidateList matches;
    7474
    75                 DeferItem( DeclarationWithType* decl, const AssertionSetValue& info, CandidateList&& matches )
     75                DeferItem( const DeclarationWithType* decl, const AssertionSetValue& info, CandidateList&& matches )
    7676                : decl(decl), info(info), matches(std::move(matches)) {}
    7777
  • src/ResolvExpr/TypeEnvironment.cc

    r6130304 r83b52f1  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 12:19:47 2015
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Mon Jun 18 11:58:00 2018
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Jun 18 14:27:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    315315        }
    316316
    317         bool isFtype( Type *type ) {
    318                 if ( dynamic_cast< FunctionType* >( type ) ) {
     317        bool isFtype( const Type * type ) {
     318                if ( dynamic_cast< const FunctionType * >( type ) ) {
    319319                        return true;
    320                 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) {
     320                } else if ( const TypeInstType *typeInst = dynamic_cast< const TypeInstType * >( type ) ) {
    321321                        return typeInst->get_isFtype();
    322322                } // if
     
    324324        }
    325325
    326         bool tyVarCompatible( const TypeDecl::Data & data, Type *type ) {
     326        bool tyVarCompatible( const TypeDecl::Data & data, const Type * type ) {
    327327                switch ( data.kind ) {
    328328                  case TypeDecl::Dtype:
     
    336336                  case TypeDecl::Ttype:
    337337                        // 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 );
    339339                  default:
    340340                        assertf(false, "Unhandled tyvar kind: %d", data.kind);
     
    343343        }
    344344
    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 ) {
    346346
    347347                // remove references from other, so that type variables can only bind to value types
     
    361361                                // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to
    362362                                std::unique_ptr< Type > newType( curClass->type->clone() );
    363                                 newType->get_qualifiers() = typeInst->get_qualifiers();
     363                                newType->tq = typeInst->tq;
    364364                                if ( unifyInexact( newType.get(), bindTo, *this, need, have, openVars, widen & WidenMode( curClass->allowWidening, true ), indexer, common ) ) {
    365365                                        if ( common ) {
     
    386386        }
    387387
    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,
    390390                        const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer ) {
    391391
  • src/ResolvExpr/TypeEnvironment.h

    r6130304 r83b52f1  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 12:24:58 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 30 23:04:10 2019
    13 // Update Count     : 9
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Jul 19 17:00:10 2019
     13// Update Count     : 10
    1414//
    1515
     
    4040        // declarations.
    4141        //
    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
    4343        // comparator.
    4444        //
     
    4646        // memory layout can alter compilation time in unpredictable ways. For example, the placement
    4747        // 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
    5353        // investigation is needed.
    5454        struct AssertCompare {
    55                 bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) const {
     55                bool operator()( const DeclarationWithType * d1, const DeclarationWithType * d2 ) const {
    5656                        int cmp = d1->get_name().compare( d2->get_name() );
    5757                        return cmp < 0 ||
     
    6565                AssertionSetValue() : isUsed(false), resnSlot(0) {}
    6666        };
    67         typedef std::map< DeclarationWithType *, AssertionSetValue, AssertCompare > AssertionSet;
     67        typedef std::map< const DeclarationWithType *, AssertionSetValue, AssertCompare > AssertionSet;
    6868        typedef std::unordered_map< std::string, TypeDecl::Data > OpenVarSet;
    6969
     
    7878        struct EqvClass {
    7979                std::set< std::string > vars;
    80                 Type *type;
     80                Type * type;
    8181                bool allowWidening;
    8282                TypeDecl::Data data;
     
    111111                bool isEmpty() const { return env.empty(); }
    112112                void print( std::ostream &os, Indenter indent = {} ) const;
    113                
     113
    114114                /// Simply concatenate the second environment onto this one; no safety checks performed
    115115                void simpleCombine( const TypeEnvironment &second );
     
    126126                /// Returns false if fails, but does NOT roll back partial changes.
    127127                bool combine( const TypeEnvironment& second, OpenVarSet& openVars, const SymTab::Indexer& indexer );
    128                
     128
    129129                void extractOpenVars( OpenVarSet &openVars ) const;
    130130                TypeEnvironment *clone() const { return new TypeEnvironment( *this ); }
     
    134134                void addActual( const TypeEnvironment& actualEnv, OpenVarSet& openVars );
    135135
    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
    137137                /// 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
    141141                /// 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 );
    143143
    144144                /// Disallows widening for all bindings in the environment
     
    151151          private:
    152152                ClassList env;
    153                
     153
    154154                ClassList::iterator internal_lookup( const std::string &var );
    155155        };
  • src/ResolvExpr/typeops.h

    r6130304 r83b52f1  
    149149
    150150        // in Occurs.cc
    151         bool occurs( Type * type, std::string varName, const TypeEnvironment & env );
     151        bool occurs( const Type * type, const std::string & varName, const TypeEnvironment & env );
    152152        // new AST version in TypeEnvironment.cpp (only place it was used in old AST)
    153153
     
    200200
    201201        // in TypeEnvironment.cc
    202         bool isFtype( Type * type );
     202        bool isFtype( const Type * type );
    203203} // namespace ResolvExpr
    204204
Note: See TracChangeset for help on using the changeset viewer.