Skip to content

Commit 8242d84

Browse files
committed
NFC, Sema: Further propagate the locator through to doesStorageProduceLValue
1 parent 42e510c commit 8242d84

File tree

5 files changed

+44
-42
lines changed

5 files changed

+44
-42
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3873,12 +3873,13 @@ class ConstraintSystem {
38733873
/// \param UseDC The context of the access. Some variables have different
38743874
/// types depending on where they are used.
38753875
///
3876-
/// \param base The optional base expression of this value reference
3876+
/// \param memberLocator The locator anchored at this value reference, when
3877+
/// it is a member reference.
38773878
///
38783879
/// \param wantInterfaceType Whether we want the interface type, if available.
38793880
Type getUnopenedTypeOfReference(VarDecl *value, Type baseType,
38803881
DeclContext *UseDC,
3881-
const DeclRefExpr *base = nullptr,
3882+
ConstraintLocator *memberLocator = nullptr,
38823883
bool wantInterfaceType = false);
38833884

38843885
/// Return the type-of-reference of the given value.
@@ -3889,15 +3890,16 @@ class ConstraintSystem {
38893890
/// \param UseDC The context of the access. Some variables have different
38903891
/// types depending on where they are used.
38913892
///
3892-
/// \param base The optional base expression of this value reference
3893+
/// \param memberLocator The locator anchored at this value reference, when
3894+
/// it is a member reference.
38933895
///
38943896
/// \param wantInterfaceType Whether we want the interface type, if available.
38953897
///
38963898
/// \param getType Optional callback to extract a type for given declaration.
38973899
static Type
38983900
getUnopenedTypeOfReference(VarDecl *value, Type baseType, DeclContext *UseDC,
38993901
llvm::function_ref<Type(VarDecl *)> getType,
3900-
const DeclRefExpr *base = nullptr,
3902+
ConstraintLocator *memberLocator = nullptr,
39013903
bool wantInterfaceType = false);
39023904

39033905
/// Retrieve the type of a reference to the given value declaration,
@@ -4017,7 +4019,8 @@ class ConstraintSystem {
40174019
ConstraintLocatorBuilder locator);
40184020

40194021
/// Retrieve the type that will be used when matching the given overload.
4020-
Type getEffectiveOverloadType(const OverloadChoice &overload,
4022+
Type getEffectiveOverloadType(ConstraintLocator *locator,
4023+
const OverloadChoice &overload,
40214024
bool allowMembers,
40224025
DeclContext *useDC);
40234026

lib/Sema/CSGen.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ namespace {
464464
return;
465465
}
466466

467-
Type overloadType =
468-
CS.getEffectiveOverloadType(constraint->getOverloadChoice(),
469-
/*allowMembers=*/true, CS.DC);
467+
Type overloadType = CS.getEffectiveOverloadType(
468+
constraint->getLocator(), constraint->getOverloadChoice(),
469+
/*allowMembers=*/true, CS.DC);
470470
if (!overloadType)
471471
continue;
472472

@@ -489,9 +489,9 @@ namespace {
489489
// result type.
490490
if (numFavoredConstraints == 1) {
491491
auto overloadChoice = firstFavored->getOverloadChoice();
492-
auto overloadType =
493-
CS.getEffectiveOverloadType(overloadChoice, /*allowMembers=*/true,
494-
CS.DC);
492+
auto overloadType = CS.getEffectiveOverloadType(
493+
firstFavored->getLocator(), overloadChoice, /*allowMembers=*/true,
494+
CS.DC);
495495
auto resultType = overloadType->castTo<AnyFunctionType>()->getResult();
496496
if (!resultType->hasTypeParameter())
497497
CS.setFavoredType(expr, resultType.getPointer());

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9282,9 +9282,9 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
92829282
}
92839283

92849284
// Determine the type that this choice will have.
9285-
Type choiceType =
9286-
getEffectiveOverloadType(choice, /*allowMembers=*/true,
9287-
constraint->getOverloadUseDC());
9285+
Type choiceType = getEffectiveOverloadType(
9286+
constraint->getLocator(), choice, /*allowMembers=*/true,
9287+
constraint->getOverloadUseDC());
92889288
if (!choiceType) {
92899289
hasUnhandledConstraints = true;
92909290
return true;

lib/Sema/CSStep.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,9 @@ bool DisjunctionStep::shouldSkip(const DisjunctionChoice &choice) const {
662662
auto *decl = constraint->getOverloadChoice().getDecl();
663663
if (decl->getBaseIdentifier().isArithmeticOperator()) {
664664
auto *useDC = constraint->getOverloadUseDC();
665-
auto choiceType = CS.getEffectiveOverloadType(constraint->getOverloadChoice(),
666-
/*allowMembers=*/true, useDC);
665+
auto choiceType = CS.getEffectiveOverloadType(
666+
constraint->getLocator(), constraint->getOverloadChoice(),
667+
/*allowMembers=*/true, useDC);
667668
auto choiceFnType = choiceType->getAs<FunctionType>();
668669
auto genericFnType = decl->getInterfaceType()->getAs<GenericFunctionType>();
669670
auto signature = genericFnType->getGenericSignature();

lib/Sema/ConstraintSystem.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,9 +1021,21 @@ ConstraintSystem::getWrappedPropertyInformation(
10211021
/// \param baseType - the type of the base on which this object
10221022
/// is being accessed; must be null if and only if this is not
10231023
/// a type member
1024-
static bool doesStorageProduceLValue(AbstractStorageDecl *storage,
1025-
Type baseType, DeclContext *useDC,
1026-
const DeclRefExpr *base = nullptr) {
1024+
static bool
1025+
doesStorageProduceLValue(AbstractStorageDecl *storage, Type baseType,
1026+
DeclContext *useDC,
1027+
ConstraintLocator *memberLocator = nullptr) {
1028+
const DeclRefExpr *base = nullptr;
1029+
if (memberLocator) {
1030+
if (auto *const E = getAsExpr(memberLocator->getAnchor())) {
1031+
if (auto *MRE = dyn_cast<MemberRefExpr>(E)) {
1032+
base = dyn_cast<DeclRefExpr>(MRE->getBase());
1033+
} else if (auto *UDE = dyn_cast<UnresolvedDotExpr>(E)) {
1034+
base = dyn_cast<DeclRefExpr>(UDE->getBase());
1035+
}
1036+
}
1037+
}
1038+
10271039
// Unsettable storage decls always produce rvalues.
10281040
if (!storage->isSettable(useDC, base))
10291041
return false;
@@ -1043,10 +1055,9 @@ static bool doesStorageProduceLValue(AbstractStorageDecl *storage,
10431055
!storage->isSetterMutating());
10441056
}
10451057

1046-
Type ConstraintSystem::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
1047-
DeclContext *UseDC,
1048-
const DeclRefExpr *base,
1049-
bool wantInterfaceType) {
1058+
Type ConstraintSystem::getUnopenedTypeOfReference(
1059+
VarDecl *value, Type baseType, DeclContext *UseDC,
1060+
ConstraintLocator *memberLocator, bool wantInterfaceType) {
10501061
return ConstraintSystem::getUnopenedTypeOfReference(
10511062
value, baseType, UseDC,
10521063
[&](VarDecl *var) -> Type {
@@ -1059,13 +1070,13 @@ Type ConstraintSystem::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
10591070

10601071
return wantInterfaceType ? var->getInterfaceType() : var->getType();
10611072
},
1062-
base, wantInterfaceType);
1073+
memberLocator, wantInterfaceType);
10631074
}
10641075

10651076
Type ConstraintSystem::getUnopenedTypeOfReference(
10661077
VarDecl *value, Type baseType, DeclContext *UseDC,
1067-
llvm::function_ref<Type(VarDecl *)> getType, const DeclRefExpr *base,
1068-
bool wantInterfaceType) {
1078+
llvm::function_ref<Type(VarDecl *)> getType,
1079+
ConstraintLocator *memberLocator, bool wantInterfaceType) {
10691080
Type requestedType =
10701081
getType(value)->getWithoutSpecifierType()->getReferenceStorageReferent();
10711082

@@ -1081,7 +1092,7 @@ Type ConstraintSystem::getUnopenedTypeOfReference(
10811092

10821093
// Qualify storage declarations with an lvalue when appropriate.
10831094
// Otherwise, they yield rvalues (and the access must be a load).
1084-
if (doesStorageProduceLValue(value, baseType, UseDC, base) &&
1095+
if (doesStorageProduceLValue(value, baseType, UseDC, memberLocator) &&
10851096
!requestedType->hasError()) {
10861097
return LValueType::get(requestedType);
10871098
}
@@ -1566,18 +1577,6 @@ ConstraintSystem::getTypeOfMemberReference(
15661577
unsigned numRemovedArgumentLabels = getNumRemovedArgumentLabels(
15671578
value, /*isCurriedInstanceReference*/ !hasAppliedSelf, functionRefKind);
15681579

1569-
const auto getBaseAsDeclRefExpr = [&] {
1570-
if (auto *E = getAsExpr(locator->getAnchor())) {
1571-
if (auto *MRE = dyn_cast<MemberRefExpr>(E)) {
1572-
return dyn_cast<DeclRefExpr>(MRE->getBase());
1573-
} else if (auto *UDE = dyn_cast<UnresolvedDotExpr>(E)) {
1574-
return dyn_cast<DeclRefExpr>(UDE->getBase());
1575-
}
1576-
}
1577-
1578-
return (DeclRefExpr *)nullptr;
1579-
};
1580-
15811580
AnyFunctionType *funcType;
15821581

15831582
if (isa<AbstractFunctionDecl>(value) ||
@@ -1593,8 +1592,7 @@ ConstraintSystem::getTypeOfMemberReference(
15931592
if (auto *subscript = dyn_cast<SubscriptDecl>(value)) {
15941593
auto elementTy = subscript->getElementInterfaceType();
15951594

1596-
if (doesStorageProduceLValue(subscript, baseTy, useDC,
1597-
getBaseAsDeclRefExpr()))
1595+
if (doesStorageProduceLValue(subscript, baseTy, useDC, locator))
15981596
elementTy = LValueType::get(elementTy);
15991597

16001598
// See ConstraintSystem::resolveOverload() -- optional and dynamic
@@ -1611,7 +1609,7 @@ ConstraintSystem::getTypeOfMemberReference(
16111609
refType = FunctionType::get(indices, elementTy);
16121610
} else {
16131611
refType = getUnopenedTypeOfReference(cast<VarDecl>(value), baseTy, useDC,
1614-
getBaseAsDeclRefExpr(),
1612+
locator,
16151613
/*wantInterfaceType=*/true);
16161614
}
16171615

0 commit comments

Comments
 (0)