Skip to content

[Concurrency] Distributed actor's unownedExecutor should be optional #64499

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 7 commits into from
Mar 21, 2023

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Mar 21, 2023

Implements the Swift Evolution feedback that it'd be better to implement this customization point properly with an UnownedSerialExecutor? which makes it more logical (and possible!) to implement correctly.

@kavon's question https://forums.swift.org/t/se-0392-custom-actor-executors/63599/13
and my writeup: https://forums.swift.org/t/se-0392-custom-actor-executors/63599/16

Note that we never shipped distributed actors that had an unownedExecutor synthesized, so we don't have to be compatible with past implementations which had it configurable or synthesized -- it never was.

The tests show various use-cases.

I took care to not break compatibility with previous implementations and we still detect "is default actor" using the old synthesized method. Though previously ALL distributed actors were default actors, even if you had provided the method yourself.

I believe this yields the right semantics but would really really ask for a review if I got the default implementation of unownedExecutor right -- the availability dance there I was unsure of.

@ktoso ktoso added concurrency Feature: umbrella label for concurrency language features distributed Feature → concurrency: distributed actor labels Mar 21, 2023
@@ -255,6 +260,29 @@ public protocol DistributedActor: AnyActor, Identifiable, Hashable
/// be introduced when not strictly required. Visible side effects
/// are therefore strongly discouraged within this property.
@available(SwiftStdlib 5.9, *)
nonisolated var localUnownedExecutor: UnownedSerialExecutor? { get }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the core of this PR, everything else is just in order to enable it.

@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

import Swift
import _Concurrency
@_spi(ConcurrencyExecutors) import _Concurrency
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: cant make use of it after all because we need the executor initializer from an inlinable function.

@ktoso ktoso force-pushed the wip-unownedExecutor-optional-on-da branch from b668f95 to dfc373a Compare March 21, 2023 11:43
@ktoso
Copy link
Contributor Author

ktoso commented Mar 21, 2023

@swift-ci please smoke test

@ktoso
Copy link
Contributor Author

ktoso commented Mar 21, 2023

This should work fine, though I'm working to get rid of the unownedExecutor completely (this PR introduces it, though somewhat un-necessarily, only so we did not have to change Lowering actor hops), if I'll manage to adjust the LowerHopToActor properly

@ktoso
Copy link
Contributor Author

ktoso commented Mar 21, 2023

This weird failure again:

37366     error: 'miscellaneous_atmainsupport': Invalid manifest (compiled with: ["/Users/ec2-user/jenkins/workspace/swift-PR-macos-smoke-test/branch-main/bu      ild/buildbot_incremental/toolchain-macosx-x86_64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", "-vfsov      erlay", "/var/folders/pf/p5g2vb2j0yx1x6vlmxdppc700000gn/T/TemporaryDirectory.VfUFtV/vfs.yaml", "-L", "/Users/ec2-user/jenkins/workspace/swift-PR-macos-      smoke-test/branch-main/build/buildbot_incremental/swiftpm-macosx-x86_64/x86_64-apple-macosx/lib/swift/pm/ManifestAPI", "-lPackageDescription", "-Xlinke      r", "-rpath", "-Xlinker", "/Users/ec2-user/jenkins/workspace/swift-PR-macos-smoke-test/branch-main/build/buildbot_incremental/swiftpm-macosx-x86_64/x86      _64-apple-macosx/lib/swift/pm/ManifestAPI", "-target", "x86_64-apple-macosx11.0", "-sdk", "/Applications/Xcode-beta.app/Contents/Developer/Platforms/Ma      cOSX.platform/Developer/SDKs/MacOSX12.0.sdk", "-F", "/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Framew      orks", "-I", "/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-L", "/Applications/Xcode-beta.app/Content      s/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-swift-version", "5", "-I", "/Users/ec2-user/jenkins/workspace/swift-PR-macos-smoke-test/bra      nch-main/build/buildbot_incremental/swiftpm-macosx-x86_64/x86_64-apple-macosx/lib/swift/pm/ManifestAPI", "-sdk", "/Applications/Xcode-beta.app/Contents      /Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk", "-package-description-version", "5.5.0", "-module-cache-path", "/Users/ec2-user/je      nkins/workspace/swift-PR-macos-smoke-test/branch-main/build/buildbot_incremental/swiftpm-macosx-x86_64/x86_64-apple-macosx/release", "/private/var/fold      ers/pf/p5g2vb2j0yx1x6vlmxdppc700000gn/T/Miscellaneous_AtMainSupport.0rtTka/Miscellaneous_AtMainSupport/Package.swift", "-Xfrontend", "-disable-implicit      -concurrency-module-import", "-Xfrontend", "-disable-implicit-string-processing-module-import", "-o", "/var/folders/pf/p5g2vb2j0yx1x6vlmxdppc700000gn/T      /TemporaryDirectory.YQgBzl/miscellaneous_atmainsupport-manifest"])
37367     /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/lib/swift/Foundation.swiftmodule/x86_64      -apple-macos.swiftinterface:4:8: error: no such module 'Combine'
37368     import Combine
37369            ^
37370     /private/var/folders/pf/p5g2vb2j0yx1x6vlmxdppc700000gn/T/Miscellaneous_AtMainSupport.0rtTka/Miscellaneous_AtMainSupport/Package.swift:1:8: error: f      ailed to build module 'Foundation'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.5 (swiftlang-1300.0.27.6 cl      ang-1300.0.27.2)', while this compiler is 'Apple Swift version 5.9-dev (LLVM 7d764ce82d6ec7f, Swift bf54bfe483bacd7)'). Please select a toolchain which       matches the SDK.
37371     import Foundation
37372            ^

@ktoso
Copy link
Contributor Author

ktoso commented Mar 21, 2023

@swift-ci please clean smoke test macOS

}

@available(SwiftStdlib 5.9, *)
public var _unwrapLocalUnownedExecutor: UnownedSerialExecutor {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or we could make this a free function... perhaps easier than a full impl in SIL

@ktoso
Copy link
Contributor Author

ktoso commented Mar 21, 2023

@swift-ci please clean smoke test

@@ -255,7 +260,7 @@ public protocol DistributedActor: AnyActor, Identifiable, Hashable
/// be introduced when not strictly required. Visible side effects
/// are therefore strongly discouraged within this property.
@available(SwiftStdlib 5.9, *)
nonisolated var unownedExecutor: UnownedSerialExecutor { get }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This requirement has never shipped and cannot have been used by anyone yet, so making sure we have the right signature/requirement in the API/ABI for distributed actors by merging this now.

@ktoso ktoso merged commit 345c221 into swiftlang:main Mar 21, 2023
@ktoso ktoso deleted the wip-unownedExecutor-optional-on-da branch March 21, 2023 23:40
@ktoso
Copy link
Contributor Author

ktoso commented Mar 23, 2023

rdar://84054793

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency Feature: umbrella label for concurrency language features distributed Feature → concurrency: distributed actor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant