Skip to content

Commit 68436ee

Browse files
committed
remove ActorMessage typealias, we're comitted to Codable for now
1 parent cfdffb1 commit 68436ee

38 files changed

+112
-120
lines changed

Sources/DistributedActors/ActorContext.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Logging
1919
/// - Warning:
2020
/// - It MUST only ever be accessed from its own Actor. It is fine though to close over it in the actors behaviours.
2121
/// - It MUST NOT be shared to other actors, and MUST NOT be accessed concurrently (e.g. from outside the actor).
22-
public class _ActorContext<Message: ActorMessage> /* TODO(sendable): NOTSendable*/ {
22+
public class _ActorContext<Message: Codable> /* TODO(sendable): NOTSendable*/ {
2323
public typealias Myself = _ActorRef<Message>
2424

2525
/// Returns `ClusterSystem` which this context belongs to.
@@ -126,7 +126,7 @@ public class _ActorContext<Message: ActorMessage> /* TODO(sendable): NOTSendable
126126
file: String = #file, line: UInt = #line,
127127
_ behavior: _Behavior<M>
128128
) throws -> _ActorRef<M>
129-
where M: ActorMessage
129+
where M: Codable
130130
{
131131
_undefined()
132132
}
@@ -145,7 +145,7 @@ public class _ActorContext<Message: ActorMessage> /* TODO(sendable): NOTSendable
145145
file: String = #file, line: UInt = #line,
146146
_ behavior: _Behavior<M>
147147
) throws -> _ActorRef<M>
148-
where M: ActorMessage
148+
where M: Codable
149149
{
150150
_undefined()
151151
}
@@ -174,7 +174,7 @@ public class _ActorContext<Message: ActorMessage> /* TODO(sendable): NOTSendable
174174
/// - Throws: an `_ActorContextError` when an actor ref is passed in that is NOT a child of the current actor.
175175
/// An actor may not terminate another's child actors. Attempting to stop `myself` using this method will
176176
/// also throw, as the proper way of stopping oneself is returning a `_Behavior.stop`.
177-
public func stop<M>(child ref: _ActorRef<M>) throws where M: ActorMessage {
177+
public func stop<M>(child ref: _ActorRef<M>) throws where M: Codable {
178178
return _undefined()
179179
}
180180

@@ -332,7 +332,7 @@ public class _ActorContext<Message: ActorMessage> /* TODO(sendable): NOTSendable
332332
/// being silently dropped. This can be useful when not all messages `From` have a valid representation in
333333
/// `Message`, or if not all `From` messages are of interest for this particular actor.
334334
public final func messageAdapter<From>(_ adapt: @escaping (From) -> Message?) -> _ActorRef<From>
335-
where From: ActorMessage
335+
where From: Codable
336336
{
337337
return self.messageAdapter(from: From.self, adapt: adapt)
338338
}
@@ -349,7 +349,7 @@ public class _ActorContext<Message: ActorMessage> /* TODO(sendable): NOTSendable
349349
/// being silently dropped. This can be useful when not all messages `From` have a valid representation in
350350
/// `Message`, or if not all `From` messages are of interest for this particular actor.
351351
public func messageAdapter<From>(from type: From.Type, adapt: @escaping (From) -> Message?) -> _ActorRef<From>
352-
where From: ActorMessage
352+
where From: Codable
353353
{
354354
return _undefined()
355355
}
@@ -365,7 +365,7 @@ public class _ActorContext<Message: ActorMessage> /* TODO(sendable): NOTSendable
365365
/// with an existing `_SubReceiveId`, it replaces the old one. All references will remain valid and point to
366366
/// the new behavior.
367367
public func subReceive<SubMessage>(_: _SubReceiveId<SubMessage>, _: SubMessage.Type, _: @escaping (SubMessage) throws -> Void) -> _ActorRef<SubMessage>
368-
where SubMessage: ActorMessage
368+
where SubMessage: Codable
369369
{
370370
return _undefined()
371371
}

Sources/DistributedActors/ActorMessage+Protobuf.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import SwiftProtobuf
2121
// ==== ----------------------------------------------------------------------------------------------------------------
2222
// MARK: Protobuf representations
2323

24-
public protocol _AnyProtobufRepresentable: ActorMessage, SerializationRepresentable {}
24+
public protocol _AnyProtobufRepresentable: Codable, SerializationRepresentable {}
2525

2626
extension _AnyProtobufRepresentable {
2727
public static var defaultSerializerID: Serialization.SerializerID? {
@@ -32,8 +32,6 @@ extension _AnyProtobufRepresentable {
3232
public protocol _AnyPublicProtobufRepresentable: _AnyProtobufRepresentable {}
3333

3434
/// A protocol that facilitates conversion between Swift and protobuf messages.
35-
///
36-
/// - SeeAlso: `ActorMessage`
3735
public protocol _ProtobufRepresentable: _AnyPublicProtobufRepresentable {
3836
associatedtype ProtobufRepresentation: SwiftProtobuf.Message
3937

Sources/DistributedActors/ActorMessages.swift

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,14 @@
1515
import struct Foundation.Data
1616
import NIO
1717

18-
// ==== ----------------------------------------------------------------------------------------------------------------
19-
// MARK: Actor Message
20-
21-
public typealias ActorMessage = Codable // FIXME: MAKE THIS SENDABLE: & Sendable
22-
2318
/// A `Never` can never be sent as message, even more so over the wire.
24-
extension Never: NonTransportableActorMessage {}
19+
extension Never: NotActuallyCodableMessage {}
2520

2621
// ==== ----------------------------------------------------------------------------------------------------------------
2722
// MARK: Common utility messages
2823

2924
// FIXME: we should not add Codable conformance onto a stdlib type, but rather fix this in stdlib
30-
extension Result: ActorMessage where Success: ActorMessage, Failure: ActorMessage {
25+
extension Result: Codable where Success: Codable, Failure: Codable {
3126
public enum DiscriminatorKeys: String, Codable {
3227
case success
3328
case failure
@@ -63,7 +58,7 @@ extension Result: ActorMessage where Success: ActorMessage, Failure: ActorMessag
6358
}
6459

6560
/// Generic transportable Error type, can be used to wrap error types and represent them as best as possible for transporting.
66-
public struct ErrorEnvelope: Error, ActorMessage {
61+
public struct ErrorEnvelope: Error, Codable {
6762
public typealias CodableError = Error & Codable
6863

6964
private let codableError: CodableError
@@ -133,7 +128,7 @@ public struct BestEffortStringError: Error, Codable, Equatable, CustomStringConv
133128
}
134129

135130
/// Useful error wrapper which performs an best effort Error serialization as configured by the actor system.
136-
public struct NonTransportableAnyError: Error, NonTransportableActorMessage {
131+
public struct NonTransportableAnyError: Error, NotActuallyCodableMessage {
137132
public let failure: Error
138133

139134
public init<Failure: Error>(_ failure: Failure) {
@@ -144,8 +139,7 @@ public struct NonTransportableAnyError: Error, NonTransportableActorMessage {
144139
// ==== ----------------------------------------------------------------------------------------------------------------
145140
// MARK: Not Transportable Actor Message (i.e. "local only")
146141

147-
/// Marks a type as `ActorMessage` however
148-
/// Attempting to send such message to a remote actor WILL FAIL and log an error.
142+
/// Marks a type as `Codable` however attempting to send such message to a remote actor WILL FAIL and log an error.
149143
///
150144
/// Use this with great caution and only for messages which are specifically designed to utilize the local assumption.
151145
///
@@ -156,22 +150,22 @@ public struct NonTransportableAnyError: Error, NonTransportableActorMessage {
156150
/// No serializer is expected to be registered for such types.
157151
///
158152
/// - Warning: Attempting to send such message over the network will fail at runtime (and log an error or warning).
159-
public protocol NonTransportableActorMessage: ActorMessage {}
153+
public protocol NotActuallyCodableMessage: Codable {}
160154

161-
extension NonTransportableActorMessage {
155+
extension NotActuallyCodableMessage {
162156
public init(from decoder: Swift.Decoder) throws {
163-
fatalError("Attempted to decode NonTransportableActorMessage message: \(Self.self)! This should never happen.")
157+
fatalError("Attempted to decode NotActuallyCodableMessage message: \(Self.self)! This should never happen.")
164158
}
165159

166160
public func encode(to encoder: Swift.Encoder) throws {
167-
fatalError("Attempted to encode NonTransportableActorMessage message: \(Self.self)! This should never happen.")
161+
fatalError("Attempted to encode NotActuallyCodableMessage message: \(Self.self)! This should never happen.")
168162
}
169163

170164
public init(context: Serialization.Context, from buffer: inout ByteBuffer, using manifest: Serialization.Manifest) throws {
171-
fatalError("Attempted to deserialize NonTransportableActorMessage message: \(Self.self)! This should never happen.")
165+
fatalError("Attempted to deserialize NotActuallyCodableMessage message: \(Self.self)! This should never happen.")
172166
}
173167

174168
public func serialize(context: Serialization.Context, to bytes: inout ByteBuffer) throws {
175-
fatalError("Attempted to serialize NonTransportableActorMessage message: \(Self.self)! This should never happen.")
169+
fatalError("Attempted to serialize NotActuallyCodableMessage message: \(Self.self)! This should never happen.")
176170
}
177171
}

Sources/DistributedActors/ActorRef+Ask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ extension AskResponse {
238238
///
239239
// TODO: replace with a special minimal `_ActorRef` that does not require spawning or scheduling.
240240
internal enum AskActor {
241-
enum Event: NonTransportableActorMessage {
241+
enum Event: NotActuallyCodableMessage {
242242
case timeout
243243
}
244244

Sources/DistributedActors/ActorRefFactory.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public protocol _ActorRefFactory {
5454
props: _Props,
5555
file: String, line: UInt,
5656
_ behavior: _Behavior<Message>
57-
) throws -> _ActorRef<Message> where Message: ActorMessage
57+
) throws -> _ActorRef<Message> where Message: Codable
5858
}
5959

6060
// ==== ----------------------------------------------------------------------------------------------------------------
@@ -64,7 +64,7 @@ public protocol _ChildActorRefFactory: _ActorRefFactory {
6464
var children: _Children { get set } // lock-protected
6565

6666
func stop<Message>(child ref: _ActorRef<Message>) throws
67-
where Message: ActorMessage
67+
where Message: Codable
6868
}
6969

7070
// ==== ----------------------------------------------------------------------------------------------------------------

Sources/DistributedActors/ActorRefProvider.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal protocol _ActorRefProvider: _ActorTreeTraversable {
3636
dispatcher: MessageDispatcher, props: _Props,
3737
startImmediately: Bool
3838
) throws -> _ActorRef<Message>
39-
where Message: ActorMessage
39+
where Message: Codable
4040

4141
/// Stops all actors created by this `_ActorRefProvider` and blocks until they have all stopped.
4242
func stopAll()
@@ -81,7 +81,7 @@ extension RemoteActorRefProvider {
8181
dispatcher: MessageDispatcher, props: _Props,
8282
startImmediately: Bool
8383
) throws -> _ActorRef<Message>
84-
where Message: ActorMessage
84+
where Message: Codable
8585
{
8686
// spawn is always local, thus we delegate to the underlying provider
8787
return try self.localProvider._spawn(system: system, behavior: behavior, id: id, dispatcher: dispatcher, props: props, startImmediately: startImmediately)
@@ -146,7 +146,7 @@ internal struct LocalActorRefProvider: _ActorRefProvider {
146146
dispatcher: MessageDispatcher, props: _Props,
147147
startImmediately: Bool
148148
) throws -> _ActorRef<Message>
149-
where Message: ActorMessage
149+
where Message: Codable
150150
{
151151
return try self.root.makeChild(path: id.path) {
152152
// the cell that holds the actual "actor", though one could say the cell *is* the actor...
@@ -203,7 +203,7 @@ public protocol _ActorTreeTraversable {
203203
/// Depending on the underlying implementation, the returned ref MAY be a remote one.
204204
///
205205
/// - Returns: `deadLetters` if actor path resolves to no live actor, a valid `_ActorRef` otherwise.
206-
func _resolve<Message>(context: ResolveContext<Message>) -> _ActorRef<Message> where Message: ActorMessage
206+
func _resolve<Message>(context: ResolveContext<Message>) -> _ActorRef<Message> where Message: Codable
207207

208208
/// Resolves the given actor path against the underlying actor tree.
209209
///
@@ -326,7 +326,7 @@ public struct _TraversalContext<T> {
326326
}
327327

328328
/// INTERNAL API: May change without any prior notice.
329-
public struct ResolveContext<Message: ActorMessage> {
329+
public struct ResolveContext<Message: Codable> {
330330
/// The "remaining path" of the resolve being performed
331331
public var selectorSegments: ArraySlice<ActorPathSegment>
332332

Sources/DistributedActors/Adapters.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public protocol _AbstractAdapter: _ActorTreeTraversable {
4040
/// The adapter can be watched and shares the lifecycle with the adapted actor,
4141
/// meaning that it will terminate when the actor terminates. It will survive
4242
/// restarts after failures.
43-
internal final class _ActorRefAdapter<To: ActorMessage>: _AbstractAdapter {
43+
internal final class _ActorRefAdapter<To: Codable>: _AbstractAdapter {
4444
public let fromType: Any.Type
4545
private let target: _ActorRef<To>
4646
let id: ActorID
@@ -235,7 +235,7 @@ internal final class _DeadLetterAdapterPersonality: _AbstractAdapter {
235235
// ==== ----------------------------------------------------------------------------------------------------------------
236236
// MARK: SubReceiveAdapter
237237

238-
internal final class SubReceiveAdapter<Message: ActorMessage, OwnerMessage: ActorMessage>: _AbstractAdapter {
238+
internal final class SubReceiveAdapter<Message: Codable, OwnerMessage: Codable>: _AbstractAdapter {
239239
internal let fromType: Any.Type
240240

241241
private let target: _ActorRef<OwnerMessage>

Sources/DistributedActors/Behaviors.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
///
1717
/// The most important behavior is `_Behavior.receive` since it allows handling incoming messages with a simple block.
1818
/// Various other predefined behaviors exist, such as "stopping" or "ignoring" a message.
19-
public struct _Behavior<Message: ActorMessage>: @unchecked Sendable {
19+
public struct _Behavior<Message: Codable>: @unchecked Sendable {
2020
@usableFromInline
2121
let underlying: __Behavior<Message>
2222

@@ -459,7 +459,7 @@ extension _Behavior {
459459
}
460460

461461
@usableFromInline
462-
internal enum __Behavior<Message: ActorMessage> {
462+
internal enum __Behavior<Message: Codable> {
463463
case setup(_ onStart: (_ActorContext<Message>) throws -> _Behavior<Message>)
464464

465465
case receive(_ handle: (_ActorContext<Message>, Message) throws -> _Behavior<Message>)
@@ -501,7 +501,7 @@ internal enum StopReason {
501501
case failure(_Supervision.Failure)
502502
}
503503

504-
public enum IllegalBehaviorError<Message: ActorMessage>: Error {
504+
public enum IllegalBehaviorError<Message: Codable>: Error {
505505
/// Some behaviors, like `.same` and `.unhandled` are not allowed to be used as initial behaviors.
506506
/// See their individual documentation for the rationale why that is so.
507507
case notAllowedAsInitial(_ behavior: _Behavior<Message>)
@@ -535,7 +535,7 @@ extension _Behavior {
535535
}
536536

537537
/// Used in combination with `_Behavior.intercept` to intercept messages and signals delivered to a behavior.
538-
open class _Interceptor<Message: ActorMessage> {
538+
open class _Interceptor<Message: Codable> {
539539
public init() {}
540540

541541
@inlinable

Sources/DistributedActors/Cluster/Cluster+Event.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension Cluster {
1919
/// Represents cluster events, most notably regarding membership and reachability of other members of the cluster.
2020
///
2121
/// Inspect them directly, or `apply` to a `Membership` copy in order to be able to react to membership state of the cluster.
22-
public enum Event: ActorMessage, Equatable {
22+
public enum Event: Codable, Equatable {
2323
case snapshot(Membership)
2424
case membershipChange(MembershipChange)
2525
case reachabilityChange(ReachabilityChange)

Sources/DistributedActors/Cluster/ClusterShell.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ internal class ClusterShell {
303303
}
304304

305305
// Due to lack of Union Types, we have to emulate them
306-
enum Message: ActorMessage {
306+
enum Message: Codable {
307307
// The external API, exposed to users of the ClusterShell
308308
case command(CommandMessage)
309309
// The external API, exposed to users of the ClusterShell to query for state
@@ -324,7 +324,7 @@ internal class ClusterShell {
324324
}
325325

326326
// this is basically our API internally for this system
327-
enum CommandMessage: NonTransportableActorMessage, SilentDeadLetter {
327+
enum CommandMessage: NotActuallyCodableMessage, SilentDeadLetter {
328328
/// Connect and handshake with remote `Node`, obtaining an `UniqueNode` in the process.
329329
/// Once the handshake is completed, reply to `replyTo` with the handshake result, and also mark the unique node as `.joining`.
330330
///
@@ -343,7 +343,7 @@ internal class ClusterShell {
343343
case cleanUpAssociationTombstones
344344
}
345345

346-
enum QueryMessage: NonTransportableActorMessage {
346+
enum QueryMessage: NotActuallyCodableMessage {
347347
case associatedNodes(_ActorRef<Set<UniqueNode>>) // TODO: better type here
348348
case currentMembership(_ActorRef<Cluster.Membership>)
349349
}
@@ -362,7 +362,7 @@ internal class ClusterShell {
362362
}
363363

364364
// TODO: reformulate as Wire.accept / reject?
365-
internal enum HandshakeResult: Equatable, NonTransportableActorMessage {
365+
internal enum HandshakeResult: Equatable, NotActuallyCodableMessage {
366366
case success(UniqueNode)
367367
case failure(HandshakeStateMachine.HandshakeConnectionError)
368368
}

0 commit comments

Comments
 (0)