Skip to content

Commit

Permalink
[Concurrency] Implicit global actor attributes imply Sendable.
Browse files Browse the repository at this point in the history
Sendable derivation was only checking for explicit global actor
attributes. It should also account for inferred global actor
attributes, e.g. from protocol conformances.
  • Loading branch information
hborla committed May 16, 2024
1 parent 29b8e6e commit e044e3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6055,7 +6055,7 @@ ProtocolConformance *swift::deriveImplicitSendableConformance(
}

// A non-protocol type with a global actor is implicitly Sendable.
if (nominal->getGlobalActorAttr()) {
if (getActorIsolation(nominal).isGlobalActor()) {
// Form the implicit conformance to Sendable.
return formConformance(nullptr);
}
Expand Down
20 changes: 20 additions & 0 deletions test/Concurrency/sendable_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,23 @@ struct DowngradeForPreconcurrency {
}
}
}

@available(SwiftStdlib 5.1, *)
@MainActor protocol InferMainActor {}

@available(SwiftStdlib 5.1, *)
struct ImplicitSendableViaMain: InferMainActor {}

@available(SwiftStdlib 5.1, *)
extension ImplicitSendableViaMain {
nonisolated func capture() {
Task { @MainActor in
_ = self
}
}
}

@available(SwiftStdlib 5.1, *)
struct TestImplicitSendable: Sendable {
var x: ImplicitSendableViaMain
}

0 comments on commit e044e3d

Please sign in to comment.