Merge pull request #342 from compnerd/blocks

BlocksRuntime: adjust implementation for Windows x64
diff --git a/dispatch/once.h b/dispatch/once.h
index 37a4950..fbce4b1 100644
--- a/dispatch/once.h
+++ b/dispatch/once.h
@@ -38,7 +38,7 @@
  * Note: static and global variables default to zero.
  */
 DISPATCH_SWIFT3_UNAVAILABLE("Use lazily initialized globals instead")
-typedef long dispatch_once_t;
+typedef intptr_t dispatch_once_t;
 
 #if defined(__x86_64__) || defined(__i386__) || defined(__s390x__)
 #define DISPATCH_ONCE_INLINE_FASTPATH 1
diff --git a/src/source.c b/src/source.c
index 730e441..21ed64c 100644
--- a/src/source.c
+++ b/src/source.c
@@ -300,7 +300,7 @@
 
 DISPATCH_ALWAYS_INLINE
 static inline void
-_dispatch_source_handler_replace(dispatch_source_t ds, long kind,
+_dispatch_source_handler_replace(dispatch_source_t ds, uintptr_t kind,
 		dispatch_continuation_t dc)
 {
 	if (!dc->dc_func) {
@@ -321,14 +321,14 @@
 	dispatch_assert(dx_type(ds) == DISPATCH_SOURCE_KEVENT_TYPE);
 
 	dispatch_continuation_t dc = context;
-	long kind = (long)dc->dc_data;
+	void *kind = dc->dc_data;
 	dc->dc_data = NULL;
-	_dispatch_source_handler_replace(ds, kind, dc);
+	_dispatch_source_handler_replace(ds, (uintptr_t)kind, dc);
 }
 
 DISPATCH_NOINLINE
 static void
-_dispatch_source_set_handler(dispatch_source_t ds, long kind,
+_dispatch_source_set_handler(dispatch_source_t ds, uintptr_t kind,
 		dispatch_continuation_t dc)
 {
 	dispatch_assert(dx_type(ds) == DISPATCH_SOURCE_KEVENT_TYPE);
diff --git a/src/swift/Block.swift b/src/swift/Block.swift
index d4cae3c..e27079a 100644
--- a/src/swift/Block.swift
+++ b/src/swift/Block.swift
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 import CDispatch
+import _SwiftDispatchOverlayShims
 
 public struct DispatchWorkItemFlags : OptionSet, RawRepresentable {
 	public let rawValue: UInt
@@ -98,6 +99,3 @@
 /// on the referential identity of a block. Particularly, dispatch_block_create.
 internal typealias _DispatchBlock = @convention(block) () -> Void
 internal typealias dispatch_block_t = @convention(block) () -> Void
-
-@_silgen_name("_swift_dispatch_block_create_noescape")
-internal func _swift_dispatch_block_create_noescape(_ flags: dispatch_block_flags_t, _ block: () -> ()) -> _DispatchBlock
diff --git a/src/swift/Data.swift b/src/swift/Data.swift
index 5ad48aa..648c45c 100644
--- a/src/swift/Data.swift
+++ b/src/swift/Data.swift
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 import CDispatch
+import _SwiftDispatchOverlayShims
 
 public struct DispatchData : RandomAccessCollection {
 	public typealias Iterator = DispatchDataIterator
@@ -37,8 +38,8 @@
 
 		fileprivate var _deallocator: (DispatchQueue?, @convention(block) () -> Void) {
 			switch self {
-			case .free: return (nil, _dispatch_data_destructor_free())
-			case .unmap: return (nil, _dispatch_data_destructor_munmap())
+			case .free: return (nil, _swift_dispatch_data_destructor_free())
+			case .unmap: return (nil, _swift_dispatch_data_destructor_munmap())
 			case .custom(let q, let b): return (q, b)
 			}
 		}
@@ -53,7 +54,7 @@
 	public init(bytes buffer: UnsafeBufferPointer<UInt8>) {
 		let d = buffer.baseAddress == nil ? _swift_dispatch_data_empty()
 					: dispatch_data_create(buffer.baseAddress!, buffer.count, nil,
-							_dispatch_data_destructor_default())
+							_swift_dispatch_data_destructor_default())
 		self.init(data: d)
 	}
 
@@ -64,7 +65,7 @@
 	public init(bytes buffer: UnsafeRawBufferPointer) {
 		let d = buffer.baseAddress == nil ? _swift_dispatch_data_empty()
 					: dispatch_data_create(buffer.baseAddress!, buffer.count, nil,
-							_dispatch_data_destructor_default())
+							_swift_dispatch_data_destructor_default())
 		self.init(data: d)
 	}
 
@@ -140,7 +141,7 @@
 	/// - parameter count: The number of bytes to copy.
 	@available(swift, deprecated: 4, message: "Use append(_: UnsafeRawBufferPointer) instead")
 	public mutating func append(_ bytes: UnsafePointer<UInt8>, count: Int) {
-		let data = dispatch_data_create(bytes, count, nil, _dispatch_data_destructor_default())
+		let data = dispatch_data_create(bytes, count, nil, _swift_dispatch_data_destructor_default())
 		self.append(DispatchData(data: data))
 	}
 
@@ -151,7 +152,7 @@
 	public mutating func append(_ bytes: UnsafeRawBufferPointer) {
 		// Nil base address does nothing.
 		guard bytes.baseAddress != nil else { return }
-		let data = dispatch_data_create(bytes.baseAddress!, bytes.count, nil, _dispatch_data_destructor_default())
+		let data = dispatch_data_create(bytes.baseAddress!, bytes.count, nil, _swift_dispatch_data_destructor_default())
 		self.append(DispatchData(data: data))
 	}
 
@@ -346,15 +347,3 @@
 	internal var _count: Int
 	internal var _position: DispatchData.Index
 }
-
-@_silgen_name("_swift_dispatch_data_empty")
-internal func _swift_dispatch_data_empty() -> dispatch_data_t
-
-@_silgen_name("_swift_dispatch_data_destructor_free")
-internal func _dispatch_data_destructor_free() -> _DispatchBlock
-
-@_silgen_name("_swift_dispatch_data_destructor_munmap")
-internal func _dispatch_data_destructor_munmap() -> _DispatchBlock
-
-@_silgen_name("_swift_dispatch_data_destructor_default")
-internal func _dispatch_data_destructor_default() -> _DispatchBlock
diff --git a/src/swift/DispatchStubs.cc b/src/swift/DispatchStubs.cc
index 9c667d5..d4f452b 100644
--- a/src/swift/DispatchStubs.cc
+++ b/src/swift/DispatchStubs.cc
@@ -53,176 +53,10 @@
 
 #endif /* USE_OBJC */
 
-
-// Replicate the SWIFT_CC(swift) calling convention macro from
-// swift/include/swift/Runtime/Config.h because it is
-// quite awkward to include Config.h and its recursive includes
-// in dispatch. This define must be manually kept in synch
-#define SWIFT_CC(CC) SWIFT_CC_##CC
-#if SWIFT_USE_SWIFTCALL
-#define SWIFT_CC_swift __attribute__((swiftcall))
-#else
-#define SWIFT_CC_swift
-#endif
-
-extern "C" dispatch_queue_attr_t _swift_dispatch_queue_concurrent(void);
-extern "C" void _swift_dispatch_apply_current(size_t iterations, __attribute__((__noescape__)) void (^block)(size_t));
-extern "C" dispatch_queue_t _swift_dispatch_get_main_queue(void);
-extern "C" dispatch_data_t _swift_dispatch_data_empty(void);
-extern "C" dispatch_block_t _swift_dispatch_data_destructor_default(void);
-extern "C" dispatch_block_t _swift_dispatch_data_destructor_free(void);
-extern "C" dispatch_block_t _swift_dispatch_data_destructor_munmap(void);
-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);
-extern "C" dispatch_block_t _swift_dispatch_block_create_noescape(dispatch_block_flags_t flags, dispatch_block_t block);
-extern "C" void _swift_dispatch_block_cancel(dispatch_block_t block);
-extern "C" long _swift_dispatch_block_wait(dispatch_block_t block, dispatch_time_t timeout);
-extern "C" void _swift_dispatch_block_notify(dispatch_block_t block, dispatch_queue_t queue, dispatch_block_t notification_block);
-extern "C" long _swift_dispatch_block_testcancel(dispatch_block_t block);
-extern "C" void _swift_dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
-extern "C" void _swift_dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block);
-extern "C" void _swift_dispatch_sync(dispatch_queue_t queue, dispatch_block_t block);
-extern "C" void _swift_dispatch_release(dispatch_object_t obj);
-extern "C" void _swift_dispatch_retain(dispatch_object_t obj);
 #if !USE_OBJC
 extern "C" void * objc_retainAutoreleasedReturnValue(void *obj);
 #endif
 
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" dispatch_queue_attr_t
-_swift_dispatch_queue_concurrent(void) {
-  return DISPATCH_QUEUE_CONCURRENT;
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" void
-_swift_dispatch_apply_current(size_t iterations, __attribute__((__noescape__)) void (^block)(size_t)) {
-  dispatch_apply(iterations, (dispatch_queue_t _Nonnull)0, block);
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" dispatch_queue_t
-_swift_dispatch_get_main_queue(void) {
-  return dispatch_get_main_queue();
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" dispatch_data_t
-_swift_dispatch_data_empty(void) {
-  return dispatch_data_empty;
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" dispatch_block_t
-_swift_dispatch_data_destructor_default(void) {
-  return DISPATCH_DATA_DESTRUCTOR_DEFAULT;
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" dispatch_block_t
-_swift_dispatch_data_destructor_free(void) {
-  return _dispatch_data_destructor_free;
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" dispatch_block_t
-_swift_dispatch_data_destructor_munmap(void) {
-  return _dispatch_data_destructor_munmap;
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-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) {
-  return dispatch_block_create_with_qos_class(flags, qos, relative_priority, block);
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" dispatch_block_t
-_swift_dispatch_block_create_noescape(dispatch_block_flags_t flags, dispatch_block_t block) {
-  return dispatch_block_create(flags, block);
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" void
-_swift_dispatch_block_cancel(dispatch_block_t block) {
-  dispatch_block_cancel(block);
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" long
-_swift_dispatch_block_wait(dispatch_block_t block, dispatch_time_t timeout) {
-  return dispatch_block_wait(block, timeout);
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" void
-_swift_dispatch_block_notify(dispatch_block_t block, dispatch_queue_t queue, dispatch_block_t notification_block) {
-  dispatch_block_notify(block, queue, notification_block);
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" long
-_swift_dispatch_block_testcancel(dispatch_block_t block) {
-  return dispatch_block_testcancel(block);
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" void
-_swift_dispatch_async(dispatch_queue_t queue, dispatch_block_t block) {
-  dispatch_async(queue, block);
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" void
-_swift_dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block) {
-  dispatch_group_async(group, queue, block);
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" void
-_swift_dispatch_sync(dispatch_queue_t queue, dispatch_block_t block) {
-  dispatch_sync(queue, block);
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" void
-_swift_dispatch_release(dispatch_object_t obj) {
-  dispatch_release(obj);
-}
-
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
-extern "C" void
-_swift_dispatch_retain(dispatch_object_t obj) {
-  dispatch_retain(obj);
-}
-
-#define SOURCE(t)                                                              \
-  extern "C" dispatch_source_type_t _swift_dispatch_source_type_##t(void);     \
-  SWIFT_CC(swift)                                                              \
-  DISPATCH_RUNTIME_STDLIB_INTERFACE extern "C" dispatch_source_type_t  \
-  _swift_dispatch_source_type_##t(void) {                                      \
-    return DISPATCH_SOURCE_TYPE_##t;                                           \
-  }
-
-SOURCE(DATA_ADD)
-SOURCE(DATA_OR)
-SOURCE(DATA_REPLACE)
-#if HAVE_MACH
-SOURCE(MACH_SEND)
-SOURCE(MACH_RECV)
-SOURCE(MEMORYPRESSURE)
-#endif
-#ifndef __linux__
-SOURCE(PROC)
-#endif
-SOURCE(READ)
-SOURCE(SIGNAL)
-SOURCE(TIMER)
-#ifndef __linux__
-SOURCE(VNODE)
-#endif
-SOURCE(WRITE)
-
 #if !USE_OBJC
 
 // For CF functions with 'Get' semantics, the compiler currently assumes that
@@ -235,7 +69,7 @@
 // platforms.
 extern "C" void swift_retain(void *);
 
-SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
+DISPATCH_RUNTIME_STDLIB_INTERFACE
 extern "C" void * objc_retainAutoreleasedReturnValue(void *obj) {
     if (obj) {
         swift_retain(obj);
diff --git a/src/swift/Queue.swift b/src/swift/Queue.swift
index bff1bc3..bd79a85 100644
--- a/src/swift/Queue.swift
+++ b/src/swift/Queue.swift
@@ -13,6 +13,7 @@
 // dispatch/queue.h
 
 import CDispatch
+import _SwiftDispatchOverlayShims
 
 public final class DispatchSpecificKey<T> {
 	public init() {}
@@ -334,9 +335,6 @@
 	}
 
 	#if os(Android)
-	@_silgen_name("_dispatch_install_thread_detach_callback")
-	private static func _dispatch_install_thread_detach_callback(_ cb: @escaping @convention(c) () -> Void)
-
 	public static func setThreadDetachCallback(_ cb: @escaping @convention(c) () -> Void) {
 		_dispatch_install_thread_detach_callback(cb)
 	}
@@ -348,12 +346,3 @@
 		Unmanaged<AnyObject>.fromOpaque(p).release()
 	}
 }
-
-@_silgen_name("_swift_dispatch_queue_concurrent")
-internal func _swift_dispatch_queue_concurrent() -> dispatch_queue_attr_t
-
-@_silgen_name("_swift_dispatch_get_main_queue")
-internal func _swift_dispatch_get_main_queue() -> dispatch_queue_t
-
-@_silgen_name("_swift_dispatch_apply_current")
-internal func _swift_dispatch_apply_current(_ iterations: Int, _ block: @convention(block) (Int) -> Void)
diff --git a/src/swift/Source.swift b/src/swift/Source.swift
index 421a6e9..a877121 100644
--- a/src/swift/Source.swift
+++ b/src/swift/Source.swift
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 import CDispatch
+import _SwiftDispatchOverlayShims
 
 public extension DispatchSourceProtocol {
 
@@ -151,71 +152,71 @@
 
 #if HAVE_MACH
 	public class func makeMachSendSource(port: mach_port_t, eventMask: MachSendEvent, queue: DispatchQueue? = nil) -> DispatchSourceMachSend {
-		let source = dispatch_source_create(_swift_dispatch_source_type_mach_send(), UInt(port), eventMask.rawValue, queue?.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_MACH_SEND(), UInt(port), eventMask.rawValue, queue?.__wrapped)
 		return DispatchSource(source: source) as DispatchSourceMachSend
 	}
 #endif
 
 #if HAVE_MACH
 	public class func makeMachReceiveSource(port: mach_port_t, queue: DispatchQueue? = nil) -> DispatchSourceMachReceive {
-		let source = dispatch_source_create(_swift_dispatch_source_type_mach_recv(), UInt(port), 0, queue?.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_MACH_RECV(), UInt(port), 0, queue?.__wrapped)
 		return DispatchSource(source) as DispatchSourceMachReceive
 	}
 #endif
 
 #if HAVE_MACH
 	public class func makeMemoryPressureSource(eventMask: MemoryPressureEvent, queue: DispatchQueue? = nil) -> DispatchSourceMemoryPressure {
-		let source = dispatch_source_create(_swift_dispatch_source_type_memorypressure(), 0, eventMask.rawValue, queue.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_MEMORYPRESSURE(), 0, eventMask.rawValue, queue.__wrapped)
 		return DispatchSourceMemoryPressure(source)
 	}
 #endif
 
 #if !os(Linux) && !os(Android)
 	public class func makeProcessSource(identifier: pid_t, eventMask: ProcessEvent, queue: DispatchQueue? = nil) -> DispatchSourceProcess {
-		let source = dispatch_source_create(_swift_dispatch_source_type_proc(), UInt(identifier), eventMask.rawValue, queue?.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_PROC(), UInt(identifier), eventMask.rawValue, queue?.__wrapped)
 		return DispatchSource(source: source) as DispatchSourceProcess
 	}
 #endif
 
 	public class func makeReadSource(fileDescriptor: Int32, queue: DispatchQueue? = nil) -> DispatchSourceRead {
-		let source = dispatch_source_create(_swift_dispatch_source_type_read(), UInt(fileDescriptor), 0, queue?.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_READ(), UInt(fileDescriptor), 0, queue?.__wrapped)
 		return DispatchSource(source: source) as DispatchSourceRead
 	}
 
 	public class func makeSignalSource(signal: Int32, queue: DispatchQueue? = nil) -> DispatchSourceSignal {
-		let source = dispatch_source_create(_swift_dispatch_source_type_signal(), UInt(signal), 0, queue?.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_SIGNAL(), UInt(signal), 0, queue?.__wrapped)
 		return DispatchSource(source: source) as DispatchSourceSignal
 	}
 
 	public class func makeTimerSource(flags: TimerFlags = [], queue: DispatchQueue? = nil) -> DispatchSourceTimer {
-		let source = dispatch_source_create(_swift_dispatch_source_type_timer(), 0, flags.rawValue, queue?.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_TIMER(), 0, flags.rawValue, queue?.__wrapped)
 		return DispatchSource(source: source) as DispatchSourceTimer
 	}
 
 	public class func makeUserDataAddSource(queue: DispatchQueue? = nil) -> DispatchSourceUserDataAdd {
-		let source = dispatch_source_create(_swift_dispatch_source_type_data_add(), 0, 0, queue?.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_DATA_ADD(), 0, 0, queue?.__wrapped)
 		return DispatchSource(source: source) as DispatchSourceUserDataAdd
 	}
 
 	public class func makeUserDataOrSource(queue: DispatchQueue? = nil) -> DispatchSourceUserDataOr {
-		let source = dispatch_source_create(_swift_dispatch_source_type_data_or(), 0, 0, queue?.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_DATA_OR(), 0, 0, queue?.__wrapped)
 		return DispatchSource(source: source) as DispatchSourceUserDataOr
 	}
     
 	public class func makeUserDataReplaceSource(queue: DispatchQueue? = nil) -> DispatchSourceUserDataReplace {
-		let source = dispatch_source_create(_swift_dispatch_source_type_data_replace(), 0, 0, queue?.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_DATA_REPLACE(), 0, 0, queue?.__wrapped)
 		return DispatchSource(source: source) as DispatchSourceUserDataReplace
 	}
 
 #if !os(Linux) && !os(Android)
 	public class func makeFileSystemObjectSource(fileDescriptor: Int32, eventMask: FileSystemEvent, queue: DispatchQueue? = nil) -> DispatchSourceFileSystemObject {
-		let source = dispatch_source_create(_swift_dispatch_source_type_vnode(), UInt(fileDescriptor), eventMask.rawValue, queue?.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_VNODE(), UInt(fileDescriptor), eventMask.rawValue, queue?.__wrapped)
 		return DispatchSource(source: source) as DispatchSourceFileSystemObject
 	}
 #endif
 
 	public class func makeWriteSource(fileDescriptor: Int32, queue: DispatchQueue? = nil) -> DispatchSourceWrite {
-		let source = dispatch_source_create(_swift_dispatch_source_type_write(), UInt(fileDescriptor), 0, queue?.__wrapped)
+		let source = dispatch_source_create(_swift_dispatch_source_type_WRITE(), UInt(fileDescriptor), 0, queue?.__wrapped)
 		return DispatchSource(source: source) as DispatchSourceWrite
 	}
 }
@@ -669,45 +670,3 @@
 		dispatch_source_merge_data((self as! DispatchSource).__wrapped, data)
 	}
 }
-
-@_silgen_name("_swift_dispatch_source_type_DATA_ADD")
-internal func _swift_dispatch_source_type_data_add() -> dispatch_source_type_t
-
-@_silgen_name("_swift_dispatch_source_type_DATA_OR")
-internal func _swift_dispatch_source_type_data_or() -> dispatch_source_type_t
-
-@_silgen_name("_swift_dispatch_source_type_DATA_REPLACE")
-internal func _swift_dispatch_source_type_data_replace() -> dispatch_source_type_t
-
-#if HAVE_MACH
-@_silgen_name("_swift_dispatch_source_type_MACH_SEND")
-internal func _swift_dispatch_source_type_mach_send() -> dispatch_source_type_t
-
-@_silgen_name("_swift_dispatch_source_type_MACH_RECV")
-internal func _swift_dispatch_source_type_mach_recv() -> dispatch_source_type_t
-
-@_silgen_name("_swift_dispatch_source_type_MEMORYPRESSURE")
-internal func _swift_dispatch_source_type_memorypressure() -> dispatch_source_type_t
-#endif
-
-#if !os(Linux) && !os(Android)
-@_silgen_name("_swift_dispatch_source_type_PROC")
-internal func _swift_dispatch_source_type_proc() -> dispatch_source_type_t
-#endif
-
-@_silgen_name("_swift_dispatch_source_type_READ")
-internal func _swift_dispatch_source_type_read() -> dispatch_source_type_t
-
-@_silgen_name("_swift_dispatch_source_type_SIGNAL")
-internal func _swift_dispatch_source_type_signal() -> dispatch_source_type_t
-
-@_silgen_name("_swift_dispatch_source_type_TIMER")
-internal func _swift_dispatch_source_type_timer() -> dispatch_source_type_t
-
-#if !os(Linux) && !os(Android)
-@_silgen_name("_swift_dispatch_source_type_VNODE")
-internal func _swift_dispatch_source_type_vnode() -> dispatch_source_type_t
-#endif
-
-@_silgen_name("_swift_dispatch_source_type_WRITE")
-internal func _swift_dispatch_source_type_write() -> dispatch_source_type_t
diff --git a/src/swift/Wrapper.swift b/src/swift/Wrapper.swift
index 5a551df..dfae9b7 100644
--- a/src/swift/Wrapper.swift
+++ b/src/swift/Wrapper.swift
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 import CDispatch
+import _SwiftDispatchOverlayShims
 
 // This file contains declarations that are provided by the
 // importer via Dispatch.apinote when the platform has Objective-C support
@@ -335,9 +336,3 @@
 		}
 	}
 }
-
-@_silgen_name("_swift_dispatch_release")
-internal func _swift_dispatch_release(_ obj: dispatch_object_t) -> Void
-
-@_silgen_name("_swift_dispatch_retain")
-internal func _swift_dispatch_retain(_ obj: dispatch_object_t) -> Void