Ignore:
Timestamp:
Jun 1, 2023, 6:29:47 PM (13 months ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ast-experimental, master
Children:
24d6572, ded6c2a6
Parents:
1803d4d
Message:

remove reference to symbol table in unify

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CommonType.cc

    r1803d4d r251ce80  
    676676                const ast::Type * type2;
    677677                WidenMode widen;
    678                 const ast::SymbolTable & symtab;
    679678                ast::TypeEnvironment & tenv;
    680679                const ast::OpenVarSet & open;
     
    686685
    687686                CommonType_new(
    688                         const ast::Type * t2, WidenMode w, const ast::SymbolTable & st,
     687                        const ast::Type * t2, WidenMode w,
    689688                        ast::TypeEnvironment & env, const ast::OpenVarSet & o,
    690689                        ast::AssertionSet & need, ast::AssertionSet & have )
    691                 : type2( t2 ), widen( w ), symtab( st ), tenv( env ), open( o ), need (need), have (have) ,result() {}
     690                : type2( t2 ), widen( w ), tenv( env ), open( o ), need (need), have (have) ,result() {}
    692691
    693692                void previsit( const ast::Node * ) { visit_children = false; }
     
    749748                                        ast::AssertionSet need, have;
    750749                                        if ( ! tenv.bindVar(
    751                                                 var, voidPtr->base, entry->second, need, have, open, widen, symtab )
     750                                                var, voidPtr->base, entry->second, need, have, open, widen )
    752751                                        ) return;
    753752                                }
     
    762761                                ast::OpenVarSet newOpen{ open };
    763762                                if (enumInst->base->base
    764                                 && unifyExact(type1, enumInst->base->base, tenv, need, have, newOpen, widen, symtab)) {
     763                                && unifyExact(type1, enumInst->base->base, tenv, need, have, newOpen, widen)) {
    765764                                        result = type1;
    766765                                        return true;
     
    799798
    800799                                        ast::OpenVarSet newOpen{ open };
    801                                         if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) {
     800                                        if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() ) ) {
    802801                                                result = pointer;
    803802                                                if ( q1.val != q2.val ) {
     
    842841                                                                if (unifyExact(
    843842                                                                        arg1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open,
    844                                                                         noWiden(), symtab )) {
     843                                                                        noWiden() )) {
    845844                                                                                break;
    846845
     
    851850                                                                if (unifyExact(
    852851                                                                        tupleFromTypes( crnt1, end1 ), arg2, tenv, need, have, open,
    853                                                                         noWiden(), symtab )) {
     852                                                                        noWiden() )) {
    854853                                                                                break;
    855854
     
    875874
    876875                                                                                if ( ! unifyExact(
    877                                                                                         base1, base2, tenv, need, have, open, noWiden(), symtab )
     876                                                                                        base1, base2, tenv, need, have, open, noWiden() )
    878877                                                                                ) return;
    879878                                                                        }       
     
    895894
    896895                                                                                if ( ! unifyExact(
    897                                                                                         base1, base2, tenv, need, have, open, noWiden(), symtab )
     896                                                                                        base1, base2, tenv, need, have, open, noWiden() )
    898897                                                                                ) return;
    899898                                                                        }       
     
    903902                                                        }
    904903                                                        else if (! unifyExact(
    905                                                                 arg1, arg2, tenv, need, have, open, noWiden(), symtab )) return;
     904                                                                arg1, arg2, tenv, need, have, open, noWiden() )) return;
    906905
    907906                                                        ++crnt1; ++crnt2;
     
    913912                                                        if (! unifyExact(
    914913                                                                t1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open,
    915                                                                 noWiden(), symtab )) return;
     914                                                                noWiden() )) return;
    916915                                                } else if ( crnt2 != end2 ) {
    917916                                                        // try unifying empty tuple with ttype
     
    920919                                                        if (! unifyExact(
    921920                                                                tupleFromTypes( crnt1, end1 ), t2, tenv, need, have, open,
    922                                                                 noWiden(), symtab )) return;
     921                                                                noWiden() )) return;
    923922                                                }
    924923                                                if ((f1->returns.size() == 0 && f2->returns.size() == 0)
    925                                                   || (f1->returns.size() == 1 && f2->returns.size() == 1 && unifyExact(f1->returns[0], f2->returns[0], tenv, need, have, open, noWiden(), symtab))) {
     924                                                  || (f1->returns.size() == 1 && f2->returns.size() == 1 && unifyExact(f1->returns[0], f2->returns[0], tenv, need, have, open, noWiden()))) {
    926925                                                        result = pointer;
    927926
     
    980979
    981980                                        ast::OpenVarSet newOpen{ open };
    982                                         if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) {
     981                                        if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() ) ) {
    983982                                                result = ref;
    984983                                                if ( q1.val != q2.val ) {
     
    995994                        } else {
    996995                                if (!dynamic_cast<const ast::EnumInstType *>(type2))
    997                                         result = commonType( type2, ref, tenv, need, have, open, widen, symtab );
     996                                        result = commonType( type2, ref, tenv, need, have, open, widen );
    998997                        }
    999998                }
     
    10131012                void postvisit( const ast::EnumInstType * enumInst ) {
    10141013                        if (!dynamic_cast<const ast::EnumInstType *>(type2))
    1015                                 result = commonType( type2, enumInst, tenv, need, have, open, widen, symtab);
     1014                                result = commonType( type2, enumInst, tenv, need, have, open, widen);
    10161015                }
    10171016
    10181017                void postvisit( const ast::TraitInstType * ) {}
    10191018
    1020                 void postvisit( const ast::TypeInstType * inst ) {
    1021                         if ( ! widen.first ) return;
    1022                         if ( const ast::NamedTypeDecl * nt = symtab.lookupType( inst->name ) ) {
    1023                                 if ( const ast::Type * base =
    1024                                                 strict_dynamic_cast< const ast::TypeDecl * >( nt )->base
    1025                                 ) {
    1026                                         ast::CV::Qualifiers q1 = inst->qualifiers, q2 = type2->qualifiers;
    1027 
    1028                                         // force t{1,2} to be cloned if their qualifiers must be mutated
    1029                                         ast::ptr< ast::Type > t1{ base }, t2{ type2 };
    1030                                         reset_qualifiers( t1, q1 );
    1031                                         reset_qualifiers( t2 );
    1032 
    1033                                         ast::OpenVarSet newOpen{ open };
    1034                                         if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) {
    1035                                                 result = type2;
    1036                                                 reset_qualifiers( result, q1 | q2 );
    1037                                         } else {
    1038                                                 tryResolveWithTypedEnum( t1 );
    1039                                         }
    1040                                 }
    1041                         }
    1042                 }
     1019                void postvisit( const ast::TypeInstType * inst ) {}
    10431020
    10441021                void postvisit( const ast::TupleType * tuple) {
     
    11031080                ast::ptr< ast::Type > handleReference(
    11041081                        const ast::ptr< ast::Type > & t1, const ast::ptr< ast::Type > & t2, WidenMode widen,
    1105                         const ast::SymbolTable & symtab, ast::TypeEnvironment & env,
     1082                        ast::TypeEnvironment & env,
    11061083                        const ast::OpenVarSet & open
    11071084                ) {
     
    11111088
    11121089                        // need unify to bind type variables
    1113                         if ( unify( t1, t2, env, have, need, newOpen, symtab, common ) ) {
     1090                        if ( unify( t1, t2, env, have, need, newOpen, common ) ) {
    11141091                                ast::CV::Qualifiers q1 = t1->qualifiers, q2 = t2->qualifiers;
    11151092                                PRINT(
     
    11351112                        const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2,
    11361113                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1137                         const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab
     1114                        const ast::OpenVarSet & open, WidenMode widen
    11381115        ) {
    11391116                unsigned depth1 = type1->referenceDepth();
     
    11501127                        if ( depth1 > depth2 ) {
    11511128                                assert( ref1 );
    1152                                 result = handleReference( ref1->base, type2, widen, symtab, env, open );
     1129                                result = handleReference( ref1->base, type2, widen, env, open );
    11531130                        } else {  // implies depth1 < depth2
    11541131                                assert( ref2 );
    1155                                 result = handleReference( type1, ref2->base, widen, symtab, env, open );
     1132                                result = handleReference( type1, ref2->base, widen, env, open );
    11561133                        }
    11571134
     
    11711148                }
    11721149                // otherwise both are reference types of the same depth and this is handled by the visitor
    1173                 ast::Pass<CommonType_new> visitor{ type2, widen, symtab, env, open, need, have };
     1150                ast::Pass<CommonType_new> visitor{ type2, widen, env, open, need, have };
    11741151                type1->accept( visitor );
    1175                 ast::ptr< ast::Type > result = visitor.core.result;
    1176 
    1177                 // handling for opaque type declarations (?)
    1178                 if ( ! result && widen.second ) {
    1179                         if ( const ast::TypeInstType * inst = type2.as< ast::TypeInstType >() ) {
    1180                                 if ( const ast::NamedTypeDecl * nt = symtab.lookupType( inst->name ) ) {
    1181                                         auto type = strict_dynamic_cast< const ast::TypeDecl * >( nt );
    1182                                         if ( type->base ) {
    1183                                                 ast::CV::Qualifiers q1 = type1->qualifiers, q2 = type2->qualifiers;
    1184                                                 ast::OpenVarSet newOpen{ open };
    1185 
    1186                                                 // force t{1,2} to be cloned if its qualifiers must be stripped, so that
    1187                                                 // type1 and type->base are left unchanged; calling convention forces
    1188                                                 // {type1,type->base}->strong_ref >= 1
    1189                                                 ast::ptr<ast::Type> t1{ type1 }, t2{ type->base };
    1190                                                 reset_qualifiers( t1 );
    1191                                                 reset_qualifiers( t2, q1 );
    1192 
    1193                                                 if ( unifyExact( t1, t2, env, have, need, newOpen, noWiden(), symtab ) ) {
    1194                                                         result = t1;
    1195                                                         reset_qualifiers( result, q1 | q2 );
    1196                                                 }
    1197                                         }
    1198                                 }
    1199                         }
    1200                 }
    1201 
    1202                 return result;
     1152                // ast::ptr< ast::Type > result = visitor.core.result;
     1153
     1154                return visitor.core.result;
    12031155        }
    12041156
Note: See TracChangeset for help on using the changeset viewer.