Skip to content

Commit 8d65fb3

Browse files
authored
Merge pull request swiftlang#77919 from hamishknight/remove-hack
[CS] Remove hack for rdar://139234188
2 parents b36b2b8 + d25bdfa commit 8d65fb3

File tree

5 files changed

+26
-40
lines changed

5 files changed

+26
-40
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6434,10 +6434,9 @@ Type getPatternTypeOfSingleUnlabeledPackExpansionTuple(Type type);
64346434
/// methods prefixed with `build*` i.e. `buildBlock`, `buildExpression` etc.
64356435
bool isResultBuilderMethodReference(ASTContext &, UnresolvedDotExpr *);
64366436

6437-
/// Determine the number of applications applied to the given overload.
6438-
unsigned getNumApplications(ValueDecl *decl, bool hasAppliedSelf,
6439-
FunctionRefInfo functionRefInfo,
6440-
ConstraintLocatorBuilder locator);
6437+
/// Determine the number of applications applied for a given FunctionRefInfo.
6438+
unsigned getNumApplications(bool hasAppliedSelf,
6439+
FunctionRefInfo functionRefInfo);
64416440

64426441
} // end namespace constraints
64436442

lib/Sema/CSFix.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,11 @@ SpecifyBaseTypeForOptionalUnresolvedMember::attempt(
22552255
if (kind != ConstraintKind::UnresolvedValueMember)
22562256
return nullptr;
22572257

2258+
// Only diagnose for UnresolvedMemberExprs.
2259+
// TODO: We ought to support diagnosing EnumElementPatterns too.
2260+
if (!isExpr<UnresolvedMemberExpr>(locator->getAnchor()))
2261+
return nullptr;
2262+
22582263
// None or only one viable candidate, there is no ambiguity.
22592264
if (result.ViableCandidates.size() <= 1)
22602265
return nullptr;

lib/Sema/CSGen.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,19 +2928,20 @@ namespace {
29282928
TVO_CanBindToLValue | TVO_CanBindToNoEscape);
29292929

29302930
// Tuple splat is still allowed for patterns (with a warning in Swift 5)
2931-
// so we need to start here from single-apply to make sure that e.g.
2931+
// so we need to set a non-compound reference to make sure that e.g.
29322932
// `case test(x: Int, y: Int)` gets the labels preserved when matched
29332933
// with `case let .test(tuple)`.
2934-
FunctionRefInfo functionRefInfo =
2935-
FunctionRefInfo::singleBaseNameApply();
2934+
auto functionRefInfo = FunctionRefInfo::unappliedBaseName();
2935+
if (enumPattern->hasSubPattern())
2936+
functionRefInfo = functionRefInfo.addingApplicationLevel();
2937+
29362938
// If sub-pattern is a tuple we'd need to mark reference as compound,
29372939
// that would make sure that the labels are dropped in cases
29382940
// when `case` has a single tuple argument (tuple explosion) or multiple
29392941
// arguments (tuple-to-tuple conversion).
2940-
// FIXME(FunctionRefInfo): This should be using single compound apply,
2941-
// at least until label matching is implemented in the solver.
2942+
// FIXME: We ought to be preserving labels and matching in the solver.
29422943
if (dyn_cast_or_null<TuplePattern>(enumPattern->getSubPattern()))
2943-
functionRefInfo = FunctionRefInfo::unappliedCompoundName();
2944+
functionRefInfo = FunctionRefInfo::singleCompoundNameApply();
29442945

29452946
auto patternLocator =
29462947
locator.withPathElement(LocatorPathElt::PatternMatch(pattern));

lib/Sema/CSSimplify.cpp

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

1016410164
auto hasAppliedSelf = decl->hasCurriedSelf() &&
1016510165
doesMemberRefApplyCurriedSelf(baseObjTy, decl);
10166-
return getNumApplications(decl, hasAppliedSelf, functionRefInfo,
10167-
memberLocator) < decl->getNumCurryLevels();
10166+
auto numApplies = getNumApplications(hasAppliedSelf, functionRefInfo);
10167+
return numApplies < decl->getNumCurryLevels();
1016810168
});
1016910169
};
1017010170

