@@ -222,18 +222,20 @@ extension DistributedActorSystem {
222
222
223
223
// Decode the return type
224
224
func allocateReturnTypeBuffer< R> ( _: R . Type ) -> UnsafeRawPointer ? {
225
- if R . self == Void . self {
226
- return nil
227
- }
228
225
return UnsafeRawPointer ( UnsafeMutablePointer< R> . allocate( capacity: 1 ) )
229
226
}
230
227
guard let returnType: Any . Type = _getReturnTypeInfo ( mangledMethodName: mangledTargetName) else {
231
228
throw ExecuteDistributedTargetError (
232
229
message: " Failed to decode distributed target return type " )
233
230
}
234
- let resultBuffer = _openExistential ( returnType, do: allocateReturnTypeBuffer)
231
+
232
+ guard let resultBuffer = _openExistential ( returnType, do: allocateReturnTypeBuffer) else {
233
+ throw ExecuteDistributedTargetError (
234
+ message: " Failed to allocate buffer for distributed target return type " )
235
+ }
236
+
235
237
func destroyReturnTypeBuffer< R> ( _: R . Type ) {
236
- resultBuffer? . assumingMemoryBound ( to: R . self) . deallocate ( )
238
+ resultBuffer. assumingMemoryBound ( to: R . self) . deallocate ( )
237
239
}
238
240
defer {
239
241
_openExistential ( returnType, do: destroyReturnTypeBuffer)
@@ -280,16 +282,11 @@ extension DistributedActorSystem {
280
282
on: actor ,
281
283
mangledTargetName, UInt ( mangledTargetName. count) ,
282
284
argumentBuffer: hargs. buffer. _rawValue,
283
- resultBuffer: resultBuffer? . _rawValue
285
+ resultBuffer: resultBuffer. _rawValue
284
286
)
285
287
286
- // Get the result out of the buffer and invoke onReturn with the right type
287
- guard let resultBuffer = resultBuffer else {
288
- try await handler. onReturn ( value: ( ) )
289
- return
290
- }
291
- func onReturn< R> ( _: R . Type ) async throws {
292
- try await handler. onReturn /*<R>*/( value: resultBuffer)
288
+ func onReturn< R> ( _ resultTy: R . Type ) async throws {
289
+ try await handler. onReturn /*<R>*/( value: resultBuffer. load ( as: resultTy) )
293
290
}
294
291
295
292
try await _openExistential ( returnType, do: onReturn)
@@ -305,7 +302,7 @@ func _executeDistributedTarget(
305
302
on actor : AnyObject , // DistributedActor
306
303
_ targetName: UnsafePointer < UInt8 > , _ targetNameLength: UInt ,
307
304
argumentBuffer: Builtin . RawPointer , // HeterogeneousBuffer of arguments
308
- resultBuffer: Builtin . RawPointer ?
305
+ resultBuffer: Builtin . RawPointer
309
306
) async throws
310
307
311
308
// ==== ----------------------------------------------------------------------------------------------------------------
0 commit comments