Skip to content

Commit 72340f3

Browse files
committed
[CSOptimizer] Look through OptionalEvaluationExprs when dealing with unapplied disjunctions
This improves performance for situations like `a?.b + 2` by giving a high score to `b` which prioritizes it over an operator.
1 parent 6bc23b5 commit 72340f3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,13 @@ static void determineBestChoicesInContext(
299299
if (applicableFn.isNull()) {
300300
auto *locator = disjunction->getLocator();
301301
if (auto expr = getAsExpr(locator->getAnchor())) {
302-
if (auto *parentExpr = cs.getParentExpr(expr)) {
302+
auto *parentExpr = cs.getParentExpr(expr);
303+
// Look through optional evaluation, so
304+
// we can cover expressions like `a?.b + 2`.
305+
if (isExpr<OptionalEvaluationExpr>(parentExpr))
306+
parentExpr = cs.getParentExpr(parentExpr);
307+
308+
if (parentExpr) {
303309
// If this is a chained member reference or a direct operator
304310
// argument it could be prioritized since it helps to establish
305311
// context for other calls i.e. `(a.)b + 2` if `a` and/or `b`

validation-test/Sema/type_checker_perf/fast/swift_package_index_1.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -typecheck %s -solver-scope-threshold=1000
1+
// RUN: %target-swift-frontend -typecheck %s -solver-scope-threshold=500
22
// REQUIRES: tools-release,no_asan
33

44
public class Cookie {

0 commit comments

Comments
 (0)