lib/Sema/TypeOfReference.cpp

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -663,26 +663,8 @@ static unsigned getNumRemovedArgumentLabels(ValueDecl *decl,
663663
llvm_unreachable("Unhandled FunctionRefInfo in switch.");
664664
}
665665

666-
/// Determine the number of applications
667-
unsigned constraints::getNumApplications(ValueDecl *decl, bool hasAppliedSelf,
668-
FunctionRefInfo functionRefInfo,
669-
ConstraintLocatorBuilder locator) {
670-
// FIXME: Narrow hack for rdar://139234188 - Currently we set
671-
// FunctionRefInfo::Compound for enum element patterns with tuple
672-
// sub-patterns to ensure the member has argument labels stripped. As such,
673-
// we need to account for the correct application level here. We ought to be
674-
// setting the correct FunctionRefInfo and properly handling the label
675-
// matching in the solver though.
676-
if (auto lastElt = locator.last()) {
677-
if (auto matchElt = lastElt->getAs<LocatorPathElt::PatternMatch>()) {
678-
if (auto *EP = dyn_cast<EnumElementPattern>(matchElt->getPattern()))
679-
return (EP->hasSubPattern() ? 1 : 0) + hasAppliedSelf;
680-
}
681-
}
682-
// FIXME(FunctionRefInfo): This matches the old behavior, but is wrong.
683-
if (functionRefInfo.isCompoundName())
684-
return 0 + hasAppliedSelf;
685-
666+
unsigned constraints::getNumApplications(bool hasAppliedSelf,
667+
FunctionRefInfo functionRefInfo) {
686668
switch (functionRefInfo.getApplyLevel()) {
687669
case FunctionRefInfo::ApplyLevel::Unapplied:
688670
return 0 + hasAppliedSelf;
@@ -908,8 +890,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
908890

909891
auto origOpenedType = openedType;
910892
if (!isRequirementOrWitness(locator)) {
911-
unsigned numApplies = getNumApplications(value, false, functionRefInfo,
912-
locator);
893+
unsigned numApplies = getNumApplications(/*hasAppliedSelf*/ false,
894+
functionRefInfo);
913895
openedType = adjustFunctionTypeForConcurrency(
914896
origOpenedType, /*baseType=*/Type(), func, useDC, numApplies, false,
915897
replacements, locator);
@@ -937,8 +919,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
937919

938920
auto origOpenedType = openedType;
939921
if (!isRequirementOrWitness(locator)) {
940-
unsigned numApplies = getNumApplications(
941-
funcDecl, false, functionRefInfo, locator);
922+
unsigned numApplies = getNumApplications(/*hasAppliedSelf*/ false,
923+
functionRefInfo);
942924
openedType = adjustFunctionTypeForConcurrency(
943925
origOpenedType->castTo<FunctionType>(), /*baseType=*/Type(), funcDecl,
944926
useDC, numApplies, false, replacements, locator);
@@ -1680,8 +1662,7 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
16801662
if (isRequirementOrWitness(locator)) {
16811663
// Don't adjust when doing witness matching, because that can cause cycles.
16821664
} else if (isa<AbstractFunctionDecl>(value) || isa<EnumElementDecl>(value)) {
1683-
unsigned numApplies = getNumApplications(
1684-
value, hasAppliedSelf, functionRefInfo, locator);
1665+
unsigned numApplies = getNumApplications(hasAppliedSelf, functionRefInfo);
16851666
openedType = adjustFunctionTypeForConcurrency(
16861667
origOpenedType->castTo<FunctionType>(), resolvedBaseTy, value, useDC,
16871668
numApplies, isMainDispatchQueueMember(locator), replacements, locator);
@@ -1864,8 +1845,8 @@ Type ConstraintSystem::getEffectiveOverloadType(ConstraintLocator *locator,
18641845

18651846
auto hasAppliedSelf =
18661847
doesMemberRefApplyCurriedSelf(overload.getBaseType(), decl);
1867-
unsigned numApplies = getNumApplications(
1868-
decl, hasAppliedSelf, overload.getFunctionRefInfo(), locator);
1848+
unsigned numApplies = getNumApplications(hasAppliedSelf,
1849+
overload.getFunctionRefInfo());
18691850

18701851
type = adjustFunctionTypeForConcurrency(
18711852
type->castTo<FunctionType>(), overload.getBaseType(), decl,

0 commit comments

Comments
 (0)