@@ -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)
@@ -252,16 +254,11 @@ extension DistributedActorSystem {
252
254
on: actor ,
253
255
mangledTargetName, UInt ( mangledTargetName. count) ,
254
256
argumentBuffer: hargs. buffer. _rawValue,
255
- resultBuffer: resultBuffer? . _rawValue
257
+ resultBuffer: resultBuffer. _rawValue
256
258
)
257
259
258
- // Get the result out of the buffer and invoke onReturn with the right type
259
- guard let resultBuffer = resultBuffer else {
260
- try await handler. onReturn ( value: ( ) )
261
- return
262
- }
263
- func onReturn< R> ( _: R . Type ) async throws {
264
- try await handler. onReturn /*<R>*/( value: resultBuffer)
260
+ func onReturn< R> ( _ resultTy: R . Type ) async throws {
261
+ try await handler. onReturn /*<R>*/( value: resultBuffer. load ( as: resultTy) )
265
262
}
266
263
267
264
try await _openExistential ( returnType, do: onReturn)
@@ -277,7 +274,7 @@ func _executeDistributedTarget(
277
274
on actor : AnyObject , // DistributedActor
278
275
_ targetName: UnsafePointer < UInt8 > , _ targetNameLength: UInt ,
279
276
argumentBuffer: Builtin . RawPointer , // HeterogeneousBuffer of arguments
280
- resultBuffer: Builtin . RawPointer ?
277
+ resultBuffer: Builtin . RawPointer
281
278
) async throws
282
279
283
280
// ==== ----------------------------------------------------------------------------------------------------------------
0 commit comments