@@ -27,59 +27,59 @@ internal final class CheckedContinuationCanary: @unchecked Sendable {
27
27
28
28
private static func _create( continuation: UnsafeRawPointer , function: String )
29
29
-> CheckedContinuationCanary {
30
- let instance = Builtin . allocWithTailElems_1 ( CheckedContinuationCanary . self,
30
+ let instance = unsafe Builtin. allocWithTailElems_1 ( CheckedContinuationCanary . self,
31
31
1 . _builtinWordValue,
32
32
( UnsafeRawPointer? , String) . self)
33
33
34
- instance. _continuationPtr. initialize ( to: continuation)
35
- instance. _functionPtr. initialize ( to: function)
34
+ unsafe instance. _continuationPtr . initialize ( to: continuation)
35
+ unsafe instance. _functionPtr . initialize ( to: function)
36
36
return instance
37
37
}
38
38
39
39
private var _continuationPtr : UnsafeMutablePointer < UnsafeRawPointer ? > {
40
- return UnsafeMutablePointer < UnsafeRawPointer ? > (
40
+ return unsafe UnsafeMutablePointer< UnsafeRawPointer ? > (
41
41
Builtin . projectTailElems ( self , ( UnsafeRawPointer? , String) . self) )
42
42
}
43
43
private var _functionPtr : UnsafeMutablePointer < String > {
44
- let tailPtr = UnsafeMutableRawPointer (
44
+ let tailPtr = unsafe UnsafeMutableRawPointer(
45
45
Builtin . projectTailElems ( self , ( UnsafeRawPointer? , String) . self) )
46
46
47
- let functionPtr = tailPtr
47
+ let functionPtr = unsafe tailPtr
48
48
+ MemoryLayout < ( UnsafeRawPointer ? , String ) > . offset( of: \( UnsafeRawPointer? , String) . 1 ) !
49
49
50
- return functionPtr. assumingMemoryBound ( to: String . self)
50
+ return unsafe func tionPtr. assumingMemoryBound ( to: String . self)
51
51
}
52
52
53
53
internal static func create< T, E> ( continuation: UnsafeContinuation < T , E > ,
54
54
function: String ) -> CheckedContinuationCanary {
55
- return _create (
55
+ return unsafe _create(
56
56
continuation: unsafeBitCast ( continuation, to: UnsafeRawPointer . self) ,
57
57
function: function)
58
58
}
59
59
60
60
internal var function : String {
61
- return _functionPtr. pointee
61
+ return unsafe _functionPtr. pointee
62
62
}
63
63
64
64
// Take the continuation away from the container, or return nil if it's
65
65
// already been taken.
66
66
internal func takeContinuation< T, E> ( ) -> UnsafeContinuation < T , E > ? {
67
67
// Atomically exchange the current continuation value with a null pointer.
68
- let rawContinuationPtr = unsafeBitCast ( _continuationPtr,
68
+ let rawContinuationPtr = unsafe unsafeBitCast( _continuationPtr,
69
69
to: Builtin . RawPointer. self)
70
70
let rawOld = Builtin . atomicrmw_xchg_seqcst_Word ( rawContinuationPtr,
71
71
0 . _builtinWordValue)
72
72
73
- return unsafeBitCast ( rawOld, to: UnsafeContinuation< T, E>? . self )
73
+ return unsafe unsafeBitCast( rawOld, to: UnsafeContinuation< T, E>? . self )
74
74
}
75
75
76
76
deinit {
77
- _functionPtr. deinitialize ( count: 1 )
77
+ unsafe _functionPtr. deinitialize ( count: 1 )
78
78
// Log if the continuation was never consumed before the instance was
79
79
// destructed.
80
- if _continuationPtr. pointee != nil {
80
+ if unsafe _continuationPtr. pointee != nil {
81
81
#if !$Embedded
82
- logFailedCheck ( " SWIFT TASK CONTINUATION MISUSE: \( function) leaked its continuation without resuming it. This may cause tasks waiting on it to remain suspended forever. \n " )
82
+ unsafe logFailedCheck( " SWIFT TASK CONTINUATION MISUSE: \( function) leaked its continuation without resuming it. This may cause tasks waiting on it to remain suspended forever. \n " )
83
83
#else
84
84
fatalError ( " SWIFT TASK CONTINUATION MISUSE " )
85
85
#endif
@@ -144,7 +144,7 @@ public struct CheckedContinuation<T, E: Error>: Sendable {
144
144
/// source for the continuation, used to identify the continuation in
145
145
/// runtime diagnostics related to misuse of this continuation.
146
146
public init ( continuation: UnsafeContinuation < T , E > , function: String = #function) {
147
- canary = CheckedContinuationCanary . create (
147
+ canary = unsafe CheckedContinuationCanary. create (
148
148
continuation: continuation,
149
149
function: function)
150
150
}
@@ -162,8 +162,8 @@ public struct CheckedContinuation<T, E: Error>: Sendable {
162
162
/// the caller. The task continues executing when its executor is
163
163
/// able to reschedule it.
164
164
public func resume( returning value: sending T) {
165
- if let c: UnsafeContinuation < T , E > = canary. takeContinuation ( ) {
166
- c. resume ( returning: value)
165
+ if let c: UnsafeContinuation < T , E > = unsafe canary. takeContinuation ( ) {
166
+ unsafe c. resume ( returning: value)
167
167
} else {
168
168
#if !$Embedded
169
169
fatalError ( " SWIFT TASK CONTINUATION MISUSE: \( canary. function) tried to resume its continuation more than once, returning \( value) ! \n " )
@@ -186,8 +186,8 @@ public struct CheckedContinuation<T, E: Error>: Sendable {
186
186
/// the caller. The task continues executing when its executor is
187
187
/// able to reschedule it.
188
188
public func resume( throwing error: __owned E) {
189
- if let c: UnsafeContinuation < T , E > = canary. takeContinuation ( ) {
190
- c. resume ( throwing: error)
189
+ if let c: UnsafeContinuation < T , E > = unsafe canary. takeContinuation ( ) {
190
+ unsafe c. resume ( throwing: error)
191
191
} else {
192
192
#if !$Embedded
193
193
fatalError ( " SWIFT TASK CONTINUATION MISUSE: \( canary. function) tried to resume its continuation more than once, throwing \( error) ! \n " )
@@ -301,9 +301,9 @@ public func withCheckedContinuation<T>(
301
301
_ body: ( CheckedContinuation < T , Never > ) -> Void
302
302
) async -> sending T {
303
303
return await Builtin . withUnsafeContinuation {
304
- let unsafeContinuation = UnsafeContinuation < T , Never > ( $0)
305
- return body ( CheckedContinuation ( continuation: unsafeContinuation,
306
- function: function) )
304
+ let unsafeContinuation = unsafe UnsafeContinuation< T , Never > ( $0)
305
+ return body ( unsafe CheckedContinuation( continuation: unsafeContinuation,
306
+ function: function) )
307
307
}
308
308
}
309
309
@@ -320,8 +320,8 @@ public func _unsafeInheritExecutor_withCheckedContinuation<T>(
320
320
function: String = #function,
321
321
_ body: ( CheckedContinuation < T , Never > ) -> Void
322
322
) async -> T {
323
- return await withUnsafeContinuation {
324
- body ( CheckedContinuation ( continuation: $0, function: function) )
323
+ return await unsafe withUnsafeContinuation {
324
+ body ( unsafe CheckedContinuation( continuation: $0, function: function) )
325
325
}
326
326
}
327
327
@@ -365,9 +365,9 @@ public func withCheckedThrowingContinuation<T>(
365
365
_ body: ( CheckedContinuation < T , Error > ) -> Void
366
366
) async throws -> sending T {
367
367
return try await Builtin . withUnsafeThrowingContinuation {
368
- let unsafeContinuation = UnsafeContinuation < T , Error > ( $0)
369
- return body ( CheckedContinuation ( continuation: unsafeContinuation,
370
- function: function) )
368
+ let unsafeContinuation = unsafe UnsafeContinuation< T , Error > ( $0)
369
+ return body ( unsafe CheckedContinuation( continuation: unsafeContinuation,
370
+ function: function) )
371
371
}
372
372
}
373
373
@@ -384,8 +384,8 @@ public func _unsafeInheritExecutor_withCheckedThrowingContinuation<T>(
384
384
function: String = #function,
385
385
_ body: ( CheckedContinuation < T , Error > ) -> Void
386
386
) async throws -> T {
387
- return try await withUnsafeThrowingContinuation {
388
- body ( CheckedContinuation ( continuation: $0, function: function) )
387
+ return try await unsafe withUnsafeThrowingContinuation {
388
+ body ( unsafe CheckedContinuation( continuation: $0, function: function) )
389
389
}
390
390
}
391
391
@@ -397,15 +397,15 @@ public func _unsafeInheritExecutor_withCheckedThrowingContinuation<T>(
397
397
internal func _createCheckedContinuation< T> (
398
398
_ continuation: __owned UnsafeContinuation< T , Never >
399
399
) -> CheckedContinuation < T , Never > {
400
- return CheckedContinuation ( continuation: continuation)
400
+ return unsafe CheckedContinuation( continuation: continuation)
401
401
}
402
402
403
403
@available ( SwiftStdlib 5 . 1 , * )
404
404
@_alwaysEmitIntoClient
405
405
internal func _createCheckedThrowingContinuation< T> (
406
406
_ continuation: __owned UnsafeContinuation< T , Error >
407
407
) -> CheckedContinuation < T , Error > {
408
- return CheckedContinuation ( continuation: continuation)
408
+ return unsafe CheckedContinuation( continuation: continuation)
409
409
}
410
410
411
411
@available ( SwiftStdlib 5 . 1 , * )
0 commit comments