Changes in src/ResolvExpr/Unify.cc [251ce80:5bf3976]
- File:
-
- 1 edited
-
src/ResolvExpr/Unify.cc (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
r251ce80 r5bf3976 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 );130 WidenMode widen, const ast::SymbolTable & symtab ); 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, 152 const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab, 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() );165 return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab ); 166 166 } 167 167 … … 183 183 184 184 bool typesCompatibleIgnoreQualifiers( 185 const ast::Type * first, const ast::Type * second, 185 const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab, 186 186 const ast::TypeEnvironment & env ) { 187 187 ast::TypeEnvironment newEnv; … … 216 216 subFirst, 217 217 subSecond, 218 newEnv, need, have, open, noWiden() );218 newEnv, need, have, open, noWiden(), symtab ); 219 219 } 220 220 … … 786 786 const ast::OpenVarSet & open; 787 787 WidenMode widen; 788 const ast::SymbolTable & symtab; 788 789 public: 789 790 static size_t traceId; … … 792 793 Unify_new( 793 794 const ast::Type * type2, ast::TypeEnvironment & env, ast::AssertionSet & need, 794 ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen ) 795 ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen, 796 const ast::SymbolTable & symtab ) 795 797 : type2(type2), tenv(env), need(need), have(have), open(open), widen(widen), 796 result(false) {}798 symtab(symtab), result(false) {} 797 799 798 800 void previsit( const ast::Node * ) { visit_children = false; } … … 812 814 result = unifyExact( 813 815 pointer->base, pointer2->base, tenv, need, have, open, 814 noWiden() );816 noWiden(), symtab ); 815 817 } 816 818 } … … 835 837 836 838 result = unifyExact( 837 array->base, array2->base, tenv, need, have, open, noWiden()); 839 array->base, array2->base, tenv, need, have, open, noWiden(), 840 symtab ); 838 841 } 839 842 … … 841 844 if ( auto ref2 = dynamic_cast< const ast::ReferenceType * >( type2 ) ) { 842 845 result = unifyExact( 843 ref->base, ref2->base, tenv, need, have, open, noWiden()); 846 ref->base, ref2->base, tenv, need, have, open, noWiden(), 847 symtab ); 844 848 } 845 849 } … … 850 854 static bool unifyTypeList( 851 855 Iter crnt1, Iter end1, Iter crnt2, Iter end2, ast::TypeEnvironment & env, 852 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open 856 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, 857 const ast::SymbolTable & symtab 853 858 ) { 854 859 while ( crnt1 != end1 && crnt2 != end2 ) { … … 863 868 return unifyExact( 864 869 t1, tupleFromTypes( crnt2, end2 ), env, need, have, open, 865 noWiden() );870 noWiden(), symtab ); 866 871 } else if ( ! isTuple1 && isTuple2 ) { 867 872 // combine remainder of list1, then unify 868 873 return unifyExact( 869 874 tupleFromTypes( crnt1, end1 ), t2, env, need, have, open, 870 noWiden() );875 noWiden(), symtab ); 871 876 } 872 877 873 878 if ( ! unifyExact( 874 t1, t2, env, need, have, open, noWiden() )879 t1, t2, env, need, have, open, noWiden(), symtab ) 875 880 ) return false; 876 881 … … 886 891 return unifyExact( 887 892 t1, tupleFromTypes( crnt2, end2 ), env, need, have, open, 888 noWiden() );893 noWiden(), symtab ); 889 894 } else if ( crnt2 != end2 ) { 890 895 // try unifying empty tuple with ttype … … 893 898 return unifyExact( 894 899 tupleFromTypes( crnt1, end1 ), t2, env, need, have, open, 895 noWiden() );900 noWiden(), symtab ); 896 901 } 897 902 … … 903 908 const std::vector< ast::ptr< ast::Type > > & list2, 904 909 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 905 const ast::OpenVarSet & open 910 const ast::OpenVarSet & open, const ast::SymbolTable & symtab 906 911 ) { 907 912 return unifyTypeList( 908 list1.begin(), list1.end(), list2.begin(), list2.end(), env, need, have, open); 913 list1.begin(), list1.end(), list2.begin(), list2.end(), env, need, have, open, 914 symtab ); 909 915 } 910 916 … … 947 953 ) return; 948 954 949 if ( ! unifyTypeList( params, params2, tenv, need, have, open ) ) return;955 if ( ! unifyTypeList( params, params2, tenv, need, have, open, symtab ) ) return; 950 956 if ( ! unifyTypeList( 951 func->returns, func2->returns, tenv, need, have, open ) ) return;957 func->returns, func2->returns, tenv, need, have, open, symtab ) ) return; 952 958 953 959 markAssertions( have, need, func ); … … 1020 1026 1021 1027 if ( ! unifyExact( 1022 pty, pty2, tenv, need, have, open, noWiden() ) ) {1028 pty, pty2, tenv, need, have, open, noWiden(), symtab ) ) { 1023 1029 result = false; 1024 1030 return; … … 1059 1065 const std::vector< ast::ptr< ast::Type > > & list1, 1060 1066 const std::vector< ast::ptr< ast::Type > > & list2, ast::TypeEnvironment & env, 1061 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open 1067 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, 1068 const ast::SymbolTable & symtab 1062 1069 ) { 1063 1070 auto crnt1 = list1.begin(); … … 1074 1081 return unifyExact( 1075 1082 t1, tupleFromTypes( list2 ), env, need, have, open, 1076 noWiden() );1083 noWiden(), symtab ); 1077 1084 } else if ( ! isTuple1 && isTuple2 ) { 1078 1085 // combine entirety of list1, then unify 1079 1086 return unifyExact( 1080 1087 tupleFromTypes( list1 ), t2, env, need, have, open, 1081 noWiden() );1088 noWiden(), symtab ); 1082 1089 } 1083 1090 1084 1091 if ( ! unifyExact( 1085 t1, t2, env, need, have, open, noWiden() )1092 t1, t2, env, need, have, open, noWiden(), symtab ) 1086 1093 ) return false; 1087 1094 … … 1097 1104 return unifyExact( 1098 1105 t1, tupleFromTypes( list2 ), env, need, have, open, 1099 noWiden() );1106 noWiden(), symtab ); 1100 1107 } else if ( crnt2 != list2.end() ) { 1101 1108 // try unifying empty tuple with ttype … … 1106 1113 return unifyExact( 1107 1114 tupleFromTypes( list1 ), t2, env, need, have, open, 1108 noWiden() );1115 noWiden(), symtab ); 1109 1116 } 1110 1117 … … 1125 1132 auto types2 = flatten( flat2 ); 1126 1133 1127 result = unifyList( types, types2, tenv, need, have, open );1134 result = unifyList( types, types2, tenv, need, have, open, symtab ); 1128 1135 } 1129 1136 … … 1149 1156 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 1150 1157 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 1151 ast::OpenVarSet & open 1158 ast::OpenVarSet & open, const ast::SymbolTable & symtab 1152 1159 ) { 1153 1160 ast::ptr<ast::Type> common; 1154 return unify( type1, type2, env, need, have, open, common );1161 return unify( type1, type2, env, need, have, open, symtab, common ); 1155 1162 } 1156 1163 … … 1158 1165 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 1159 1166 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 1160 ast::OpenVarSet & open, ast::ptr<ast::Type> & common1167 ast::OpenVarSet & open, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common 1161 1168 ) { 1162 1169 ast::OpenVarSet closed; … … 1164 1171 findOpenVars( type2, open, closed, need, have, FirstOpen ); 1165 1172 return unifyInexact( 1166 type1, type2, env, need, have, open, WidenMode{ true, true }, common );1173 type1, type2, env, need, have, open, WidenMode{ true, true }, symtab, common ); 1167 1174 } 1168 1175 … … 1170 1177 const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env, 1171 1178 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, 1172 WidenMode widen 1179 WidenMode widen, const ast::SymbolTable & symtab 1173 1180 ) { 1174 1181 if ( type1->qualifiers != type2->qualifiers ) return false; … … 1186 1193 return env.bindVarToVar( 1187 1194 var1, var2, ast::TypeData{ entry1->second, entry2->second }, need, have, 1188 open, widen );1195 open, widen, symtab ); 1189 1196 } else if ( isopen1 ) { 1190 return env.bindVar( var1, type2, entry1->second, need, have, open, widen );1197 return env.bindVar( var1, type2, entry1->second, need, have, open, widen, symtab ); 1191 1198 } else if ( isopen2 ) { 1192 return env.bindVar( var2, type1, entry2->second, need, have, open, widen );1199 return env.bindVar( var2, type1, entry2->second, need, have, open, widen, symtab ); 1193 1200 } else { 1194 1201 return ast::Pass<Unify_new>::read( 1195 type1, type2, env, need, have, open, widen );1202 type1, type2, env, need, have, open, widen, symtab ); 1196 1203 } 1197 1204 } … … 1200 1207 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 1201 1208 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 1202 const ast::OpenVarSet & open, WidenMode widen, 1209 const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab, 1203 1210 ast::ptr<ast::Type> & common 1204 1211 ) { … … 1214 1221 ast::ptr< ast::Type > t2_(t2); 1215 1222 1216 if ( unifyExact( t1, t2, env, need, have, open, widen ) ) {1223 if ( unifyExact( t1, t2, env, need, have, open, widen, symtab ) ) { 1217 1224 // if exact unification on unqualified types, try to merge qualifiers 1218 1225 if ( q1 == q2 || ( ( q1 > q2 || widen.first ) && ( q2 > q1 || widen.second ) ) ) { … … 1224 1231 } 1225 1232 1226 } else if (( common = commonType( t1, t2, env, need, have, open, widen ))) {1233 } else if (( common = commonType( t1, t2, env, need, have, open, widen, symtab ))) { 1227 1234 // no exact unification, but common type 1228 1235 auto c = shallowCopy(common.get());
Note:
See TracChangeset
for help on using the changeset viewer.