Fix compile errors for Swift 6 language mode#317
Fix compile errors for Swift 6 language mode#317b1ackturtle wants to merge 1 commit intoapple:mainfrom
Conversation
|
|
||
| #if canImport(Darwin) | ||
| func start_thread(_ raw: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer? { | ||
| @Sendable func start_thread(_ raw: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer? { |
There was a problem hiding this comment.
Adding @Sendable to functions isn't the right fix often. Where did the original error come from?
There was a problem hiding this comment.
This @Sendable is intended to address the compilation error that occurs in TaskDriver's pthread_create(&thread, nil, start_thread, Unmanaged.passRetained(self).toOpaque()) when the Swift 6 language mode is enabled.
The compilation error that occurs is as follows:
A C function pointer can only be formed from a reference to a 'func' or a literal closure
After reconsidering based on your comments, I realized that defining start_thread within start can also suppress the compilation error.
I have tried fixing it with ea58d5d.
| } | ||
| } | ||
|
|
||
| final class LockIsolated<Value>: @unchecked Sendable { |
There was a problem hiding this comment.
We do have this type already called ManagedCriticalState
There was a problem hiding this comment.
I did not realize that ManagedCriticalState was already defined. I have fixed it to use ManagedCriticalState.
|
|
||
|
|
||
| static var driver: TaskDriver? | ||
| static let clock = LockIsolated<Clock?>(nil) |
There was a problem hiding this comment.
Having multiple separate locks here to protect the state is problematic since there might be invariants that aren't enforced this way. I would rather put all the state behind one lock
There was a problem hiding this comment.
I have modified it to protect all states with a single lock.
8469d80 to
ea58d5d
Compare
|
@swift-ci please test |
This PR fixes code that caused compile errors when enabling the Swift 6 language mode.