Skip to content

Commit 0995608

Browse files
committed
[ConstraintSystem] Only factor in existing operator bindings in
selectDisjunction if both disjunctions are operator bindings.
1 parent 0d8a161 commit 0995608

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,10 @@ Constraint *ConstraintSystem::selectDisjunction() {
21912191
unsigned firstFavored = first->countFavoredNestedConstraints();
21922192
unsigned secondFavored = second->countFavoredNestedConstraints();
21932193

2194+
if (!isOperatorBindOverload(first->getNestedConstraints().front()) ||
2195+
!isOperatorBindOverload(second->getNestedConstraints().front()))
2196+
return first->countActiveNestedConstraints() < second->countActiveNestedConstraints();
2197+
21942198
if (firstFavored == secondFavored) {
21952199
// Look for additional choices to favor
21962200
SmallVector<unsigned, 4> firstExisting;
@@ -2201,12 +2205,12 @@ Constraint *ConstraintSystem::selectDisjunction() {
22012205
existingOperatorBindingsForDisjunction(*cs, second->getNestedConstraints(), secondExisting);
22022206
secondFavored = secondExisting.size() ? secondExisting.size() : second->countActiveNestedConstraints();
22032207

2204-
return firstFavored < secondFavored;
2205-
} else {
2206-
firstFavored = firstFavored ? firstFavored : first->countActiveNestedConstraints();
2207-
secondFavored = secondFavored ? secondFavored : second->countActiveNestedConstraints();
22082208
return firstFavored < secondFavored;
22092209
}
2210+
2211+
firstFavored = firstFavored ? firstFavored : first->countActiveNestedConstraints();
2212+
secondFavored = secondFavored ? secondFavored : second->countActiveNestedConstraints();
2213+
return firstFavored < secondFavored;
22102214
});
22112215

22122216
if (minDisjunction != disjunctions.end())

validation-test/Sema/type_checker_perf/slow/fast-operator-typechecking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ func f(tail: UInt64, byteCount: UInt64) {
1818
func size(count: Int) {
1919
// Size of the buffer we need to allocate
2020
let _ = count * MemoryLayout<Float>.size * (4 + 3 + 3 + 2 + 4)
21+
// expected-error@-1 {{the compiler is unable to type-check this expression in reasonable time}}
2122
}

validation-test/Sema/type_checker_perf/fast/rdar23682605.swift renamed to validation-test/Sema/type_checker_perf/slow/rdar23682605.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func memoize<T: Hashable, U>( body: @escaping ((T)->U, T)->U ) -> (T)->U {
1414
}
1515

1616
let fibonacci = memoize {
17+
// expected-error@-1 {{reasonable time}}
1718
fibonacci, n in
1819
n < 2 ? Double(n) : fibonacci(n - 1) + fibonacci(n - 2)
1920
}

0 commit comments

Comments
 (0)