Skip to content

Commit 7db95fb

Browse files
authored
Merge pull request #77827 from hamishknight/rdar139234188-6.1
[6.1] [CS] Add a narrow hack for rdar://139234188
2 parents d865a8e + 5c48012 commit 7db95fb

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6445,7 +6445,8 @@ bool isResultBuilderMethodReference(ASTContext &, UnresolvedDotExpr *);
64456445

64466446
/// Determine the number of applications applied to the given overload.
64476447
unsigned getNumApplications(ValueDecl *decl, bool hasAppliedSelf,
6448-
FunctionRefKind functionRefKind);
6448+
FunctionRefKind functionRefKind,
6449+
ConstraintLocatorBuilder locator);
64496450

64506451
} // end namespace constraints
64516452

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10153,8 +10153,8 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
1015310153

1015410154
auto hasAppliedSelf = decl->hasCurriedSelf() &&
1015510155
doesMemberRefApplyCurriedSelf(baseObjTy, decl);
10156-
return getNumApplications(decl, hasAppliedSelf, functionRefKind) <
10157-
decl->getNumCurryLevels();
10156+
return getNumApplications(decl, hasAppliedSelf, functionRefKind,
10157+
memberLocator) < decl->getNumCurryLevels();
1015810158
});
1015910159
};
1016010160

lib/Sema/TypeOfReference.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,20 @@ static unsigned getNumRemovedArgumentLabels(ValueDecl *decl,
662662

663663
/// Determine the number of applications
664664
unsigned constraints::getNumApplications(ValueDecl *decl, bool hasAppliedSelf,
665-
FunctionRefKind functionRefKind) {
665+
FunctionRefKind functionRefKind,
666+
ConstraintLocatorBuilder locator) {
667+
// FIXME: Narrow hack for rdar://139234188 - Currently we set
668+
// FunctionRefKind::Compound for enum element patterns with tuple
669+
// sub-patterns to ensure the member has argument labels stripped. As such,
670+
// we need to account for the correct application level here. We ought to be
671+
// setting the correct FunctionRefKind and properly handling the label
672+
// matching in the solver though.
673+
if (auto lastElt = locator.last()) {
674+
if (auto matchElt = lastElt->getAs<LocatorPathElt::PatternMatch>()) {
675+
if (auto *EP = dyn_cast<EnumElementPattern>(matchElt->getPattern()))
676+
return (EP->hasSubPattern() ? 1 : 0) + hasAppliedSelf;
677+
}
678+
}
666679
switch (functionRefKind) {
667680
case FunctionRefKind::Unapplied:
668681
case FunctionRefKind::Compound:
@@ -886,7 +899,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
886899

887900
auto origOpenedType = openedType;
888901
if (!isRequirementOrWitness(locator)) {
889-
unsigned numApplies = getNumApplications(value, false, functionRefKind);
902+
unsigned numApplies = getNumApplications(value, false, functionRefKind,
903+
locator);
890904
openedType = adjustFunctionTypeForConcurrency(
891905
origOpenedType, /*baseType=*/Type(), func, useDC, numApplies, false,
892906
replacements, locator);
@@ -915,7 +929,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
915929
auto origOpenedType = openedType;
916930
if (!isRequirementOrWitness(locator)) {
917931
unsigned numApplies = getNumApplications(
918-
funcDecl, false, functionRefKind);
932+
funcDecl, false, functionRefKind, locator);
919933
openedType = adjustFunctionTypeForConcurrency(
920934
origOpenedType->castTo<FunctionType>(), /*baseType=*/Type(), funcDecl,
921935
useDC, numApplies, false, replacements, locator);
@@ -1665,7 +1679,7 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
16651679
// Don't adjust when doing witness matching, because that can cause cycles.
16661680
} else if (isa<AbstractFunctionDecl>(value) || isa<EnumElementDecl>(value)) {
16671681
unsigned numApplies = getNumApplications(
1668-
value, hasAppliedSelf, functionRefKind);
1682+
value, hasAppliedSelf, functionRefKind, locator);
16691683
openedType = adjustFunctionTypeForConcurrency(
16701684
origOpenedType->castTo<FunctionType>(), resolvedBaseTy, value, useDC,
16711685
numApplies, isMainDispatchQueueMember(locator), replacements, locator);
@@ -1849,7 +1863,7 @@ Type ConstraintSystem::getEffectiveOverloadType(ConstraintLocator *locator,
18491863
auto hasAppliedSelf =
18501864
doesMemberRefApplyCurriedSelf(overload.getBaseType(), decl);
18511865
unsigned numApplies = getNumApplications(
1852-
decl, hasAppliedSelf, overload.getFunctionRefKind());
1866+
decl, hasAppliedSelf, overload.getFunctionRefKind(), locator);
18531867

18541868
type = adjustFunctionTypeForConcurrency(
18551869
type->castTo<FunctionType>(), overload.getBaseType(), decl,

test/Constraints/rdar139234188.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-emit-silgen %s -verify -swift-version 6
2+
3+
struct S: Equatable {
4+
static func foo() -> Self { fatalError() }
5+
static func bar(_ x: Int) -> Self { fatalError() }
6+
static func baz(x: Int, y: Int) -> Self { fatalError() }
7+
public static func == (_: Self, _: Self) -> Bool { false }
8+
}
9+
10+
// rdar://139234188 - Make sure we don't consider these members to be partially
11+
// applied for concurrency adjustment.
12+
func foo(_ x: S) {
13+
_ = {
14+
switch x {
15+
case .foo():
16+
break
17+
case .bar(0):
18+
break
19+
case .baz(x: 1, y: 2):
20+
break
21+
default:
22+
break
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)