Skip to content

Commit 36a49a6

Browse files
committed
Make matchFunctionTypes take a callback to match parameter and result types.
1 parent 29258b4 commit 36a49a6

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lib/AST/Type.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,14 +2178,10 @@ namespace {
21782178
};
21792179
} // end anonymous namespace
21802180

2181-
static bool matches(CanType t1, CanType t2, TypeMatchOptions matchMode,
2182-
ParameterPosition paramPosition,
2183-
OptionalUnwrapping insideOptional);
2184-
21852181
static bool matchFunctionTypes(CanAnyFunctionType fn1, CanAnyFunctionType fn2,
21862182
TypeMatchOptions matchMode,
2187-
ParameterPosition paramPosition,
2188-
OptionalUnwrapping insideOptional) {
2183+
OptionalUnwrapping insideOptional,
2184+
std::function<bool()> paramsAndResultMatch) {
21892185
// FIXME: Handle generic functions in non-ABI matches.
21902186
if (!matchMode.contains(TypeMatchFlags::AllowABICompatible)) {
21912187
if (!isa<FunctionType>(fn1) || !isa<FunctionType>(fn2))
@@ -2214,11 +2210,7 @@ static bool matchFunctionTypes(CanAnyFunctionType fn1, CanAnyFunctionType fn2,
22142210
if (ext1 != ext2)
22152211
return false;
22162212

2217-
// Inputs are contravariant, results are covariant.
2218-
return (matches(fn2.getInput(), fn1.getInput(), matchMode,
2219-
ParameterPosition::Parameter, OptionalUnwrapping::None) &&
2220-
matches(fn1.getResult(), fn2.getResult(), matchMode,
2221-
ParameterPosition::NotParameter, OptionalUnwrapping::None));
2213+
return paramsAndResultMatch();
22222214
}
22232215

22242216
static bool matches(CanType t1, CanType t2, TypeMatchOptions matchMode,
@@ -2298,8 +2290,17 @@ static bool matches(CanType t1, CanType t2, TypeMatchOptions matchMode,
22982290
if (!fn1)
22992291
return false;
23002292

2301-
return matchFunctionTypes(fn1, fn2, matchMode, paramPosition,
2302-
insideOptional);
2293+
std::function<bool()> paramsAndResultMatch = [=]() {
2294+
// Inputs are contravariant, results are covariant.
2295+
return (matches(fn2.getInput(), fn1.getInput(), matchMode,
2296+
ParameterPosition::Parameter, OptionalUnwrapping::None) &&
2297+
matches(fn1.getResult(), fn2.getResult(), matchMode,
2298+
ParameterPosition::NotParameter,
2299+
OptionalUnwrapping::None));
2300+
};
2301+
2302+
return matchFunctionTypes(fn1, fn2, matchMode, insideOptional,
2303+
paramsAndResultMatch);
23032304
}
23042305

23052306
if (matchMode.contains(TypeMatchFlags::AllowNonOptionalForIUOParam) &&

0 commit comments

Comments
 (0)