Changeset 837ce06


Ignore:
Timestamp:
Oct 19, 2017, 2:20:53 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:
72f85de
Parents:
6840e7c
Message:

Fix cleanup function generation to always generate monomorphic functions

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r6840e7c r837ce06  
    653653                        // wraps the more complicated code.
    654654                        static UniqueName dtorNamer( "__cleanup_dtor" );
    655                         FunctionDecl * dtorFunc = FunctionDecl::newFunction( dtorNamer.newName(), SymTab::genDefaultType( objDecl->type ), new CompoundStmt( noLabels ) );
     655                        FunctionDecl * dtorFunc = FunctionDecl::newFunction( dtorNamer.newName(), SymTab::genDefaultType( objDecl->type, false ), new CompoundStmt( noLabels ) );
    656656                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, dtorFunc ) );
    657657
    658658                        // the original code contains uses of objDecl - replace them with the newly generated 'this' parameter.
    659                         ObjectDecl * thisParam = getThisParam( dtorFunc->type );
     659                        ObjectDecl * thisParam = getParamThis( dtorFunc->type );
    660660                        VarExprReplacer::replace( dtor, { std::make_pair( objDecl, thisParam ) } );
    661661                        dtorFunc->statements->push_back( dtor );
  • src/SymTab/Autogen.cc

    r6840e7c r837ce06  
    4646        /// Data used to generate functions generically. Specifically, the name of the generated function and a function which generates the routine protoype
    4747        struct FuncData {
    48                 typedef FunctionType * (*TypeGen)( Type * );
     48                typedef FunctionType * (*TypeGen)( Type *, bool );
    4949                FuncData( const std::string & fname, const TypeGen & genType ) : fname( fname ), genType( genType ) {}
    5050                std::string fname;
     
    236236
    237237        /// given type T, generate type of default ctor/dtor, i.e. function type void (*) (T *)
    238         FunctionType * genDefaultType( Type * paramType ) {
    239                 const auto & typeParams = getGenericParams( paramType );
     238        FunctionType * genDefaultType( Type * paramType, bool maybePolymorphic ) {
    240239                FunctionType *ftype = new FunctionType( Type::Qualifiers(), false );
    241                 cloneAll( typeParams, ftype->forall );
     240                if ( maybePolymorphic ) {
     241                        // only copy in
     242                        const auto & typeParams = getGenericParams( paramType );
     243                        cloneAll( typeParams, ftype->forall );
     244                }
    242245                ObjectDecl *dstParam = new ObjectDecl( "_dst", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), paramType->clone() ), nullptr );
    243246                ftype->parameters.push_back( dstParam );
     
    246249
    247250        /// given type T, generate type of copy ctor, i.e. function type void (*) (T *, T)
    248         FunctionType * genCopyType( Type * paramType ) {
    249                 FunctionType *ftype = genDefaultType( paramType );
     251        FunctionType * genCopyType( Type * paramType, bool maybePolymorphic ) {
     252                FunctionType *ftype = genDefaultType( paramType, maybePolymorphic );
    250253                ObjectDecl *srcParam = new ObjectDecl( "_src", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, paramType->clone(), nullptr );
    251254                ftype->parameters.push_back( srcParam );
     
    254257
    255258        /// given type T, generate type of assignment, i.e. function type T (*) (T *, T)
    256         FunctionType * genAssignType( Type * paramType ) {
    257                 FunctionType *ftype = genCopyType( paramType );
     259        FunctionType * genAssignType( Type * paramType, bool maybePolymorphic ) {
     260                FunctionType *ftype = genCopyType( paramType, maybePolymorphic );
    258261                ObjectDecl *returnVal = new ObjectDecl( "_ret", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, paramType->clone(), nullptr );
    259262                ftype->returnVals.push_back( returnVal );
     
    313316                for ( const FuncData & data : data ) {
    314317                        // generate a function (?{}, ?=?, ^?{}) based on the current FuncData.
    315                         FunctionType * ftype = data.genType( type );
     318                        FunctionType * ftype = data.genType( type, true );
    316319
    317320                        // destructor for concurrent type must be mutex
  • src/SymTab/Autogen.h

    r6840e7c r837ce06  
    4545        extern FunctionDecl * dereferenceOperator;
    4646
    47         // generate the type of an assignment function for paramType
    48         FunctionType * genAssignType( Type * paramType );
    49 
    50         // generate the type of a default constructor or destructor for paramType
    51         FunctionType * genDefaultType( Type * paramType );
    52 
    53         // generate the type of a copy constructor for paramType
    54         FunctionType * genCopyType( Type * paramType );
     47        /// generate the type of an assignment function for paramType.
     48        /// maybePolymorphic is true if the resulting FunctionType is allowed to be polymorphic
     49        FunctionType * genAssignType( Type * paramType, bool maybePolymorphic = true );
     50
     51        /// generate the type of a default constructor or destructor for paramType.
     52        /// maybePolymorphic is true if the resulting FunctionType is allowed to be polymorphic
     53        FunctionType * genDefaultType( Type * paramType, bool maybePolymorphic = true );
     54
     55        /// generate the type of a copy constructor for paramType.
     56        /// maybePolymorphic is true if the resulting FunctionType is allowed to be polymorphic
     57        FunctionType * genCopyType( Type * paramType, bool maybePolymorphic = true );
    5558
    5659        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
Note: See TracChangeset for help on using the changeset viewer.