Changeset 623ecf3 for src


Ignore:
Timestamp:
Mar 21, 2017, 3:26:09 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
597db97
Parents:
f5392c1
Message:

trim type environment for specialized expressions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Specialize.cc

    rf5392c1 r623ecf3  
    168168        }
    169169
     170        struct EnvTrimmer : public Visitor {
     171                TypeSubstitution * env, * newEnv;
     172                EnvTrimmer( TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){}
     173                virtual void visit( TypeDecl * tyDecl ) {
     174                        // transfer known bindings for seen type variables
     175                        if ( Type * t = env->lookup( tyDecl->get_name() ) ) {
     176                                newEnv->add( tyDecl->get_name(), t );
     177                        }
     178                }
     179        };
     180
     181        /// reduce environment to just the parts that are referenced in a given expression
     182        TypeSubstitution * trimEnv( ApplicationExpr * expr, TypeSubstitution * env ) {
     183                if ( env ) {
     184                        TypeSubstitution * newEnv = new TypeSubstitution();
     185                        EnvTrimmer trimmer( env, newEnv );
     186                        expr->accept( trimmer );
     187                        return newEnv;
     188                }
     189                return nullptr;
     190        }
     191
    170192        /// Generates a thunk that calls `actual` with type `funType` and returns its address
    171193        Expression * Specialize::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) {
     
    211233                }
    212234
    213                 appExpr->set_env( maybeClone( env ) );
     235                appExpr->set_env( trimEnv( appExpr, env ) );
    214236                if ( inferParams ) {
    215237                        appExpr->get_inferParams() = *inferParams;
Note: See TracChangeset for help on using the changeset viewer.