Ignore:
Timestamp:
Sep 14, 2023, 11:44:35 AM (10 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
697c957
Parents:
a738c68
Message:

Some mistakes in isPolyType found while working on the box pass. There was a new-ast verison using the old type map and, perhaps relatedly, the new type map version recursed into the no type map form. Also some clean-up in related functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/GenPoly.cc

    ra738c68 r3df4cd9  
    4848                }
    4949
    50                 bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const ast::TypeSubstitution * env) {
    51                         for (auto &param : params) {
    52                                 auto paramType = param.strict_as<ast::TypeExpr>();
    53                                 if (isPolyType(paramType->type, env)) return true;
     50                bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const ast::TypeSubstitution * env ) {
     51                        for ( auto &param : params ) {
     52                                auto paramType = param.as<ast::TypeExpr>();
     53                                assertf( paramType, "Aggregate parameters should be type expressions" );
     54                                if ( isPolyType( paramType->type, env ) ) return true;
    5455                        }
    5556                        return false;
     
    6263                                assertf(paramType, "Aggregate parameters should be type expressions");
    6364                                if ( isPolyType( paramType->get_type(), tyVars, env ) ) return true;
     65                        }
     66                        return false;
     67                }
     68
     69                bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const TypeVarMap & typeVars, const ast::TypeSubstitution * env ) {
     70                        for ( auto & param : params ) {
     71                                auto paramType = param.as<ast::TypeExpr>();
     72                                assertf( paramType, "Aggregate parameters should be type expressions" );
     73                                if ( isPolyType( paramType->type, typeVars, env ) ) return true;
    6474                        }
    6575                        return false;
     
    185195        }
    186196
    187         const ast::Type * isPolyType(const ast::Type * type, const TyVarMap & tyVars, const ast::TypeSubstitution * env) {
    188                 type = replaceTypeInst( type, env );
    189 
    190                 if ( auto typeInst = dynamic_cast< const ast::TypeInstType * >( type ) ) {
    191                         if ( tyVars.contains( typeInst->typeString() ) ) return type;
    192                 } else if ( auto arrayType = dynamic_cast< const ast::ArrayType * >( type ) ) {
    193                         return isPolyType( arrayType->base, env );
    194                 } else if ( auto structType = dynamic_cast< const ast::StructInstType* >( type ) ) {
    195                         if ( hasPolyParams( structType->params, env ) ) return type;
    196                 } else if ( auto unionType = dynamic_cast< const ast::UnionInstType* >( type ) ) {
    197                         if ( hasPolyParams( unionType->params, env ) ) return type;
    198                 }
    199                 return nullptr;
    200         }
    201 
    202197const ast::Type * isPolyType( const ast::Type * type,
    203198                const TypeVarMap & typeVars, const ast::TypeSubstitution * subst ) {
     
    207202                if ( typeVars.contains( *inst ) ) return type;
    208203        } else if ( auto array = dynamic_cast< const ast::ArrayType * >( type ) ) {
    209                 return isPolyType( array->base, subst );
     204                return isPolyType( array->base, typeVars, subst );
    210205        } else if ( auto sue = dynamic_cast< const ast::StructInstType * >( type ) ) {
    211                 if ( hasPolyParams( sue->params, subst ) ) return type;
     206                if ( hasPolyParams( sue->params, typeVars, subst ) ) return type;
    212207        } else if ( auto sue = dynamic_cast< const ast::UnionInstType * >( type ) ) {
    213                 if ( hasPolyParams( sue->params, subst ) ) return type;
     208                if ( hasPolyParams( sue->params, typeVars, subst ) ) return type;
    214209        }
    215210        return nullptr;
Note: See TracChangeset for help on using the changeset viewer.