Ignore:
Timestamp:
Jun 12, 2023, 12:05:58 PM (3 years ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
fec8bd1
Parents:
2b78949 (diff), 38e266ca (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    r2b78949 r8a930c03  
    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, const ast::SymbolTable & symtab );
     130                WidenMode widen );
    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, const ast::SymbolTable & symtab,
     152                        const ast::Type * first, const ast::Type * second,
    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(), symtab );
     165                return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden() );
    166166        }
    167167
     
    183183
    184184        bool typesCompatibleIgnoreQualifiers(
    185                         const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,
     185                        const ast::Type * first, const ast::Type * second,
    186186                        const ast::TypeEnvironment & env ) {
    187187                ast::TypeEnvironment newEnv;
     
    216216                        subFirst,
    217217                        subSecond,
    218                         newEnv, need, have, open, noWiden(), symtab );
     218                        newEnv, need, have, open, noWiden() );
    219219        }
    220220
     
    786786                const ast::OpenVarSet & open;
    787787                WidenMode widen;
    788                 const ast::SymbolTable & symtab;
    789788        public:
    790789                static size_t traceId;
     
    793792                Unify_new(
    794793                        const ast::Type * type2, ast::TypeEnvironment & env, ast::AssertionSet & need,
    795                         ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen,
    796                         const ast::SymbolTable & symtab )
     794                        ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen )
    797795                : type2(type2), tenv(env), need(need), have(have), open(open), widen(widen),
    798                   symtab(symtab), result(false) {}
     796                result(false) {}
    799797
    800798                void previsit( const ast::Node * ) { visit_children = false; }
     
    814812                                result = unifyExact(
    815813                                        pointer->base, pointer2->base, tenv, need, have, open,
    816                                         noWiden(), symtab );
     814                                        noWiden());
    817815                        }
    818816                }
     
    837835
    838836                        result = unifyExact(
    839                                 array->base, array2->base, tenv, need, have, open, noWiden(),
    840                                 symtab );
     837                                array->base, array2->base, tenv, need, have, open, noWiden());
    841838                }
    842839
     
    844841                        if ( auto ref2 = dynamic_cast< const ast::ReferenceType * >( type2 ) ) {
    845842                                result = unifyExact(
    846                                         ref->base, ref2->base, tenv, need, have, open, noWiden(),
    847                                         symtab );
     843                                        ref->base, ref2->base, tenv, need, have, open, noWiden());
    848844                        }
    849845                }
     
    854850                static bool unifyTypeList(
    855851                        Iter crnt1, Iter end1, Iter crnt2, Iter end2, ast::TypeEnvironment & env,
    856                         ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    857                         const ast::SymbolTable & symtab
     852                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open
    858853                ) {
    859854                        while ( crnt1 != end1 && crnt2 != end2 ) {
     
    868863                                        return unifyExact(
    869864                                                t1, tupleFromTypes( crnt2, end2 ), env, need, have, open,
    870                                                 noWiden(), symtab );
     865                                                noWiden() );
    871866                                } else if ( ! isTuple1 && isTuple2 ) {
    872867                                        // combine remainder of list1, then unify
    873868                                        return unifyExact(
    874869                                                tupleFromTypes( crnt1, end1 ), t2, env, need, have, open,
    875                                                 noWiden(), symtab );
     870                                                noWiden() );
    876871                                }
    877872
    878873                                if ( ! unifyExact(
    879                                         t1, t2, env, need, have, open, noWiden(), symtab )
     874                                        t1, t2, env, need, have, open, noWiden() )
    880875                                ) return false;
    881876
     
    891886                                return unifyExact(
    892887                                        t1, tupleFromTypes( crnt2, end2 ), env, need, have, open,
    893                                         noWiden(), symtab );
     888                                        noWiden() );
    894889                        } else if ( crnt2 != end2 ) {
    895890                                // try unifying empty tuple with ttype
     
    898893                                return unifyExact(
    899894                                        tupleFromTypes( crnt1, end1 ), t2, env, need, have, open,
    900                                         noWiden(), symtab );
     895                                        noWiden() );
    901896                        }
    902897
     
    908903                        const std::vector< ast::ptr< ast::Type > > & list2,
    909904                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    910                         const ast::OpenVarSet & open, const ast::SymbolTable & symtab
     905                        const ast::OpenVarSet & open
    911906                ) {
    912907                        return unifyTypeList(
    913                                 list1.begin(), list1.end(), list2.begin(), list2.end(), env, need, have, open,
    914                                 symtab );
     908                                list1.begin(), list1.end(), list2.begin(), list2.end(), env, need, have, open);
    915909                }
    916910
     
    953947                        ) return;
    954948
    955                         if ( ! unifyTypeList( params, params2, tenv, need, have, open, symtab ) ) return;
     949                        if ( ! unifyTypeList( params, params2, tenv, need, have, open ) ) return;
    956950                        if ( ! unifyTypeList(
    957                                 func->returns, func2->returns, tenv, need, have, open, symtab ) ) return;
     951                                func->returns, func2->returns, tenv, need, have, open ) ) return;
    958952
    959953                        markAssertions( have, need, func );
     
    10261020
    10271021                                if ( ! unifyExact(
    1028                                                 pty, pty2, tenv, need, have, open, noWiden(), symtab ) ) {
     1022                                                pty, pty2, tenv, need, have, open, noWiden() ) ) {
    10291023                                        result = false;
    10301024                                        return;
     
    10651059                        const std::vector< ast::ptr< ast::Type > > & list1,
    10661060                        const std::vector< ast::ptr< ast::Type > > & list2, ast::TypeEnvironment & env,
    1067                         ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    1068                         const ast::SymbolTable & symtab
     1061                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open
    10691062                ) {
    10701063                        auto crnt1 = list1.begin();
     
    10811074                                        return unifyExact(
    10821075                                                t1, tupleFromTypes( list2 ), env, need, have, open,
    1083                                                 noWiden(), symtab );
     1076                                                noWiden() );
    10841077                                } else if ( ! isTuple1 && isTuple2 ) {
    10851078                                        // combine entirety of list1, then unify
    10861079                                        return unifyExact(
    10871080                                                tupleFromTypes( list1 ), t2, env, need, have, open,
    1088                                                 noWiden(), symtab );
     1081                                                noWiden() );
    10891082                                }
    10901083
    10911084                                if ( ! unifyExact(
    1092                                         t1, t2, env, need, have, open, noWiden(), symtab )
     1085                                        t1, t2, env, need, have, open, noWiden() )
    10931086                                ) return false;
    10941087
     
    11041097                                return unifyExact(
    11051098                                                t1, tupleFromTypes( list2 ), env, need, have, open,
    1106                                                 noWiden(), symtab );
     1099                                                noWiden() );
    11071100                        } else if ( crnt2 != list2.end() ) {
    11081101                                // try unifying empty tuple with ttype
     
    11131106                                return unifyExact(
    11141107                                                tupleFromTypes( list1 ), t2, env, need, have, open,
    1115                                                 noWiden(), symtab );
     1108                                                noWiden() );
    11161109                        }
    11171110
     
    11321125                        auto types2 = flatten( flat2 );
    11331126
    1134                         result = unifyList( types, types2, tenv, need, have, open, symtab );
     1127                        result = unifyList( types, types2, tenv, need, have, open );
    11351128                }
    11361129
     
    11561149                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    11571150                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1158                         ast::OpenVarSet & open, const ast::SymbolTable & symtab
     1151                        ast::OpenVarSet & open
    11591152        ) {
    11601153                ast::ptr<ast::Type> common;
    1161                 return unify( type1, type2, env, need, have, open, symtab, common );
     1154                return unify( type1, type2, env, need, have, open, common );
    11621155        }
    11631156
     
    11651158                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    11661159                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1167                         ast::OpenVarSet & open, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common
     1160                        ast::OpenVarSet & open, ast::ptr<ast::Type> & common
    11681161        ) {
    11691162                ast::OpenVarSet closed;
     
    11711164                findOpenVars( type2, open, closed, need, have, FirstOpen );
    11721165                return unifyInexact(
    1173                         type1, type2, env, need, have, open, WidenMode{ true, true }, symtab, common );
     1166                        type1, type2, env, need, have, open, WidenMode{ true, true }, common );
    11741167        }
    11751168
     
    11771170                        const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
    11781171                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    1179                         WidenMode widen, const ast::SymbolTable & symtab
     1172                        WidenMode widen
    11801173        ) {
    11811174                if ( type1->qualifiers != type2->qualifiers ) return false;
     
    11931186                        return env.bindVarToVar(
    11941187                                var1, var2, ast::TypeData{ entry1->second, entry2->second }, need, have,
    1195                                 open, widen, symtab );
     1188                                open, widen );
    11961189                } else if ( isopen1 ) {
    1197                         return env.bindVar( var1, type2, entry1->second, need, have, open, widen, symtab );
     1190                        return env.bindVar( var1, type2, entry1->second, need, have, open, widen );
    11981191                } else if ( isopen2 ) {
    1199                         return env.bindVar( var2, type1, entry2->second, need, have, open, widen, symtab );
     1192                        return env.bindVar( var2, type1, entry2->second, need, have, open, widen );
    12001193                } else {
    12011194                        return ast::Pass<Unify_new>::read(
    1202                                 type1, type2, env, need, have, open, widen, symtab );
     1195                                type1, type2, env, need, have, open, widen );
    12031196                }
    12041197        }
     
    12071200                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    12081201                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1209                         const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab,
     1202                        const ast::OpenVarSet & open, WidenMode widen,
    12101203                        ast::ptr<ast::Type> & common
    12111204        ) {
     
    12211214                ast::ptr< ast::Type > t2_(t2);
    12221215
    1223                 if ( unifyExact( t1, t2, env, need, have, open, widen, symtab ) ) {
     1216                if ( unifyExact( t1, t2, env, need, have, open, widen ) ) {
    12241217                        // if exact unification on unqualified types, try to merge qualifiers
    12251218                        if ( q1 == q2 || ( ( q1 > q2 || widen.first ) && ( q2 > q1 || widen.second ) ) ) {
     
    12311224                        }
    12321225
    1233                 } else if (( common = commonType( t1, t2, env, need, have, open, widen, symtab ))) {
     1226                } else if (( common = commonType( t1, t2, env, need, have, open, widen ))) {
    12341227                        // no exact unification, but common type
    12351228                        auto c = shallowCopy(common.get());
Note: See TracChangeset for help on using the changeset viewer.