Skip to content

Commit b8d5810

Browse files
committed
[CSSolver] Prioritize bindings with fewer default types
With all else equal prioritize bindings with fewer defaultable types, which always gets us closer to solution since defaultable bindings mostly come from the collections and could be checked at the end. This also makes sure that solver not as aggresive at assigning bindings to trailing closures and allows solver to consider types which come from inside the closure. Resolves: rdar://problem/37290898 (cherry picked from commit aff4974)
1 parent 583a11d commit b8d5810

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/Sema/ConstraintSystem.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,9 @@ class ConstraintSystem {
26392639
if (!x.hasNonDefaultableBindings())
26402640
return false;
26412641

2642+
if (x.FullyBound || x.SubtypeOfExistentialType)
2643+
return false;
2644+
26422645
llvm::SmallPtrSet<Constraint *, 8> intersection(x.Sources);
26432646
llvm::set_intersect(intersection, y.Sources);
26442647

@@ -2655,7 +2658,9 @@ class ConstraintSystem {
26552658
return x.TypeVar == typeVar;
26562659
}
26572660

2658-
return false;
2661+
// If the only difference is default types,
2662+
// prioritize bindings with fewer of them.
2663+
return x.NumDefaultableBindings < y.NumDefaultableBindings;
26592664
}
26602665

26612666
void foundLiteralBinding(ProtocolDecl *proto) {

test/Constraints/operator.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,10 @@ struct S_35740653 {
194194
func rdar35740653(val: S_35740653) {
195195
let _ = 0...Int(val / .value(1.0 / 42.0)) // Ok
196196
}
197+
198+
protocol P_37290898 {}
199+
struct S_37290898: P_37290898 {}
200+
201+
func rdar37290898(_ arr: inout [P_37290898], _ element: S_37290898?) {
202+
arr += [element].compactMap { $0 } // Ok
203+
}

0 commit comments

Comments
 (0)