@@ -438,8 +438,8 @@ extension DistributedActorSystem {
438
438
439
439
// Gen the generic environment (if any) associated with the target.
440
440
let genericEnv =
441
- targetNameUTF8. withUnsafeBufferPointer { targetNameUTF8 in
442
- _getGenericEnvironmentOfDistributedTarget (
441
+ unsafe targetNameUTF8 . withUnsafeBufferPointer { targetNameUTF8 in
442
+ unsafe _getGenericEnvironmentOfDistributedTarget (
443
443
targetNameUTF8. baseAddress!,
444
444
UInt ( targetNameUTF8. endIndex) )
445
445
}
@@ -449,26 +449,26 @@ extension DistributedActorSystem {
449
449
var numWitnessTables : Int = 0
450
450
451
451
defer {
452
- substitutionsBuffer? . deallocate ( )
453
- witnessTablesBuffer? . deallocate ( )
452
+ unsafe substitutionsBuffer? . deallocate ( )
453
+ unsafe witnessTablesBuffer? . deallocate ( )
454
454
}
455
455
456
- if let genericEnv = genericEnv {
456
+ if let genericEnv = unsafe genericEnv {
457
457
let subs = try invocationDecoder. decodeGenericSubstitutions ( )
458
458
if subs. isEmpty {
459
459
throw ExecuteDistributedTargetError (
460
460
message: " Cannot call generic method without generic argument substitutions " ,
461
461
errorCode: . missingGenericSubstitutions)
462
462
}
463
463
464
- substitutionsBuffer = . allocate( capacity: subs. count)
464
+ unsafe substitutionsBuffer = . allocate( capacity: subs. count)
465
465
466
466
for (offset, substitution) in subs. enumerated ( ) {
467
- let element = substitutionsBuffer? . advanced ( by: offset)
468
- element? . initialize ( to: substitution)
467
+ let element = unsafe substitutionsBuffer? . advanced ( by: offset)
468
+ unsafe element? . initialize ( to: substitution)
469
469
}
470
470
471
- ( witnessTablesBuffer, numWitnessTables) = _getWitnessTablesFor ( environment: genericEnv,
471
+ unsafe ( witnessTablesBuffer, numWitnessTables) = unsafe _getWitnessTablesFor( environment: genericEnv,
472
472
genericArguments: substitutionsBuffer!)
473
473
if numWitnessTables < 0 {
474
474
throw ExecuteDistributedTargetError (
@@ -478,8 +478,8 @@ extension DistributedActorSystem {
478
478
}
479
479
480
480
let paramCount =
481
- targetNameUTF8. withUnsafeBufferPointer { targetNameUTF8 in
482
- __getParameterCount (
481
+ unsafe targetNameUTF8 . withUnsafeBufferPointer { targetNameUTF8 in
482
+ unsafe __getParameterCount(
483
483
targetNameUTF8. baseAddress!,
484
484
UInt ( targetNameUTF8. endIndex) )
485
485
}
@@ -497,12 +497,12 @@ extension DistributedActorSystem {
497
497
// Prepare buffer for the parameter types to be decoded into:
498
498
let argumentTypesBuffer = UnsafeMutableBufferPointer< Any . Type> . allocate( capacity: Int ( paramCount) )
499
499
defer {
500
- argumentTypesBuffer. deallocate ( )
500
+ unsafe argumentTypesBuffer. deallocate ( )
501
501
}
502
502
503
503
// Demangle and write all parameter types into the prepared buffer
504
- let decodedNum = targetNameUTF8. withUnsafeBufferPointer { targetNameUTF8 in
505
- __getParameterTypeInfo (
504
+ let decodedNum = unsafe targetNameUTF8 . withUnsafeBufferPointer { targetNameUTF8 in
505
+ unsafe __getParameterTypeInfo(
506
506
targetNameUTF8. baseAddress!,
507
507
UInt ( targetNameUTF8. endIndex) ,
508
508
genericEnv,
@@ -525,7 +525,7 @@ extension DistributedActorSystem {
525
525
var argumentTypes : [ Any . Type ] = [ ]
526
526
do {
527
527
argumentTypes. reserveCapacity ( Int ( decodedNum) )
528
- for argumentType in argumentTypesBuffer {
528
+ for unsafe argumentType in unsafe argumentTypesBuffer {
529
529
argumentTypes. append ( argumentType)
530
530
}
531
531
}
@@ -536,8 +536,8 @@ extension DistributedActorSystem {
536
536
}
537
537
538
538
let maybeReturnTypeFromTypeInfo =
539
- targetNameUTF8. withUnsafeBufferPointer { targetNameUTF8 in
540
- __getReturnTypeInfo (
539
+ unsafe targetNameUTF8 . withUnsafeBufferPointer { targetNameUTF8 in
540
+ unsafe __getReturnTypeInfo(
541
541
/*targetName:*/targetNameUTF8. baseAddress!,
542
542
/*targetLength:*/UInt ( targetNameUTF8. endIndex) ,
543
543
/*genericEnv:*/genericEnv,
@@ -549,7 +549,7 @@ extension DistributedActorSystem {
549
549
errorCode: . typeDeserializationFailure)
550
550
}
551
551
552
- guard let resultBuffer = _openExistential ( returnTypeFromTypeInfo, do: doAllocateReturnTypeBuffer) else {
552
+ guard let resultBuffer = _openExistential ( returnTypeFromTypeInfo, do: unsafe do AllocateReturnTypeBuffer) else {
553
553
throw ExecuteDistributedTargetError (
554
554
message: " Failed to allocate buffer for distributed target return type " ,
555
555
errorCode: . typeDeserializationFailure)
@@ -560,16 +560,16 @@ extension DistributedActorSystem {
560
560
var executeDistributedTargetHasThrown = true
561
561
562
562
func doDestroyReturnTypeBuffer< R> ( _: R . Type ) {
563
- let buf = resultBuffer. assumingMemoryBound ( to: R . self)
563
+ let buf = unsafe resultBuffer. assumingMemoryBound ( to: R . self)
564
564
565
565
if !executeDistributedTargetHasThrown {
566
566
// since the _execute function has NOT thrown,
567
567
// there must be a value in the result buffer that we must deinitialize
568
- buf. deinitialize ( count: 1 )
568
+ unsafe buf. deinitialize ( count: 1 )
569
569
} // otherwise, the _execute has thrown and not populated the result buffer
570
570
571
571
// finally, deallocate the buffer
572
- buf. deallocate ( )
572
+ unsafe buf. deallocate ( )
573
573
}
574
574
575
575
defer {
@@ -581,7 +581,7 @@ extension DistributedActorSystem {
581
581
// let errorType = try invocationDecoder.decodeErrorType() // TODO(distributed): decide how to use when typed throws are done
582
582
583
583
// Execute the target!
584
- try await _executeDistributedTarget (
584
+ try unsafe await _executeDistributedTarget (
585
585
on: actor ,
586
586
/*targetNameData:*/targetName,
587
587
/*targetNameLength:*/UInt ( targetName. count) ,
@@ -599,7 +599,7 @@ extension DistributedActorSystem {
599
599
if returnType == Void . self {
600
600
try await handler. onReturnVoid ( )
601
601
} else {
602
- try await self . invokeHandlerOnReturn (
602
+ try unsafe await self . invokeHandlerOnReturn (
603
603
handler: handler,
604
604
resultBuffer: resultBuffer,
605
605
metatype: returnType
0 commit comments