Skip to content

Commit 9c792ac

Browse files
authored
Merge pull request #192 from jrose-apple/excise-silgen_name-once-more
Replace uses of @_silgen_name with uses of a shims header.
2 parents 698220e + d7c4fc7 commit 9c792ac

File tree

6 files changed

+24
-260
lines changed

6 files changed

+24
-260
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: 7 additions & 18 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
}
@@ -53,7 +54,7 @@ public struct DispatchData : RandomAccessCollection {
5354
public init(bytes buffer: UnsafeBufferPointer<UInt8>) {
5455
let d = buffer.baseAddress == nil ? _swift_dispatch_data_empty()
5556
: dispatch_data_create(buffer.baseAddress!, buffer.count, nil,
56-
_dispatch_data_destructor_default())
57+
_swift_dispatch_data_destructor_default())
5758
self.init(data: d)
5859
}
5960

@@ -64,7 +65,7 @@ public struct DispatchData : RandomAccessCollection {
6465
public init(bytes buffer: UnsafeRawBufferPointer) {
6566
let d = buffer.baseAddress == nil ? _swift_dispatch_data_empty()
6667
: dispatch_data_create(buffer.baseAddress!, buffer.count, nil,
67-
_dispatch_data_destructor_default())
68+
_swift_dispatch_data_destructor_default())
6869
self.init(data: d)
6970
}
7071

