Ignore:
Timestamp:
Jul 11, 2018, 4:26:22 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env
Children:
d318a18
Parents:
184557e
git-author:
Aaron Moss <a3moss@…> (07/11/18 16:10:36)
git-committer:
Aaron Moss <a3moss@…> (07/11/18 16:26:22)
Message:

Persistent-array environment compiles

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/TypeEnvironment.cc

    r184557e r5c14030  
    2727#include "SynTree/Type.h"              // for Type, FunctionType, Type::Fora...
    2828#include "SynTree/TypeSubstitution.h"  // for TypeSubstitution
     29#include "Tuples/Tuples.h"             // for isTtype
    2930#include "TypeEnvironment.h"
    3031#include "typeops.h"                   // for occurs
     
    104105                auto tyVar = openVars.find( typeInst->get_name() );
    105106                assert( tyVar != openVars.end() );
    106                 if ( ! tyVarCompatible( tyVar->second, other ) ) return false;
     107                if ( ! tyVarCompatible( tyVar->second, bindTo ) ) return false;
    107108
    108109                if ( occurs( bindTo, typeInst->get_name(), *this ) ) return false;
     
    135136                } else {
    136137                        // make new class consisting entirely of this variable
    137                         BoundType curData{ bindTo->clone(), widenMode.first && widenMode.second, data };
     138                        BoundType curData{
     139                                bindTo->clone(), widenMode.widenFirst && widenMode.widenSecond, data };
    138140                        curData.type->get_qualifiers() = Type::Qualifiers{};
    139141                        classes = classes->add( curClass.get_root() );
     
    146148                        const TypeDecl::Data& data, AssertionSet& need, AssertionSet& have,
    147149                        const OpenVarSet& openVars, WidenMode widenMode, const SymTab::Indexer& indexer ) {
    148                 ClassRef class1 = env.lookup( var1->get_name() );
    149                 ClassRef class2 = env.lookup( var2->get_name() );
     150                ClassRef class1 = lookup( var1->get_name() );
     151                ClassRef class2 = lookup( var2->get_name() );
    150152               
    151153                // exit early if variables already bound together
     
    153155                        BoundType data1 = class1.get_bound();
    154156                        // narrow the binding if needed
    155                         if ( data1.allowWidening && widenMode.first != widenMode.second ) {
     157                        if ( data1.allowWidening && widenMode.widenFirst != widenMode.widenSecond ) {
    156158                                data1.allowWidening = false;
    157159                                bindings = bindings->set( class1.get_root(), data1 );
     
    172174                                        openVars, WidenMode{ widen1, widen2 }, indexer, common ) ) {
    173175                                // merge type variables
    174                                 interned_string root = mergeClasses( class1.update_root(), class2.update_root() );
     176                                interned_string root =
     177                                        mergeClasses( class1.update_root(), class2.update_root() ).first;
    175178                                // update bindings
    176179                                data1.allowWidening = widen1 && widen2;
     
    197200                                if ( data2.allowWidening != widen2 ) {
    198201                                        data2.allowWidening = widen2;
    199                                         bindings = bindings->set( root, data2 );
     202                                        bindings = bindings->set( merged.first, data2 );
    200203                                } else if ( merged.first == class1.get_root() ) {
    201204                                        bindings = bindings->set( merged.first, data2 );
     
    249252                        // filter overlapping classes out of existing environment
    250253                        // (this is a very shady assumption, but has worked for a long time...)
    251                         interned_string root = classes->find_or_default( v, not_found );
     254                        interned_string root = classes->find_or_default( var, not_found );
    252255                        if ( root != not_found ) {
    253256                                classes = classes->remove_class( root );
     
    262265                        // add variable to class and bindings
    263266                        classes = classes->add( var );
    264                         bindings = bindings->set( var, BoundType{ p.second->clone, false, data } );
     267                        bindings = bindings->set( var, BoundType{ p.second->clone(), false, data } );
    265268                }
    266269        }
    267270
    268271        void TypeEnvironment::makeSubstitution( TypeSubstitution &sub ) const {
    269                 bindings->apply_to_all([classes, &sub]( interned_string root, const BoundType& bound ){
    270                         classes->apply_to_class(root, [&]( interned_string var ) {
     272                bindings->for_each([&]( interned_string root, const BoundType& bound ){
     273                        classes->for_class(root, [&]( interned_string var ) {
    271274                                if ( bound.type ) {
    272275                                        sub.add( var, bound.type );
     
    282285
    283286        void TypeEnvironment::print( std::ostream &os, Indenter indent ) const {
    284                 bindings->apply_to_all([classes,&]( interned_string root, const BoundType& bound ) {
     287                bindings->for_each([&]( interned_string root, const BoundType& bound ) {
    285288                        os << "( ";
    286                         classes->apply_to_class( root, [&os]( interned_string var ) { os << var << " "; } );
     289                        classes->for_class( root, [&os]( interned_string var ) { os << var << " "; } );
    287290                        os << ")";
    288291                        if ( bound.type ) {
    289292                                os << " -> ";
    290                                 type->print( os, indent+1 );
     293                                bound.type->print( os, indent+1 );
    291294                        }
    292295                        if ( ! bound.allowWidening ) {
     
    298301
    299302        void TypeEnvironment::simpleCombine( const TypeEnvironment &o ) {
    300                 o.bindings->apply_to_all( [&]( interned_string root, const BoundType& bound ) {
     303                o.bindings->for_each( [&]( interned_string root, const BoundType& bound ) {
    301304                        // add members of new class
    302305                        interned_string new_root{nullptr};
    303                         o.classes->apply_to_class( root, [this,&new_root]( interned_string var ) {
     306                        o.classes->for_class( root, [this,&new_root]( interned_string var ) {
    304307                                classes = classes->add( var );
    305308                                new_root = new_root ? mergeClasses( new_root, var ).first : var;
     
    311314
    312315        void TypeEnvironment::extractOpenVars( OpenVarSet &openVars ) const {
    313                 bindings->apply_to_all( [classes,&openVars]( interned_string root, const BoundType& bound ) {
    314                         classes->apply_to_class( root, [&openVars,&bound]( interned_string var ) {
     316                bindings->for_each( [&]( interned_string root, const BoundType& bound ) {
     317                        classes->for_class( root, [&openVars,&bound]( interned_string var ) {
    315318                                openVars[ var ] = bound.data;
    316319                        } );
     
    319322
    320323        void TypeEnvironment::addActual( const TypeEnvironment& actualEnv, OpenVarSet& openVars ) {
    321                 actualEnv.bindings->apply_to_all( [&]( interned_string root, const BoundType& bound ) {
     324                actualEnv.bindings->for_each( [&]( interned_string root, const BoundType& bound ) {
    322325                        // add members of new class, setting openVars concurrently
    323326                        interned_string new_root{nullptr};
    324                         actualEnv.classes->apply_to_class( root, [&]( interned_string var ) {
     327                        actualEnv.classes->for_class( root, [&]( interned_string var ) {
    325328                                classes = classes->add( var );
    326329                                new_root = new_root ? mergeClasses( new_root, var ).first : var;
     
    334337
    335338        void TypeEnvironment::forbidWidening() {
    336                 bindings = bindings->apply_to_all([]( const interned_string& k, BoundType& c ) {
     339                bindings = bindings->mutate_each([]( const interned_string&, BoundType& c ) {
    337340                        if ( c.allowWidening ) {
    338341                                option<BoundType> ret = c;
Note: See TracChangeset for help on using the changeset viewer.