Changeset f229fc2 for src/ResolvExpr


Ignore:
Timestamp:
Apr 13, 2018, 12:25:33 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
b5aa3d8
Parents:
09a1ae6
Message:

Modify resolver to use young-generation collection per-top-level expression

Location:
src/ResolvExpr
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Alternative.cc

    r09a1ae6 rf229fc2  
    2020#include <utility>                       // for move
    2121
     22#include "Common/GC.h"
     23#include "Common/PassVisitor.h"
    2224#include "Common/utility.h"              // for maybeClone
    2325#include "ResolvExpr/Cost.h"             // for Cost, Cost::zero, operator<<
    2426#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
    2527#include "SynTree/Expression.h"          // for Expression
     28#include "SynTree/GcTracer.h"
    2629#include "SynTree/Type.h"                // for Type
    2730
     
    6467        }
    6568
     69        const GC& operator<< ( const GC& gc, const Alternative& alt ) {
     70                PassVisitor<GcTracer> tracer{ gc };
     71                maybeAccept( alt.expr, tracer );
     72                tracer << alt.env;
     73                return gc;
     74        }
     75
    6676} // namespace ResolvExpr
    6777
  • src/ResolvExpr/Alternative.h

    r09a1ae6 rf229fc2  
    2323
    2424class Expression;
     25
     26class GC;
    2527
    2628namespace ResolvExpr {
     
    5254                return os;
    5355        }
     56
     57        const GC& operator<< ( const GC&, const Alternative& );
    5458} // namespace ResolvExpr
    5559
  • src/ResolvExpr/Resolver.cc

    r09a1ae6 rf229fc2  
    2222#include "Alternative.h"                 // for Alternative, AltList
    2323#include "AlternativeFinder.h"           // for AlternativeFinder, resolveIn...
     24#include "Common/GC.h"                   // for new_generation, collect_young
    2425#include "Common/PassVisitor.h"          // for PassVisitor
    2526#include "Common/SemanticError.h"        // for SemanticError
     
    146147                void findUnfinishedKindExpression(Expression * untyped, Alternative & alt, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, bool adjust = false, bool prune = true, bool failFast = true) {
    147148                        assertf( untyped, "expected a non-null expression." );
     149
     150                        new_generation();  // set up GC young generation for this top-level expression
     151
    148152                        TypeEnvironment env;
    149153                        AlternativeFinder finder( indexer, env );
     
    173177                        findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) );
    174178                        if ( winners.size() == 0 ) {
    175                                 SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") );
     179                                collect_young();
     180                                SemanticError( untyped, toString(
     181                                        "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""),
     182                                        "expression: ") );
    176183                        } else if ( winners.size() != 1 ) {
    177184                                std::ostringstream stream;
    178                                 stream << "Cannot choose between " << winners.size() << " alternatives for " << kindStr << (kindStr != "" ? " " : "") << "expression\n";
     185                                stream << "Cannot choose between " << winners.size() << " alternatives for "
     186                                        << kindStr << (kindStr != "" ? " " : "") << "expression\n";
    179187                                untyped->print( stream );
    180188                                stream << " Alternatives are:\n";
    181189                                printAlts( winners, stream, 1 );
     190                               
     191                                collect_young();
    182192                                SemanticError( untyped->location, stream.str() );
    183193                        }
     
    186196                        Alternative & choice = winners.front();
    187197                        if ( findDeletedExpr( choice.expr ) ) {
    188                                 SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " );
     198                                collect_young( choice.expr );
     199                                SemanticError( choice.expr,
     200                                        "Unique best alternative includes deleted identifier in " );
    189201                        }
    190202                        alt = std::move( choice );
     203                        collect_young( alt );
    191204                }
    192205
  • src/ResolvExpr/TypeEnvironment.cc

    r09a1ae6 rf229fc2  
    1919#include <utility>                     // for pair
    2020
     21#include "Common/PassVisitor.h"        // for PassVisitor<GcTracer>
    2122#include "Common/utility.h"            // for maybeClone
     23#include "SynTree/GcTracer.h"          // for PassVisitor<GcTracer>
    2224#include "SynTree/Type.h"              // for Type, FunctionType, Type::Fora...
    2325#include "SynTree/TypeSubstitution.h"  // for TypeSubstitution
     
    222224                return out;
    223225        }
     226
     227        PassVisitor<GcTracer> & operator<<( PassVisitor<GcTracer> & gc, const TypeEnvironment & env ) {
     228                for ( const EqvClass & c : env ) {
     229                        maybeAccept( c.type, gc );
     230                }
     231                return gc;
     232        }
    224233} // namespace ResolvExpr
    225234
  • src/ResolvExpr/TypeEnvironment.h

    r09a1ae6 rf229fc2  
    2626#include "SynTree/Type.h"              // for Type, Type::ForallList
    2727#include "SynTree/TypeSubstitution.h"  // for TypeSubstitution
     28
     29template< typename Pass >
     30class PassVisitor;
     31class GcTracer;
    2832
    2933namespace ResolvExpr {
     
    116120
    117121        std::ostream & operator<<( std::ostream & out, const TypeEnvironment & env );
     122
     123        PassVisitor<GcTracer> & operator<<( PassVisitor<GcTracer> & gc, const TypeEnvironment & env );
    118124} // namespace ResolvExpr
    119125
Note: See TracChangeset for help on using the changeset viewer.