Changeset 5cf1228


Ignore:
Timestamp:
Jul 26, 2022, 10:15:26 AM (21 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
e8616b6
Parents:
ffec1bf
Message:

Clean-up the new specialize pass. (Especially the cruft from the hand-off.)

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Specialize.h

    rffec1bf r5cf1228  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Specialize.h --
     7// Specialize.h -- Generate thunks to specialize polymorphic functions.
    88//
    99// Author           : Richard C. Bilson
     
    1717
    1818#include <list>  // for list
    19 #include "AST/TranslationUnit.hpp"
    2019
    2120class Declaration;
     21namespace ast {
     22        class TranslationUnit;
     23}
    2224
    2325namespace GenPoly {
  • src/GenPoly/SpecializeNew.cpp

    rffec1bf r5cf1228  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // SpecializeNew.cpp --
     7// SpecializeNew.cpp -- Generate thunks to specialize polymorphic functions.
    88//
    99// Author           : Andrew Beach
     
    201201                        *formal, *actual, getInferredParams( expr ) );
    202202        }
    203         //for ( auto pair : group_iterate( formal->params, mut->args ) ) {
    204         //      const ast::ptr<ast::Type> & formal = std::get<0>( pair );
    205         //      ast::ptr<ast::Expr> & actual = std::get<1>( pair );
    206         //      *actual = doSpecialization( (*actual)->location, *formal, *actual, getInferredParams( expr ) );
    207         //}
    208203        return mut;
    209204}
     
    227222}
    228223
    229 // Restructures the arguments to match the structure of the formal parameters
    230 // of the actual function. [begin, end) are the exploded arguments.
    231 template<typename Iterator, typename OutIterator>
    232 void structureArg( const CodeLocation & location, const ast::Type * type,
    233                 Iterator & begin, Iterator end, OutIterator out ) {
    234         if ( auto tuple = dynamic_cast<const ast::TupleType *>( type ) ) {
    235                 std::vector<ast::ptr<ast::Expr>> exprs;
    236                 for ( const ast::Type * t : *tuple ) {
    237                         structureArg( location, t, begin, end, std::back_inserter( exprs ) );
    238                 }
    239                 *out++ = new ast::TupleExpr( location, std::move( exprs ) );
    240         } else {
    241                 assertf( begin != end, "reached the end of the arguments while structuring" );
    242                 *out++ = *begin++;
    243         }
    244 }
    245 
    246 #if 0
     224// Restructures arguments to match the structure of the formal parameters
     225// of the actual function. Returns the next structured argument.
    247226template<typename Iterator>
    248227const ast::Expr * structureArg(
    249228                const CodeLocation& location, const ast::ptr<ast::Type> & type,
    250229                Iterator & begin, const Iterator & end ) {
    251         if ( auto tuple = type->as<ast::TupleType>() ) {
     230        if ( auto tuple = type.as<ast::TupleType>() ) {
    252231                std::vector<ast::ptr<ast::Expr>> exprs;
    253232                for ( const ast::Type * t : *tuple ) {
     
    260239        }
    261240}
    262 #endif
    263241
    264242namespace {
     
    291269                // Must replace only occurrences of type variables
    292270                // that occure free in the thunk's type.
    293                 //ast::TypeSubstitution::ApplyResult<ast::FunctionType>
    294                 //      typeSubs->applyFree( newType );
    295271                auto result = typeSubs->applyFree( newType );
    296272                newType = result.node.release();
     
    300276        using DeclVector = std::vector<ast::ptr<ast::TypeDecl>>;
    301277
    302         //const std::string & thunkName = thunkNamer.newName();
    303         //UniqueName paramNamer(thunkName + "Param");
    304278        UniqueName paramNamer( paramPrefix );
    305279
    306         //auto toParamDecl = [&location, &paramNamer]( const ast::Type * type ) {
    307         //      return new ast::ObjectDecl(
    308         //              location, paramNamer.newName(), ast::deepCopy( type ) );
    309         //};
    310 
    311280        // Create new thunk with same signature as formal type.
    312 
    313         // std::map<const ast::TypeDecl *, std::pair<int, int>> typeMap;
    314281        ast::Pass<TypeInstFixer> fixer;
    315282        for (const auto & kv : newType->forall) {
    316283                if (fixer.core.typeMap.count(kv->base)) {
    317                         std::cerr << location << ' ' << kv->base->name << ' ' << kv->expr_id << '_' << kv->formal_usage << ','
    318                         << fixer.core.typeMap[kv->base].first << '_' << fixer.core.typeMap[kv->base].second << std::endl;
     284                        std::cerr << location << ' ' << kv->base->name
     285                                << ' ' << kv->expr_id << '_' << kv->formal_usage
     286                                << ',' << fixer.core.typeMap[kv->base].first
     287                                << '_' << fixer.core.typeMap[kv->base].second << std::endl;
    319288                        assertf(false, "multiple formals in specialize");
    320289                }
     
    322291                        fixer.core.typeMap[kv->base] = std::make_pair(kv->expr_id, kv->formal_usage);
    323292                }
    324         } 
     293        }
    325294
    326295        ast::CompoundStmt * thunkBody = new ast::CompoundStmt( location );
     
    345314                );
    346315
    347         // thunkFunc->accept(fixer);
    348316        thunkFunc->fixUniqueId();
    349 
    350 
    351317
    352318        // Thunks may be generated and not used, avoid them.
     
    375341                // Name each thunk parameter and explode it.
    376342                // These are then threaded back into the actual function call.
    377                 //param->name = paramNamer.newName();
    378343                ast::DeclWithType * mutParam = ast::mutate( param.get() );
    379                 // - Should be renamed earlier. -
    380                 //mutParam->name = paramNamer.newName();
    381344                explodeSimple( location, new ast::VariableExpr( location, mutParam ),
    382345                        std::back_inserter( args ) );
     
    388351                argBegin = args.begin(), argEnd = args.end();
    389352        for ( const auto & actualArg : actualType->params ) {
    390                 structureArg( location, actualArg.get(), argBegin, argEnd,
    391                         std::back_inserter( app->args ) );
     353                app->args.push_back(
     354                        structureArg( location, actualArg.get(), argBegin, argEnd ) );
    392355        }
    393356        assertf( argBegin == argEnd, "Did not structure all arguments." );
     
    469432        // Create thunks for the inferred parameters.
    470433        // This is not needed for intrinsic calls, because they aren't
    471         // actually passed
    472         //
    473         // need to handle explicit params before inferred params so that
    474         // explicit params do not recieve a changed set of inferParams (and
    475         // change them again) alternatively, if order starts to matter then
    476         // copy appExpr's inferParams and pass them to handleExplicitParams.
     434        // actually passed to the function. It needs to handle explicit params
     435        // before inferred params so that explicit params do not recieve a
     436        // changed set of inferParams (and change them again).
     437        // Alternatively, if order starts to matter then copy expr's inferParams
     438        // and pass them to handleExplicitParams.
    477439        ast::ApplicationExpr * mut = handleExplicitParams( expr );
    478440        if ( !mut->inferred.hasParams() ) {
  • src/ResolvExpr/Resolver.cc

    rffec1bf r5cf1228  
    15421542        }
    15431543
    1544 
    15451544        const ast::StaticAssertDecl * Resolver_new::previsit(
    15461545                const ast::StaticAssertDecl * assertDecl
     
    15541553        const PtrType * handlePtrType( const PtrType * type, const ResolveContext & context ) {
    15551554                if ( type->dimension ) {
    1556                         ast::ptr< ast::Type > sizeType = context.global.sizeType;
     1555                        const ast::Type * sizeType = context.global.sizeType.get();
    15571556                        ast::ptr< ast::Expr > dimension = findSingleExpression( type->dimension, sizeType, context );
    15581557                        assertf(dimension->env->empty(), "array dimension expr has nonempty env");
    15591558                        dimension.get_and_mutate()->env = nullptr;
    1560                         ast::mutate_field(
    1561                                 type, &PtrType::dimension,
    1562                                 dimension);
     1559                        ast::mutate_field( type, &PtrType::dimension, dimension );
    15631560                }
    15641561                return type;
  • src/main.cc

    rffec1bf r5cf1228  
    439439                        PASS( "Translate Tries", ControlStruct::translateTries( transUnit ) );
    440440                        PASS( "Gen Waitfor", Concurrency::generateWaitFor( transUnit ) );
    441                         PASS( "Convert Specializations",  GenPoly::convertSpecializations( transUnit ) ); // needs to happen before tuple types are expanded
    442 
     441
     442                        // Needs to happen before tuple types are expanded.
     443                        PASS( "Convert Specializations",  GenPoly::convertSpecializations( transUnit ) );
    443444
    444445                        translationUnit = convert( move( transUnit ) );
     
    516517                        PASS( "Gen Waitfor", Concurrency::generateWaitFor( translationUnit ) );
    517518                        PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
    518 
    519519                }
    520 
    521 
    522                 // PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
    523520
    524521                PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
Note: See TracChangeset for help on using the changeset viewer.