Skip to content

Commit 2f4f3df

Browse files
committed
[ConstraintSystem] Discount effects while filtering call overload sets
Before these changes filtering would not favor some members because their function types have `escaping` bit set when argument function type never has it. Double/CGFloat implicit conversion is one of such cases where `CGFloat.init` overloads have `escaping` bit, which leads to solver checking more overloads then it should. Note that the difference in effects such as `async` is going to be handled by scoring and ranking after partial solution is produced, so overloads that differ only in `async` or `throws` are still going to be solved for as part of "favored" set. (cherry picked from commit 14dab87)
1 parent 472f7b6 commit 2f4f3df

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11084,9 +11084,19 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1108411084
return true;
1108511085
}
1108611086

11087-
// If types lined up exactly, let's favor this overload choice.
11088-
if (Type(argFnType)->isEqual(choiceType))
11089-
constraint->setFavored();
11087+
// If types of arguments/parameters and result lined up exactly,
11088+
// let's favor this overload choice.
11089+
//
11090+
// Note this check ignores `ExtInfo` on purpose and only compares
11091+
// types, if there are overloads that differ only in effects then
11092+
// all of them are going to be considered and filtered as part of
11093+
// "favored" group after forming a valid partial solution.
11094+
if (auto *choiceFnType = choiceType->getAs<FunctionType>()) {
11095+
if (FunctionType::equalParams(argFnType->getParams(),
11096+
choiceFnType->getParams()) &&
11097+
argFnType->getResult()->isEqual(choiceFnType->getResult()))
11098+
constraint->setFavored();
11099+
}
1109011100

1109111101
// Account for any optional unwrapping/binding
1109211102
for (unsigned i : range(numOptionalUnwraps)) {

test/Constraints/overload_filtering_objc.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,24 @@ func testOptional(obj: P) {
2222
// CHECK: [disabled] $T2 bound to decl overload_filtering_objc.(file).P.opt(double:)
2323
_ = obj.opt?(1)
2424
}
25+
26+
27+
func test_double_cgfloat_conversion_filtering(d: Double, cgf: CGFloat) {
28+
// CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).CGFloat.init(_:)@{{.*}} : (CGFloat.Type) -> (Double) -> CGFloat {{.*}} -> implicit conversion [Double-to-CGFloat] -> apply function -> constructor member
29+
let _: CGFloat = d
30+
31+
// CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).Double extension.init(_:)@{{.*}} : (Double.Type) -> (CGFloat) -> Double {{.*}} -> implicit conversion [CGFloat-to-Double] -> apply function -> constructor member
32+
let _: Double = cgf
33+
34+
func test_optional_cgf(_: CGFloat??) {
35+
}
36+
37+
func test_optional_double(_: Double??) {
38+
}
39+
40+
// CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).CGFloat.init(_:)@{{.*}} : (CGFloat.Type) -> (Double) -> CGFloat {{.*}} -> implicit conversion [Double-to-CGFloat] -> apply function -> constructor member
41+
test_optional_cgf(d)
42+
43+
// CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).Double extension.init(_:)@{{.*}} : (Double.Type) -> (CGFloat) -> Double {{.*}} -> implicit conversion [CGFloat-to-Double] -> apply function -> constructor member
44+
test_optional_double(cgf)
45+
}

0 commit comments

Comments
 (0)