Changeset 251ce80


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

remove reference to symbol table in unify

Location:
src
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • src/AST/SymbolTable.cpp

    r1803d4d r251ce80  
    278278                } else {
    279279                        // typedef redeclarations are errors only if types are different
    280                         if ( ! ResolvExpr::typesCompatible( existing->base, added->base, SymbolTable{} ) ) {
     280                        if ( ! ResolvExpr::typesCompatible( existing->base, added->base ) ) {
    281281                                SemanticError( added->location, "redeclaration of " + added->name );
    282282                        }
     
    643643        } else if ( existing.id->linkage.is_mangled
    644644                        || ResolvExpr::typesCompatible(
    645                                 added->get_type(), existing.id->get_type(), SymbolTable{} ) ) {
     645                                added->get_type(), existing.id->get_type() ) ) {
    646646
    647647                // it is a conflict if one declaration is deleted and the other is not
  • src/AST/TypeEnvironment.cpp

    r1803d4d r251ce80  
    178178
    179179bool TypeEnvironment::combine(
    180                 const TypeEnvironment & o, OpenVarSet & open, const SymbolTable & symtab ) {
     180                const TypeEnvironment & o, OpenVarSet & open ) {
    181181        // short-circuit easy cases
    182182        if ( o.empty() ) return true;
     
    201201                        EqvClass & r = *rt;
    202202                        // merge bindings
    203                         if ( ! mergeBound( r, c, open, symtab ) ) return false;
     203                        if ( ! mergeBound( r, c, open ) ) return false;
    204204                        // merge previous unbound variables into this class, checking occurs if needed
    205205                        if ( r.bound ) for ( const auto & u : c.vars ) {
     
    216216                                } else if ( st != rt ) {
    217217                                        // bound, but not to the same class
    218                                         if ( ! mergeClasses( rt, st, open, symtab ) ) return false;
     218                                        if ( ! mergeClasses( rt, st, open ) ) return false;
    219219                                }       // ignore bound into the same class
    220220                        }
     
    280280bool TypeEnvironment::bindVar(
    281281                const TypeInstType * typeInst, const Type * bindTo, const TypeData & data,
    282                 AssertionSet & need, AssertionSet & have, const OpenVarSet & open, WidenMode widen,
    283                 const SymbolTable & symtab
     282                AssertionSet & need, AssertionSet & have, const OpenVarSet & open, WidenMode widen
    284283) {
    285284        // remove references from bound type, so that type variables can only bind to value types
     
    300299                        if ( unifyInexact(
    301300                                        newType, target, *this, need, have, open,
    302                                         widen & WidenMode{ it->allowWidening, true }, symtab, common ) ) {
     301                                        widen & WidenMode{ it->allowWidening, true }, common ) ) {
    303302                                if ( common ) {
    304303                                        it->bound = std::move(common);
     
    321320                const TypeInstType * var1, const TypeInstType * var2, TypeData && data,
    322321                AssertionSet & need, AssertionSet & have, const OpenVarSet & open,
    323                 WidenMode widen, const SymbolTable & symtab
     322                WidenMode widen
    324323) {
    325324        auto c1 = internal_lookup( *var1 );
     
    358357
    359358                if ( unifyInexact(
    360                                 newType1, newType2, *this, need, have, open, newWidenMode, symtab, common ) ) {
     359                                newType1, newType2, *this, need, have, open, newWidenMode, common ) ) {
    361360                        c1->vars.insert( c2->vars.begin(), c2->vars.end() );
    362361                        c1->allowWidening = widen1 && widen2;
     
    409408
    410409bool TypeEnvironment::mergeBound(
    411                 EqvClass & to, const EqvClass & from, OpenVarSet & open, const SymbolTable & symtab ) {
     410                EqvClass & to, const EqvClass & from, OpenVarSet & open ) {
    412411        if ( from.bound ) {
    413412                if ( to.bound ) {
     
    419418
    420419                        if ( unifyInexact(
    421                                         toType, fromType, *this, need, have, open, widen, symtab, common ) ) {
     420                                        toType, fromType, *this, need, have, open, widen, common ) ) {
    422421                                // unifies, set common type if necessary
    423422                                if ( common ) {
     
    437436
    438437bool TypeEnvironment::mergeClasses(
    439         ClassList::iterator to, ClassList::iterator from, OpenVarSet & open, const SymbolTable & symtab
     438        ClassList::iterator to, ClassList::iterator from, OpenVarSet & open
    440439) {
    441440        EqvClass & r = *to, & s = *from;
    442441
    443442        // ensure bounds match
    444         if ( ! mergeBound( r, s, open, symtab ) ) return false;
     443        if ( ! mergeBound( r, s, open ) ) return false;
    445444
    446445        // check safely bindable
  • src/AST/TypeEnvironment.hpp

    r1803d4d r251ce80  
    169169        /// Merge environment with this one, checking compatibility.
    170170        /// Returns false if fails, but does NOT roll back partial changes.
    171         bool combine( const TypeEnvironment & o, OpenVarSet & openVars, const SymbolTable & symtab );
     171        bool combine( const TypeEnvironment & o, OpenVarSet & openVars );
    172172
    173173        /// Add all type variables in environment to open var list
     
    183183                const TypeInstType * typeInst, const Type * bindTo, const TypeData & data,
    184184                AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars,
    185                 ResolvExpr::WidenMode widen, const SymbolTable & symtab );
     185                ResolvExpr::WidenMode widen );
    186186
    187187        /// Binds the type classes represented by `var1` and `var2` together; will add one or both
     
    190190                const TypeInstType * var1, const TypeInstType * var2, TypeData && data,
    191191                AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars,
    192                 ResolvExpr::WidenMode widen, const SymbolTable & symtab );
     192                ResolvExpr::WidenMode widen );
    193193
    194194        /// Disallows widening for all bindings in the environment
     
    205205        /// Unifies the type bound of `to` with the type bound of `from`, returning false if fails
    206206        bool mergeBound(
    207                 EqvClass & to, const EqvClass & from, OpenVarSet & openVars, const SymbolTable & symtab );
     207                EqvClass & to, const EqvClass & from, OpenVarSet & openVars );
    208208
    209209        /// Merges two type classes from local environment, returning false if fails
    210210        bool mergeClasses(
    211                 ClassList::iterator to, ClassList::iterator from, OpenVarSet & openVars,
    212                 const SymbolTable & symtab );
     211                ClassList::iterator to, ClassList::iterator from, OpenVarSet & openVars);
    213212
    214213        /// Private lookup API; returns array index of string, or env.size() for not found
  • src/GenPoly/InstantiateGenericNew.cpp

    r1803d4d r251ce80  
    362362                        ResolvExpr::typesCompatible(
    363363                                memberExpr->result,
    364                                 memberExpr->member->get_type(), ast::SymbolTable() ) ) {
     364                                memberExpr->member->get_type() ) ) {
    365365                return memberExpr;
    366366        }
  • src/GenPoly/LvalueNew.cpp

    r1803d4d r251ce80  
    359359                                !ResolvExpr::typesCompatible(
    360360                                        srcType,
    361                                         strict_dynamic_cast<ast::ReferenceType const *>( dstType )->base,
    362                                         ast::SymbolTable() ) ) {
     361                                        strict_dynamic_cast<ast::ReferenceType const *>( dstType )->base ) ) {
    363362                        // Must keep cast if cast-to type is different from the actual type.
    364363                        return ast::mutate_field( expr, &ast::CastExpr::arg, ret );
     
    377376                if ( !ResolvExpr::typesCompatibleIgnoreQualifiers(
    378377                                dstType->stripReferences(),
    379                                 srcType->stripReferences(),
    380                                 ast::SymbolTable() ) ) {
     378                                srcType->stripReferences() ) ) {
    381379                        return ast::mutate_field( expr, &ast::CastExpr::arg, ret );
    382380                }
     
    393391                                ResolvExpr::typesCompatible(
    394392                                        expr->result,
    395                                         expr->arg->result, ast::SymbolTable() ) ) {
     393                                        expr->arg->result ) ) {
    396394                        PRINT(
    397395                                std::cerr << "types are compatible, removing cast: " << expr << '\n';
     
    590588                ast::OpenVarSet openVars;
    591589                ResolvExpr::unify( ret->arg2->result, ret->arg3->result, newEnv,
    592                         needAssertions, haveAssertions, openVars,
    593                         ast::SymbolTable(), common );
     590                        needAssertions, haveAssertions, openVars, common );
    594591                ret->result = common ? common : ast::deepCopy( ret->arg2->result );
    595592                return ret;
  • src/InitTweak/InitTweak.cc

    r1803d4d r251ce80  
    10661066        const ast::Type * t2 = ftype->params.back();
    10671067
    1068         return ResolvExpr::typesCompatibleIgnoreQualifiers( t1, t2, ast::SymbolTable() );
     1068        return ResolvExpr::typesCompatibleIgnoreQualifiers( t1, t2 );
    10691069}
    10701070
  • src/ResolvExpr/CandidateFinder.cpp

    r1803d4d r251ce80  
    373373                                                        unify(
    374374                                                                ttype, argType, newResult.env, newResult.need, newResult.have,
    375                                                                 newResult.open, symtab )
     375                                                                newResult.open )
    376376                                                ) {
    377377                                                        finalResults.emplace_back( std::move( newResult ) );
     
    444444                                )
    445445
    446                                 if ( unify( paramType, argType, env, need, have, open, symtab ) ) {
     446                                if ( unify( paramType, argType, env, need, have, open ) ) {
    447447                                        unsigned nextExpl = results[i].nextExpl + 1;
    448448                                        if ( nextExpl == expl.exprs.size() ) { nextExpl = 0; }
     
    463463                                        ast::OpenVarSet open = results[i].open;
    464464
    465                                         if ( unify( paramType, cnst->result, env, need, have, open, symtab ) ) {
     465                                        if ( unify( paramType, cnst->result, env, need, have, open ) ) {
    466466                                                results.emplace_back(
    467467                                                        i, new ast::DefaultArgExpr{ cnst->location, cnst }, std::move( env ),
     
    506506
    507507                                // attempt to unify types
    508                                 if ( unify( paramType, argType, env, need, have, open, symtab ) ) {
     508                                if ( unify( paramType, argType, env, need, have, open ) ) {
    509509                                        // add new result
    510510                                        results.emplace_back(
     
    750750                        const ast::Type * returnType = funcType->returns.front();
    751751                        if ( ! unify(
    752                                 returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen, symtab )
     752                                returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen )
    753753                        ) {
    754754                                // unification failed, do not pursue this candidate
     
    11591159
    11601160                        // unification run for side-effects
    1161                         unify( toType, cand->expr->result, cand->env, need, have, open, symtab );
     1161                        unify( toType, cand->expr->result, cand->env, need, have, open );
    11621162                        Cost thisCost =
    11631163                                (castExpr->isGenerated == ast::GeneratedFlag::GeneratedCast)
     
    14831483                                        if (
    14841484                                                unify(
    1485                                                         r2->expr->result, r3->expr->result, env, need, have, open, symtab,
     1485                                                        r2->expr->result, r3->expr->result, env, need, have, open,
    14861486                                                        common )
    14871487                                        ) {
     
    15561556                                if (
    15571557                                        unify(
    1558                                                 r1->expr->result, r2->expr->result, env, need, have, open, symtab,
     1558                                                r1->expr->result, r2->expr->result, env, need, have, open,
    15591559                                                common )
    15601560                                ) {
     
    16591659
    16601660                                // unification run for side-effects
    1661                                 bool canUnify = unify( toType, cand->expr->result, env, need, have, open, symtab );
     1661                                bool canUnify = unify( toType, cand->expr->result, env, need, have, open );
    16621662                                (void) canUnify;
    16631663                                Cost thisCost = computeConversionCost( cand->expr->result, toType, cand->expr->get_lvalue(),
  • src/ResolvExpr/CastCost.cc

    r1803d4d r251ce80  
    165165                                if (
    166166                                        pointerType->qualifiers <= ptr->qualifiers
    167                                         && typesCompatibleIgnoreQualifiers( pointerType->base, ptr->base, symtab, env )
     167                                        && typesCompatibleIgnoreQualifiers( pointerType->base, ptr->base, env )
    168168                                ) {
    169169                                        cost = Cost::safe;
     
    232232        )
    233233
    234         if ( typesCompatibleIgnoreQualifiers( src, dst, symtab, env ) ) {
     234        if ( typesCompatibleIgnoreQualifiers( src, dst, env ) ) {
    235235                PRINT( std::cerr << "compatible!" << std::endl; )
    236236                return Cost::zero;
  • 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
  • src/ResolvExpr/CommonType.hpp

    r1803d4d r251ce80  
    3636        ast::TypeEnvironment & env,
    3737        ast::AssertionSet & need, ast::AssertionSet & have,
    38         const ast::OpenVarSet & open, WidenMode widen,
    39         const ast::SymbolTable & symtab );
     38        const ast::OpenVarSet & open, WidenMode widen);
    4039
    4140}
  • src/ResolvExpr/ConversionCost.cc

    r1803d4d r251ce80  
    532532                }
    533533        }
    534         if ( typesCompatibleIgnoreQualifiers( src, dst, symtab, env ) ) {
     534        if ( typesCompatibleIgnoreQualifiers( src, dst, env ) ) {
    535535                return Cost::zero;
    536536        } else if ( dynamic_cast< const ast::VoidType * >( dst ) ) {
     
    566566                        ast::CV::Qualifiers tq2 = dstAsRef->base->qualifiers;
    567567                        if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers(
    568                                         srcAsRef->base, dstAsRef->base, symtab, env ) ) {
     568                                        srcAsRef->base, dstAsRef->base, env ) ) {
    569569                                if ( tq1 == tq2 ) {
    570570                                        return Cost::zero;
     
    587587                const ast::ReferenceType * dstAsRef = dynamic_cast< const ast::ReferenceType * >( dst );
    588588                assert( dstAsRef );
    589                 if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, symtab, env ) ) {
     589                if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, env ) ) {
    590590                        if ( srcIsLvalue ) {
    591591                                if ( src->qualifiers == dstAsRef->base->qualifiers ) {
     
    653653                ast::CV::Qualifiers tq2 = dstAsPtr->base->qualifiers;
    654654                if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers(
    655                                 pointerType->base, dstAsPtr->base, symtab, env ) ) {
     655                                pointerType->base, dstAsPtr->base, env ) ) {
    656656                        if ( tq1 == tq2 ) {
    657657                                cost = Cost::zero;
  • src/ResolvExpr/Resolver.cc

    r1803d4d r251ce80  
    11081108                void removeExtraneousCast( ast::ptr<ast::Expr> & expr, const ast::SymbolTable & symtab ) {
    11091109                        if ( const ast::CastExpr * castExpr = expr.as< ast::CastExpr >() ) {
    1110                                 if ( typesCompatible( castExpr->arg->result, castExpr->result, symtab ) ) {
     1110                                if ( typesCompatible( castExpr->arg->result, castExpr->result ) ) {
    11111111                                        // cast is to the same type as its argument, remove it
    11121112                                        swap_and_save_env( expr, castExpr->arg );
     
    18341834                                                                if (
    18351835                                                                        ! unify(
    1836                                                                                 arg->expr->result, *param, resultEnv, need, have, open,
    1837                                                                                 symtab )
     1836                                                                                arg->expr->result, *param, resultEnv, need, have, open )
    18381837                                                                ) {
    18391838                                                                        // Type doesn't match
  • src/ResolvExpr/SatisfyAssertions.cpp

    r1803d4d r251ce80  
    215215                        findOpenVars( adjType, newOpen, closed, newNeed, have, FirstOpen );
    216216                        if ( allowConversion ) {
    217                                 if ( auto c = commonType( toType, adjType, newEnv, newNeed, have, newOpen, WidenMode {true, true}, sat.symtab ) ) {
     217                                if ( auto c = commonType( toType, adjType, newEnv, newNeed, have, newOpen, WidenMode {true, true} ) ) {
    218218                                        // set up binding slot for recursive assertions
    219219                                        ast::UniqueId crntResnSlot = 0;
     
    229229                        }
    230230                        else {
    231                                 if ( unifyExact( toType, adjType, newEnv, newNeed, have, newOpen, WidenMode {true, true}, sat.symtab ) ) {
     231                                if ( unifyExact( toType, adjType, newEnv, newNeed, have, newOpen, WidenMode {true, true} ) ) {
    232232                                        // set up binding slot for recursive assertions
    233233                                        ast::UniqueId crntResnSlot = 0;
     
    392392                        mergeOpenVars( open, i.match.open );
    393393
    394                         if ( ! env.combine( i.match.env, open, symtab ) ) return false;
     394                        if ( ! env.combine( i.match.env, open ) ) return false;
    395395
    396396                        crnt.emplace_back( i );
  • src/ResolvExpr/Unify.cc

    r1803d4d r251ce80  
    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());
  • src/ResolvExpr/Unify.h

    r1803d4d r251ce80  
    5959        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    6060        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    61         ast::OpenVarSet & open, const ast::SymbolTable & symtab );
     61        ast::OpenVarSet & open );
    6262
    6363bool unify(
    6464        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    6565        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    66         ast::OpenVarSet & open, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common );
     66        ast::OpenVarSet & open, ast::ptr<ast::Type> & common );
    6767
    6868bool unifyExact(
    6969        const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
    7070        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    71         WidenMode widen, const ast::SymbolTable & symtab );
     71        WidenMode widen );
    7272
    7373bool unifyInexact(
    7474        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    7575        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    76         const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab,
     76        const ast::OpenVarSet & open, WidenMode widen,
    7777        ast::ptr<ast::Type> & common );
    7878
    7979bool typesCompatible(
    80         const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {},
     80        const ast::Type *, const ast::Type *,
    8181        const ast::TypeEnvironment & env = {} );
    8282
    8383bool typesCompatibleIgnoreQualifiers(
    84         const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {},
     84        const ast::Type *, const ast::Type *,
    8585        const ast::TypeEnvironment & env = {} );
    8686
  • src/Validate/ReplaceTypedef.cpp

    r1803d4d r251ce80  
    150150                // constant/enumerator. The effort required to fix this corner case
    151151                // likely outweighs the utility of allowing it.
    152                 if ( !ResolvExpr::typesCompatible( t0, t1, ast::SymbolTable() )
     152                if ( !ResolvExpr::typesCompatible( t0, t1 )
    153153                                || ast::Pass<VarLenChecker>::read( t0 )
    154154                                || ast::Pass<VarLenChecker>::read( t1 ) ) {
Note: See TracChangeset for help on using the changeset viewer.