Skip to content

[Concurrency] Handle self apply exprs when computing @preconcurency in the availability checker. #77510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3552,7 +3552,11 @@ class ExprAvailabilityWalker : public ASTWalker {

if (auto *apply = dyn_cast<ApplyExpr>(E)) {
bool preconcurrency = false;
auto declRef = apply->getFn()->getReferencedDecl();
auto *fn = apply->getFn();
if (auto *selfApply = dyn_cast<SelfApplyExpr>(fn)) {
fn = selfApply->getFn();
}
auto declRef = fn->getReferencedDecl();
if (auto *decl = declRef.getDecl()) {
preconcurrency = decl->preconcurrency();
}
Expand Down
48 changes: 44 additions & 4 deletions test/Concurrency/predates_concurrency_swift6.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,46 @@ func requireSendable<T: Sendable>(_: T) {}
@preconcurrency
struct RequireSendable<T: Sendable> {}

class NotSendable {} // expected-note 4 {{class 'NotSendable' does not conform to the 'Sendable' protocol}}
class NotSendable {} // expected-note 8 {{class 'NotSendable' does not conform to the 'Sendable' protocol}}

class UnavailableSendable {}

@available(*, unavailable)
extension UnavailableSendable: @unchecked Sendable {}
// expected-note@-1 4 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}
// expected-note@-1 8 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}

typealias T = RequireSendable<NotSendable>
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}

typealias T2 = RequireSendable<UnavailableSendable>
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}

func testRequirementDowngrade(ns: NotSendable, us: UnavailableSendable) {
class C {
@preconcurrency
func requireSendable<T: Sendable>(_: T) {}

@preconcurrency
static func requireSendableStatic<T: Sendable>(_: T) {}
}

func testRequirementDowngrade(ns: NotSendable, us: UnavailableSendable, c: C) {
requireSendable(ns)
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}

c.requireSendable(ns)
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}

C.requireSendableStatic(ns)
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}

requireSendable(us)
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}

c.requireSendable(us)
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}

C.requireSendableStatic(us)
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
}


Expand All @@ -232,13 +252,33 @@ func requireSendableExistential(_: any P2 & Sendable) {}

func requireSendableExistentialAlways(_: any P2 & Sendable) {}

func testErasureDowngrade(ns: NotSendable, us: UnavailableSendable) {
extension C {
@preconcurrency
func requireSendableExistential(_: any P2 & Sendable) {}

@preconcurrency
static func requireSendableExistentialStatic(_: any P2 & Sendable) {}
}

func testErasureDowngrade(ns: NotSendable, us: UnavailableSendable, c: C) {
requireSendableExistential(ns)
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}

c.requireSendableExistential(ns)
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}

C.requireSendableExistentialStatic(ns)
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}

requireSendableExistential(us)
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}

c.requireSendableExistential(us)
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}

C.requireSendableExistentialStatic(us)
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}

withSendableClosure {
let ns = NotSendable()
requireSendableExistentialAlways(ns)
Expand Down