Skip to content

Commit 1a8477a

Browse files
committed
[CS] NFC: Inline getCalleeDeclAndArgs
1 parent c6b6e72 commit 1a8477a

File tree

1 file changed

+20
-45
lines changed

1 file changed

+20
-45
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -764,38 +764,6 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
764764
return listener.relabelArguments(actualArgNames);
765765
}
766766

767-
/// Find the callee declaration and uncurry level for a given call
768-
/// locator.
769-
static std::tuple<ValueDecl *, bool, ArrayRef<Identifier>, bool,
770-
ConstraintLocator *>
771-
getCalleeDeclAndArgs(ConstraintSystem &cs,
772-
ConstraintLocatorBuilder callBuilder) {
773-
auto *callLocator = cs.getConstraintLocator(callBuilder);
774-
assert(callLocator->isLastElement<LocatorPathElt::ApplyArgument>());
775-
776-
// Dig out the argument information.
777-
auto argInfo = cs.getArgumentInfo(callLocator);
778-
assert(argInfo);
779-
780-
auto argLabels = argInfo->Labels;
781-
auto hasTrailingClosure = argInfo->HasTrailingClosure;
782-
783-
// Find the overload choice corresponding to the callee locator.
784-
auto *calleeLocator = cs.getCalleeLocator(callLocator);
785-
auto selectedOverload = cs.findSelectedOverloadFor(calleeLocator);
786-
787-
// If we didn't find any matching overloads, we're done. Just return the
788-
// argument info.
789-
if (!selectedOverload)
790-
return std::make_tuple(/*decl*/ nullptr, /*hasAppliedSelf*/ false,
791-
argLabels, hasTrailingClosure, calleeLocator);
792-
793-
// Return the found declaration, assuming there is one.
794-
auto choice = selectedOverload->choice;
795-
return std::make_tuple(choice.getDeclOrNull(), hasAppliedSelf(cs, choice),
796-
argLabels, hasTrailingClosure, calleeLocator);
797-
}
798-
799767
class ArgumentFailureTracker : public MatchCallArgumentListener {
800768
ConstraintSystem &CS;
801769
SmallVectorImpl<AnyFunctionType::Param> &Arguments;
@@ -982,22 +950,29 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
982950
ArrayRef<AnyFunctionType::Param> args,
983951
ArrayRef<AnyFunctionType::Param> params, ConstraintKind subKind,
984952
ConstraintLocatorBuilder locator) {
985-
// Extract the parameters.
986-
ValueDecl *callee;
987-
bool hasAppliedSelf;
988-
ArrayRef<Identifier> argLabels;
989-
bool hasTrailingClosure = false;
990-
ConstraintLocator *calleeLocator;
991-
std::tie(callee, hasAppliedSelf, argLabels, hasTrailingClosure,
992-
calleeLocator) =
993-
getCalleeDeclAndArgs(cs, locator);
994-
995-
ParameterListInfo paramInfo(params, callee, hasAppliedSelf);
953+
auto *loc = cs.getConstraintLocator(locator);
954+
assert(loc->isLastElement<LocatorPathElt::ApplyArgument>());
955+
956+
ValueDecl *callee = nullptr;
957+
bool appliedSelf = false;
958+
959+
// Resolve the callee for the application.
960+
auto *calleeLocator = cs.getCalleeLocator(loc);
961+
if (auto overload = cs.findSelectedOverloadFor(calleeLocator)) {
962+
callee = overload->choice.getDeclOrNull();
963+
appliedSelf = hasAppliedSelf(cs, overload->choice);
964+
}
965+
966+
ParameterListInfo paramInfo(params, callee, appliedSelf);
967+
968+
// Dig out the argument information.
969+
auto argInfo = cs.getArgumentInfo(loc);
970+
assert(argInfo);
996971

997972
// Apply labels to arguments.
998973
SmallVector<AnyFunctionType::Param, 8> argsWithLabels;
999974
argsWithLabels.append(args.begin(), args.end());
1000-
AnyFunctionType::relabelParams(argsWithLabels, argLabels);
975+
AnyFunctionType::relabelParams(argsWithLabels, argInfo->Labels);
1001976

1002977
// Special case when a single tuple argument if used
1003978
// instead of N distinct arguments e.g.:
@@ -1039,7 +1014,7 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
10391014
ArgumentFailureTracker listener(cs, argsWithLabels, params,
10401015
parameterBindings, locator);
10411016
if (constraints::matchCallArguments(
1042-
argsWithLabels, params, paramInfo, hasTrailingClosure,
1017+
argsWithLabels, params, paramInfo, argInfo->HasTrailingClosure,
10431018
cs.shouldAttemptFixes(), listener, parameterBindings))
10441019
return cs.getTypeMatchFailure(locator);
10451020

0 commit comments

Comments
 (0)