Changes in / [6ce9a4f2:aac5dfd]


Ignore:
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.hfa

    r6ce9a4f2 raac5dfd  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec  8 18:27:22 2020
    13 // Update Count     : 524
     12// Last Modified On : Sat Dec 12 13:52:34 2020
     13// Update Count     : 536
    1414//
    1515
     
    4949
    5050static inline forall( dtype T | sized(T) ) {
    51         // Cforall safe equivalents, i.e., implicit size specification
     51        // CFA safe equivalents, i.e., implicit size specification
    5252
    5353        T * malloc( void ) {
     
    234234
    235235static inline forall( dtype T | sized(T) ) {
    236         // Cforall safe initialization/copy, i.e., implicit size specification, non-array types
     236        // CFA safe initialization/copy, i.e., implicit size specification, non-array types
    237237        T * memset( T * dest, char fill ) {
    238238                return (T *)memset( dest, fill, sizeof(T) );
     
    243243        } // memcpy
    244244
    245         // Cforall safe initialization/copy, i.e., implicit size specification, array types
     245        // CFA safe initialization/copy, i.e., implicit size specification, array types
    246246        T * amemset( T dest[], char fill, size_t dim ) {
    247247                return (T *)(void *)memset( dest, fill, dim * sizeof(T) ); // C memset
     
    253253} // distribution
    254254
    255 // Cforall deallocation for multiple objects
     255// CFA deallocation for multiple objects
     256static inline forall( dtype T )                                                 // FIX ME, problems with 0p in list
     257void free( T * ptr ) {
     258        free( (void *)ptr );                                                            // C free
     259} // free
    256260static inline forall( dtype T, ttype TT | { void free( TT ); } )
    257 void free( T * addr, TT rest ) {
    258         free( ( void *)addr );                                                          // use C free
     261void free( T * ptr, TT rest ) {
     262        free( ptr );
    259263        free( rest );
    260264} // free
    261265
    262 // Cforall allocation/deallocation and constructor/destructor, non-array types
     266// CFA allocation/deallocation and constructor/destructor, non-array types
    263267static inline forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } )
    264268T * new( TT p ) {
     
    272276                ^(*ptr){};                                                                              // run destructor
    273277        } // if
    274         free( ptr );
     278        free( ptr );                                                                            // always call free
    275279} // delete
    276 
    277280static inline forall( dtype T, ttype TT | { void ^?{}( T & ); void delete( TT ); } )
    278281void delete( T * ptr, TT rest ) {
     
    281284} // delete
    282285
    283 // Cforall allocation/deallocation and constructor/destructor, array types
     286// CFA allocation/deallocation and constructor/destructor, array types
    284287forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );
    285288forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );
  • src/AST/Convert.cpp

    r6ce9a4f2 raac5dfd  
    12171217
    12181218        const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) {
    1219                 ty->forall = get<TypeDecl>().acceptL( old->forall );
    12201219                ty->parameters = get<Expression>().acceptL( old->params );
    12211220                ty->hoistType = old->hoistType;
     
    26162615
    26172616        void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) {
    2618                 ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    26192617                ty->params = GET_ACCEPT_V( parameters, Expr );
    26202618                ty->hoistType = old->hoistType;
  • src/AST/ForallSubstitutor.hpp

    r6ce9a4f2 raac5dfd  
    2929       
    3030        /// Make new forall-list clone
    31         ParameterizedType::ForallList operator() ( const ParameterizedType::ForallList & o ) {
     31        FunctionType::ForallList operator() ( const FunctionType::ForallList & o ) {
    3232                return subs.clone( o, *visitor );
    3333        }
  • src/AST/Pass.hpp

    r6ce9a4f2 raac5dfd  
    287287        /// Internal RAII guard for forall substitutions
    288288        struct guard_forall_subs {
    289                 guard_forall_subs( Pass<core_t> & pass, const ParameterizedType * type )
     289                guard_forall_subs( Pass<core_t> & pass, const FunctionType * type )
    290290                : pass( pass ), type( type ) { __pass::forall::enter(pass.core, 0, type ); }
    291291                ~guard_forall_subs()         { __pass::forall::leave(pass.core, 0, type ); }
    292292                Pass<core_t> & pass;
    293                 const ParameterizedType * type;
     293                const FunctionType * type;
    294294        };
    295295
  • src/AST/Pass.impl.hpp

    r6ce9a4f2 raac5dfd  
    17771777        VISIT({
    17781778                guard_symtab guard { *this };
    1779                 guard_forall_subs forall_guard { *this, node };
    1780                 mutate_forall( node );
    17811779                maybe_accept( node, &StructInstType::params );
    17821780        })
     
    17951793        VISIT({
    17961794                guard_symtab guard { *this };
    1797                 guard_forall_subs forall_guard { *this, node };
    1798                 mutate_forall( node );
    17991795                maybe_accept( node, &UnionInstType::params );
    18001796        })
     
    18101806
    18111807        VISIT({
    1812                 guard_forall_subs forall_guard { *this, node };
    1813                 mutate_forall( node );
    18141808                maybe_accept( node, &EnumInstType::params );
    18151809        })
     
    18251819
    18261820        VISIT({
    1827                 guard_forall_subs forall_guard { *this, node };
    1828                 mutate_forall( node );
    18291821                maybe_accept( node, &TraitInstType::params );
    18301822        })
     
    18411833        VISIT(
    18421834                {
    1843                         guard_forall_subs forall_guard { *this, node };
    1844                         mutate_forall( node );
    18451835                        maybe_accept( node, &TypeInstType::params );
    18461836                }
  • src/AST/Pass.proto.hpp

    r6ce9a4f2 raac5dfd  
    396396                // Some simple scoping rules
    397397                template<typename core_t>
    398                 static inline auto enter( core_t & core, int, const ast::ParameterizedType * type )
     398                static inline auto enter( core_t & core, int, const ast::FunctionType * type )
    399399                -> decltype( core.subs, void() ) {
    400400                        if ( ! type->forall.empty() ) core.subs.beginScope();
     
    402402
    403403                template<typename core_t>
    404                 static inline auto enter( core_t &, long, const ast::ParameterizedType * ) {}
    405 
    406                 template<typename core_t>
    407                 static inline auto leave( core_t & core, int, const ast::ParameterizedType * type )
     404                static inline auto enter( core_t &, long, const ast::FunctionType * ) {}
     405
     406                template<typename core_t>
     407                static inline auto leave( core_t & core, int, const ast::FunctionType * type )
    408408                -> decltype( core.subs, void() ) {
    409409                        if ( ! type->forall.empty() ) { core.subs.endScope(); }
     
    411411
    412412                template<typename core_t>
    413                 static inline auto leave( core_t &, long, const ast::ParameterizedType * ) {}
     413                static inline auto leave( core_t &, long, const ast::FunctionType * ) {}
    414414
    415415                // Get the substitution table, if present
  • src/AST/Print.cpp

    r6ce9a4f2 raac5dfd  
    146146        }
    147147
    148         void print( const ast::ParameterizedType::ForallList & forall ) {
     148        void print( const ast::FunctionType::ForallList & forall ) {
    149149                if ( forall.empty() ) return;
    150150                os << "forall" << endl;
     
    259259        }
    260260
    261         void preprint( const ast::ParameterizedType * node ) {
     261        void preprint( const ast::FunctionType * node ) {
    262262                print( node->forall );
    263263                print( node->qualifiers );
     
    265265
    266266        void preprint( const ast::BaseInstType * node ) {
    267                 print( node->forall );
    268267                print( node->attributes );
    269268                print( node->qualifiers );
  • src/AST/Type.cpp

    r6ce9a4f2 raac5dfd  
    9494// --- ParameterizedType
    9595
    96 void ParameterizedType::initWithSub(
    97         const ParameterizedType & o, Pass< ForallSubstitutor > & sub
     96void FunctionType::initWithSub(
     97        const FunctionType & o, Pass< ForallSubstitutor > & sub
    9898) {
    9999        forall = sub.core( o.forall );
     
    104104
    105105FunctionType::FunctionType( const FunctionType & o )
    106 : ParameterizedType( o.qualifiers, copy( o.attributes ) ), returns(), params(),
     106: Type( o.qualifiers, copy( o.attributes ) ), returns(), params(),
    107107  isVarArgs( o.isVarArgs ) {
    108108        Pass< ForallSubstitutor > sub;
     
    125125}
    126126
    127 // --- BaseInstType
    128 
    129 void BaseInstType::initWithSub( const BaseInstType & o, Pass< ForallSubstitutor > & sub ) {
    130         ParameterizedType::initWithSub( o, sub ); // initialize substitution
    131         params = sub.core( o.params );            // apply to parameters
    132 }
    133 
    134 BaseInstType::BaseInstType( const BaseInstType & o )
    135 : ParameterizedType( o.qualifiers, copy( o.attributes ) ), params(), name( o.name ),
    136   hoistType( o.hoistType ) {
    137         Pass< ForallSubstitutor > sub;
    138         initWithSub( o, sub );
    139 }
    140 
    141127std::vector<readonly<Decl>> BaseInstType::lookup( const std::string& name ) const {
    142128        assertf( aggr(), "Must have aggregate to perform lookup" );
     
    176162        const TraitDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
    177163: BaseInstType( b->name, q, move(as) ), base( b ) {}
    178 
    179 // --- TypeInstType
    180 
    181 TypeInstType::TypeInstType( const TypeInstType & o )
    182 : BaseInstType( o.name, o.qualifiers, copy( o.attributes ) ), base(), kind( o.kind ) {
    183         Pass< ForallSubstitutor > sub;
    184         initWithSub( o, sub );      // initialize substitution
    185         base = sub.core( o.base );  // apply to base type
    186 }
    187164
    188165void TypeInstType::set_base( const TypeDecl * b ) {
  • src/AST/Type.hpp

    r6ce9a4f2 raac5dfd  
    267267};
    268268
    269 /// Base type for potentially forall-qualified types
    270 class ParameterizedType : public Type {
    271 protected:
    272         /// initializes forall with substitutor
    273         void initWithSub( const ParameterizedType & o, Pass< ForallSubstitutor > & sub );
    274 public:
    275         using ForallList = std::vector<ptr<TypeDecl>>;
    276 
    277         ForallList forall;
    278 
    279         ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {},
    280                 std::vector<ptr<Attribute>> && as = {} )
    281         : Type(q, std::move(as)), forall(std::move(fs)) {}
    282 
    283         ParameterizedType( CV::Qualifiers q, std::vector<ptr<Attribute>> && as = {} )
    284         : Type(q, std::move(as)), forall() {}
    285 
    286         // enforce use of ForallSubstitutor to copy parameterized type
    287         ParameterizedType( const ParameterizedType & ) = delete;
    288 
    289         ParameterizedType( ParameterizedType && ) = default;
    290 
    291         // no need to change destructor, and operator= deleted in Node
    292 
    293 private:
    294         virtual ParameterizedType * clone() const override = 0;
    295         MUTATE_FRIEND
    296 };
    297 
    298269/// Function variable arguments flag
    299270enum ArgumentFlag { FixedArgs, VariableArgs };
    300271
    301272/// Type of a function `[R1, R2](*)(P1, P2, P3)`
    302 class FunctionType final : public ParameterizedType {
    303 public:
     273class FunctionType final : public Type {
     274        protected:
     275        /// initializes forall with substitutor
     276        void initWithSub( const FunctionType & o, Pass< ForallSubstitutor > & sub );
     277public:
     278        using ForallList = std::vector<ptr<TypeDecl>>;
     279        ForallList forall;
     280
    304281        std::vector<ptr<Type>> returns;
    305282        std::vector<ptr<Type>> params;
     
    313290
    314291        FunctionType( ArgumentFlag va = FixedArgs, CV::Qualifiers q = {} )
    315         : ParameterizedType(q), returns(), params(), isVarArgs(va) {}
     292        : Type(q), returns(), params(), isVarArgs(va) {}
    316293
    317294        FunctionType( const FunctionType & o );
     
    329306
    330307/// base class for types that refer to types declared elsewhere (aggregates and typedefs)
    331 class BaseInstType : public ParameterizedType {
    332 protected:
    333         /// Initializes forall and parameters based on substitutor
    334         void initWithSub( const BaseInstType & o, Pass< ForallSubstitutor > & sub );
     308class BaseInstType : public Type {
    335309public:
    336310        std::vector<ptr<Expr>> params;
     
    340314        BaseInstType(
    341315                const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    342         : ParameterizedType(q, std::move(as)), params(), name(n) {}
     316        : Type(q, std::move(as)), params(), name(n) {}
    343317
    344318        BaseInstType(
    345319                const std::string& n, std::vector<ptr<Expr>> && params,
    346320                CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    347         : ParameterizedType(q, std::move(as)), params(std::move(params)), name(n) {}
    348 
    349         BaseInstType( const BaseInstType & o );
     321        : Type(q, std::move(as)), params(std::move(params)), name(n) {}
     322
     323        BaseInstType( const BaseInstType & o ) = default;
    350324
    351325        /// Gets aggregate declaration this type refers to
     
    433407        : BaseInstType( n, q, std::move(as) ), base(), kind( k ) {}
    434408
    435         TypeInstType( const TypeInstType & o );
     409        TypeInstType( const TypeInstType & o ) = default;
    436410
    437411        /// sets `base`, updating `kind` correctly
  • src/AST/TypeEnvironment.cpp

    r6ce9a4f2 raac5dfd  
    105105}
    106106
    107 void TypeEnvironment::add( const ParameterizedType::ForallList & tyDecls ) {
     107void TypeEnvironment::add( const FunctionType::ForallList & tyDecls ) {
    108108        for ( const TypeDecl * tyDecl : tyDecls ) {
    109109                env.emplace_back( tyDecl );
  • src/AST/TypeEnvironment.hpp

    r6ce9a4f2 raac5dfd  
    134134
    135135        /// Add a new equivalence class for each type variable
    136         void add( const ParameterizedType::ForallList & tyDecls );
     136        void add( const FunctionType::ForallList & tyDecls );
    137137
    138138        /// Add a new equivalence class for each branch of the substitution, checking for conflicts
  • src/AST/TypeSubstitution.cpp

    r6ce9a4f2 raac5dfd  
    166166}
    167167
    168 void TypeSubstitution::Substituter::previsit( const ParameterizedType * ptype ) {
     168void TypeSubstitution::Substituter::previsit( const FunctionType * ptype ) {
    169169        GuardValue( boundVars );
    170170        // bind type variables from forall-qualifiers
     
    180180        // bind type variables from forall-qualifiers
    181181        if ( freeOnly ) {
    182                 for ( const TypeDecl * tyvar : type->forall ) {
    183                         boundVars.insert( tyvar->name );
    184                 } // for
    185182                // bind type variables from generic type instantiations
    186183                if ( auto decl = type->aggr() ) {
  • src/AST/TypeSubstitution.hpp

    r6ce9a4f2 raac5dfd  
    167167
    168168                /// Records type variable bindings from forall-statements
    169                 void previsit( const ParameterizedType * type );
     169                void previsit( const FunctionType * type );
    170170                /// Records type variable bindings from forall-statements and instantiations of generic types
    171171                void handleAggregateType( const BaseInstType * type );
  • src/GenPoly/GenPoly.cc

    r6ce9a4f2 raac5dfd  
    567567
    568568        void makeTyVarMap(const ast::Type * type, TyVarMap & tyVarMap) {
    569                 if (auto ptype = dynamic_cast<const ast::ParameterizedType *>(type)) {
     569                if (auto ptype = dynamic_cast<const ast::FunctionType *>(type)) {
    570570                        for (auto & tyVar : ptype->forall) {
    571571                                assert (tyVar);
  • src/ResolvExpr/CandidateFinder.cpp

    r6ce9a4f2 raac5dfd  
    220220
    221221        void makeUnifiableVars(
    222                 const ast::ParameterizedType * type, ast::OpenVarSet & unifiableVars,
     222                const ast::FunctionType * type, ast::OpenVarSet & unifiableVars,
    223223                ast::AssertionSet & need
    224224        ) {
  • src/ResolvExpr/CastCost.cc

    r6ce9a4f2 raac5dfd  
    165165                                } else {
    166166                                        ast::TypeEnvironment newEnv{ env };
    167                                         if ( auto wParams = pointerType->base.as< ast::ParameterizedType >() ) {
     167                                        if ( auto wParams = pointerType->base.as< ast::FunctionType >() ) {
    168168                                                newEnv.add( wParams->forall );
    169169                                        }
  • src/ResolvExpr/RenameVars.cc

    r6ce9a4f2 raac5dfd  
    9393                }
    9494
    95                 template<typename NodeT>
    96                 const NodeT * openLevel( const NodeT * type ) {
     95                const ast::FunctionType * openLevel( const ast::FunctionType * type ) {
    9796                        if ( type->forall.empty() ) return type;
    9897
     
    10099
    101100                        // Load new names from this forall clause and perform renaming.
    102                         NodeT * mutType = ast::mutate( type );
     101                        auto mutType = ast::mutate( type );
    103102                        assert( type == mutType && "mutated type must be unique from ForallSubstitutor" );
    104103                        for ( ast::ptr< ast::TypeDecl > & td : mutType->forall ) {
     104                                assertf(dynamic_cast<ast::FunctionType *>(mutType), "renaming vars in non-function type");
    105105                                std::ostringstream output;
    106106                                output << "_" << resetCount << "_" << level << "_" << td->name;
     
    119119                }
    120120
    121                 void closeLevel( const ast::ParameterizedType * type ) {
     121                void closeLevel( const ast::FunctionType * type ) {
    122122                        if ( type->forall.empty() ) return;
    123123
     
    149149                        return renaming.openLevel( type );
    150150                }
     151
     152                /*
    151153                const ast::StructInstType * previsit( const ast::StructInstType * type ) {
    152154                        return renaming.openLevel( type );
     
    158160                        return renaming.openLevel( type );
    159161                }
     162                */
     163
    160164                const ast::TypeInstType * previsit( const ast::TypeInstType * type ) {
    161                         return renaming.rename( renaming.openLevel( type ) );
     165                        return renaming.rename( type );
    162166                }
    163                 void postvisit( const ast::ParameterizedType * type ) {
     167                void postvisit( const ast::FunctionType * type ) {
    164168                        renaming.closeLevel( type );
    165169                }
  • src/ResolvExpr/Resolver.cc

    r6ce9a4f2 raac5dfd  
    968968        namespace {
    969969                /// Finds deleted expressions in an expression tree
    970                 struct DeleteFinder_new final : public ast::WithShortCircuiting {
     970                struct DeleteFinder_new final : public ast::WithShortCircuiting, public ast::WithVisitorRef<DeleteFinder_new> {
    971971                        const ast::DeletedExpr * result = nullptr;
    972972
     
    976976                        }
    977977
    978                         void previsit( const ast::Expr * ) {
     978                        void previsit( const ast::Expr * expr ) {
    979979                                if ( result ) { visit_children = false; }
     980                                if (expr->inferred.hasParams()) {
     981                                        for (auto & imp : expr->inferred.inferParams() ) {
     982                                                imp.second.expr->accept(*visitor);
     983                                        }
     984                                }
    980985                        }
    981986                };
  • src/ResolvExpr/SatisfyAssertions.cpp

    r6ce9a4f2 raac5dfd  
    194194                        // if we should implement the same rule here
    195195                        // (i.e. error if unique best match is deleted)
    196                         if (candidate->isDeleted) continue;
     196                        if (candidate->isDeleted && candidate->linkage == ast::Linkage::AutoGen) continue;
    197197
    198198                        // build independent unification context for candidate
  • src/ResolvExpr/Unify.cc

    r6ce9a4f2 raac5dfd  
    898898                static void markAssertions(
    899899                        ast::AssertionSet & assn1, ast::AssertionSet & assn2,
    900                         const ast::ParameterizedType * type
     900                        const ast::FunctionType * type
    901901                ) {
    902902                        for ( const auto & tyvar : type->forall ) {
  • src/SymTab/Mangler.cc

    r6ce9a4f2 raac5dfd  
    666666                        // skip if not including qualifiers
    667667                        if ( typeMode ) return;
    668                         if ( auto ptype = dynamic_cast< const ast::ParameterizedType * >(type) ) {
     668                        if ( auto ptype = dynamic_cast< const ast::FunctionType * >(type) ) {
    669669                                if ( ! ptype->forall.empty() ) {
    670670                                        std::list< std::string > assertionNames;
  • src/SymTab/Validate.cc

    r6ce9a4f2 raac5dfd  
    17931793                static const node_t * forallFixer(
    17941794                        const CodeLocation & loc, const node_t * node,
    1795                         ast::ParameterizedType::ForallList parent_t::* forallField
     1795                        ast::FunctionType::ForallList parent_t::* forallField
    17961796                ) {
    17971797                        for ( unsigned i = 0; i < (node->* forallField).size(); ++i ) {
Note: See TracChangeset for help on using the changeset viewer.