Skip to content

Commit 930c72a

Browse files
committed
Fix DispatchQueueShim to work correctly in a debug build.
The self object isn't actually a Swift object, so we can neither do class dispatch on it nor retain it with swift_retain. Some of the credit goes to Mike Ash on this one. All the blame is mine, of course.
1 parent bc39e19 commit 930c72a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

stdlib/public/Concurrency/Executor.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,14 @@ func _checkExpectedExecutor(_filenameStart: Builtin.RawPointer,
9393
_filenameStart, _filenameLength, _filenameIsASCII, _line, _executor)
9494
}
9595

96+
// This must take a DispatchQueueShim, not something like AnyObject,
97+
// or else SILGen will emit a retain/release in unoptimized builds,
98+
// which won't work because DispatchQueues aren't actually
99+
// Swift-retainable.
96100
@available(SwiftStdlib 5.5, *)
97101
@_silgen_name("swift_task_enqueueOnDispatchQueue")
98-
internal func _enqueueOnDispatchQueue(_ job: UnownedJob, queue: AnyObject)
102+
internal func _enqueueOnDispatchQueue(_ job: UnownedJob,
103+
queue: DispatchQueueShim)
99104

100105
/// Used by the runtime solely for the witness table it produces.
101106
/// FIXME: figure out some way to achieve that which doesn't generate
@@ -105,13 +110,11 @@ internal func _enqueueOnDispatchQueue(_ job: UnownedJob, queue: AnyObject)
105110
/// means a dispatch_queue_t, which is not the same as DispatchQueue
106111
/// on platforms where that is an instance of a wrapper class.
107112
@available(SwiftStdlib 5.5, *)
108-
internal class DispatchQueueShim: UnsafeSendable, SerialExecutor {
109-
@inlinable
113+
internal final class DispatchQueueShim: UnsafeSendable, SerialExecutor {
110114
func enqueue(_ job: UnownedJob) {
111115
_enqueueOnDispatchQueue(job, queue: self)
112116
}
113117

114-
@inlinable
115118
func asUnownedSerialExecutor() -> UnownedSerialExecutor {
116119
return UnownedSerialExecutor(ordinary: self)
117120
}

0 commit comments

Comments
 (0)