Changeset 8a930c03 for src/ResolvExpr/Unify.cc
- Timestamp:
- Jun 12, 2023, 12:05:58 PM (3 years ago)
- Branches:
- master
- Children:
- fec8bd1
- Parents:
- 2b78949 (diff), 38e266ca (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
src/ResolvExpr/Unify.cc (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
r2b78949 r8a930c03 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());
Note:
See TracChangeset
for help on using the changeset viewer.