Skip to content

Commit cd8f4ff

Browse files
committed
Replace uses of @_silgen_name with uses of a shims header.
The header is in the main Swift repo because it's shared with the Darwin Dispatch overlay. No intended functionality change.
1 parent b628e5c commit cd8f4ff

File tree

6 files changed

+22
-240
lines changed

6 files changed

+22
-240
lines changed

src/swift/Block.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import CDispatch
14+
import _SwiftDispatchOverlayShims
1415

1516
public struct DispatchWorkItemFlags : OptionSet, RawRepresentable {
1617
public let rawValue: UInt
@@ -98,6 +99,3 @@ public class DispatchWorkItem {
9899
/// on the referential identity of a block. Particularly, dispatch_block_create.
99100
internal typealias _DispatchBlock = @convention(block) () -> Void
100101
internal typealias dispatch_block_t = @convention(block) () -> Void
101-
102-
@_silgen_name("_swift_dispatch_block_create_noescape")
103-
internal func _swift_dispatch_block_create_noescape(_ flags: dispatch_block_flags_t, _ block: () -> ()) -> _DispatchBlock

src/swift/Data.swift

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import CDispatch
14+
import _SwiftDispatchOverlayShims
1415

1516
public struct DispatchData : RandomAccessCollection {
1617
public typealias Iterator = DispatchDataIterator
@@ -37,8 +38,8 @@ public struct DispatchData : RandomAccessCollection {
3738

3839
fileprivate var _deallocator: (DispatchQueue?, @convention(block) () -> Void) {
3940
switch self {
40-
case .free: return (nil, _dispatch_data_destructor_free())
41-
case .unmap: return (nil, _dispatch_data_destructor_munmap())
41+
case .free: return (nil, _swift_dispatch_data_destructor_free())
42+
case .unmap: return (nil, _swift_dispatch_data_destructor_munmap())
4243
case .custom(let q, let b): return (q, b)
4344
}
4445
}
@@ -50,7 +51,7 @@ public struct DispatchData : RandomAccessCollection {
5051
///
5152
/// - parameter bytes: A pointer to the memory. It will be copied.
5253
public init(bytes buffer: UnsafeBufferPointer<UInt8>) {
53-
let d = dispatch_data_create(buffer.baseAddress!, buffer.count, nil, _dispatch_data_destructor_default())
54+
let d = dispatch_data_create(buffer.baseAddress!, buffer.count, nil, _swift_dispatch_data_destructor_default())
5455
self.init(data: d)
5556
}
5657

@@ -91,7 +92,7 @@ public struct DispatchData : RandomAccessCollection {
9192
public func enumerateBytes(
9293
block: (_ buffer: UnsafeBufferPointer<UInt8>, _ byteIndex: Int, _ stop: inout Bool) -> Void)
9394
{
94-
_swift_dispatch_data_apply(__wrapped.__wrapped) { (_, offset: Int, ptr: UnsafeRawPointer, size: Int) in
95+
_swift_dispatch_data_apply(UnsafeMutableRawPointer(__wrapped.__wrapped)) { (_, offset: Int, ptr: UnsafeRawPointer, size: Int) in
9596
let bytePtr = ptr.bindMemory(to: UInt8.self, capacity: size)
9697
let bp = UnsafeBufferPointer(start: bytePtr, count: size)
9798
var stop = false
@@ -105,7 +106,7 @@ public struct DispatchData : RandomAccessCollection {
105106
/// - parameter bytes: A pointer to the bytes to copy in to the data.
106107
/// - parameter count: The number of bytes to copy.
107108
public mutating func append(_ bytes: UnsafePointer<UInt8>, count: Int) {
108-
let data = dispatch_data_create(bytes, count, nil, _dispatch_data_destructor_default())
109+
let data = dispatch_data_create(bytes, count, nil, _swift_dispatch_data_destructor_default())
109110
self.append(DispatchData(data: data))
110111
}
111112

@@ -272,18 +273,3 @@ public struct DispatchDataIterator : IteratorProtocol, Sequence {
272273
}
273274

274275
typealias _swift_data_applier = @convention(block) (dispatch_data_t, Int, UnsafeRawPointer, Int) -> Bool
275-
276-
@_silgen_name("_swift_dispatch_data_apply")
277-
internal func _swift_dispatch_data_apply(_ data: dispatch_data_t, _ block: _swift_data_applier)
278-
279-
@_silgen_name("_swift_dispatch_data_empty")
280-
internal func _swift_dispatch_data_empty() -> dispatch_data_t
281-
282-
@_silgen_name("_swift_dispatch_data_destructor_free")
283-
internal func _dispatch_data_destructor_free() -> _DispatchBlock
284-
285-
@_silgen_name("_swift_dispatch_data_destructor_munmap")
286-
internal func _dispatch_data_destructor_munmap() -> _DispatchBlock
287-
288-
@_silgen_name("_swift_dispatch_data_destructor_default")
289-
internal func _dispatch_data_destructor_default() -> _DispatchBlock

src/swift/DispatchStubs.cc

Lines changed: 0 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -51,157 +51,6 @@ static void _dispatch_overlay_constructor() {
5151

5252
#endif /* USE_OBJC */
5353

54-
55-
// Replicate the SWIFT_CC(swift) calling convention macro from
56-
// swift/include/swift/Runtime/Config.h because it is
57-
// quite awkward to include Config.h and its recursive includes
58-
// in dispatch. This define must be manually kept in synch
59-
#define SWIFT_CC(CC) SWIFT_CC_##CC
60-
#if SWIFT_USE_SWIFTCALL
61-
#define SWIFT_CC_swift __attribute__((swiftcall))
62-
#else
63-
#define SWIFT_CC_swift
64-
#endif
65-
66-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
67-
extern "C" dispatch_queue_attr_t
68-
_swift_dispatch_queue_concurrent(void) {
69-
return DISPATCH_QUEUE_CONCURRENT;
70-
}
71-
72-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
73-
extern "C" void
74-
_swift_dispatch_apply_current(size_t iterations, __attribute__((__noescape__)) void (^block)(size_t)) {
75-
dispatch_apply(iterations, (dispatch_queue_t _Nonnull)0, block);
76-
}
77-
78-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
79-
extern "C" dispatch_queue_t
80-
_swift_dispatch_get_main_queue(void) {
81-
return dispatch_get_main_queue();
82-
}
83-
84-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
85-
extern "C" dispatch_data_t
86-
_swift_dispatch_data_empty(void) {
87-
return dispatch_data_empty;
88-
}
89-
90-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
91-
extern "C" dispatch_block_t
92-
_swift_dispatch_data_destructor_default(void) {
93-
return DISPATCH_DATA_DESTRUCTOR_DEFAULT;
94-
}
95-
96-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
97-
extern "C" dispatch_block_t
98-
_swift_dispatch_data_destructor_free(void) {
99-
return _dispatch_data_destructor_free;
100-
}
101-
102-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
103-
extern "C" dispatch_block_t
104-
_swift_dispatch_data_destructor_munmap(void) {
105-
return _dispatch_data_destructor_munmap;
106-
}
107-
108-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
109-
extern "C" dispatch_block_t
110-
_swift_dispatch_block_create_with_qos_class(dispatch_block_flags_t flags, dispatch_qos_class_t qos, int relative_priority, dispatch_block_t block) {
111-
return dispatch_block_create_with_qos_class(flags, qos, relative_priority, block);
112-
}
113-
114-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
115-
extern "C" dispatch_block_t
116-
_swift_dispatch_block_create_noescape(dispatch_block_flags_t flags, dispatch_block_t block) {
117-
return dispatch_block_create(flags, block);
118-
}
119-
120-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
121-
extern "C" void
122-
_swift_dispatch_block_cancel(dispatch_block_t block) {
123-
dispatch_block_cancel(block);
124-
}
125-
126-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
127-
extern "C" long
128-
_swift_dispatch_block_wait(dispatch_block_t block, dispatch_time_t timeout) {
129-
return dispatch_block_wait(block, timeout);
130-
}
131-
132-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
133-
extern "C" void
134-
_swift_dispatch_block_notify(dispatch_block_t block, dispatch_queue_t queue, dispatch_block_t notification_block) {
135-
dispatch_block_notify(block, queue, notification_block);
136-
}
137-
138-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
139-
extern "C" long
140-
_swift_dispatch_block_testcancel(dispatch_block_t block) {
141-
return dispatch_block_testcancel(block);
142-
}
143-
144-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
145-
extern "C" bool
146-
_swift_dispatch_data_apply(dispatch_data_t data, bool (^applier)(dispatch_data_t, size_t, const void *, size_t)) {
147-
return dispatch_data_apply(data, applier);
148-
}
149-
150-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
151-
extern "C" void
152-
_swift_dispatch_async(dispatch_queue_t queue, dispatch_block_t block) {
153-
dispatch_async(queue, block);
154-
}
155-
156-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
157-
extern "C" void
158-
_swift_dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block) {
159-
dispatch_group_async(group, queue, block);
160-
}
161-
162-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
163-
extern "C" void
164-
_swift_dispatch_sync(dispatch_queue_t queue, dispatch_block_t block) {
165-
dispatch_sync(queue, block);
166-
}
167-
168-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
169-
extern "C" void
170-
_swift_dispatch_release(dispatch_object_t obj) {
171-
dispatch_release(obj);
172-
}
173-
174-
// DISPATCH_RUNTIME_STDLIB_INTERFACE
175-
// extern "C" dispatch_queue_t
176-
// _swift_apply_current_root_queue() {
177-
// return DISPATCH_APPLY_CURRENT_ROOT_QUEUE;
178-
// }
179-
180-
#define SOURCE(t) \
181-
SWIFT_CC(swift) \
182-
DISPATCH_RUNTIME_STDLIB_INTERFACE extern "C" dispatch_source_type_t \
183-
_swift_dispatch_source_type_##t(void) { \
184-
return DISPATCH_SOURCE_TYPE_##t; \
185-
}
186-
187-
SOURCE(DATA_ADD)
188-
SOURCE(DATA_OR)
189-
#if HAVE_MACH
190-
SOURCE(MACH_SEND)
191-
SOURCE(MACH_RECV)
192-
SOURCE(MEMORYPRESSURE)
193-
#endif
194-
#ifndef __linux__
195-
SOURCE(PROC)
196-
#endif
197-
SOURCE(READ)
198-
SOURCE(SIGNAL)
199-
SOURCE(TIMER)
200-
#ifndef __linux__
201-
SOURCE(VNODE)
202-
#endif
203-
SOURCE(WRITE)
204-
20554
// See comment in CFFuntime.c explaining why objc_retainAutoreleasedReturnValue is needed.
20655
extern "C" void swift_release(void *);
20756
extern "C" void * objc_retainAutoreleasedReturnValue(void *obj) {

src/swift/Queue.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// dispatch/queue.h
1414

1515
import CDispatch
16+
import _SwiftDispatchOverlayShims
1617

1718
public final class DispatchSpecificKey<T> {
1819
public init() {}
@@ -104,7 +105,7 @@ public extension DispatchQueue {
104105
}
105106

106107
public class func concurrentPerform(iterations: Int, execute work: (Int) -> Void) {
107-
_swift_dispatch_apply_current(iterations, work)
108+
_swift_dispatch_apply_current(UInt32(iterations), work)
108109
}
109110

110111
public class var main: DispatchQueue {
@@ -337,15 +338,3 @@ private func _destructDispatchSpecificValue(ptr: UnsafeMutableRawPointer?) {
337338
Unmanaged<AnyObject>.fromOpaque(p).release()
338339
}
339340
}
340-
341-
@_silgen_name("_swift_dispatch_queue_concurrent")
342-
internal func _swift_dispatch_queue_concurrent() -> dispatch_queue_attr_t
343-
344-
@_silgen_name("_swift_dispatch_get_main_queue")
345-
internal func _swift_dispatch_get_main_queue() -> dispatch_queue_t
346-
347-
@_silgen_name("_swift_dispatch_apply_current_root_queue")
348-
internal func _swift_dispatch_apply_current_root_queue() -> dispatch_queue_t
349-
350-
@_silgen_name("_swift_dispatch_apply_current")
351-
internal func _swift_dispatch_apply_current(_ iterations: Int, _ block: @convention(block) (Int) -> Void)

src/swift/Source.swift

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import CDispatch
14+
import _SwiftDispatchOverlayShims
1415

1516
public extension DispatchSourceProtocol {
1617

@@ -151,66 +152,66 @@ public extension DispatchSource {
151152

152153
#if HAVE_MACH
153154
public class func makeMachSendSource(port: mach_port_t, eventMask: MachSendEvent, queue: DispatchQueue? = nil) -> DispatchSourceMachSend {
154-
let source = dispatch_source_create(_swift_dispatch_source_type_mach_send(), UInt(port), eventMask.rawValue, queue?.__wrapped)
155+
let source = dispatch_source_create(_swift_dispatch_source_type_MACH_SEND(), UInt(port), eventMask.rawValue, queue?.__wrapped)
155156
return DispatchSource(source: source) as DispatchSourceMachSend
156157
}
157158
#endif
158159

159160
#if HAVE_MACH
160161
public class func makeMachReceiveSource(port: mach_port_t, queue: DispatchQueue? = nil) -> DispatchSourceMachReceive {
161-
let source = dispatch_source_create(_swift_dispatch_source_type_mach_recv(), UInt(port), 0, queue?.__wrapped)
162+
let source = dispatch_source_create(_swift_dispatch_source_type_MACH_RECV(), UInt(port), 0, queue?.__wrapped)
162163
return DispatchSource(source) as DispatchSourceMachReceive
163164
}
164165
#endif
165166

166167
#if HAVE_MACH
167168
public class func makeMemoryPressureSource(eventMask: MemoryPressureEvent, queue: DispatchQueue? = nil) -> DispatchSourceMemoryPressure {
168-
let source = dispatch_source_create(_swift_dispatch_source_type_memorypressure(), 0, eventMask.rawValue, queue.__wrapped)
169+
let source = dispatch_source_create(_swift_dispatch_source_type_MEMORYPRESSURE(), 0, eventMask.rawValue, queue.__wrapped)
169170
return DispatchSourceMemoryPressure(source)
170171
}
171172
#endif
172173

173174
#if !os(Linux) && !os(Android)
174175
public class func makeProcessSource(identifier: pid_t, eventMask: ProcessEvent, queue: DispatchQueue? = nil) -> DispatchSourceProcess {
175-
let source = dispatch_source_create(_swift_dispatch_source_type_proc(), UInt(identifier), eventMask.rawValue, queue?.__wrapped)
176+
let source = dispatch_source_create(_swift_dispatch_source_type_PROC(), UInt(identifier), eventMask.rawValue, queue?.__wrapped)
176177
return DispatchSource(source: source) as DispatchSourceProcess
177178
}
178179
#endif
179180

180181
public class func makeReadSource(fileDescriptor: Int32, queue: DispatchQueue? = nil) -> DispatchSourceRead {
181-
let source = dispatch_source_create(_swift_dispatch_source_type_read(), UInt(fileDescriptor), 0, queue?.__wrapped)
182+
let source = dispatch_source_create(_swift_dispatch_source_type_READ(), UInt(fileDescriptor), 0, queue?.__wrapped)
182183
return DispatchSource(source: source) as DispatchSourceRead
183184
}
184185

185186
public class func makeSignalSource(signal: Int32, queue: DispatchQueue? = nil) -> DispatchSourceSignal {
186-
let source = dispatch_source_create(_swift_dispatch_source_type_signal(), UInt(signal), 0, queue?.__wrapped)
187+
let source = dispatch_source_create(_swift_dispatch_source_type_SIGNAL(), UInt(signal), 0, queue?.__wrapped)
187188
return DispatchSource(source: source) as DispatchSourceSignal
188189
}
189190

190191
public class func makeTimerSource(flags: TimerFlags = [], queue: DispatchQueue? = nil) -> DispatchSourceTimer {
191-
let source = dispatch_source_create(_swift_dispatch_source_type_timer(), 0, flags.rawValue, queue?.__wrapped)
192+
let source = dispatch_source_create(_swift_dispatch_source_type_TIMER(), 0, flags.rawValue, queue?.__wrapped)
192193
return DispatchSource(source: source) as DispatchSourceTimer
193194
}
194195

195196
public class func makeUserDataAddSource(queue: DispatchQueue? = nil) -> DispatchSourceUserDataAdd {
196-
let source = dispatch_source_create(_swift_dispatch_source_type_data_add(), 0, 0, queue?.__wrapped)
197+
let source = dispatch_source_create(_swift_dispatch_source_type_DATA_ADD(), 0, 0, queue?.__wrapped)
197198
return DispatchSource(source: source) as DispatchSourceUserDataAdd
198199
}
199200

200201
public class func makeUserDataOrSource(queue: DispatchQueue? = nil) -> DispatchSourceUserDataOr {
201-
let source = dispatch_source_create(_swift_dispatch_source_type_data_or(), 0, 0, queue?.__wrapped)
202+
let source = dispatch_source_create(_swift_dispatch_source_type_DATA_OR(), 0, 0, queue?.__wrapped)
202203
return DispatchSource(source: source) as DispatchSourceUserDataOr
203204
}
204205

205206
#if !os(Linux) && !os(Android)
206207
public class func makeFileSystemObjectSource(fileDescriptor: Int32, eventMask: FileSystemEvent, queue: DispatchQueue? = nil) -> DispatchSourceFileSystemObject {
207-
let source = dispatch_source_create(_swift_dispatch_source_type_vnode(), UInt(fileDescriptor), eventMask.rawValue, queue?.__wrapped)
208+
let source = dispatch_source_create(_swift_dispatch_source_type_VNODE(), UInt(fileDescriptor), eventMask.rawValue, queue?.__wrapped)
208209
return DispatchSource(source: source) as DispatchSourceFileSystemObject
209210
}
210211
#endif
211212

212213
public class func makeWriteSource(fileDescriptor: Int32, queue: DispatchQueue? = nil) -> DispatchSourceWrite {
213-
let source = dispatch_source_create(_swift_dispatch_source_type_write(), UInt(fileDescriptor), 0, queue?.__wrapped)
214+
let source = dispatch_source_create(_swift_dispatch_source_type_WRITE(), UInt(fileDescriptor), 0, queue?.__wrapped)
214215
return DispatchSource(source: source) as DispatchSourceWrite
215216
}
216217
}
@@ -350,42 +351,3 @@ public extension DispatchSourceUserDataOr {
350351
dispatch_source_merge_data((self as! DispatchSource).__wrapped, data)
351352
}
352353
}
353-
354-
@_silgen_name("_swift_dispatch_source_type_DATA_ADD")
355-
internal func _swift_dispatch_source_type_data_add() -> dispatch_source_type_t
356-
357-
@_silgen_name("_swift_dispatch_source_type_DATA_OR")
358-
internal func _swift_dispatch_source_type_data_or() -> dispatch_source_type_t
359-
360-
#if HAVE_MACH
361-
@_silgen_name("_swift_dispatch_source_type_MACH_SEND")
362-
internal func _swift_dispatch_source_type_mach_send() -> dispatch_source_type_t
363-
364-
@_silgen_name("_swift_dispatch_source_type_MACH_RECV")
365-
internal func _swift_dispatch_source_type_mach_recv() -> dispatch_source_type_t
366-
367-
@_silgen_name("_swift_dispatch_source_type_MEMORYPRESSURE")
368-
internal func _swift_dispatch_source_type_memorypressure() -> dispatch_source_type_t
369-
#endif
370-
371-
#if !os(Linux) && !os(Android)
372-
@_silgen_name("_swift_dispatch_source_type_PROC")
373-
internal func _swift_dispatch_source_type_proc() -> dispatch_source_type_t
374-
#endif
375-
376-
@_silgen_name("_swift_dispatch_source_type_READ")
377-
internal func _swift_dispatch_source_type_read() -> dispatch_source_type_t
378-
379-
@_silgen_name("_swift_dispatch_source_type_SIGNAL")
380-
internal func _swift_dispatch_source_type_signal() -> dispatch_source_type_t
381-
382-
@_silgen_name("_swift_dispatch_source_type_TIMER")
383-
internal func _swift_dispatch_source_type_timer() -> dispatch_source_type_t
384-
385-
#if !os(Linux) && !os(Android)
386-
@_silgen_name("_swift_dispatch_source_type_VNODE")
387-
internal func _swift_dispatch_source_type_vnode() -> dispatch_source_type_t
388-
#endif
389-
390-
@_silgen_name("_swift_dispatch_source_type_WRITE")
391-
internal func _swift_dispatch_source_type_write() -> dispatch_source_type_t

0 commit comments

Comments
 (0)