Skip to content

Commit fdbc219

Browse files
committed
[CS] Don't create new locator when simplifying to anchor
We can directly use the version of `simplifyLocator` that works on an anchor and path array ref instead.
1 parent 7e5e00a commit fdbc219

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ bool FailureDiagnosis::diagnoseGeneralOverloadFailure(Constraint *constraint) {
820820
// Get the referenced expression from the failed constraint.
821821
auto anchor = expr;
822822
if (auto locator = bindOverload->getLocator()) {
823-
anchor = simplifyLocatorToAnchor(CS, locator);
823+
anchor = simplifyLocatorToAnchor(locator);
824824
if (!anchor)
825825
return false;
826826
}
@@ -1002,7 +1002,7 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){
10021002
bool resolvedAnchorToExpr = false;
10031003

10041004
if (auto locator = constraint->getLocator()) {
1005-
anchor = simplifyLocatorToAnchor(CS, locator);
1005+
anchor = simplifyLocatorToAnchor(locator);
10061006
if (anchor)
10071007
resolvedAnchorToExpr = true;
10081008
else
@@ -5390,7 +5390,7 @@ bool FailureDiagnosis::visitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
53905390
Constraint *memberConstraint = nullptr;
53915391
auto checkConstraint = [&](Constraint *C) {
53925392
if (C->getKind() == ConstraintKind::UnresolvedValueMember &&
5393-
simplifyLocatorToAnchor(CS, C->getLocator()) == E)
5393+
simplifyLocatorToAnchor(C->getLocator()) == E)
53945394
memberConstraint = C;
53955395
};
53965396

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
212212
auto *argLocator = cs.getConstraintLocator(
213213
anchor, argPath, ConstraintLocator::getSummaryFlagsForPath(argPath));
214214

215-
auto *argExpr = simplifyLocatorToAnchor(cs, argLocator);
215+
auto *argExpr = simplifyLocatorToAnchor(argLocator);
216216

217217
// If we were unable to simplify down to the argument expression, we don't
218218
// know what this is.

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ static ConstraintFix *fixPropertyWrapperFailure(
21612161
baseExpr = SE->getBase();
21622162
else if (auto *MRE = dyn_cast<MemberRefExpr>(anchor))
21632163
baseExpr = MRE->getBase();
2164-
else if (auto *anchor = simplifyLocatorToAnchor(cs, locator))
2164+
else if (auto *anchor = simplifyLocatorToAnchor(locator))
21652165
baseExpr = anchor;
21662166
}
21672167

@@ -2300,9 +2300,7 @@ bool ConstraintSystem::repairFailures(
23002300
// default values, let's see whether error is related to missing
23012301
// explicit call.
23022302
if (fnType->getNumParams() > 0) {
2303-
auto *anchor =
2304-
simplifyLocatorToAnchor(*this, getConstraintLocator(locator));
2305-
2303+
auto *anchor = simplifyLocatorToAnchor(getConstraintLocator(locator));
23062304
if (!anchor)
23072305
return false;
23082306

lib/Sema/ConstraintSystem.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,7 +2625,7 @@ bool ConstraintSystem::diagnoseAmbiguity(Expr *expr,
26252625

26262626
// If we can't resolve the locator to an anchor expression with no path,
26272627
// we can't diagnose this well.
2628-
auto *anchor = simplifyLocatorToAnchor(*this, overload.locator);
2628+
auto *anchor = simplifyLocatorToAnchor(overload.locator);
26292629
if (!anchor)
26302630
continue;
26312631
auto it = indexMap.find(anchor);
@@ -2666,7 +2666,7 @@ bool ConstraintSystem::diagnoseAmbiguity(Expr *expr,
26662666
if (bestOverload) {
26672667
auto &overload = diff.overloads[*bestOverload];
26682668
auto name = getOverloadChoiceName(overload.choices);
2669-
auto anchor = simplifyLocatorToAnchor(*this, overload.locator);
2669+
auto anchor = simplifyLocatorToAnchor(overload.locator);
26702670

26712671
// Emit the ambiguity diagnostic.
26722672
auto &tc = getTypeChecker();
@@ -2718,17 +2718,21 @@ bool ConstraintSystem::diagnoseAmbiguity(Expr *expr,
27182718
return false;
27192719
}
27202720

2721-
Expr *constraints::simplifyLocatorToAnchor(ConstraintSystem &cs,
2722-
ConstraintLocator *locator) {
2723-
if (!locator || !locator->getAnchor())
2721+
Expr *constraints::simplifyLocatorToAnchor(ConstraintLocator *locator) {
2722+
if (!locator)
27242723
return nullptr;
27252724

2726-
SourceRange range;
2727-
locator = simplifyLocator(cs, locator, range);
2728-
if (!locator->getAnchor() || !locator->getPath().empty())
2725+
auto *anchor = locator->getAnchor();
2726+
if (!anchor)
27292727
return nullptr;
27302728

2731-
return locator->getAnchor();
2729+
SourceRange range;
2730+
auto path = locator->getPath();
2731+
simplifyLocator(anchor, path, range);
2732+
2733+
// We only want the new anchor if all the path elements have been simplified
2734+
// away.
2735+
return path.empty() ? anchor : nullptr;
27322736
}
27332737

27342738
Expr *constraints::getArgumentExpr(Expr *expr, unsigned index) {

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3950,7 +3950,7 @@ void simplifyLocator(Expr *&anchor,
39503950
///
39513951
/// \returns the anchor expression if it fully describes the locator, or
39523952
/// null otherwise.
3953-
Expr *simplifyLocatorToAnchor(ConstraintSystem &cs, ConstraintLocator *locator);
3953+
Expr *simplifyLocatorToAnchor(ConstraintLocator *locator);
39543954

39553955
/// Retrieve argument at specified index from given expression.
39563956
/// The expression could be "application", "subscript" or "member" call.

0 commit comments

Comments
 (0)