Changeset 23a0e576 for src/GenPoly


Ignore:
Timestamp:
Feb 6, 2024, 12:35:12 PM (5 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
dacd2c19
Parents:
e11cdc0
Message:

Remove mid-array assertion from the Box pass.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cpp

    re11cdc0 r23a0e576  
    366366
    367367        /// Passes extra layout arguments for sized polymorphic type parameters.
    368         ast::vector<ast::Expr>::iterator passTypeVars(
     368        void passTypeVars(
    369369                ast::ApplicationExpr * expr,
     370                ast::vector<ast::Expr> & extraArgs,
    370371                ast::FunctionType const * funcType );
    371372        /// Wraps a function application with a new temporary for the
     
    387388        /// parameter list. arg should point into expr's argument list.
    388389        void boxParams(
    389                 ast::ApplicationExpr const * expr,
    390                 ast::vector<ast::Expr>::iterator arg,
     390                ast::ApplicationExpr * expr,
     391                ast::Type const * polyRetType,
    391392                ast::FunctionType const * function,
    392393                const TypeVarMap & typeVars );
     
    395396        void addInferredParams(
    396397                ast::ApplicationExpr * expr,
    397                 ast::vector<ast::Expr>::iterator arg,
     398                ast::vector<ast::Expr> & extraArgs,
    398399                ast::FunctionType const * functionType,
    399400                const TypeVarMap & typeVars );
     
    636637        ast::Expr const * ret = expr;
    637638
    638         // TODO: This entire section should probably be refactored to do less
    639         // pushing to the front/middle of a vector.
    640         ptrdiff_t initArgCount = mutExpr->args.size();
    641 
    642639        TypeVarMap exprTypeVars;
    643640        makeTypeVarMap( function, exprTypeVars );
     
    662659        }
    663660
    664         assert( typeSubs );
    665         ast::vector<ast::Expr>::iterator argIt =
    666                 passTypeVars( mutExpr, function );
    667         addInferredParams( mutExpr, argIt, function, exprTypeVars );
    668 
    669         argIt = mutExpr->args.begin();
    670         std::advance( argIt, ( mutExpr->args.size() - initArgCount ) );
    671 
    672         boxParams( mutExpr, argIt, function, exprTypeVars );
     661        ast::vector<ast::Expr> prependArgs;
     662        passTypeVars( mutExpr, prependArgs, function );
     663        addInferredParams( mutExpr, prependArgs, function, exprTypeVars );
     664
     665        boxParams( mutExpr, dynRetType, function, exprTypeVars );
     666        spliceBegin( mutExpr->args, prependArgs );
    673667        passAdapters( mutExpr, function, exprTypeVars );
    674668
     
    766760}
    767761
    768 ast::vector<ast::Expr>::iterator CallAdapter::passTypeVars(
     762void CallAdapter::passTypeVars(
    769763                ast::ApplicationExpr * expr,
     764                ast::vector<ast::Expr> & extraArgs,
    770765                ast::FunctionType const * function ) {
    771766        assert( typeSubs );
    772         ast::vector<ast::Expr>::iterator arg = expr->args.begin();
    773767        // Pass size/align for type variables.
    774768        for ( ast::ptr<ast::TypeInstType> const & typeVar : function->forall ) {
     
    780774                                                   toString( typeSubs ).c_str(), typeVar->typeString().c_str() );
    781775                }
    782                 arg = expr->args.insert( arg,
     776                extraArgs.emplace_back(
    783777                        new ast::SizeofExpr( expr->location, ast::deepCopy( concrete ) ) );
    784                 arg++;
    785                 arg = expr->args.insert( arg,
     778                extraArgs.emplace_back(
    786779                        new ast::AlignofExpr( expr->location, ast::deepCopy( concrete ) ) );
    787                 arg++;
    788         }
    789         return arg;
     780        }
    790781}
    791782
     
    913904
    914905void CallAdapter::boxParams(
    915                 ast::ApplicationExpr const * expr,
    916                 ast::vector<ast::Expr>::iterator arg,
     906                ast::ApplicationExpr * expr,
     907                ast::Type const * polyRetType,
    917908                ast::FunctionType const * function,
    918909                const TypeVarMap & typeVars ) {
     910        // Start at the beginning, but the return argument may have been added.
     911        auto arg = expr->args.begin();
     912        if ( polyRetType ) ++arg;
     913
    919914        for ( auto param : function->params ) {
    920915                assertf( arg != expr->args.end(),
     
    928923void CallAdapter::addInferredParams(
    929924                ast::ApplicationExpr * expr,
    930                 ast::vector<ast::Expr>::iterator arg,
     925                ast::vector<ast::Expr> & extraArgs,
    931926                ast::FunctionType const * functionType,
    932927                TypeVarMap const & typeVars ) {
    933         ast::vector<ast::Expr>::iterator cur = arg;
    934928        for ( auto assertion : functionType->assertions ) {
    935929                auto inferParam = expr->inferred.inferParams().find(
     
    940934                ast::ptr<ast::Expr> newExpr = ast::deepCopy( inferParam->second.expr );
    941935                boxParam( newExpr, assertion->result, typeVars );
    942                 cur = expr->args.insert( cur, newExpr.release() );
    943                 ++cur;
     936                extraArgs.emplace_back( newExpr.release() );
    944937        }
    945938}
Note: See TracChangeset for help on using the changeset viewer.