Skip to content

Commit 09a1f0b

Browse files
committed
[CS] NFC: Factor out includingParentApply
1 parent 85c0555 commit 09a1f0b

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,10 @@ class ConstraintSystem {
28262826
/// Associate an argument list with a call at a given locator.
28272827
void associateArgumentList(ConstraintLocator *locator, ArgumentList *args);
28282828

2829+
/// If the given node is a function expression with a parent ApplyExpr,
2830+
/// returns the apply, otherwise returns the node itself.
2831+
ASTNode includingParentApply(ASTNode node);
2832+
28292833
std::optional<SelectedOverload>
28302834
findSelectedOverloadFor(ConstraintLocator *locator) const {
28312835
auto result = ResolvedOverloads.find(locator);

lib/Sema/CSRanking.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,18 +1036,9 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
10361036
if (cs.isForCodeCompletion()) {
10371037
// Don't rank based on overload choices of function calls that contain the
10381038
// code completion token.
1039-
ASTNode anchor = simplifyLocatorToAnchor(overload.locator);
1040-
if (auto expr = getAsExpr(anchor)) {
1041-
// If the anchor is a called function, also don't rank overload choices
1042-
// if any of the arguments contain the code completion token.
1043-
if (auto apply = dyn_cast_or_null<ApplyExpr>(cs.getParentExpr(expr))) {
1044-
if (apply->getFn() == expr) {
1045-
anchor = apply;
1046-
}
1047-
}
1048-
}
1049-
if (anchor && cs.containsIDEInspectionTarget(anchor)) {
1050-
continue;
1039+
if (auto anchor = simplifyLocatorToAnchor(overload.locator)) {
1040+
if (cs.containsIDEInspectionTarget(cs.includingParentApply(anchor)))
1041+
continue;
10511042
}
10521043
}
10531044

lib/Sema/ConstraintSystem.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6658,6 +6658,16 @@ static bool shouldHaveDirectCalleeOverload(const CallExpr *callExpr) {
66586658
}
66596659
#endif
66606660

6661+
ASTNode ConstraintSystem::includingParentApply(ASTNode node) {
6662+
if (auto *expr = getAsExpr(node)) {
6663+
if (auto apply = getAsExpr<ApplyExpr>(getParentExpr(expr))) {
6664+
if (apply->getFn() == expr)
6665+
return apply;
6666+
}
6667+
}
6668+
return node;
6669+
}
6670+
66616671
Type Solution::resolveInterfaceType(Type type) const {
66626672
auto resolvedType = type.transform([&](Type type) -> Type {
66636673
if (auto *tvt = type->getAs<TypeVariableType>()) {

0 commit comments

Comments
 (0)