@@ -140,7 +141,7 @@ public struct DispatchData : RandomAccessCollection {
140141
/// - parameter count: The number of bytes to copy.
141142
@available(swift, deprecated: 4, message: "Use append(_: UnsafeRawBufferPointer) instead")
142143
public mutating func append(_ bytes: UnsafePointer<UInt8>, count: Int) {
143-
let data = dispatch_data_create(bytes, count, nil, _dispatch_data_destructor_default())
144+
let data = dispatch_data_create(bytes, count, nil, _swift_dispatch_data_destructor_default())
144145
self.append(DispatchData(data: data))
145146
}
146147

@@ -151,7 +152,7 @@ public struct DispatchData : RandomAccessCollection {
151152
public mutating func append(_ bytes: UnsafeRawBufferPointer) {
152153
// Nil base address does nothing.
153154
guard bytes.baseAddress != nil else { return }
154-
let data = dispatch_data_create(bytes.baseAddress!, bytes.count, nil, _dispatch_data_destructor_default())
155+
let data = dispatch_data_create(bytes.baseAddress!, bytes.count, nil, _swift_dispatch_data_destructor_default())
155156
self.append(DispatchData(data: data))
156157
}
157158

@@ -346,15 +347,3 @@ public struct DispatchDataIterator : IteratorProtocol, Sequence {
346347
internal var _count: Int
347348
internal var _position: DispatchData.Index
348349
}
349-
350-
@_silgen_name("_swift_dispatch_data_empty")
351-
internal func _swift_dispatch_data_empty() -> dispatch_data_t
352-
353-
@_silgen_name("_swift_dispatch_data_destructor_free")
354-
internal func _dispatch_data_destructor_free() -> _DispatchBlock
355-
356-
@_silgen_name("_swift_dispatch_data_destructor_munmap")
357-
internal func _dispatch_data_destructor_munmap() -> _DispatchBlock
358-
359-
@_silgen_name("_swift_dispatch_data_destructor_default")
360-
internal func _dispatch_data_destructor_default() -> _DispatchBlock

src/swift/DispatchStubs.cc

Lines changed: 1 addition & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -53,176 +53,10 @@ static void _dispatch_overlay_constructor() {
5353

5454
#endif /* USE_OBJC */
5555

56-
57-
// Replicate the SWIFT_CC(swift) calling convention macro from
58-
// swift/include/swift/Runtime/Config.h because it is
59-
// quite awkward to include Config.h and its recursive includes
60-
// in dispatch. This define must be manually kept in synch
61-
#define SWIFT_CC(CC) SWIFT_CC_##CC
62-
#if SWIFT_USE_SWIFTCALL
63-
#define SWIFT_CC_swift __attribute__((swiftcall))
64-
#else
65-
#define SWIFT_CC_swift
66-
#endif
67-
68-
extern "C" dispatch_queue_attr_t _swift_dispatch_queue_concurrent(void);
69-
extern "C" void _swift_dispatch_apply_current(size_t iterations, __attribute__((__noescape__)) void (^block)(size_t));
70-
extern "C" dispatch_queue_t _swift_dispatch_get_main_queue(void);
71-
extern "C" dispatch_data_t _swift_dispatch_data_empty(void);
72-
extern "C" dispatch_block_t _swift_dispatch_data_destructor_default(void);
73-
extern "C" dispatch_block_t _swift_dispatch_data_destructor_free(void);
74-
extern "C" dispatch_block_t _swift_dispatch_data_destructor_munmap(void);
75-
extern "C" dispatch_block_t _swift_dispatch_block_create_with_qos_class(dispatch_block_flags_t flags, dispatch_qos_class_t qos, int relative_priority, dispatch_block_t block);
76-
extern "C" dispatch_block_t _swift_dispatch_block_create_noescape(dispatch_block_flags_t flags, dispatch_block_t block);
77-
extern "C" void _swift_dispatch_block_cancel(dispatch_block_t block);
78-
extern "C" long _swift_dispatch_block_wait(dispatch_block_t block, dispatch_time_t timeout);
79-
extern "C" void _swift_dispatch_block_notify(dispatch_block_t block, dispatch_queue_t queue, dispatch_block_t notification_block);
80-
extern "C" long _swift_dispatch_block_testcancel(dispatch_block_t block);
81-
extern "C" void _swift_dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
82-
extern "C" void _swift_dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block);
83-
extern "C" void _swift_dispatch_sync(dispatch_queue_t queue, dispatch_block_t block);
84-
extern "C" void _swift_dispatch_release(dispatch_object_t obj);
85-
extern "C" void _swift_dispatch_retain(dispatch_object_t obj);
8656
#if !USE_OBJC
8757
extern "C" void * objc_retainAutoreleasedReturnValue(void *obj);
8858
#endif
8959

90-
91-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
92-
extern "C" dispatch_queue_attr_t
93-
_swift_dispatch_queue_concurrent(void) {
94-
return DISPATCH_QUEUE_CONCURRENT;
95-
}
96-
97-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
98-
extern "C" void
99-
_swift_dispatch_apply_current(size_t iterations, __attribute__((__noescape__)) void (^block)(size_t)) {
100-
dispatch_apply(iterations, (dispatch_queue_t _Nonnull)0, block);
101-
}
102-
103-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
104-
extern "C" dispatch_queue_t
105-
_swift_dispatch_get_main_queue(void) {
106-
return dispatch_get_main_queue();
107-
}
108-
109-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
110-
extern "C" dispatch_data_t
111-
_swift_dispatch_data_empty(void) {
112-
return dispatch_data_empty;
113-
}
114-
115-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
116-
extern "C" dispatch_block_t
117-
_swift_dispatch_data_destructor_default(void) {
118-
return DISPATCH_DATA_DESTRUCTOR_DEFAULT;
119-
}
120-
121-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
122-
extern "C" dispatch_block_t
123-
_swift_dispatch_data_destructor_free(void) {
124-
return _dispatch_data_destructor_free;
125-
}
126-
127-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
128-
extern "C" dispatch_block_t
129-
_swift_dispatch_data_destructor_munmap(void) {
130-
return _dispatch_data_destructor_munmap;
131-
}
132-
133-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
134-
extern "C" dispatch_block_t
135-
_swift_dispatch_block_create_with_qos_class(dispatch_block_flags_t flags, dispatch_qos_class_t qos, int relative_priority, dispatch_block_t block) {
136-
return dispatch_block_create_with_qos_class(flags, qos, relative_priority, block);
137-
}
138-
139-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
140-
extern "C" dispatch_block_t
141-
_swift_dispatch_block_create_noescape(dispatch_block_flags_t flags, dispatch_block_t block) {
142-
return dispatch_block_create(flags, block);
143-
}
144-
145-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
146-
extern "C" void
147-
_swift_dispatch_block_cancel(dispatch_block_t block) {
148-
dispatch_block_cancel(block);
149-
}
150-
151-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
152-
extern "C" long
153-
_swift_dispatch_block_wait(dispatch_block_t block, dispatch_time_t timeout) {
154-
return dispatch_block_wait(block, timeout);
155-
}
156-
157-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
158-
extern "C" void
159-
_swift_dispatch_block_notify(dispatch_block_t block, dispatch_queue_t queue, dispatch_block_t notification_block) {
160-
dispatch_block_notify(block, queue, notification_block);
161-
}
162-
163-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
164-
extern "C" long
165-
_swift_dispatch_block_testcancel(dispatch_block_t block) {
166-
return dispatch_block_testcancel(block);
167-
}
168-
169-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
170-
extern "C" void
171-
_swift_dispatch_async(dispatch_queue_t queue, dispatch_block_t block) {
172-
dispatch_async(queue, block);
173-
}
174-
175-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
176-
extern "C" void
177-
_swift_dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block) {
178-
dispatch_group_async(group, queue, block);
179-
}
180-
181-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
182-
extern "C" void
183-
_swift_dispatch_sync(dispatch_queue_t queue, dispatch_block_t block) {
184-
dispatch_sync(queue, block);
185-
}
186-
187-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
188-
extern "C" void
189-
_swift_dispatch_release(dispatch_object_t obj) {
190-
dispatch_release(obj);
191-
}
192-
193-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
194-
extern "C" void
195-
_swift_dispatch_retain(dispatch_object_t obj) {
196-
dispatch_retain(obj);
197-
}
198-
199-
#define SOURCE(t) \
200-
extern "C" dispatch_source_type_t _swift_dispatch_source_type_##t(void); \
201-
SWIFT_CC(swift) \
202-
DISPATCH_RUNTIME_STDLIB_INTERFACE extern "C" dispatch_source_type_t \
203-
_swift_dispatch_source_type_##t(void) { \
204-
return DISPATCH_SOURCE_TYPE_##t; \
205-
}
206-
207-
SOURCE(DATA_ADD)
208-
SOURCE(DATA_OR)
209-
SOURCE(DATA_REPLACE)
210-
#if HAVE_MACH
211-
SOURCE(MACH_SEND)
212-
SOURCE(MACH_RECV)
213-
SOURCE(MEMORYPRESSURE)
214-
#endif
215-
#ifndef __linux__
216-
SOURCE(PROC)
217-
#endif
218-
SOURCE(READ)
219-
SOURCE(SIGNAL)
220-
SOURCE(TIMER)
221-
#ifndef __linux__
222-
SOURCE(VNODE)
223-
#endif
224-
SOURCE(WRITE)
225-
22660
#if !USE_OBJC
22761

