Changeset 251ce80
- Timestamp:
- Jun 1, 2023, 6:29:47 PM (23 months ago)
- Branches:
- ast-experimental, master
- Children:
- 24d6572, ded6c2a6
- Parents:
- 1803d4d
- Location:
- src
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/AST/SymbolTable.cpp ¶
r1803d4d r251ce80 278 278 } else { 279 279 // 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 ) ) { 281 281 SemanticError( added->location, "redeclaration of " + added->name ); 282 282 } … … 643 643 } else if ( existing.id->linkage.is_mangled 644 644 || ResolvExpr::typesCompatible( 645 added->get_type(), existing.id->get_type() , SymbolTable{}) ) {645 added->get_type(), existing.id->get_type() ) ) { 646 646 647 647 // it is a conflict if one declaration is deleted and the other is not -
TabularUnified src/AST/TypeEnvironment.cpp ¶
r1803d4d r251ce80 178 178 179 179 bool TypeEnvironment::combine( 180 const TypeEnvironment & o, OpenVarSet & open , const SymbolTable & symtab) {180 const TypeEnvironment & o, OpenVarSet & open ) { 181 181 // short-circuit easy cases 182 182 if ( o.empty() ) return true; … … 201 201 EqvClass & r = *rt; 202 202 // merge bindings 203 if ( ! mergeBound( r, c, open , symtab) ) return false;203 if ( ! mergeBound( r, c, open ) ) return false; 204 204 // merge previous unbound variables into this class, checking occurs if needed 205 205 if ( r.bound ) for ( const auto & u : c.vars ) { … … 216 216 } else if ( st != rt ) { 217 217 // bound, but not to the same class 218 if ( ! mergeClasses( rt, st, open , symtab) ) return false;218 if ( ! mergeClasses( rt, st, open ) ) return false; 219 219 } // ignore bound into the same class 220 220 } … … 280 280 bool TypeEnvironment::bindVar( 281 281 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 284 283 ) { 285 284 // remove references from bound type, so that type variables can only bind to value types … … 300 299 if ( unifyInexact( 301 300 newType, target, *this, need, have, open, 302 widen & WidenMode{ it->allowWidening, true }, symtab,common ) ) {301 widen & WidenMode{ it->allowWidening, true }, common ) ) { 303 302 if ( common ) { 304 303 it->bound = std::move(common); … … 321 320 const TypeInstType * var1, const TypeInstType * var2, TypeData && data, 322 321 AssertionSet & need, AssertionSet & have, const OpenVarSet & open, 323 WidenMode widen , const SymbolTable & symtab322 WidenMode widen 324 323 ) { 325 324 auto c1 = internal_lookup( *var1 ); … … 358 357 359 358 if ( unifyInexact( 360 newType1, newType2, *this, need, have, open, newWidenMode, symtab,common ) ) {359 newType1, newType2, *this, need, have, open, newWidenMode, common ) ) { 361 360 c1->vars.insert( c2->vars.begin(), c2->vars.end() ); 362 361 c1->allowWidening = widen1 && widen2; … … 409 408 410 409 bool TypeEnvironment::mergeBound( 411 EqvClass & to, const EqvClass & from, OpenVarSet & open , const SymbolTable & symtab) {410 EqvClass & to, const EqvClass & from, OpenVarSet & open ) { 412 411 if ( from.bound ) { 413 412 if ( to.bound ) { … … 419 418 420 419 if ( unifyInexact( 421 toType, fromType, *this, need, have, open, widen, symtab,common ) ) {420 toType, fromType, *this, need, have, open, widen, common ) ) { 422 421 // unifies, set common type if necessary 423 422 if ( common ) { … … 437 436 438 437 bool TypeEnvironment::mergeClasses( 439 ClassList::iterator to, ClassList::iterator from, OpenVarSet & open , const SymbolTable & symtab438 ClassList::iterator to, ClassList::iterator from, OpenVarSet & open 440 439 ) { 441 440 EqvClass & r = *to, & s = *from; 442 441 443 442 // ensure bounds match 444 if ( ! mergeBound( r, s, open , symtab) ) return false;443 if ( ! mergeBound( r, s, open ) ) return false; 445 444 446 445 // check safely bindable -
TabularUnified src/AST/TypeEnvironment.hpp ¶
r1803d4d r251ce80 169 169 /// Merge environment with this one, checking compatibility. 170 170 /// 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 ); 172 172 173 173 /// Add all type variables in environment to open var list … … 183 183 const TypeInstType * typeInst, const Type * bindTo, const TypeData & data, 184 184 AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars, 185 ResolvExpr::WidenMode widen , const SymbolTable & symtab);185 ResolvExpr::WidenMode widen ); 186 186 187 187 /// Binds the type classes represented by `var1` and `var2` together; will add one or both … … 190 190 const TypeInstType * var1, const TypeInstType * var2, TypeData && data, 191 191 AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars, 192 ResolvExpr::WidenMode widen , const SymbolTable & symtab);192 ResolvExpr::WidenMode widen ); 193 193 194 194 /// Disallows widening for all bindings in the environment … … 205 205 /// Unifies the type bound of `to` with the type bound of `from`, returning false if fails 206 206 bool mergeBound( 207 EqvClass & to, const EqvClass & from, OpenVarSet & openVars , const SymbolTable & symtab);207 EqvClass & to, const EqvClass & from, OpenVarSet & openVars ); 208 208 209 209 /// Merges two type classes from local environment, returning false if fails 210 210 bool mergeClasses( 211 ClassList::iterator to, ClassList::iterator from, OpenVarSet & openVars, 212 const SymbolTable & symtab ); 211 ClassList::iterator to, ClassList::iterator from, OpenVarSet & openVars); 213 212 214 213 /// Private lookup API; returns array index of string, or env.size() for not found -
TabularUnified src/GenPoly/InstantiateGenericNew.cpp ¶
r1803d4d r251ce80 362 362 ResolvExpr::typesCompatible( 363 363 memberExpr->result, 364 memberExpr->member->get_type() , ast::SymbolTable()) ) {364 memberExpr->member->get_type() ) ) { 365 365 return memberExpr; 366 366 } -
TabularUnified src/GenPoly/LvalueNew.cpp ¶
r1803d4d r251ce80 359 359 !ResolvExpr::typesCompatible( 360 360 srcType, 361 strict_dynamic_cast<ast::ReferenceType const *>( dstType )->base, 362 ast::SymbolTable() ) ) { 361 strict_dynamic_cast<ast::ReferenceType const *>( dstType )->base ) ) { 363 362 // Must keep cast if cast-to type is different from the actual type. 364 363 return ast::mutate_field( expr, &ast::CastExpr::arg, ret ); … … 377 376 if ( !ResolvExpr::typesCompatibleIgnoreQualifiers( 378 377 dstType->stripReferences(), 379 srcType->stripReferences(), 380 ast::SymbolTable() ) ) { 378 srcType->stripReferences() ) ) { 381 379 return ast::mutate_field( expr, &ast::CastExpr::arg, ret ); 382 380 } … … 393 391 ResolvExpr::typesCompatible( 394 392 expr->result, 395 expr->arg->result , ast::SymbolTable()) ) {393 expr->arg->result ) ) { 396 394 PRINT( 397 395 std::cerr << "types are compatible, removing cast: " << expr << '\n'; … … 590 588 ast::OpenVarSet openVars; 591 589 ResolvExpr::unify( ret->arg2->result, ret->arg3->result, newEnv, 592 needAssertions, haveAssertions, openVars, 593 ast::SymbolTable(), common ); 590 needAssertions, haveAssertions, openVars, common ); 594 591 ret->result = common ? common : ast::deepCopy( ret->arg2->result ); 595 592 return ret; -
TabularUnified src/InitTweak/InitTweak.cc ¶
r1803d4d r251ce80 1066 1066 const ast::Type * t2 = ftype->params.back(); 1067 1067 1068 return ResolvExpr::typesCompatibleIgnoreQualifiers( t1, t2 , ast::SymbolTable());1068 return ResolvExpr::typesCompatibleIgnoreQualifiers( t1, t2 ); 1069 1069 } 1070 1070 -
TabularUnified src/ResolvExpr/CandidateFinder.cpp ¶
r1803d4d r251ce80 373 373 unify( 374 374 ttype, argType, newResult.env, newResult.need, newResult.have, 375 newResult.open , symtab)375 newResult.open ) 376 376 ) { 377 377 finalResults.emplace_back( std::move( newResult ) ); … … 444 444 ) 445 445 446 if ( unify( paramType, argType, env, need, have, open , symtab) ) {446 if ( unify( paramType, argType, env, need, have, open ) ) { 447 447 unsigned nextExpl = results[i].nextExpl + 1; 448 448 if ( nextExpl == expl.exprs.size() ) { nextExpl = 0; } … … 463 463 ast::OpenVarSet open = results[i].open; 464 464 465 if ( unify( paramType, cnst->result, env, need, have, open , symtab) ) {465 if ( unify( paramType, cnst->result, env, need, have, open ) ) { 466 466 results.emplace_back( 467 467 i, new ast::DefaultArgExpr{ cnst->location, cnst }, std::move( env ), … … 506 506 507 507 // attempt to unify types 508 if ( unify( paramType, argType, env, need, have, open , symtab) ) {508 if ( unify( paramType, argType, env, need, have, open ) ) { 509 509 // add new result 510 510 results.emplace_back( … … 750 750 const ast::Type * returnType = funcType->returns.front(); 751 751 if ( ! unify( 752 returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen , symtab)752 returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen ) 753 753 ) { 754 754 // unification failed, do not pursue this candidate … … 1159 1159 1160 1160 // 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 ); 1162 1162 Cost thisCost = 1163 1163 (castExpr->isGenerated == ast::GeneratedFlag::GeneratedCast) … … 1483 1483 if ( 1484 1484 unify( 1485 r2->expr->result, r3->expr->result, env, need, have, open, symtab,1485 r2->expr->result, r3->expr->result, env, need, have, open, 1486 1486 common ) 1487 1487 ) { … … 1556 1556 if ( 1557 1557 unify( 1558 r1->expr->result, r2->expr->result, env, need, have, open, symtab,1558 r1->expr->result, r2->expr->result, env, need, have, open, 1559 1559 common ) 1560 1560 ) { … … 1659 1659 1660 1660 // 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 ); 1662 1662 (void) canUnify; 1663 1663 Cost thisCost = computeConversionCost( cand->expr->result, toType, cand->expr->get_lvalue(), -
TabularUnified src/ResolvExpr/CastCost.cc ¶
r1803d4d r251ce80 165 165 if ( 166 166 pointerType->qualifiers <= ptr->qualifiers 167 && typesCompatibleIgnoreQualifiers( pointerType->base, ptr->base, symtab,env )167 && typesCompatibleIgnoreQualifiers( pointerType->base, ptr->base, env ) 168 168 ) { 169 169 cost = Cost::safe; … … 232 232 ) 233 233 234 if ( typesCompatibleIgnoreQualifiers( src, dst, symtab,env ) ) {234 if ( typesCompatibleIgnoreQualifiers( src, dst, env ) ) { 235 235 PRINT( std::cerr << "compatible!" << std::endl; ) 236 236 return Cost::zero; -
TabularUnified src/ResolvExpr/CommonType.cc ¶
r1803d4d r251ce80 676 676 const ast::Type * type2; 677 677 WidenMode widen; 678 const ast::SymbolTable & symtab;679 678 ast::TypeEnvironment & tenv; 680 679 const ast::OpenVarSet & open; … … 686 685 687 686 CommonType_new( 688 const ast::Type * t2, WidenMode w, const ast::SymbolTable & st,687 const ast::Type * t2, WidenMode w, 689 688 ast::TypeEnvironment & env, const ast::OpenVarSet & o, 690 689 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() {} 692 691 693 692 void previsit( const ast::Node * ) { visit_children = false; } … … 749 748 ast::AssertionSet need, have; 750 749 if ( ! tenv.bindVar( 751 var, voidPtr->base, entry->second, need, have, open, widen , symtab)750 var, voidPtr->base, entry->second, need, have, open, widen ) 752 751 ) return; 753 752 } … … 762 761 ast::OpenVarSet newOpen{ open }; 763 762 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)) { 765 764 result = type1; 766 765 return true; … … 799 798 800 799 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() ) ) { 802 801 result = pointer; 803 802 if ( q1.val != q2.val ) { … … 842 841 if (unifyExact( 843 842 arg1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open, 844 noWiden() , symtab)) {843 noWiden() )) { 845 844 break; 846 845 … … 851 850 if (unifyExact( 852 851 tupleFromTypes( crnt1, end1 ), arg2, tenv, need, have, open, 853 noWiden() , symtab)) {852 noWiden() )) { 854 853 break; 855 854 … … 875 874 876 875 if ( ! unifyExact( 877 base1, base2, tenv, need, have, open, noWiden() , symtab)876 base1, base2, tenv, need, have, open, noWiden() ) 878 877 ) return; 879 878 } … … 895 894 896 895 if ( ! unifyExact( 897 base1, base2, tenv, need, have, open, noWiden() , symtab)896 base1, base2, tenv, need, have, open, noWiden() ) 898 897 ) return; 899 898 } … … 903 902 } 904 903 else if (! unifyExact( 905 arg1, arg2, tenv, need, have, open, noWiden() , symtab)) return;904 arg1, arg2, tenv, need, have, open, noWiden() )) return; 906 905 907 906 ++crnt1; ++crnt2; … … 913 912 if (! unifyExact( 914 913 t1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open, 915 noWiden() , symtab)) return;914 noWiden() )) return; 916 915 } else if ( crnt2 != end2 ) { 917 916 // try unifying empty tuple with ttype … … 920 919 if (! unifyExact( 921 920 tupleFromTypes( crnt1, end1 ), t2, tenv, need, have, open, 922 noWiden() , symtab)) return;921 noWiden() )) return; 923 922 } 924 923 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()))) { 926 925 result = pointer; 927 926 … … 980 979 981 980 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() ) ) { 983 982 result = ref; 984 983 if ( q1.val != q2.val ) { … … 995 994 } else { 996 995 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 ); 998 997 } 999 998 } … … 1013 1012 void postvisit( const ast::EnumInstType * enumInst ) { 1014 1013 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); 1016 1015 } 1017 1016 1018 1017 void postvisit( const ast::TraitInstType * ) {} 1019 1018 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 ) {} 1043 1020 1044 1021 void postvisit( const ast::TupleType * tuple) { … … 1103 1080 ast::ptr< ast::Type > handleReference( 1104 1081 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, 1106 1083 const ast::OpenVarSet & open 1107 1084 ) { … … 1111 1088 1112 1089 // 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 ) ) { 1114 1091 ast::CV::Qualifiers q1 = t1->qualifiers, q2 = t2->qualifiers; 1115 1092 PRINT( … … 1135 1112 const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2, 1136 1113 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 1137 const ast::OpenVarSet & open, WidenMode widen , const ast::SymbolTable & symtab1114 const ast::OpenVarSet & open, WidenMode widen 1138 1115 ) { 1139 1116 unsigned depth1 = type1->referenceDepth(); … … 1150 1127 if ( depth1 > depth2 ) { 1151 1128 assert( ref1 ); 1152 result = handleReference( ref1->base, type2, widen, symtab,env, open );1129 result = handleReference( ref1->base, type2, widen, env, open ); 1153 1130 } else { // implies depth1 < depth2 1154 1131 assert( ref2 ); 1155 result = handleReference( type1, ref2->base, widen, symtab,env, open );1132 result = handleReference( type1, ref2->base, widen, env, open ); 1156 1133 } 1157 1134 … … 1171 1148 } 1172 1149 // 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 }; 1174 1151 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; 1203 1155 } 1204 1156 -
TabularUnified src/ResolvExpr/CommonType.hpp ¶
r1803d4d r251ce80 36 36 ast::TypeEnvironment & env, 37 37 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); 40 39 41 40 } -
TabularUnified src/ResolvExpr/ConversionCost.cc ¶
r1803d4d r251ce80 532 532 } 533 533 } 534 if ( typesCompatibleIgnoreQualifiers( src, dst, symtab,env ) ) {534 if ( typesCompatibleIgnoreQualifiers( src, dst, env ) ) { 535 535 return Cost::zero; 536 536 } else if ( dynamic_cast< const ast::VoidType * >( dst ) ) { … … 566 566 ast::CV::Qualifiers tq2 = dstAsRef->base->qualifiers; 567 567 if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers( 568 srcAsRef->base, dstAsRef->base, symtab,env ) ) {568 srcAsRef->base, dstAsRef->base, env ) ) { 569 569 if ( tq1 == tq2 ) { 570 570 return Cost::zero; … … 587 587 const ast::ReferenceType * dstAsRef = dynamic_cast< const ast::ReferenceType * >( dst ); 588 588 assert( dstAsRef ); 589 if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, symtab,env ) ) {589 if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, env ) ) { 590 590 if ( srcIsLvalue ) { 591 591 if ( src->qualifiers == dstAsRef->base->qualifiers ) { … … 653 653 ast::CV::Qualifiers tq2 = dstAsPtr->base->qualifiers; 654 654 if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers( 655 pointerType->base, dstAsPtr->base, symtab,env ) ) {655 pointerType->base, dstAsPtr->base, env ) ) { 656 656 if ( tq1 == tq2 ) { 657 657 cost = Cost::zero; -
TabularUnified src/ResolvExpr/Resolver.cc ¶
r1803d4d r251ce80 1108 1108 void removeExtraneousCast( ast::ptr<ast::Expr> & expr, const ast::SymbolTable & symtab ) { 1109 1109 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 ) ) { 1111 1111 // cast is to the same type as its argument, remove it 1112 1112 swap_and_save_env( expr, castExpr->arg ); … … 1834 1834 if ( 1835 1835 ! unify( 1836 arg->expr->result, *param, resultEnv, need, have, open, 1837 symtab ) 1836 arg->expr->result, *param, resultEnv, need, have, open ) 1838 1837 ) { 1839 1838 // Type doesn't match -
TabularUnified src/ResolvExpr/SatisfyAssertions.cpp ¶
r1803d4d r251ce80 215 215 findOpenVars( adjType, newOpen, closed, newNeed, have, FirstOpen ); 216 216 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} ) ) { 218 218 // set up binding slot for recursive assertions 219 219 ast::UniqueId crntResnSlot = 0; … … 229 229 } 230 230 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} ) ) { 232 232 // set up binding slot for recursive assertions 233 233 ast::UniqueId crntResnSlot = 0; … … 392 392 mergeOpenVars( open, i.match.open ); 393 393 394 if ( ! env.combine( i.match.env, open , symtab) ) return false;394 if ( ! env.combine( i.match.env, open ) ) return false; 395 395 396 396 crnt.emplace_back( i ); -
TabularUnified src/ResolvExpr/Unify.cc ¶
r1803d4d r251ce80 128 128 const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env, 129 129 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, 130 WidenMode widen , const ast::SymbolTable & symtab);130 WidenMode widen ); 131 131 132 132 bool typesCompatible( const Type * first, const Type * second, const SymTab::Indexer & indexer, const TypeEnvironment & env ) { … … 150 150 151 151 bool typesCompatible( 152 const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,152 const ast::Type * first, const ast::Type * second, 153 153 const ast::TypeEnvironment & env ) { 154 154 ast::TypeEnvironment newEnv; … … 163 163 findOpenVars( newSecond, open, closed, need, have, FirstOpen ); 164 164 165 return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden() , symtab);165 return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden() ); 166 166 } 167 167 … … 183 183 184 184 bool typesCompatibleIgnoreQualifiers( 185 const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,185 const ast::Type * first, const ast::Type * second, 186 186 const ast::TypeEnvironment & env ) { 187 187 ast::TypeEnvironment newEnv; … … 216 216 subFirst, 217 217 subSecond, 218 newEnv, need, have, open, noWiden() , symtab);218 newEnv, need, have, open, noWiden() ); 219 219 } 220 220 … … 786 786 const ast::OpenVarSet & open; 787 787 WidenMode widen; 788 const ast::SymbolTable & symtab;789 788 public: 790 789 static size_t traceId; … … 793 792 Unify_new( 794 793 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 ) 797 795 : type2(type2), tenv(env), need(need), have(have), open(open), widen(widen), 798 symtab(symtab),result(false) {}796 result(false) {} 799 797 800 798 void previsit( const ast::Node * ) { visit_children = false; } … … 814 812 result = unifyExact( 815 813 pointer->base, pointer2->base, tenv, need, have, open, 816 noWiden() , symtab);814 noWiden()); 817 815 } 818 816 } … … 837 835 838 836 result = unifyExact( 839 array->base, array2->base, tenv, need, have, open, noWiden(), 840 symtab ); 837 array->base, array2->base, tenv, need, have, open, noWiden()); 841 838 } 842 839 … … 844 841 if ( auto ref2 = dynamic_cast< const ast::ReferenceType * >( type2 ) ) { 845 842 result = unifyExact( 846 ref->base, ref2->base, tenv, need, have, open, noWiden(), 847 symtab ); 843 ref->base, ref2->base, tenv, need, have, open, noWiden()); 848 844 } 849 845 } … … 854 850 static bool unifyTypeList( 855 851 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 858 853 ) { 859 854 while ( crnt1 != end1 && crnt2 != end2 ) { … … 868 863 return unifyExact( 869 864 t1, tupleFromTypes( crnt2, end2 ), env, need, have, open, 870 noWiden() , symtab);865 noWiden() ); 871 866 } else if ( ! isTuple1 && isTuple2 ) { 872 867 // combine remainder of list1, then unify 873 868 return unifyExact( 874 869 tupleFromTypes( crnt1, end1 ), t2, env, need, have, open, 875 noWiden() , symtab);870 noWiden() ); 876 871 } 877 872 878 873 if ( ! unifyExact( 879 t1, t2, env, need, have, open, noWiden() , symtab)874 t1, t2, env, need, have, open, noWiden() ) 880 875 ) return false; 881 876 … … 891 886 return unifyExact( 892 887 t1, tupleFromTypes( crnt2, end2 ), env, need, have, open, 893 noWiden() , symtab);888 noWiden() ); 894 889 } else if ( crnt2 != end2 ) { 895 890 // try unifying empty tuple with ttype … … 898 893 return unifyExact( 899 894 tupleFromTypes( crnt1, end1 ), t2, env, need, have, open, 900 noWiden() , symtab);895 noWiden() ); 901 896 } 902 897 … … 908 903 const std::vector< ast::ptr< ast::Type > > & list2, 909 904 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 910 const ast::OpenVarSet & open , const ast::SymbolTable & symtab905 const ast::OpenVarSet & open 911 906 ) { 912 907 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); 915 909 } 916 910 … … 953 947 ) return; 954 948 955 if ( ! unifyTypeList( params, params2, tenv, need, have, open , symtab) ) return;949 if ( ! unifyTypeList( params, params2, tenv, need, have, open ) ) return; 956 950 if ( ! unifyTypeList( 957 func->returns, func2->returns, tenv, need, have, open , symtab) ) return;951 func->returns, func2->returns, tenv, need, have, open ) ) return; 958 952 959 953 markAssertions( have, need, func ); … … 1026 1020 1027 1021 if ( ! unifyExact( 1028 pty, pty2, tenv, need, have, open, noWiden() , symtab) ) {1022 pty, pty2, tenv, need, have, open, noWiden() ) ) { 1029 1023 result = false; 1030 1024 return; … … 1065 1059 const std::vector< ast::ptr< ast::Type > > & list1, 1066 1060 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 1069 1062 ) { 1070 1063 auto crnt1 = list1.begin(); … … 1081 1074 return unifyExact( 1082 1075 t1, tupleFromTypes( list2 ), env, need, have, open, 1083 noWiden() , symtab);1076 noWiden() ); 1084 1077 } else if ( ! isTuple1 && isTuple2 ) { 1085 1078 // combine entirety of list1, then unify 1086 1079 return unifyExact( 1087 1080 tupleFromTypes( list1 ), t2, env, need, have, open, 1088 noWiden() , symtab);1081 noWiden() ); 1089 1082 } 1090 1083 1091 1084 if ( ! unifyExact( 1092 t1, t2, env, need, have, open, noWiden() , symtab)1085 t1, t2, env, need, have, open, noWiden() ) 1093 1086 ) return false; 1094 1087 … … 1104 1097 return unifyExact( 1105 1098 t1, tupleFromTypes( list2 ), env, need, have, open, 1106 noWiden() , symtab);1099 noWiden() ); 1107 1100 } else if ( crnt2 != list2.end() ) { 1108 1101 // try unifying empty tuple with ttype … … 1113 1106 return unifyExact( 1114 1107 tupleFromTypes( list1 ), t2, env, need, have, open, 1115 noWiden() , symtab);1108 noWiden() ); 1116 1109 } 1117 1110 … … 1132 1125 auto types2 = flatten( flat2 ); 1133 1126 1134 result = unifyList( types, types2, tenv, need, have, open , symtab);1127 result = unifyList( types, types2, tenv, need, have, open ); 1135 1128 } 1136 1129 … … 1156 1149 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 1157 1150 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 1158 ast::OpenVarSet & open , const ast::SymbolTable & symtab1151 ast::OpenVarSet & open 1159 1152 ) { 1160 1153 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 ); 1162 1155 } 1163 1156 … … 1165 1158 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 1166 1159 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 1167 ast::OpenVarSet & open, const ast::SymbolTable & symtab,ast::ptr<ast::Type> & common1160 ast::OpenVarSet & open, ast::ptr<ast::Type> & common 1168 1161 ) { 1169 1162 ast::OpenVarSet closed; … … 1171 1164 findOpenVars( type2, open, closed, need, have, FirstOpen ); 1172 1165 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 ); 1174 1167 } 1175 1168 … … 1177 1170 const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env, 1178 1171 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, 1179 WidenMode widen , const ast::SymbolTable & symtab1172 WidenMode widen 1180 1173 ) { 1181 1174 if ( type1->qualifiers != type2->qualifiers ) return false; … … 1193 1186 return env.bindVarToVar( 1194 1187 var1, var2, ast::TypeData{ entry1->second, entry2->second }, need, have, 1195 open, widen , symtab);1188 open, widen ); 1196 1189 } 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 ); 1198 1191 } 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 ); 1200 1193 } else { 1201 1194 return ast::Pass<Unify_new>::read( 1202 type1, type2, env, need, have, open, widen , symtab);1195 type1, type2, env, need, have, open, widen ); 1203 1196 } 1204 1197 } … … 1207 1200 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 1208 1201 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, 1210 1203 ast::ptr<ast::Type> & common 1211 1204 ) { … … 1221 1214 ast::ptr< ast::Type > t2_(t2); 1222 1215 1223 if ( unifyExact( t1, t2, env, need, have, open, widen , symtab) ) {1216 if ( unifyExact( t1, t2, env, need, have, open, widen ) ) { 1224 1217 // if exact unification on unqualified types, try to merge qualifiers 1225 1218 if ( q1 == q2 || ( ( q1 > q2 || widen.first ) && ( q2 > q1 || widen.second ) ) ) { … … 1231 1224 } 1232 1225 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 ))) { 1234 1227 // no exact unification, but common type 1235 1228 auto c = shallowCopy(common.get()); -
TabularUnified src/ResolvExpr/Unify.h ¶
r1803d4d r251ce80 59 59 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 60 60 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 61 ast::OpenVarSet & open , const ast::SymbolTable & symtab);61 ast::OpenVarSet & open ); 62 62 63 63 bool unify( 64 64 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 65 65 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 ); 67 67 68 68 bool unifyExact( 69 69 const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env, 70 70 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, 71 WidenMode widen , const ast::SymbolTable & symtab);71 WidenMode widen ); 72 72 73 73 bool unifyInexact( 74 74 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 75 75 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, 77 77 ast::ptr<ast::Type> & common ); 78 78 79 79 bool typesCompatible( 80 const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {},80 const ast::Type *, const ast::Type *, 81 81 const ast::TypeEnvironment & env = {} ); 82 82 83 83 bool typesCompatibleIgnoreQualifiers( 84 const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {},84 const ast::Type *, const ast::Type *, 85 85 const ast::TypeEnvironment & env = {} ); 86 86 -
TabularUnified src/Validate/ReplaceTypedef.cpp ¶
r1803d4d r251ce80 150 150 // constant/enumerator. The effort required to fix this corner case 151 151 // likely outweighs the utility of allowing it. 152 if ( !ResolvExpr::typesCompatible( t0, t1 , ast::SymbolTable())152 if ( !ResolvExpr::typesCompatible( t0, t1 ) 153 153 || ast::Pass<VarLenChecker>::read( t0 ) 154 154 || ast::Pass<VarLenChecker>::read( t1 ) ) {
Note: See TracChangeset
for help on using the changeset viewer.