Skip to content

[Distributed] Adjust whenLocal impl to avoid potential ABI issues #74606

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
Jun 27, 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
14 changes: 14 additions & 0 deletions stdlib/public/Distributed/DistributedActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ extension DistributedActor {
///
/// When the actor is remote, the closure won't be executed and this function will return nil.
@_alwaysEmitIntoClient
// we need to silgen_name here because the signature is the same as __abi_whenLocal,
// and even though this is @AEIC, the symbol name would conflict.
@_silgen_name("$s11Distributed0A5ActorPAAE20whenLocalTypedThrowsyqd__Sgqd__xYiYaYbqd_0_YKXEYaqd_0_YKs8SendableRd__s5ErrorRd_0_r0_lF")
public nonisolated func whenLocal<T: Sendable, E>(
_ body: @Sendable (isolated Self) async throws(E) -> T
) async throws(E) -> T? {
Expand All @@ -374,6 +377,17 @@ extension DistributedActor {
}
}

// ABI: This is a workaround when in Swift 6 this method was introduced
// in order to support typed-throws, but missed to add @_aeic.
// In practice, this method should not ever be used by anyone, ever.
@usableFromInline
@_silgen_name("$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbqd_0_YKXEYaqd_0_YKs8SendableRd__s5ErrorRd_0_r0_lF")
internal nonisolated func __abi_whenLocal<T: Sendable, E>(
_ body: @Sendable (isolated Self) async throws(E) -> T
) async throws(E) -> T? {
try await whenLocal(body)
}

// ABI: Historical whenLocal, rethrows was changed to typed throws `throws(E)`
@_silgen_name("$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbKXEYaKs8SendableRd__lF")
@usableFromInline
Expand Down
6 changes: 6 additions & 0 deletions test/abi/macOS/arm64/distributed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,9 @@ Added: _$s11Distributed0A5ActorPAAE22__actorUnownedExecutorScevpMV

// Distributed._distributedStubFatalError(function: Swift.String) -> Swift.Never
Added: _$s11Distributed26_distributedStubFatalError8functions5NeverOSS_tF

// Bin compat for typed throws overload of whenLocal
// (extension in Distributed):Distributed.DistributedActor.whenLocal<A, B where A1: Swift.Sendable, B1: Swift.Error>(@Sendable (isolated A) async throws(B1) -> A1) async throws(B1) -> A1?
Added: _$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbqd_0_YKXEYaqd_0_YKs8SendableRd__s5ErrorRd_0_r0_lF
// async function pointer to (extension in Distributed):Distributed.DistributedActor.whenLocal<A, B where A1: Swift.Sendable, B1: Swift.Error>(@Sendable (isolated A) async throws(B1) -> A1) async throws(B1) -> A1?
Added: _$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbqd_0_YKXEYaqd_0_YKs8SendableRd__s5ErrorRd_0_r0_lFTu
6 changes: 6 additions & 0 deletions test/abi/macOS/x86_64/distributed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,9 @@ Added: _$s11Distributed0A5ActorPAAE22__actorUnownedExecutorScevpMV

// Distributed._distributedStubFatalError(function: Swift.String) -> Swift.Never
Added: _$s11Distributed26_distributedStubFatalError8functions5NeverOSS_tF

// Bin compat for typed throws overload of whenLocal
// (extension in Distributed):Distributed.DistributedActor.whenLocal<A, B where A1: Swift.Sendable, B1: Swift.Error>(@Sendable (isolated A) async throws(B1) -> A1) async throws(B1) -> A1?
Added: _$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbqd_0_YKXEYaqd_0_YKs8SendableRd__s5ErrorRd_0_r0_lF
// async function pointer to (extension in Distributed):Distributed.DistributedActor.whenLocal<A, B where A1: Swift.Sendable, B1: Swift.Error>(@Sendable (isolated A) async throws(B1) -> A1) async throws(B1) -> A1?
Added: _$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbqd_0_YKXEYaqd_0_YKs8SendableRd__s5ErrorRd_0_r0_lFTu