Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/TypeEnvironment.h

    rf9feab8 r90152a4  
    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 : Sat Jul 22 09:35:45 2017
    13 // Update Count     : 3
     11// Last Modified By : Aaron B. Moss
     12// Last Modified On : Mon Jun 18 11:58:00 2018
     13// Update Count     : 4
    1414//
    1515
     
    2121#include <set>                         // for set
    2222#include <string>                      // for string
     23#include <utility>                     // for move, swap
     24
     25#include "WidenMode.h"                 // for WidenMode
    2326
    2427#include "SynTree/Declaration.h"       // for TypeDecl::Data, DeclarationWit...
     
    3740        //
    3841        // 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.
    3951        struct AssertCompare {
    4052                bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) const {
     
    6476
    6577                void initialize( const EqvClass &src, EqvClass &dest );
     78                void initialize( const EqvClass &src, EqvClass &dest, const Type *ty );
    6679                EqvClass();
    6780                EqvClass( const EqvClass &other );
     81                EqvClass( const EqvClass &other, const Type *ty );
     82                EqvClass( EqvClass &&other );
    6883                EqvClass &operator=( const EqvClass &other );
     84                EqvClass &operator=( EqvClass &&other );
    6985                ~EqvClass();
    7086                void print( std::ostream &os, Indenter indent = {} ) const;
     87
     88                /// Takes ownership of `ty`, freeing old `type`
     89                void set_type(Type* ty);
    7190        };
    7291
    7392        class TypeEnvironment {
    7493          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:
    7798                void add( const Type::ForallList &tyDecls );
     99                void add( const TypeSubstitution & sub );
    78100                template< typename SynTreeClass > int apply( SynTreeClass *&type ) const;
    79101                template< typename SynTreeClass > int applyFree( SynTreeClass *&type ) const;
     
    81103                bool isEmpty() const { return env.empty(); }
    82104                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* ) );
    84106                void simpleCombine( const TypeEnvironment &second );
    85107                void extractOpenVars( OpenVarSet &openVars ) const;
     
    90112                void addActual( const TypeEnvironment& actualEnv, OpenVarSet& openVars );
    91113
    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
    98129          private:
    99130                std::list< EqvClass > env;
     131               
    100132                std::list< EqvClass >::iterator internal_lookup( const std::string &var );
    101133        };
Note: See TracChangeset for help on using the changeset viewer.