Skip to content

Commit c745c17

Browse files
committed
Revert naming changes to getCalleeLocator & getChoiceFor
In addition, add a document comment to `getCalleeLocator` to clarify its semantics.
1 parent dba850f commit c745c17

File tree

6 files changed

+21
-25
lines changed

6 files changed

+21
-25
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4247,7 +4247,7 @@ namespace {
42474247
// Adjust the locator such that it includes any additional elements to
42484248
// point to the component's callee, e.g a SubscriptMember for a
42494249
// subscript component.
4250-
locator = cs.getAnchormostCalleeLocator(locator);
4250+
locator = cs.getCalleeLocator(locator);
42514251

42524252
bool isDynamicMember = false;
42534253
// If this is an unresolved link, make sure we resolved it.

lib/Sema/CSDiagnostics.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,10 @@ Expr *FailureDiagnostic::getBaseExprFor(Expr *anchor) const {
121121
return nullptr;
122122
}
123123

124-
Optional<SelectedOverload> FailureDiagnostic::getAnchormostChoice() const {
125-
return getAnchormostChoiceFor(getLocator());
126-
}
127-
128124
Optional<SelectedOverload>
129-
FailureDiagnostic::getAnchormostChoiceFor(ConstraintLocator *locator) const {
125+
FailureDiagnostic::getChoiceFor(ConstraintLocator *locator) const {
130126
auto &cs = getConstraintSystem();
131-
return getOverloadChoiceIfAvailable(cs.getAnchormostCalleeLocator(locator));
127+
return getOverloadChoiceIfAvailable(cs.getCalleeLocator(locator));
132128
}
133129

134130
Type FailureDiagnostic::resolveInterfaceType(Type type,
@@ -163,8 +159,7 @@ Type FailureDiagnostic::resolveInterfaceType(Type type,
163159
}
164160

165161
/// Given an apply expr, returns true if it is expected to have a direct callee
166-
/// overload, resolvable using `getAnchormostChoiceFor`. Otherwise, returns
167-
/// false.
162+
/// overload, resolvable using `getChoiceFor`. Otherwise, returns false.
168163
static bool shouldHaveDirectCalleeOverload(const CallExpr *callExpr) {
169164
auto *fnExpr = callExpr->getDirectCallee();
170165

@@ -226,7 +221,7 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
226221

227222
ValueDecl *callee = nullptr;
228223
Type rawFnType;
229-
if (auto overload = getAnchormostChoiceFor(argLocator)) {
224+
if (auto overload = getChoiceFor(argLocator)) {
230225
// If we have resolved an overload for the callee, then use that to get the
231226
// function type and callee.
232227
callee = overload->choice.getDeclOrNull();
@@ -380,7 +375,7 @@ ValueDecl *RequirementFailure::getDeclRef() const {
380375
if (isFromContextualType())
381376
return getAffectedDeclFromType(cs.getContextualType());
382377

383-
if (auto overload = getAnchormostChoice()) {
378+
if (auto overload = getChoiceFor(getLocator())) {
384379
// If there is a declaration associated with this
385380
// failure e.g. an overload choice of the call
386381
// expression, let's see whether failure is
@@ -752,7 +747,7 @@ bool LabelingFailure::diagnoseAsNote() {
752747
return "(" + str + ")";
753748
};
754749

755-
auto selectedOverload = getAnchormostChoice();
750+
auto selectedOverload = getChoiceFor(getLocator());
756751
if (!selectedOverload)
757752
return false;
758753

@@ -3127,7 +3122,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
31273122
};
31283123

31293124
auto *baseLoc = cs.getConstraintLocator(ctorRef->getBase());
3130-
if (auto selection = getAnchormostChoiceFor(baseLoc)) {
3125+
if (auto selection = getChoiceFor(baseLoc)) {
31313126
OverloadChoice choice = selection->choice;
31323127
if (choice.isDecl() && isMutable(choice.getDecl()) &&
31333128
!isCallArgument(initCall) &&
@@ -4287,7 +4282,7 @@ bool MutatingMemberRefOnImmutableBase::diagnoseAsError() {
42874282
}
42884283

42894284
bool InvalidTupleSplatWithSingleParameterFailure::diagnoseAsError() {
4290-
auto selectedOverload = getAnchormostChoice();
4285+
auto selectedOverload = getChoiceFor(getLocator());
42914286
if (!selectedOverload || !selectedOverload->choice.isDecl())
42924287
return false;
42934288

lib/Sema/CSDiagnostics.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,9 @@ class FailureDiagnostic {
176176
/// reference or subscript, nullptr otherwise.
177177
Expr *getArgumentExprFor(Expr *anchor) const;
178178

179-
/// \returns The overload choice made by the constraint system for the callee
180-
/// of this failure's raw anchor, or \c None if no such choice can be found.
181-
Optional<SelectedOverload> getAnchormostChoice() const;
182-
183179
/// \returns The overload choice made by the constraint system for the callee
184180
/// of a given locator's anchor, or \c None if no such choice can be found.
185-
Optional<SelectedOverload> getAnchormostChoiceFor(ConstraintLocator *) const;
181+
Optional<SelectedOverload> getChoiceFor(ConstraintLocator *) const;
186182

187183
/// For a given locator describing a function argument conversion, or a
188184
/// constraint within an argument conversion, returns information about the

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,8 +3023,8 @@ namespace {
30233023
}
30243024

30253025
case KeyPathExpr::Component::Kind::TupleElement: {
3026-
// Note: If implemented, the logic in `getAnchormostCalleeLocator`
3027-
// will need updating to return the correct callee locator for this.
3026+
// Note: If implemented, the logic in `getCalleeLocator` will need
3027+
// updating to return the correct callee locator for this.
30283028
llvm_unreachable("not implemented");
30293029
break;
30303030
}

lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ ConstraintLocator *ConstraintSystem::getConstraintLocator(
414414
}
415415

416416
ConstraintLocator *
417-
ConstraintSystem::getAnchormostCalleeLocator(ConstraintLocator *locator) {
417+
ConstraintSystem::getCalleeLocator(ConstraintLocator *locator) {
418418
auto *anchor = locator->getAnchor();
419419
assert(anchor && "Expected an anchor!");
420420

@@ -2497,7 +2497,7 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
24972497
return false;
24982498

24992499
const auto *fix = fixes.front();
2500-
auto *calleeLocator = getAnchormostCalleeLocator(fix->getLocator());
2500+
auto *calleeLocator = getCalleeLocator(fix->getLocator());
25012501
if (commonCalleeLocator && commonCalleeLocator != calleeLocator)
25022502
return false;
25032503

@@ -2875,7 +2875,7 @@ ConstraintSystem::getArgumentInfoLocator(ConstraintLocator *locator) {
28752875
return getConstraintLocator(fnExpr);
28762876
}
28772877

2878-
return getAnchormostCalleeLocator(locator);
2878+
return getCalleeLocator(locator);
28792879
}
28802880

28812881
Optional<ConstraintSystem::ArgumentInfo>

lib/Sema/ConstraintSystem.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,12 @@ class ConstraintSystem {
20232023
/// - For a function application anchor, this will be a locator describing the
20242024
/// 'direct callee' of the call. For example, for the expression \c x.foo?()
20252025
/// the returned locator will describe the member \c foo.
2026-
ConstraintLocator *getAnchormostCalleeLocator(ConstraintLocator *locator);
2026+
///
2027+
/// Note that because this function deals with the anchor, given a locator
2028+
/// anchored on \c functionA(functionB()) with path elements pointing to the
2029+
/// argument \c functionB(), the returned callee locator will describe
2030+
/// \c functionA rather than \c functionB.
2031+
ConstraintLocator *getCalleeLocator(ConstraintLocator *locator);
20272032

20282033
public:
20292034

0 commit comments

Comments
 (0)