Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    r251ce80 r5bf3976  
    128128                const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
    129129                ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    130                 WidenMode widen );
     130                WidenMode widen, const ast::SymbolTable & symtab );
    131131
    132132        bool typesCompatible( const Type * first, const Type * second, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {
     
    150150
    151151        bool typesCompatible(
    152                         const ast::Type * first, const ast::Type * second,
     152                        const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,
    153153                        const ast::TypeEnvironment & env ) {
    154154                ast::TypeEnvironment newEnv;
     
    163163                findOpenVars( newSecond, open, closed, need, have, FirstOpen );
    164164
    165                 return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden() );
     165                return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab );
    166166        }
    167167
     
    183183
    184184        bool typesCompatibleIgnoreQualifiers(
    185                         const ast::Type * first, const ast::Type * second,
     185                        const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,
    186186                        const ast::TypeEnvironment & env ) {
    187187                ast::TypeEnvironment newEnv;
     
    216216                        subFirst,
    217217                        subSecond,
    218                         newEnv, need, have, open, noWiden() );
     218                        newEnv, need, have, open, noWiden(), symtab );
    219219        }
    220220
     
    786786                const ast::OpenVarSet & open;
    787787                WidenMode widen;
     788                const ast::SymbolTable & symtab;
    788789        public:
    789790                static size_t traceId;
     
    792793                Unify_new(
    793794                        const ast::Type * type2, ast::TypeEnvironment & env, ast::AssertionSet & need,
    794                         ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen )
     795                        ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen,
     796                        const ast::SymbolTable & symtab )
    795797                : type2(type2), tenv(env), need(need), have(have), open(open), widen(widen),
    796                 result(false) {}
     798                  symtab(symtab), result(false) {}
    797799
    798800                void previsit( const ast::Node * ) { visit_children = false; }
     
    812814                                result = unifyExact(
    813815                                        pointer->base, pointer2->base, tenv, need, have, open,
    814                                         noWiden());
     816                                        noWiden(), symtab );
    815817                        }
    816818                }
     
    835837
    836838                        result = unifyExact(
    837                                 array->base, array2->base, tenv, need, have, open, noWiden());
     839                                array->base, array2->base, tenv, need, have, open, noWiden(),
     840                                symtab );
    838841                }
    839842
     
    841844                        if ( auto ref2 = dynamic_cast< const ast::ReferenceType * >( type2 ) ) {
    842845                                result = unifyExact(
    843                                         ref->base, ref2->base, tenv, need, have, open, noWiden());
     846                                        ref->base, ref2->base, tenv, need, have, open, noWiden(),
     847                                        symtab );
    844848                        }
    845849                }
     
    850854                static bool unifyTypeList(
    851855                        Iter crnt1, Iter end1, Iter crnt2, Iter end2, ast::TypeEnvironment & env,
    852                         ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open
     856                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
     857                        const ast::SymbolTable & symtab
    853858                ) {
    854859                        while ( crnt1 != end1 && crnt2 != end2 ) {
     
    863868                                        return unifyExact(
    864869                                                t1, tupleFromTypes( crnt2, end2 ), env, need, have, open,
    865                                                 noWiden() );
     870                                                noWiden(), symtab );
    866871                                } else if ( ! isTuple1 && isTuple2 ) {
    867872                                        // combine remainder of list1, then unify
    868873                                        return unifyExact(
    869874                                                tupleFromTypes( crnt1, end1 ), t2, env, need, have, open,
    870                                                 noWiden() );
     875                                                noWiden(), symtab );
    871876                                }
    872877
    873878                                if ( ! unifyExact(
    874                                         t1, t2, env, need, have, open, noWiden() )
     879                                        t1, t2, env, need, have, open, noWiden(), symtab )
    875880                                ) return false;
    876881
     
    886891                                return unifyExact(
    887892                                        t1, tupleFromTypes( crnt2, end2 ), env, need, have, open,
    888                                         noWiden() );
     893                                        noWiden(), symtab );
    889894                        } else if ( crnt2 != end2 ) {
    890895                                // try unifying empty tuple with ttype
     
    893898                                return unifyExact(
    894899                                        tupleFromTypes( crnt1, end1 ), t2, env, need, have, open,
    895                                         noWiden() );
     900                                        noWiden(), symtab );
    896901                        }
    897902
     
    903908                        const std::vector< ast::ptr< ast::Type > > & list2,
    904909                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    905                         const ast::OpenVarSet & open
     910                        const ast::OpenVarSet & open, const ast::SymbolTable & symtab
    906911                ) {
    907912                        return unifyTypeList(
    908                                 list1.begin(), list1.end(), list2.begin(), list2.end(), env, need, have, open);
     913                                list1.begin(), list1.end(), list2.begin(), list2.end(), env, need, have, open,
     914                                symtab );
    909915                }
    910916
     
    947953                        ) return;
    948954
    949                         if ( ! unifyTypeList( params, params2, tenv, need, have, open ) ) return;
     955                        if ( ! unifyTypeList( params, params2, tenv, need, have, open, symtab ) ) return;
    950956                        if ( ! unifyTypeList(
    951                                 func->returns, func2->returns, tenv, need, have, open ) ) return;
     957                                func->returns, func2->returns, tenv, need, have, open, symtab ) ) return;
    952958
    953959                        markAssertions( have, need, func );
     
    10201026
    10211027                                if ( ! unifyExact(
    1022                                                 pty, pty2, tenv, need, have, open, noWiden() ) ) {
     1028                                                pty, pty2, tenv, need, have, open, noWiden(), symtab ) ) {
    10231029                                        result = false;
    10241030                                        return;
     
    10591065                        const std::vector< ast::ptr< ast::Type > > & list1,
    10601066                        const std::vector< ast::ptr< ast::Type > > & list2, ast::TypeEnvironment & env,
    1061                         ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open
     1067                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
     1068                        const ast::SymbolTable & symtab
    10621069                ) {
    10631070                        auto crnt1 = list1.begin();
     
    10741081                                        return unifyExact(
    10751082                                                t1, tupleFromTypes( list2 ), env, need, have, open,
    1076                                                 noWiden() );
     1083                                                noWiden(), symtab );
    10771084                                } else if ( ! isTuple1 && isTuple2 ) {
    10781085                                        // combine entirety of list1, then unify
    10791086                                        return unifyExact(
    10801087                                                tupleFromTypes( list1 ), t2, env, need, have, open,
    1081                                                 noWiden() );
     1088                                                noWiden(), symtab );
    10821089                                }
    10831090
    10841091                                if ( ! unifyExact(
    1085                                         t1, t2, env, need, have, open, noWiden() )
     1092                                        t1, t2, env, need, have, open, noWiden(), symtab )
    10861093                                ) return false;
    10871094
     
    10971104                                return unifyExact(
    10981105                                                t1, tupleFromTypes( list2 ), env, need, have, open,
    1099                                                 noWiden() );
     1106                                                noWiden(), symtab );
    11001107                        } else if ( crnt2 != list2.end() ) {
    11011108                                // try unifying empty tuple with ttype
     
    11061113                                return unifyExact(
    11071114                                                tupleFromTypes( list1 ), t2, env, need, have, open,
    1108                                                 noWiden() );
     1115                                                noWiden(), symtab );
    11091116                        }
    11101117
     
    11251132                        auto types2 = flatten( flat2 );
    11261133
    1127                         result = unifyList( types, types2, tenv, need, have, open );
     1134                        result = unifyList( types, types2, tenv, need, have, open, symtab );
    11281135                }
    11291136
     
    11491156                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    11501157                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1151                         ast::OpenVarSet & open
     1158                        ast::OpenVarSet & open, const ast::SymbolTable & symtab
    11521159        ) {
    11531160                ast::ptr<ast::Type> common;
    1154                 return unify( type1, type2, env, need, have, open, common );
     1161                return unify( type1, type2, env, need, have, open, symtab, common );
    11551162        }
    11561163
     
    11581165                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    11591166                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1160                         ast::OpenVarSet & open, ast::ptr<ast::Type> & common
     1167                        ast::OpenVarSet & open, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common
    11611168        ) {
    11621169                ast::OpenVarSet closed;
     
    11641171                findOpenVars( type2, open, closed, need, have, FirstOpen );
    11651172                return unifyInexact(
    1166                         type1, type2, env, need, have, open, WidenMode{ true, true }, common );
     1173                        type1, type2, env, need, have, open, WidenMode{ true, true }, symtab, common );
    11671174        }
    11681175
     
    11701177                        const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
    11711178                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    1172                         WidenMode widen
     1179                        WidenMode widen, const ast::SymbolTable & symtab
    11731180        ) {
    11741181                if ( type1->qualifiers != type2->qualifiers ) return false;
     
    11861193                        return env.bindVarToVar(
    11871194                                var1, var2, ast::TypeData{ entry1->second, entry2->second }, need, have,
    1188                                 open, widen );
     1195                                open, widen, symtab );
    11891196                } else if ( isopen1 ) {
    1190                         return env.bindVar( var1, type2, entry1->second, need, have, open, widen );
     1197                        return env.bindVar( var1, type2, entry1->second, need, have, open, widen, symtab );
    11911198                } else if ( isopen2 ) {
    1192                         return env.bindVar( var2, type1, entry2->second, need, have, open, widen );
     1199                        return env.bindVar( var2, type1, entry2->second, need, have, open, widen, symtab );
    11931200                } else {
    11941201                        return ast::Pass<Unify_new>::read(
    1195                                 type1, type2, env, need, have, open, widen );
     1202                                type1, type2, env, need, have, open, widen, symtab );
    11961203                }
    11971204        }
     
    12001207                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    12011208                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1202                         const ast::OpenVarSet & open, WidenMode widen,
     1209                        const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab,
    12031210                        ast::ptr<ast::Type> & common
    12041211        ) {
     
    12141221                ast::ptr< ast::Type > t2_(t2);
    12151222
    1216                 if ( unifyExact( t1, t2, env, need, have, open, widen ) ) {
     1223                if ( unifyExact( t1, t2, env, need, have, open, widen, symtab ) ) {
    12171224                        // if exact unification on unqualified types, try to merge qualifiers
    12181225                        if ( q1 == q2 || ( ( q1 > q2 || widen.first ) && ( q2 > q1 || widen.second ) ) ) {
     
    12241231                        }
    12251232
    1226                 } else if (( common = commonType( t1, t2, env, need, have, open, widen ))) {
     1233                } else if (( common = commonType( t1, t2, env, need, have, open, widen, symtab ))) {
    12271234                        // no exact unification, but common type
    12281235                        auto c = shallowCopy(common.get());
Note: See TracChangeset for help on using the changeset viewer.