Skip to content

Commit 51a2a1d

Browse files
committed
Merge branch 'main' into wip-address-revamp-for-da-world
2 parents d3c9f31 + 41cafad commit 51a2a1d

File tree

68 files changed

+651
-654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+651
-654
lines changed

.swiftformat

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# file options
22

3-
--swiftversion 5.2
3+
--swiftversion 5.4
44
--exclude .build
55
--exclude "**/*.pb.swift"
66
--exclude "**/*+GenActor.swift"
@@ -23,3 +23,7 @@
2323
--disable redundantInit
2424
--disable redundantGet
2525
--disable redundantReturn
26+
27+
# we want to have fine grained control over extensions by marking each function
28+
# explicitly, rather than it being forced onto the extension entirely.
29+
--extensionacl on-declarations

Sources/ActorSingletonPlugin/ActorSingletonPlugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ extension ActorSingletonPlugin: Plugin {
9595
// ==== ----------------------------------------------------------------------------------------------------------------
9696
// MARK: Singleton refs and actors
9797

98-
public extension ClusterSystem {
99-
var singleton: ActorSingletonControl {
98+
extension ClusterSystem {
99+
public var singleton: ActorSingletonControl {
100100
.init(self)
101101
}
102102
}

Sources/DistributedActors/ActorAddress.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ extension ActorAddress {
213213
}
214214
}
215215

216-
public extension ActorAddress {
216+
extension ActorAddress {
217217
/// :nodoc:
218218
@inlinable
219-
var _isLocal: Bool {
219+
public var _isLocal: Bool {
220220
switch self._location {
221221
case .local: return true
222222
default: return false
@@ -225,20 +225,20 @@ public extension ActorAddress {
225225

226226
/// :nodoc:
227227
@inlinable
228-
var _isRemote: Bool {
228+
public var _isRemote: Bool {
229229
!self._isLocal
230230
}
231231

232232
/// :nodoc:
233233
@inlinable
234-
var _asRemote: Self {
234+
public var _asRemote: Self {
235235
let remote = Self(remote: self.uniqueNode, path: self.path, incarnation: self.incarnation)
236236
return remote
237237
}
238238

239239
/// :nodoc:
240240
@inlinable
241-
var _asLocal: Self {
241+
public var _asLocal: Self {
242242
let local = Self(local: self.uniqueNode, path: self.path, incarnation: self.incarnation)
243243
return local
244244
}
@@ -392,10 +392,10 @@ extension ActorPath: CustomStringConvertible {
392392
}
393393
}
394394

395-
public extension ActorPath {
396-
static let _root: ActorPath = .init() // also known as "/"
397-
static let _user: ActorPath = try! ActorPath(root: "user")
398-
static let _system: ActorPath = try! ActorPath(root: "system")
395+
extension ActorPath {
396+
public static let _root: ActorPath = .init() // also known as "/"
397+
public static let _user: ActorPath = try! ActorPath(root: "user")
398+
public static let _system: ActorPath = try! ActorPath(root: "system")
399399

400400
internal func makeLocalAddress(on node: UniqueNode, incarnation: ActorIncarnation) -> ActorAddress {
401401
.init(local: node, path: self, incarnation: incarnation)
@@ -421,14 +421,14 @@ public protocol _PathRelationships {
421421
func appending(segment: ActorPathSegment) -> Self
422422
}
423423

424-
public extension _PathRelationships {
424+
extension _PathRelationships {
425425
/// Combines the base path with a child segment returning the concatenated path.
426426
internal static func / (base: Self, child: ActorPathSegment) -> Self {
427427
base.appending(segment: child)
428428
}
429429

430430
/// Checks whether this path starts with the passed in `path`.
431-
func starts(with path: ActorPath) -> Bool {
431+
public func starts(with path: ActorPath) -> Bool {
432432
self.segments.starts(with: path.segments)
433433
}
434434

@@ -440,7 +440,7 @@ public extension _PathRelationships {
440440
///
441441
/// - Parameter path: The path that is suspected to be the parent of `self`
442442
/// - Returns: `true` if this [ActorPath] is a direct descendant of `maybeParentPath`, `false` otherwise
443-
func isChildPathOf(_ maybeParentPath: _PathRelationships) -> Bool {
443+
public func isChildPathOf(_ maybeParentPath: _PathRelationships) -> Bool {
444444
Array(self.segments.dropLast()) == maybeParentPath.segments // TODO: more efficient impl, without the copying
445445
}
446446

@@ -452,7 +452,7 @@ public extension _PathRelationships {
452452
///
453453
/// - Parameter path: The path that is suspected to be a child of `self`
454454
/// - Returns: `true` if this [ActorPath] is a direct ancestor of `maybeChildPath`, `false` otherwise
455-
func isParentOf(_ maybeChildPath: _PathRelationships) -> Bool {
455+
public func isParentOf(_ maybeChildPath: _PathRelationships) -> Bool {
456456
maybeChildPath.isChildPathOf(self)
457457
}
458458

@@ -582,18 +582,18 @@ public struct ActorIncarnation: Equatable, Hashable, ExpressibleByIntegerLiteral
582582
}
583583
}
584584

585-
public extension ActorIncarnation {
585+
extension ActorIncarnation {
586586
/// To be used ONLY by special actors whose existence is wellKnown and identity never-changing.
587587
/// Examples: `/system/deadLetters` or `/system/cluster`.
588-
static let wellKnown: ActorIncarnation = .init(0)
588+
public static let wellKnown: ActorIncarnation = .init(0)
589589

590-
static func random() -> ActorIncarnation {
590+
public static func random() -> ActorIncarnation {
591591
ActorIncarnation(UInt32.random(in: UInt32(1) ... UInt32.max))
592592
}
593593
}
594594

595-
internal extension ActorIncarnation {
596-
init?(_ value: String?) {
595+
extension ActorIncarnation {
596+
internal init?(_ value: String?) {
597597
guard let int = (value.flatMap {
598598
Int($0)
599599
}), int >= 0 else {
@@ -778,8 +778,8 @@ extension UniqueNodeID: CustomStringConvertible {
778778
}
779779
}
780780

781-
public extension UniqueNodeID {
782-
static func random() -> UniqueNodeID {
781+
extension UniqueNodeID {
782+
public static func random() -> UniqueNodeID {
783783
UniqueNodeID(UInt64.random(in: 1 ... .max))
784784
}
785785
}

Sources/DistributedActors/ActorLogging.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ internal final class LoggingContext {
7373
/// such as it's path or node on which it resides.
7474
///
7575
/// The preferred way of obtaining a logger for an actor or system is `context.log` or `system.log`, rather than creating new ones.
76-
public extension Logger {
76+
extension Logger {
7777
/// Create a logger specific to this actor.
78-
init<Act: DistributedActor>(actor: Act) where Act.ActorSystem == ClusterSystem {
78+
public init<Act: DistributedActor>(actor: Act) where Act.ActorSystem == ClusterSystem {
7979
var log = Logger(label: "\(actor.id)")
8080
log[metadataKey: "actor/path"] = "\(actor.id.path)"
8181
log[metadataKey: "actor/id"] = "\(actor.id)"
8282
self = log
8383
}
8484

85-
static func make<T>(context: _ActorContext<T>) -> Logger {
85+
public static func make<T>(context: _ActorContext<T>) -> Logger {
8686
Logger.make(context.log, path: context.path)
8787
}
8888

@@ -283,12 +283,12 @@ public struct LogMessage {
283283
let line: UInt
284284
}
285285

286-
public extension Logger.MetadataValue {
287-
static func pretty<T>(_ value: T) -> Logger.Metadata.Value where T: CustomPrettyStringConvertible {
286+
extension Logger.MetadataValue {
287+
public static func pretty<T>(_ value: T) -> Logger.Metadata.Value where T: CustomPrettyStringConvertible {
288288
Logger.MetadataValue.stringConvertible(CustomPrettyStringConvertibleMetadataValue(value))
289289
}
290290

291-
static func pretty<T>(_ value: T) -> Logger.Metadata.Value {
291+
public static func pretty<T>(_ value: T) -> Logger.Metadata.Value {
292292
if let pretty = value as? CustomPrettyStringConvertible {
293293
return Logger.MetadataValue.stringConvertible(CustomPrettyStringConvertibleMetadataValue(pretty))
294294
} else {
@@ -309,12 +309,12 @@ struct CustomPrettyStringConvertibleMetadataValue: CustomStringConvertible {
309309
}
310310
}
311311

312-
public extension Optional where Wrapped == Logger.MetadataValue {
313-
static func lazyStringConvertible(_ makeValue: @escaping () -> CustomStringConvertible) -> Logger.Metadata.Value {
312+
extension Optional where Wrapped == Logger.MetadataValue {
313+
public static func lazyStringConvertible(_ makeValue: @escaping () -> CustomStringConvertible) -> Logger.Metadata.Value {
314314
.stringConvertible(LazyMetadataBox { makeValue() })
315315
}
316316

317-
static func lazyString(_ makeValue: @escaping () -> String) -> Logger.Metadata.Value {
317+
public static func lazyString(_ makeValue: @escaping () -> String) -> Logger.Metadata.Value {
318318
self.lazyStringConvertible(makeValue)
319319
}
320320
}
@@ -350,10 +350,10 @@ internal class LazyMetadataBox: CustomStringConvertible {
350350
// ==== ----------------------------------------------------------------------------------------------------------------
351351
// MARK: Logger extensions
352352

353-
public extension Logger {
353+
extension Logger {
354354
/// Allows passing in a `Logger.Level?` and not log if it was `nil`.
355355
@inlinable
356-
func log(
356+
public func log(
357357
level: Logger.Level?,
358358
_ message: @autoclosure () -> Logger.Message,
359359
metadata: @autoclosure () -> Logger.Metadata? = nil,

Sources/DistributedActors/ActorMessage+Protobuf.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import SwiftProtobuf
2323

2424
public protocol Any_ProtobufRepresentable: ActorMessage, SerializationRepresentable {}
2525

26-
public extension Any_ProtobufRepresentable {
27-
static var defaultSerializerID: Serialization.SerializerID? {
26+
extension Any_ProtobufRepresentable {
27+
public static var defaultSerializerID: Serialization.SerializerID? {
2828
._ProtobufRepresentable
2929
}
3030
}
@@ -47,8 +47,8 @@ public protocol _ProtobufRepresentable: _AnyPublic_ProtobufRepresentable {
4747
// Implementation note:
4848
// This conformance is a bit weird, and it is not usually going to be invoked through Codable
4949
// however it could, so we allow for this use case.
50-
public extension _ProtobufRepresentable {
51-
init(from decoder: Decoder) throws {
50+
extension _ProtobufRepresentable {
51+
public init(from decoder: Decoder) throws {
5252
guard let context = decoder.actorSerializationContext else {
5353
throw SerializationError.missingSerializationContext(decoder, Self.self)
5454
}
@@ -61,7 +61,7 @@ public extension _ProtobufRepresentable {
6161
try self.init(fromProto: proto, context: context)
6262
}
6363

64-
func encode(to encoder: Encoder) throws {
64+
public func encode(to encoder: Encoder) throws {
6565
guard let context = encoder.actorSerializationContext else {
6666
throw SerializationError.missingSerializationContext(encoder, self)
6767
}
@@ -134,13 +134,13 @@ extension Internal_ProtobufRepresentable {
134134
}
135135
}
136136

137-
public extension _ProtobufRepresentable {
138-
init(context: Serialization.Context, from buffer: Serialization.Buffer, using manifest: Serialization.Manifest) throws {
137+
extension _ProtobufRepresentable {
138+
public init(context: Serialization.Context, from buffer: Serialization.Buffer, using manifest: Serialization.Manifest) throws {
139139
let proto = try ProtobufRepresentation(serializedData: buffer.readData())
140140
try self.init(fromProto: proto, context: context)
141141
}
142142

143-
func serialize(context: Serialization.Context) throws -> Serialization.Buffer {
143+
public func serialize(context: Serialization.Context) throws -> Serialization.Buffer {
144144
try .data(self.toProto(context: context).serializedData())
145145
}
146146
}

Sources/DistributedActors/ActorMessages.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,20 @@ public struct NonTransportableAnyError: Error, NonTransportableActorMessage {
164164
/// - Warning: Attempting to send such message over the network will fail at runtime (and log an error or warning).
165165
public protocol NonTransportableActorMessage: ActorMessage {}
166166

167-
public extension NonTransportableActorMessage {
168-
init(from decoder: Swift.Decoder) throws {
167+
extension NonTransportableActorMessage {
168+
public init(from decoder: Swift.Decoder) throws {
169169
fatalError("Attempted to decode NonTransportableActorMessage message: \(Self.self)! This should never happen.")
170170
}
171171

172-
func encode(to encoder: Swift.Encoder) throws {
172+
public func encode(to encoder: Swift.Encoder) throws {
173173
fatalError("Attempted to encode NonTransportableActorMessage message: \(Self.self)! This should never happen.")
174174
}
175175

176-
init(context: Serialization.Context, from buffer: inout ByteBuffer, using manifest: Serialization.Manifest) throws {
176+
public init(context: Serialization.Context, from buffer: inout ByteBuffer, using manifest: Serialization.Manifest) throws {
177177
fatalError("Attempted to deserialize NonTransportableActorMessage message: \(Self.self)! This should never happen.")
178178
}
179179

180-
func serialize(context: Serialization.Context, to bytes: inout ByteBuffer) throws {
180+
public func serialize(context: Serialization.Context, to bytes: inout ByteBuffer) throws {
181181
fatalError("Attempted to serialize NonTransportableActorMessage message: \(Self.self)! This should never happen.")
182182
}
183183
}

Sources/DistributedActors/ActorNaming.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import DistributedActorsConcurrencyHelpers
1717
// ==== ----------------------------------------------------------------------------------------------------------------
1818
// MARK: Actor Name
1919

20-
public extension ActorNaming {
20+
extension ActorNaming {
2121
/// Default actor naming strategy; whereas the name MUST be unique under a given path.
2222
///
2323
/// I.e. if a parent actor spawns `.unique(worker)`
2424
///
2525
/// This naming is used by the `ExpressibleByStringLiteral` and `ExpressibleByStringInterpolation` conversions.
2626
///
2727
/// - Faults: when passed in name contains illegal characters. See `ActorNaming` for detailed rules about actor naming.
28-
static func unique(_ name: String) -> ActorNaming {
28+
public static func unique(_ name: String) -> ActorNaming {
2929
ActorNaming.validateUserProvided(nameOrPrefix: name)
3030
return .init(unchecked: .unique(name))
3131
}
@@ -35,13 +35,13 @@ public extension ActorNaming {
3535
/// actor, it may name them with subsequent numbers or letters of a limited alphabet.
3636
///
3737
/// - Faults: when passed in name contains illegal characters. See `ActorNaming` for detailed rules about actor naming.
38-
static func prefixed(with prefix: String) -> ActorNaming {
38+
public static func prefixed(with prefix: String) -> ActorNaming {
3939
ActorNaming.validateUserProvided(nameOrPrefix: prefix)
4040
return .init(unchecked: .prefixed(prefix: prefix, suffixScheme: .letters))
4141
}
4242

4343
/// Shorthand for defining "anonymous" actor names, which carry
44-
static var anonymous: ActorNaming {
44+
public static var anonymous: ActorNaming {
4545
.init(unchecked: .prefixed(prefix: "$anonymous", suffixScheme: .letters))
4646
}
4747

Sources/DistributedActors/ActorRef+Ask.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ extension _ActorRef: ReceivesQuestions {
7171
_ makeQuestion: @escaping (_ActorRef<Answer>) -> Question
7272
) -> AskResponse<Answer> {
7373
guard let system = self._system else {
74-
return .completed(.failure(AskError.systemAlreadyShutDown))
74+
return .completed(.failure(RemoteCallError.clusterAlreadyShutDown))
7575
}
7676

7777
if system.isShuttingDown {
78-
return .completed(.failure(AskError.systemAlreadyShutDown))
78+
return .completed(.failure(RemoteCallError.clusterAlreadyShutDown))
7979
}
8080

8181
do {
@@ -147,11 +147,6 @@ enum AskResponse<Value> {
147147
case nioFuture(EventLoopFuture<Value>)
148148
}
149149

150-
enum AskError: DistributedActorSystemError, Error {
151-
case timedOut(TimeoutError)
152-
case systemAlreadyShutDown
153-
}
154-
155150
extension AskResponse {
156151
/// Blocks and waits until there is a response or fails with an error.
157152
@available(*, deprecated, message: "Blocking API will be removed in favor of async await")
@@ -203,7 +198,7 @@ extension AskResponse: _AsyncResult {
203198
let eventLoop = nioFuture.eventLoop
204199
let promise: EventLoopPromise<Value> = eventLoop.makePromise()
205200
let timeoutTask = eventLoop.scheduleTask(in: timeout.toNIO) {
206-
promise.fail(AskError.timedOut(TimeoutError(message: "\(type(of: self)) timed out after \(timeout.prettyDescription)", timeout: timeout)))
201+
promise.fail(RemoteCallError.timedOut(TimeoutError(message: "\(type(of: self)) timed out after \(timeout.prettyDescription)", timeout: timeout)))
207202
}
208203
nioFuture.whenFailure {
209204
timeoutTask.cancel()
@@ -283,7 +278,7 @@ internal enum AskActor {
283278
Ask was initiated from function [\(function)] in [\(file):\(line)] and \
284279
expected response of type [\(String(reflecting: ResponseType.self))].
285280
"""
286-
completable.fail(AskError.timedOut(TimeoutError(message: errorMessage, timeout: timeout)))
281+
completable.fail(RemoteCallError.timedOut(TimeoutError(message: errorMessage, timeout: timeout)))
287282

288283
// FIXME: Hack to stop from subReceive. Should we allow this somehow?
289284
// Maybe add a SubReceiveContext or similar?

Sources/DistributedActors/ActorTags.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public protocol ActorTag: Sendable where Value == Key.Value {
6363
var value: Value { get }
6464
}
6565

66-
public extension ActorTag {
67-
var keyType: Key.Type { Key.self }
68-
var id: String { Key.id }
66+
extension ActorTag {
67+
public var keyType: Key.Type { Key.self }
68+
public var id: String { Key.id }
6969
}
7070

7171
public protocol ActorTagKey: Sendable {

0 commit comments

Comments
 (0)