@@ -34,6 +34,36 @@ public struct ActorAddress: Hashable, Sendable, Codable {
3434 }
3535}
3636
37+ /// This type is same as ActorAddress however for purposes of SIL tests we make it not-loadable.
38+ ///
39+ /// By adding the `Any` we don't know the full size of the struct making the type in SIL `$*ActorAddress`
40+ /// when we try to store or pass it around, which triggers `isAddressOnly` guarded paths which we need to test.
41+ public struct NotLoadableActorAddress : Hashable , Sendable , Codable {
42+ public let address : String
43+ public let any : Sendable = " " // DO NOT REMOVE, this makes this struct address-only which is crucial for testing.
44+
45+ public init ( parse address: String ) {
46+ self . address = address
47+ }
48+
49+ public init ( from decoder: Decoder ) throws {
50+ let container = try decoder. singleValueContainer ( )
51+ self . address = try container. decode ( String . self)
52+ }
53+
54+ public func encode( to encoder: Encoder ) throws {
55+ var container = encoder. singleValueContainer ( )
56+ try container. encode ( self . address)
57+ }
58+
59+ public func hash( into hasher: inout Swift . Hasher ) {
60+ }
61+
62+ public static func == ( lhs: NotLoadableActorAddress , rhs: NotLoadableActorAddress ) -> Bool {
63+ lhs. address == rhs. address
64+ }
65+ }
66+
3767// ==== Noop Transport ---------------------------------------------------------
3868
3969@available ( SwiftStdlib 5 . 7 , * )
@@ -109,9 +139,81 @@ public struct FakeActorSystem: DistributedActorSystem, CustomStringConvertible {
109139 }
110140}
111141
142+ @available ( SwiftStdlib 5 . 7 , * )
143+ public struct FakeNotLoadableAddressActorSystem : DistributedActorSystem , CustomStringConvertible {
144+ public typealias ActorID = NotLoadableActorAddress
145+ public typealias InvocationDecoder = FakeInvocationDecoder
146+ public typealias InvocationEncoder = FakeInvocationEncoder
147+ public typealias SerializationRequirement = Codable
148+ public typealias ResultHandler = FakeRoundtripResultHandler
149+
150+ // just so that the struct does not become "trivial"
151+ let someValue : String = " "
152+ let someValue2 : String = " "
153+ let someValue3 : String = " "
154+ let someValue4 : String = " "
155+
156+ public init ( ) {
157+ print ( " Initialized new FakeActorSystem " )
158+ }
159+
160+ public func resolve< Act> ( id: ActorID , as actorType: Act . Type ) throws -> Act ?
161+ where Act: DistributedActor ,
162+ Act. ID == ActorID {
163+ nil
164+ }
165+
166+ public func assignID< Act> ( _ actorType: Act . Type ) -> ActorID
167+ where Act: DistributedActor ,
168+ Act. ID == ActorID {
169+ NotLoadableActorAddress ( parse: " xxx " )
170+ }
171+
172+ public func actorReady< Act> ( _ actor : Act )
173+ where Act: DistributedActor ,
174+ Act. ID == ActorID {
175+ }
176+
177+ public func resignID( _ id: ActorID ) {
178+ }
179+
180+ public func makeInvocationEncoder( ) -> InvocationEncoder {
181+ . init( )
182+ }
183+
184+ public func remoteCall< Act, Err, Res> (
185+ on actor : Act ,
186+ target: RemoteCallTarget ,
187+ invocation invocationEncoder: inout InvocationEncoder ,
188+ throwing: Err . Type ,
189+ returning: Res . Type
190+ ) async throws -> Res
191+ where Act: DistributedActor ,
192+ Act. ID == ActorID ,
193+ Err: Error ,
194+ Res: SerializationRequirement {
195+ throw ExecuteDistributedTargetError ( message: " \( #function) not implemented. " )
196+ }
197+
198+ public func remoteCallVoid< Act, Err> (
199+ on actor : Act ,
200+ target: RemoteCallTarget ,
201+ invocation invocationEncoder: inout InvocationEncoder ,
202+ throwing: Err . Type
203+ ) async throws
204+ where Act: DistributedActor ,
205+ Act. ID == ActorID ,
206+ Err: Error {
207+ throw ExecuteDistributedTargetError ( message: " \( #function) not implemented. " )
208+ }
209+
210+ public nonisolated var description : Swift . String {
211+ " \( Self . self) () "
212+ }
213+ }
214+
112215// ==== Fake Roundtrip Transport -----------------------------------------------
113216
114- // TODO(distributed): not thread safe...
115217@available ( SwiftStdlib 5 . 7 , * )
116218public final class FakeRoundtripActorSystem : DistributedActorSystem , @unchecked Sendable {
117219 public typealias ActorID = ActorAddress
0 commit comments