Skip to content

Commit d01c9cb

Browse files
committed
[CSBindings] Revert changes in BindingSet::isViable
This change although correct cases performance issues in some scenarios.
1 parent 4f32598 commit d01c9cb

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,19 +1208,7 @@ bool BindingSet::isViable(PotentialBinding &binding, bool isTransitive) {
12081208
if (!existingNTD || NTD != existingNTD)
12091209
continue;
12101210

1211-
// What is going on here needs to be thoroughly re-evaluated,
1212-
// but at least for now, let's not filter bindings of different
1213-
// kinds so if we have a situation like: `Array<$T0> conv $T1`
1214-
// and `$T1 conv Array<(String, Int)>` we can't lose `Array<$T0>`
1215-
// as a binding because `$T0` could be inferred to
1216-
// `(key: String, value: Int)` and binding `$T1` to `Array<(String, Int)>`
1217-
// eagerly would be incorrect.
1218-
if (existing->Kind != binding.Kind) {
1219-
// Array, Set and Dictionary allow conversions, everything else
1220-
// requires their generic arguments to match exactly.
1221-
if (existingType->isKnownStdlibCollectionType())
1222-
continue;
1223-
}
1211+
// FIXME: What is going on here needs to be thoroughly re-evaluated.
12241212

12251213
// If new type has a type variable it shouldn't
12261214
// be considered viable.

test/Constraints/rdar139812024.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %target-typecheck-verify-swift %clang-importer-sdk
2+
3+
// REQUIRES: objc_interop
4+
5+
// rdar://139812024 - error: cannot convert return expression of type 'NSObject' to return type 'NSImage'
6+
7+
import Foundation
8+
9+
@objc
10+
final class Image: NSObject {
11+
}
12+
13+
@available(*, unavailable)
14+
extension Image: Sendable {} // expected-note {{explicitly marked unavailable here}}
15+
16+
class Lock<State> {
17+
func withLock<R: Sendable>(_: @Sendable (inout State) -> R) -> R {
18+
fatalError()
19+
}
20+
}
21+
22+
extension Lock where State == Void {
23+
func withLock<R: Sendable>(_: @Sendable () -> R) -> R {
24+
fatalError()
25+
}
26+
}
27+
28+
class Test {
29+
var images: [Int: Image] = [:]
30+
31+
func fetchImage(lock: Lock<Void>, id: Int) -> Image? {
32+
if let existingImage = lock.withLock({ return images[id] }) { // expected-warning {{unavailable}}
33+
return existingImage
34+
}
35+
return nil
36+
}
37+
}

0 commit comments

Comments
 (0)