Skip to content

[Distributed] whenLocal adoption of typed throws #71439

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 2 commits into from
Feb 10, 2024
Merged
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
15 changes: 12 additions & 3 deletions stdlib/public/Distributed/DistributedActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,25 @@ extension DistributedActor {
/// state.
///
/// When the actor is remote, the closure won't be executed and this function will return nil.
public nonisolated func whenLocal<T: Sendable>(
_ body: @Sendable (isolated Self) async throws -> T
) async rethrows -> T? {
public nonisolated func whenLocal<T: Sendable, E>(
_ body: @Sendable (isolated Self) async throws(E) -> T
) async throws(E) -> T? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an ABI break. There's a little song-and-dance you can do to maintain ABI. See, e.g., #70971

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Okey so the silgenname, thanks I’ll follow the same pattern 🙏

Copy link
Contributor Author

@ktoso ktoso Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to revive the effort to bring abi compat checking to Distributed but can't figure out how to dump the macos.json equivalent of Concurrency etc as we use in the digester tests 🤔

Meanwhile I fixed this signature: to $s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbKXEYaKs8SendableRd__lF which seems to be right.

 822 sil [available 13.0] [ossa] @$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbKXEYaKs8SendableRd__lF : $@convention(method) @async <Self where Self : DistributedActor><T where T : Sendable> (@guaranteed @noescape @Sendable @async @callee_guaranteed @substituted <τ_0_0, τ_0_1 where      τ_0_0 : AnyObject> (@sil_isolated @guaranteed τ_0_0) -> (@out τ_0_1, @error any Error) for <Self, T>, @guaranteed Self) -> (@out Optional<T>, @error any Error) {

if __isLocalActor(self) {
_local let localSelf = self
return try await body(localSelf)
} else {
return nil
}
}

// ABI: Historical whenLocal, rethrows was changed to typed throws `throws(E)`
@_silgen_name("$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbKXEYaKs8SendableRd__lF")
@usableFromInline
nonisolated func __abi_whenLocal<T: Sendable>(
_ body: @Sendable (isolated Self) async throws -> T
) async rethrows -> T? {
try await whenLocal(body)
}
}

/// Supports the operation to produce an any Actor instance from a local
Expand Down