@@ -803,8 +803,6 @@ getCalleeDeclAndArgs(ConstraintSystem &cs,
803
803
auto calleeLocator = cs.getCalleeLocator (callLocator);
804
804
805
805
// Find the overload choice corresponding to the callee locator.
806
- // FIXME: This linearly walks the list of resolved overloads, which is
807
- // potentially very expensive.
808
806
auto selectedOverload = cs.findSelectedOverloadFor (calleeLocator);
809
807
810
808
// If we didn't find any matching overloads, we're done. Just return the
@@ -815,7 +813,7 @@ getCalleeDeclAndArgs(ConstraintSystem &cs,
815
813
/* calleeLocator*/ nullptr );
816
814
817
815
// Return the found declaration, assuming there is one.
818
- auto choice = selectedOverload->Choice ;
816
+ auto choice = selectedOverload->choice ;
819
817
return std::make_tuple (choice.getDeclOrNull (), hasAppliedSelf (cs, choice),
820
818
argLabels, hasTrailingClosure, calleeLocator);
821
819
}
@@ -1385,9 +1383,9 @@ assessRequirementFailureImpact(ConstraintSystem &cs, Type requirementType,
1385
1383
return 1 ;
1386
1384
1387
1385
unsigned choiceImpact = 0 ;
1388
- if (auto * choice = cs.findSelectedOverloadFor (ODRE)) {
1386
+ if (auto choice = cs.findSelectedOverloadFor (ODRE)) {
1389
1387
auto *typeVar = requirementType->castTo <TypeVariableType>();
1390
- choice->ImpliedType .visit ([&](Type type) {
1388
+ choice->openedType .visit ([&](Type type) {
1391
1389
if (type->isEqual (typeVar))
1392
1390
++choiceImpact;
1393
1391
});
@@ -2450,8 +2448,7 @@ static ConstraintFix *fixRequirementFailure(ConstraintSystem &cs, Type type1,
2450
2448
2451
2449
static ConstraintFix *fixPropertyWrapperFailure (
2452
2450
ConstraintSystem &cs, Type baseTy, ConstraintLocator *locator,
2453
- llvm::function_ref<bool (ResolvedOverloadSetListItem *, VarDecl *, Type)>
2454
- attemptFix,
2451
+ llvm::function_ref<bool (SelectedOverload, VarDecl *, Type)> attemptFix,
2455
2452
Optional<Type> toType = None) {
2456
2453
2457
2454
Expr *baseExpr = nullptr ;
@@ -2486,7 +2483,7 @@ static ConstraintFix *fixPropertyWrapperFailure(
2486
2483
if (baseTy->isEqual (type))
2487
2484
return nullptr ;
2488
2485
2489
- if (!attemptFix (resolvedOverload, decl, type))
2486
+ if (!attemptFix (* resolvedOverload, decl, type))
2490
2487
return nullptr ;
2491
2488
2492
2489
switch (fix) {
@@ -2503,20 +2500,21 @@ static ConstraintFix *fixPropertyWrapperFailure(
2503
2500
llvm_unreachable (" Unhandled Fix type in switch" );
2504
2501
};
2505
2502
2506
- if (auto storageWrapper = cs.getStorageWrapperInformation (resolvedOverload)) {
2503
+ if (auto storageWrapper =
2504
+ cs.getStorageWrapperInformation (*resolvedOverload)) {
2507
2505
if (auto *fix = applyFix (Fix::StorageWrapper, storageWrapper->first ,
2508
2506
storageWrapper->second ))
2509
2507
return fix;
2510
2508
}
2511
2509
2512
- if (auto wrapper = cs.getPropertyWrapperInformation (resolvedOverload)) {
2510
+ if (auto wrapper = cs.getPropertyWrapperInformation (* resolvedOverload)) {
2513
2511
if (auto *fix =
2514
2512
applyFix (Fix::PropertyWrapper, wrapper->first , wrapper->second ))
2515
2513
return fix;
2516
2514
}
2517
2515
2518
2516
if (auto wrappedProperty =
2519
- cs.getWrappedPropertyInformation (resolvedOverload)) {
2517
+ cs.getWrappedPropertyInformation (* resolvedOverload)) {
2520
2518
if (auto *fix = applyFix (Fix::WrappedValue, wrappedProperty->first ,
2521
2519
wrappedProperty->second ))
2522
2520
return fix;
@@ -2561,8 +2559,8 @@ repairViaBridgingCast(ConstraintSystem &cs, Type fromType, Type toType,
2561
2559
if (!anchor)
2562
2560
return false ;
2563
2561
2564
- if (auto * overload = cs.findSelectedOverloadFor (anchor)) {
2565
- auto *decl = overload->Choice .getDeclOrNull ();
2562
+ if (auto overload = cs.findSelectedOverloadFor (anchor)) {
2563
+ auto *decl = overload->choice .getDeclOrNull ();
2566
2564
if (decl && decl->isImplicitlyUnwrappedOptional ())
2567
2565
fromType = objectType1;
2568
2566
}
@@ -2703,11 +2701,11 @@ bool ConstraintSystem::repairFailures(
2703
2701
if (!anchor)
2704
2702
return false ;
2705
2703
2706
- auto * overload = findSelectedOverloadFor (anchor);
2707
- if (!(overload && overload->Choice .isDecl ()))
2704
+ auto overload = findSelectedOverloadFor (anchor);
2705
+ if (!(overload && overload->choice .isDecl ()))
2708
2706
return false ;
2709
2707
2710
- const auto &choice = overload->Choice ;
2708
+ const auto &choice = overload->choice ;
2711
2709
ParameterListInfo info (fnType->getParams (), choice.getDecl (),
2712
2710
hasAppliedSelf (*this , choice));
2713
2711
@@ -3093,8 +3091,7 @@ bool ConstraintSystem::repairFailures(
3093
3091
3094
3092
if (auto *fix = fixPropertyWrapperFailure (
3095
3093
*this , lhs, loc,
3096
- [&](ResolvedOverloadSetListItem *overload, VarDecl *decl,
3097
- Type newBase) {
3094
+ [&](SelectedOverload overload, VarDecl *decl, Type newBase) {
3098
3095
// FIXME: There is currently no easy way to avoid attempting
3099
3096
// fixes, matchTypes do not propagate `TMF_ApplyingFix` flag.
3100
3097
llvm::SaveAndRestore<ConstraintSystemOptions> options (
@@ -5317,8 +5314,8 @@ static bool isSelfRecursiveKeyPathDynamicMemberLookup(
5317
5314
auto *choiceLoc =
5318
5315
cs.getConstraintLocator (locator->getAnchor (), path.drop_back ());
5319
5316
5320
- if (auto * overload = cs.findSelectedOverloadFor (choiceLoc)) {
5321
- auto baseTy = overload->Choice .getBaseType ();
5317
+ if (auto overload = cs.findSelectedOverloadFor (choiceLoc)) {
5318
+ auto baseTy = overload->choice .getBaseType ();
5322
5319
5323
5320
// If it's `Foo<Int>` vs. `Foo<String>` it doesn't really matter
5324
5321
// for dynamic lookup because it's going to be performed on `Foo`.
@@ -6268,16 +6265,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
6268
6265
if (auto dotExpr =
6269
6266
dyn_cast_or_null<UnresolvedDotExpr>(locator->getAnchor ())) {
6270
6267
auto baseExpr = dotExpr->getBase ();
6271
- auto resolvedOverload = getResolvedOverloadSets ();
6272
- while (resolvedOverload) {
6273
- if (resolvedOverload->Locator ->getAnchor () == baseExpr) {
6274
- if (resolvedOverload->Choice
6275
- .isImplicitlyUnwrappedValueOrReturnValue ())
6276
- return SolutionKind::Error;
6277
- break ;
6278
- }
6279
- resolvedOverload = resolvedOverload->Previous ;
6280
- }
6268
+ if (auto overload = findSelectedOverloadFor (baseExpr))
6269
+ if (overload->choice .isImplicitlyUnwrappedValueOrReturnValue ())
6270
+ return SolutionKind::Error;
6281
6271
}
6282
6272
6283
6273
// Let's check whether the problem is related to optionality of base
@@ -6337,8 +6327,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
6337
6327
// properties that have matching members.
6338
6328
if (auto *fix = fixPropertyWrapperFailure (
6339
6329
*this , baseTy, locator,
6340
- [&](ResolvedOverloadSetListItem *overload, VarDecl *decl,
6341
- Type newBase) {
6330
+ [&](SelectedOverload overload, VarDecl *decl, Type newBase) {
6342
6331
return solveWithNewBaseOrName (newBase, member) ==
6343
6332
SolutionKind::Solved;
6344
6333
})) {
@@ -6915,30 +6904,6 @@ ConstraintSystem::simplifyKeyPathConstraint(
6915
6904
return SolutionKind::Error;
6916
6905
}
6917
6906
6918
- // First gather the callee locators for the individual components.
6919
- SmallVector<std::pair<ConstraintLocator *, OverloadChoice>, 4 > choices;
6920
- for (unsigned i : indices (keyPath->getComponents ())) {
6921
- auto *componentLoc = getConstraintLocator (
6922
- locator.withPathElement (LocatorPathElt::KeyPathComponent (i)));
6923
- auto *calleeLoc = getCalleeLocator (componentLoc);
6924
- choices.push_back ({calleeLoc, OverloadChoice ()});
6925
- }
6926
-
6927
- // Then search for the resolved overloads.
6928
- for (auto resolvedItem = resolvedOverloadSets; resolvedItem;
6929
- resolvedItem = resolvedItem->Previous ) {
6930
- auto locator = resolvedItem->Locator ;
6931
- auto kpElt = locator->getFirstElementAs <LocatorPathElt::KeyPathComponent>();
6932
- if (!kpElt || locator->getAnchor () != keyPath)
6933
- continue ;
6934
-
6935
- auto &choice = choices[kpElt->getIndex ()];
6936
- if (choice.first == locator) {
6937
- assert (choice.second .isInvalid () && " Resolved same component twice?" );
6938
- choice.second = resolvedItem->Choice ;
6939
- }
6940
- }
6941
-
6942
6907
// See if we resolved overloads for all the components involved.
6943
6908
enum {
6944
6909
ReadOnly,
@@ -6960,15 +6925,17 @@ ConstraintSystem::simplifyKeyPathConstraint(
6960
6925
case KeyPathExpr::Component::Kind::Subscript:
6961
6926
case KeyPathExpr::Component::Kind::UnresolvedProperty:
6962
6927
case KeyPathExpr::Component::Kind::UnresolvedSubscript: {
6963
- auto *calleeLoc = choices[i].first ;
6964
- auto choice = choices[i].second ;
6928
+ auto *componentLoc = getConstraintLocator (
6929
+ locator.withPathElement (LocatorPathElt::KeyPathComponent (i)));
6930
+ auto *calleeLoc = getCalleeLocator (componentLoc);
6931
+ auto overload = findSelectedOverloadFor (calleeLoc);
6965
6932
6966
6933
// If no choice was made, leave the constraint unsolved. But when
6967
6934
// generating constraints, we may already have enough information
6968
6935
// to determine whether the result will be a function type vs BGT KeyPath
6969
6936
// type, so continue through components to create new constraint at the
6970
6937
// end.
6971
- if (choice. isInvalid () || anyComponentsUnresolved) {
6938
+ if (!overload || anyComponentsUnresolved) {
6972
6939
if (flags.contains (TMF_GenerateConstraints)) {
6973
6940
anyComponentsUnresolved = true ;
6974
6941
continue ;
@@ -7000,6 +6967,7 @@ ConstraintSystem::simplifyKeyPathConstraint(
7000
6967
}
7001
6968
7002
6969
// tuple elements do not change the capability of the key path
6970
+ auto choice = overload->choice ;
7003
6971
if (choice.getKind () == OverloadChoiceKind::TupleIndex) {
7004
6972
continue ;
7005
6973
}
0 commit comments