mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CS] NFC: Inline getCalleeDeclAndArgs
This commit is contained in:
@@ -764,38 +764,6 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
|
||||
return listener.relabelArguments(actualArgNames);
|
||||
}
|
||||
|
||||
/// Find the callee declaration and uncurry level for a given call
|
||||
/// locator.
|
||||
static std::tuple<ValueDecl *, bool, ArrayRef<Identifier>, bool,
|
||||
ConstraintLocator *>
|
||||
getCalleeDeclAndArgs(ConstraintSystem &cs,
|
||||
ConstraintLocatorBuilder callBuilder) {
|
||||
auto *callLocator = cs.getConstraintLocator(callBuilder);
|
||||
assert(callLocator->isLastElement<LocatorPathElt::ApplyArgument>());
|
||||
|
||||
// Dig out the argument information.
|
||||
auto argInfo = cs.getArgumentInfo(callLocator);
|
||||
assert(argInfo);
|
||||
|
||||
auto argLabels = argInfo->Labels;
|
||||
auto hasTrailingClosure = argInfo->HasTrailingClosure;
|
||||
|
||||
// Find the overload choice corresponding to the callee locator.
|
||||
auto *calleeLocator = cs.getCalleeLocator(callLocator);
|
||||
auto selectedOverload = cs.findSelectedOverloadFor(calleeLocator);
|
||||
|
||||
// If we didn't find any matching overloads, we're done. Just return the
|
||||
// argument info.
|
||||
if (!selectedOverload)
|
||||
return std::make_tuple(/*decl*/ nullptr, /*hasAppliedSelf*/ false,
|
||||
argLabels, hasTrailingClosure, calleeLocator);
|
||||
|
||||
// Return the found declaration, assuming there is one.
|
||||
auto choice = selectedOverload->choice;
|
||||
return std::make_tuple(choice.getDeclOrNull(), hasAppliedSelf(cs, choice),
|
||||
argLabels, hasTrailingClosure, calleeLocator);
|
||||
}
|
||||
|
||||
class ArgumentFailureTracker : public MatchCallArgumentListener {
|
||||
ConstraintSystem &CS;
|
||||
SmallVectorImpl<AnyFunctionType::Param> &Arguments;
|
||||
@@ -982,22 +950,29 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
|
||||
ArrayRef<AnyFunctionType::Param> args,
|
||||
ArrayRef<AnyFunctionType::Param> params, ConstraintKind subKind,
|
||||
ConstraintLocatorBuilder locator) {
|
||||
// Extract the parameters.
|
||||
ValueDecl *callee;
|
||||
bool hasAppliedSelf;
|
||||
ArrayRef<Identifier> argLabels;
|
||||
bool hasTrailingClosure = false;
|
||||
ConstraintLocator *calleeLocator;
|
||||
std::tie(callee, hasAppliedSelf, argLabels, hasTrailingClosure,
|
||||
calleeLocator) =
|
||||
getCalleeDeclAndArgs(cs, locator);
|
||||
auto *loc = cs.getConstraintLocator(locator);
|
||||
assert(loc->isLastElement<LocatorPathElt::ApplyArgument>());
|
||||
|
||||
ParameterListInfo paramInfo(params, callee, hasAppliedSelf);
|
||||
ValueDecl *callee = nullptr;
|
||||
bool appliedSelf = false;
|
||||
|
||||
// Resolve the callee for the application.
|
||||
auto *calleeLocator = cs.getCalleeLocator(loc);
|
||||
if (auto overload = cs.findSelectedOverloadFor(calleeLocator)) {
|
||||
callee = overload->choice.getDeclOrNull();
|
||||
appliedSelf = hasAppliedSelf(cs, overload->choice);
|
||||
}
|
||||
|
||||
ParameterListInfo paramInfo(params, callee, appliedSelf);
|
||||
|
||||
// Dig out the argument information.
|
||||
auto argInfo = cs.getArgumentInfo(loc);
|
||||
assert(argInfo);
|
||||
|
||||
// Apply labels to arguments.
|
||||
SmallVector<AnyFunctionType::Param, 8> argsWithLabels;
|
||||
argsWithLabels.append(args.begin(), args.end());
|
||||
AnyFunctionType::relabelParams(argsWithLabels, argLabels);
|
||||
AnyFunctionType::relabelParams(argsWithLabels, argInfo->Labels);
|
||||
|
||||
// Special case when a single tuple argument if used
|
||||
// instead of N distinct arguments e.g.:
|
||||
@@ -1039,7 +1014,7 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
|
||||
ArgumentFailureTracker listener(cs, argsWithLabels, params,
|
||||
parameterBindings, locator);
|
||||
if (constraints::matchCallArguments(
|
||||
argsWithLabels, params, paramInfo, hasTrailingClosure,
|
||||
argsWithLabels, params, paramInfo, argInfo->HasTrailingClosure,
|
||||
cs.shouldAttemptFixes(), listener, parameterBindings))
|
||||
return cs.getTypeMatchFailure(locator);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user