mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema: Remove matchFunctionParamTypes()
Now that function types cannot have a naked type variable as their input type we should never end up down this code path with an associated declaration and argument labels, so it's OK to just call matchTypes() on the input types instead.
This commit is contained in:
@@ -1085,76 +1085,6 @@ static bool matchFunctionRepresentations(FunctionTypeRepresentation rep1,
|
||||
llvm_unreachable("Unhandled ConstraintKind in switch.");
|
||||
}
|
||||
|
||||
ConstraintSystem::TypeMatchResult
|
||||
ConstraintSystem::matchFunctionParamTypes(ArrayRef<AnyFunctionType::Param> type1,
|
||||
ArrayRef<AnyFunctionType::Param> type2,
|
||||
Type argType,
|
||||
Type paramType,
|
||||
ConstraintKind kind,
|
||||
TypeMatchOptions flags,
|
||||
ConstraintLocatorBuilder locator) {
|
||||
// Short-circuit matching zero-argument function types.
|
||||
if (type1.empty() && type2.empty()) {
|
||||
return getTypeMatchSuccess();
|
||||
}
|
||||
|
||||
TypeMatchOptions subflags = getDefaultDecompositionOptions(flags) | TMF_GenerateConstraints;
|
||||
|
||||
// Extract the parameters.
|
||||
ValueDecl *callee;
|
||||
unsigned calleeLevel;
|
||||
ArrayRef<Identifier> argLabels;
|
||||
SmallVector<Identifier, 2> argLabelsScratch;
|
||||
bool hasTrailingClosure = false;
|
||||
std::tie(callee, calleeLevel, argLabels, hasTrailingClosure) =
|
||||
getCalleeDeclAndArgs(*this, locator, argLabelsScratch);
|
||||
// FIXME: If we're unable to dig out a callee, defer to match types. This
|
||||
// occurs e.g. when we bind overloads. These code paths occur too early to
|
||||
// set resolvedOverloads, so require special handling to bind any latent
|
||||
// type variables.
|
||||
if (!callee) {
|
||||
return matchTypes(argType, paramType, kind, flags, locator);
|
||||
}
|
||||
|
||||
llvm::SmallBitVector defaultMap =
|
||||
computeDefaultMap(type1, callee, calleeLevel);
|
||||
|
||||
// Match up the call arguments to the parameters.
|
||||
MatchCallArgumentListener listener;
|
||||
SmallVector<ParamBinding, 4> parameterBindings;
|
||||
if (constraints::matchCallArguments(
|
||||
type2, type1, defaultMap, hasTrailingClosure,
|
||||
/*allowFixes=*/false, listener, parameterBindings))
|
||||
return getTypeMatchFailure(locator);
|
||||
|
||||
// Compare each of the bound arguments for this parameter.
|
||||
for (unsigned paramIdx = 0, numParams = parameterBindings.size();
|
||||
paramIdx != numParams; ++paramIdx){
|
||||
// Skip unfulfilled parameters. There's nothing to do for them.
|
||||
if (parameterBindings[paramIdx].empty())
|
||||
continue;
|
||||
|
||||
// Determine the parameter type.
|
||||
const auto ¶m = type2[paramIdx];
|
||||
auto paramTy = param.getType();
|
||||
|
||||
// Compare each of the bound arguments for this parameter.
|
||||
for (auto argIdx : parameterBindings[paramIdx]) {
|
||||
auto loc = locator.withPathElement(LocatorPathElt::
|
||||
getApplyArgToParam(argIdx,
|
||||
paramIdx));
|
||||
auto argTy = type1[argIdx].getType();
|
||||
|
||||
auto result = matchTypes(argTy, paramTy, kind, subflags, loc);
|
||||
if (result.isFailure())
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return getTypeMatchSuccess();
|
||||
}
|
||||
|
||||
|
||||
ConstraintSystem::TypeMatchResult
|
||||
ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
|
||||
ConstraintKind kind, TypeMatchOptions flags,
|
||||
@@ -1306,16 +1236,9 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
|
||||
}
|
||||
|
||||
// Input types can be contravariant (or equal).
|
||||
SmallVector<AnyFunctionType::Param, 4> func1Params;
|
||||
SmallVector<AnyFunctionType::Param, 4> func2Params;
|
||||
AnyFunctionType::decomposeInput(func1Input, func1Params);
|
||||
AnyFunctionType::decomposeInput(func2Input, func2Params);
|
||||
|
||||
auto result =
|
||||
matchFunctionParamTypes(func2Params, func1Params, func2Input, func1Input,
|
||||
subKind, subflags,
|
||||
matchTypes(func2Input, func1Input, subKind, subflags,
|
||||
locator.withPathElement(ConstraintLocator::FunctionArgument));
|
||||
|
||||
if (result.isFailure())
|
||||
return result;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user