22862
// For CF functions with 'Get' semantics, the compiler currently assumes that
@@ -235,7 +69,7 @@ SOURCE(WRITE)
23569
// platforms.
23670
extern "C" void swift_retain(void *);
23771

238-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
72+
DISPATCH_RUNTIME_STDLIB_INTERFACE
23973
extern "C" void * objc_retainAutoreleasedReturnValue(void *obj) {
24074
if (obj) {
24175
swift_retain(obj);

src/swift/Queue.swift

Lines changed: 1 addition & 12 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() {}
@@ -334,9 +335,6 @@ public extension DispatchQueue {
334335
}
335336

336337
#if os(Android)
337-
@_silgen_name("_dispatch_install_thread_detach_callback")
338-
private static func _dispatch_install_thread_detach_callback(_ cb: @escaping @convention(c) () -> Void)
339-
340338
public static func setThreadDetachCallback(_ cb: @escaping @convention(c) () -> Void) {
341339
_dispatch_install_thread_detach_callback(cb)
342340
}
@@ -348,12 +346,3 @@ private func _destructDispatchSpecificValue(ptr: UnsafeMutableRawPointer?) {
348346
Unmanaged<AnyObject>.fromOpaque(p).release()
349347
}
350348
}
351-
352-
@_silgen_name("_swift_dispatch_queue_concurrent")
353-
internal func _swift_dispatch_queue_concurrent() -> dispatch_queue_attr_t
354-
355-
@_silgen_name("_swift_dispatch_get_main_queue")
356-
internal func _swift_dispatch_get_main_queue() -> dispatch_queue_t
357-
358-
@_silgen_name("_swift_dispatch_apply_current")
359-
internal func _swift_dispatch_apply_current(_ iterations: Int, _ block: @convention(block) (Int) -> Void)

0 commit comments

Comments
 (0)