@@ -2093,94 +2093,6 @@ static Type getDynamicComparisonType(ValueDecl *value) {
2093
2093
return interfaceType->removeArgumentLabels (numArgumentLabels);
2094
2094
}
2095
2095
2096
- static OpaqueTypeArchetypeType *getOpaqueResulType (const AbstractFunctionDecl *func) {
2097
- auto funTy =
2098
- (func->getDeclContext ()->isTypeContext () ? func->getMethodInterfaceType ()
2099
- : func->getInterfaceType ())
2100
- ->getCanonicalType ()
2101
- ->getAs <AnyFunctionType>();
2102
- auto resultTy = funTy->getResult ()->getCanonicalType ()->getAs <OpaqueTypeArchetypeType>();
2103
- return resultTy;
2104
- }
2105
-
2106
- static AnyFunctionType::CanParamArrayRef getParameters (const AbstractFunctionDecl *func) {
2107
- auto funTy =
2108
- (func->getDeclContext ()->isTypeContext () ? func->getMethodInterfaceType ()
2109
- : func->getInterfaceType ())
2110
- ->getCanonicalType ()
2111
- ->getAs <AnyFunctionType>();
2112
- assert (funTy);
2113
- return funTy->getParams ();
2114
- }
2115
-
2116
- static bool
2117
- matchFunctionWithOpaqueResultType (const AbstractFunctionDecl *replacement,
2118
- AbstractFunctionDecl *replaced) {
2119
- if (!replaced)
2120
- return false ;
2121
-
2122
- auto resultTy = getOpaqueResulType (replacement);
2123
- if (!resultTy)
2124
- return false ;
2125
- auto replacedResultTy = getOpaqueResulType (replaced);
2126
- if (!replacedResultTy)
2127
- return false ;
2128
-
2129
- if (resultTy->getBoundSignature () != replacedResultTy->getBoundSignature () ||
2130
- !resultTy->getInterfaceType ()->getCanonicalType ()->matches (
2131
- replacedResultTy->getInterfaceType ()->getCanonicalType (),
2132
- TypeMatchFlags::AllowABICompatible))
2133
- return false ;
2134
-
2135
- auto params = getParameters (replacement);
2136
- auto replacedParams = getParameters (replaced);
2137
- if (params.size () != replacedParams.size ())
2138
- return false ;
2139
- for (auto i : indices (params)) {
2140
- if (!params[i].getOldType ()->matchesParameter (
2141
- replacedParams[i].getOldType (), TypeMatchFlags::AllowABICompatible))
2142
- return false ;
2143
- }
2144
-
2145
- return true ;
2146
- }
2147
-
2148
- static bool matchOpaqueResultType (Type replacement, Type replaced) {
2149
- if (replacement->isEqual (replaced))
2150
- return true ;
2151
-
2152
- if (auto fn1 = dyn_cast<AnyFunctionType>(replacement->getCanonicalType ())) {
2153
- auto fn2 = dyn_cast<AnyFunctionType>(replaced->getCanonicalType ());
2154
- if (!fn2)
2155
- return false ;
2156
- auto fn2Params = fn2.getParams ();
2157
- auto fn1Params = fn1.getParams ();
2158
- if (fn2Params.size () != fn1Params.size ()) {
2159
- return false ;
2160
- }
2161
- for (auto i : indices (fn2Params)) {
2162
- if (!matchOpaqueResultType (fn2Params[i].getOldType (),
2163
- fn1Params[i].getOldType ()))
2164
- return false ;
2165
- }
2166
- return matchOpaqueResultType (fn1.getResult (), fn2.getResult ());
2167
- }
2168
-
2169
- auto resultTy = replacement->getAs <OpaqueTypeArchetypeType>();
2170
- if (!resultTy)
2171
- return false ;
2172
- auto replacedResultTy = replaced->getAs <OpaqueTypeArchetypeType>();
2173
- if (!replacedResultTy)
2174
- return false ;
2175
-
2176
- if (resultTy->getBoundSignature () != replacedResultTy->getBoundSignature () ||
2177
- !resultTy->getInterfaceType ()->getCanonicalType ()->matches (
2178
- replacedResultTy->getInterfaceType ()->getCanonicalType (),
2179
- TypeMatchFlags::AllowABICompatible))
2180
- return false ;
2181
- return true ;
2182
- }
2183
-
2184
2096
static FuncDecl *findReplacedAccessor (DeclName replacedVarName,
2185
2097
AccessorDecl *replacement,
2186
2098
DynamicReplacementAttr *attr,
@@ -2205,7 +2117,9 @@ static FuncDecl *findReplacedAccessor(DeclName replacedVarName,
2205
2117
TC.validateDecl (result);
2206
2118
auto resultType = getDynamicComparisonType (result);
2207
2119
if (!resultType->isEqual (replacementStorageType) &&
2208
- !matchOpaqueResultType (resultType, replacementStorageType)) {
2120
+ !resultType->matches (
2121
+ replacementStorageType,
2122
+ TypeMatchFlags::AllowCompatibleOpaqueTypeArchetypes)) {
2209
2123
return true ;
2210
2124
}
2211
2125
@@ -2281,11 +2195,10 @@ findReplacedFunction(DeclName replacedFunctionName,
2281
2195
continue ;
2282
2196
if (TC)
2283
2197
TC->validateDecl (result);
2284
- if (matchFunctionWithOpaqueResultType (
2285
- replacement, dyn_cast<AbstractFunctionDecl>(result)) ||
2286
- result->getInterfaceType ()->getCanonicalType ()->matches (
2287
- replacement->getInterfaceType ()->getCanonicalType (),
2288
- TypeMatchFlags::AllowABICompatible)) {
2198
+ TypeMatchOptions matchMode = TypeMatchFlags::AllowABICompatible;
2199
+ matchMode |= TypeMatchFlags::AllowCompatibleOpaqueTypeArchetypes;
2200
+ if (result->getInterfaceType ()->getCanonicalType ()->matches (
2201
+ replacement->getInterfaceType ()->getCanonicalType (), matchMode)) {
2289
2202
if (!result->isDynamic ()) {
2290
2203
if (TC) {
2291
2204
TC->diagnose (attr->getLocation (),
0 commit comments