swift-distributed-actors icon indicating copy to clipboard operation
swift-distributed-actors copied to clipboard

WorkerPool cannot have additional protocol conformance

Open pbk20191 opened this issue 2 years ago • 4 comments

Context: Just learning about swift-distributed actor and system. I tried to make WorkerPool to adapt ClusterSingleton protocol to use it as single instance. extension WorkerPool: ClusterSingleton {}

Then Xcode compiler fails with following message:

/Users/pbk/Documents/XcodeWorkSpace/ToyWorkSpace/DemoToycraft/DistributedActors.WorkerPool:3:16: Property 'actorSystem' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property /Users/pbk/Documents/XcodeWorkSpace/ToyWorkSpace/DemoToycraft/DistributedActors.WorkerPool:2:16: Property 'id' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property

Also WorkerPool cannot conform to empty protocol.

protocol EmptyProtocol {}
extension WorkerPool: EmptyProtocol {}

Commit hash: 811d2e88a12db8477a0edde6311c1299102314d3 ( 1.0.0-beta.2 )

Environment:

IDE and tool chain : Xcode 14.0 RC, Xcode 14 RC tool chain My application targets iOS 16.0 iphone 8 simulator $ swift --version swift-driver version: 1.45.2 Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12) Target: x86_64-apple-macosx12.0

Operating system: macOS Monterey 12.5.1

$ uname -a Darwin iquest1127ui-MacBookPro.local 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:25:27 PDT 2022; root:xnu-8020.141.5~2/RELEASE_X86_64 x86_64

My system has IPv6 enabled.

pbk20191 avatar Sep 12 '22 11:09 pbk20191

Hmm, thanks for the report, I wonder if that's a language issue actually... Will look into it soon.

ktoso avatar Sep 12 '22 12:09 ktoso

Having that said, it is a bit weird to make a worker pool a singleton -- are you sure that's what you'd need? usually you'd reach for one or the other.

ktoso avatar Sep 12 '22 12:09 ktoso

Having that said, it is a bit weird to make a worker pool a singleton -- are you sure that's what you'd need? usually you'd reach for one or the other.

I thought it would be appropriate to have one Worker Pool instance per WorkerPoolSetting.Selector in actorSystem, so I tried the above approach. I don't have specific goal or need for this. Just working around learning new features of swift 5.7.

If you can afford it, could you explain why it's weird or where the reference or url about it?

pbk20191 avatar Sep 12 '22 13:09 pbk20191

I guess this issue is not related to singleton. WorkerPool can't adapt any additional protocol. This two line of code is enough for compiler to fail.

protocol EmptyProtocol {}
extension WorkerPool: EmptyProtocol {}

pbk20191 avatar Sep 12 '22 13:09 pbk20191