Skip to content

Commit 0a49d28

Browse files
committedApr 5, 2024
Partially revert: "[TypeChecker] TypeChecker::isSubtypeOf should recognize @sendable subtyping"
Reverts code chagnes introduced by 5626881 but leaves (modified) test-cases This approach regressed existing ternary expressions that join to `any Sendable` and one branch is inferred from the ternary type variable.
1 parent cd472fe commit 0a49d28

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed
 

Diff for: ‎lib/Sema/TypeCheckConstraints.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -1071,16 +1071,6 @@ bool TypeChecker::typesSatisfyConstraint(Type type1, Type type2,
10711071
if (unwrappedIUO)
10721072
*unwrappedIUO = solution->getFixedScore().Data[SK_ForceUnchecked] > 0;
10731073

1074-
// Make sure that Sendable vs. no-Sendable mismatches are
1075-
// failures here to establish subtyping relationship
1076-
// (unlike in the solver where they are warnings until Swift 6).
1077-
if (kind == ConstraintKind::Subtype) {
1078-
if (llvm::any_of(solution->Fixes, [](const auto *fix) {
1079-
return fix->getKind() == FixKind::AddSendableAttribute;
1080-
}))
1081-
return false;
1082-
}
1083-
10841074
return true;
10851075
}
10861076

Diff for: ‎test/Concurrency/sendable_keypaths.swift

+23-2
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,14 @@ do {
221221
fatalError()
222222
}
223223

224+
// TODO(rdar://125948508): This shouldn't be ambiguous (@Sendable version should be preferred)
224225
func test() -> KeyPath<String, Int> {
225-
true ? kp() : kp() // Ok
226+
true ? kp() : kp() // expected-error {{type of expression is ambiguous without a type annotation}}
226227
}
227228

228229
func forward<T>(_ v: T) -> T { v }
229-
let _: KeyPath<String, Int> = forward(kp()) // Ok
230+
// TODO(rdar://125948508): This shouldn't be ambiguous (@Sendable version should be preferred)
231+
let _: KeyPath<String, Int> = forward(kp()) // expected-error {{conflicting arguments to generic parameter 'T' ('any KeyPath<String, Int> & Sendable' vs. 'KeyPath<String, Int>')}}
230232
}
231233

232234
do {
@@ -236,3 +238,22 @@ do {
236238

237239
_ = \C<Int>.immutable as? ReferenceWritableKeyPath // Ok
238240
}
241+
242+
// Should be moved back to sendable_methods.swift once ambiguities are fixed
243+
do {
244+
struct Test {
245+
static func fn() {}
246+
static func otherFn() {}
247+
}
248+
249+
// TODO(rdar://125948508): This shouldn't be ambiguous (@Sendable version should be preferred)
250+
func fnRet(cond: Bool) -> () -> Void {
251+
cond ? Test.fn : Test.otherFn // expected-error {{type of expression is ambiguous without a type annotation}}
252+
}
253+
254+
func forward<T>(_: T) -> T {
255+
}
256+
257+
// TODO(rdar://125948508): This shouldn't be ambiguous (@Sendable version should be preferred)
258+
let _: () -> Void = forward(Test.fn) // expected-error {{conflicting arguments to generic parameter 'T' ('@Sendable () -> ()' vs. '() -> Void')}}
259+
}

Diff for: ‎test/Concurrency/sendable_methods.swift

-17
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,6 @@ do {
229229
}
230230
}
231231

232-
do {
233-
struct Test {
234-
static func fn() {}
235-
static func otherFn() {}
236-
}
237-
238-
func fnRet(cond: Bool) -> () -> Void {
239-
cond ? Test.fn : Test.otherFn // Ok
240-
}
241-
242-
func forward<T>(_: T) -> T {
243-
}
244-
245-
let _: () -> Void = forward(Test.fn) // Ok
246-
}
247-
248-
249232
func test_initializer_ref() {
250233
func test<T>(_: @Sendable (T, T) -> Array<T>) {
251234
}

0 commit comments

Comments
 (0)