@@ -719,43 +719,34 @@ matchCallArguments(ArrayRef<AnyFunctionType::Param> args,
719
719
static std::tuple<ValueDecl *, bool , ArrayRef<Identifier>, bool ,
720
720
ConstraintLocator *>
721
721
getCalleeDeclAndArgs (ConstraintSystem &cs,
722
- ConstraintLocatorBuilder callLocator,
723
- SmallVectorImpl<Identifier> &argLabelsScratch) {
722
+ ConstraintLocatorBuilder callBuilder) {
724
723
ArrayRef<Identifier> argLabels;
725
724
bool hasTrailingClosure = false ;
725
+ ConstraintLocator *targetLocator = nullptr ;
726
+
727
+ auto *callLocator = cs.getConstraintLocator (callBuilder);
728
+ auto *callExpr = callLocator->getAnchor ();
726
729
727
730
// Break down the call.
728
- SmallVector<LocatorPathElt, 2 > path;
729
- auto callExpr = callLocator.getLocatorParts (path);
730
731
if (!callExpr)
731
732
return std::make_tuple (nullptr , /* hasAppliedSelf=*/ false , argLabels,
732
- hasTrailingClosure, nullptr );
733
+ hasTrailingClosure, targetLocator );
733
734
735
+ auto path = callLocator->getPath ();
734
736
// Our remaining path can only be 'ApplyArgument'.
735
737
if (!path.empty () &&
736
738
!(path.size () <= 2 &&
737
739
path.back ().getKind () == ConstraintLocator::ApplyArgument))
738
740
return std::make_tuple (nullptr , /* hasAppliedSelf=*/ false , argLabels,
739
- hasTrailingClosure, nullptr );
740
-
741
- // Dig out the callee.
742
- ConstraintLocator *targetLocator;
743
- if (auto call = dyn_cast<CallExpr>(callExpr)) {
744
- targetLocator = cs.getConstraintLocator (call->getDirectCallee ());
745
- argLabels = call->getArgumentLabels ();
746
- hasTrailingClosure = call->hasTrailingClosure ();
747
- } else if (auto unresolved = dyn_cast<UnresolvedMemberExpr>(callExpr)) {
748
- targetLocator = cs.getConstraintLocator (callExpr);
749
- argLabels = unresolved->getArgumentLabels ();
750
- hasTrailingClosure = unresolved->hasTrailingClosure ();
751
- } else if (auto subscript = dyn_cast<SubscriptExpr>(callExpr)) {
752
- targetLocator = cs.getConstraintLocator (callExpr);
753
- argLabels = subscript->getArgumentLabels ();
754
- hasTrailingClosure = subscript->hasTrailingClosure ();
755
- } else if (auto dynSubscript = dyn_cast<DynamicSubscriptExpr>(callExpr)) {
756
- targetLocator = cs.getConstraintLocator (callExpr);
757
- argLabels = dynSubscript->getArgumentLabels ();
758
- hasTrailingClosure = dynSubscript->hasTrailingClosure ();
741
+ hasTrailingClosure, targetLocator);
742
+
743
+ // Dig out the callee information.
744
+ if (auto argInfo = cs.getArgumentInfo (callLocator)) {
745
+ argLabels = argInfo->Labels ;
746
+ hasTrailingClosure = argInfo->HasTrailingClosure ;
747
+ targetLocator = cs.getConstraintLocator (
748
+ isa<CallExpr>(callExpr) ? cast<CallExpr>(callExpr)->getDirectCallee ()
749
+ : callExpr);
759
750
} else if (auto keyPath = dyn_cast<KeyPathExpr>(callExpr)) {
760
751
if (path.size () != 2 ||
761
752
path[0 ].getKind () != ConstraintLocator::KeyPathComponent ||
@@ -788,17 +779,9 @@ getCalleeDeclAndArgs(ConstraintSystem &cs,
788
779
return std::make_tuple (nullptr , /* hasAppliedSelf=*/ false , argLabels,
789
780
hasTrailingClosure, nullptr );
790
781
}
791
-
792
782
} else {
793
- if (auto apply = dyn_cast<ApplyExpr>(callExpr)) {
794
- argLabels = apply->getArgumentLabels (argLabelsScratch);
795
- assert (!apply->hasTrailingClosure ());
796
- } else if (auto objectLiteral = dyn_cast<ObjectLiteralExpr>(callExpr)) {
797
- argLabels = objectLiteral->getArgumentLabels ();
798
- hasTrailingClosure = objectLiteral->hasTrailingClosure ();
799
- }
800
783
return std::make_tuple (nullptr , /* hasAppliedSelf=*/ false , argLabels,
801
- hasTrailingClosure, nullptr );
784
+ hasTrailingClosure, targetLocator );
802
785
}
803
786
804
787
// Find the overload choice corresponding to the callee locator.
@@ -941,12 +924,11 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
941
924
ValueDecl *callee;
942
925
bool hasAppliedSelf;
943
926
ArrayRef<Identifier> argLabels;
944
- SmallVector<Identifier, 2 > argLabelsScratch;
945
927
bool hasTrailingClosure = false ;
946
928
ConstraintLocator *calleeLocator;
947
929
std::tie (callee, hasAppliedSelf, argLabels, hasTrailingClosure,
948
930
calleeLocator) =
949
- getCalleeDeclAndArgs (cs, locator, argLabelsScratch );
931
+ getCalleeDeclAndArgs (cs, locator);
950
932
951
933
ParameterListInfo paramInfo (params, callee, hasAppliedSelf);
952
934
@@ -3931,49 +3913,6 @@ ConstraintSystem::simplifyFunctionComponentConstraint(
3931
3913
return SolutionKind::Solved;
3932
3914
}
3933
3915
3934
- // / Retrieve the argument labels that are provided for a member
3935
- // / reference at the given locator.
3936
- static Optional<ConstraintSystem::ArgumentLabelState>
3937
- getArgumentLabels (ConstraintSystem &cs, ConstraintLocatorBuilder locator) {
3938
- SmallVector<LocatorPathElt, 2 > parts;
3939
- Expr *anchor = locator.getLocatorParts (parts);
3940
- if (!anchor)
3941
- return None;
3942
-
3943
- while (!parts.empty ()) {
3944
- if (parts.back ().getKind () == ConstraintLocator::Member ||
3945
- parts.back ().getKind () == ConstraintLocator::SubscriptMember) {
3946
- parts.pop_back ();
3947
- continue ;
3948
- }
3949
-
3950
- if (parts.back ().getKind () == ConstraintLocator::ApplyFunction) {
3951
- if (auto applyExpr = dyn_cast<ApplyExpr>(anchor)) {
3952
- anchor = applyExpr->getSemanticFn ();
3953
- }
3954
- parts.pop_back ();
3955
- continue ;
3956
- }
3957
-
3958
- if (parts.back ().getKind () == ConstraintLocator::ConstructorMember) {
3959
- parts.pop_back ();
3960
- continue ;
3961
- }
3962
-
3963
- break ;
3964
- }
3965
-
3966
- if (!parts.empty ())
3967
- return None;
3968
-
3969
- anchor = getArgumentLabelTargetExpr (anchor);
3970
- auto known = cs.ArgumentLabels .find (cs.getConstraintLocator (anchor));
3971
- if (known == cs.ArgumentLabels .end ())
3972
- return None;
3973
-
3974
- return known->second ;
3975
- }
3976
-
3977
3916
// / Return true if the specified type or a super-class/super-protocol has the
3978
3917
// / @dynamicMemberLookup attribute on it. This implementation is not
3979
3918
// / particularly fast in the face of deep class hierarchies or lots of protocol
@@ -4194,10 +4133,8 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
4194
4133
// the argument labels into the name: we don't want to look for
4195
4134
// anything else, because the cost of the general search is so
4196
4135
// high.
4197
- if (auto argumentLabels =
4198
- getArgumentLabels (*this , ConstraintLocatorBuilder (memberLocator))) {
4199
- memberName = DeclName (TC.Context , memberName.getBaseName (),
4200
- argumentLabels->Labels );
4136
+ if (auto info = getArgumentInfo (memberLocator)) {
4137
+ memberName = DeclName (TC.Context , memberName.getBaseName (), info->Labels );
4201
4138
}
4202
4139
}
4203
4140
@@ -4473,8 +4410,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
4473
4410
if (::hasDynamicMemberLookupAttribute (instanceTy,
4474
4411
DynamicMemberLookupCache) &&
4475
4412
isValidKeyPathDynamicMemberLookup (subscript, TC)) {
4476
- auto info =
4477
- getArgumentLabels (*this , ConstraintLocatorBuilder (memberLocator));
4413
+ auto info = getArgumentInfo (memberLocator);
4478
4414
4479
4415
if (!(info && info->Labels .size () == 1 &&
4480
4416
info->Labels [0 ] == getASTContext ().Id_dynamicMember )) {
@@ -5906,7 +5842,7 @@ Type ConstraintSystem::simplifyAppliedOverloads(
5906
5842
return markFailure ();
5907
5843
};
5908
5844
5909
- auto argumentInfo = getArgumentLabels (* this , locator);
5845
+ auto argumentInfo = getArgumentInfo ( getConstraintLocator ( locator) );
5910
5846
5911
5847
// Consider each of the constraints in the disjunction.
5912
5848
retry_after_fail:
0 commit comments