diff --git a/stdlib/public/SDK/Dispatch/Block.swift b/stdlib/public/SDK/Dispatch/Block.swift index 36549453cb94f..691e95ed18535 100644 --- a/stdlib/public/SDK/Dispatch/Block.swift +++ b/stdlib/public/SDK/Dispatch/Block.swift @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -import SwiftShims +import _SwiftDispatchOverlayShims public struct DispatchWorkItemFlags : OptionSet, RawRepresentable { public let rawValue: UInt @@ -39,14 +39,16 @@ public class DispatchWorkItem { internal var _block: _DispatchBlock public init(qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], block: @escaping @convention(block) () -> ()) { - _block = _swift_dispatch_block_create_with_qos_class(flags.rawValue, - qos.qosClass.rawValue.rawValue, Int32(qos.relativePriority), block) + _block = _swift_dispatch_block_create_with_qos_class( + __dispatch_block_flags_t(rawValue: flags.rawValue), + qos.qosClass.rawValue, Int32(qos.relativePriority), block) } // Used by DispatchQueue.synchronously to provide a path through // dispatch_block_t, as we know the lifetime of the block in question. internal init(flags: DispatchWorkItemFlags = [], noescapeBlock: () -> ()) { - _block = _swift_dispatch_block_create_noescape(flags.rawValue, noescapeBlock) + _block = _swift_dispatch_block_create_noescape( + __dispatch_block_flags_t(rawValue: flags.rawValue), noescapeBlock) } public func perform() { diff --git a/stdlib/public/SDK/Dispatch/Data.swift b/stdlib/public/SDK/Dispatch/Data.swift index 0af42496c05bb..b32132c0bc0a4 100644 --- a/stdlib/public/SDK/Dispatch/Data.swift +++ b/stdlib/public/SDK/Dispatch/Data.swift @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -import SwiftShims +import _SwiftDispatchOverlayShims public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable { public typealias Iterator = DispatchDataIterator @@ -31,8 +31,8 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable { 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) } } @@ -46,7 +46,7 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable { /// - parameter count: The number of bytes to copy. public init(bytes buffer: UnsafeBufferPointer) { __wrapped = _swift_dispatch_data_create( - buffer.baseAddress!, buffer.count, nil, _dispatch_data_destructor_default()) as! __DispatchData + buffer.baseAddress!, buffer.count, nil, _swift_dispatch_data_destructor_default()) as! __DispatchData } /// Initialize a `Data` without copying the bytes. @@ -98,7 +98,7 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable { /// - parameter bytes: A pointer to the bytes to copy in to the data. /// - parameter count: The number of bytes to copy. public mutating func append(_ bytes: UnsafePointer, count: Int) { - let data = _swift_dispatch_data_create(bytes, count, nil, _dispatch_data_destructor_default()) as! __DispatchData + let data = _swift_dispatch_data_create(bytes, count, nil, _swift_dispatch_data_destructor_default()) as! __DispatchData self.append(DispatchData(data: data)) } @@ -285,16 +285,3 @@ extension DispatchData { return result! } } - -@_silgen_name("_swift_dispatch_data_empty") -internal func _swift_dispatch_data_empty() -> __DispatchData - -@_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/stdlib/public/SDK/Dispatch/Dispatch.mm b/stdlib/public/SDK/Dispatch/Dispatch.mm index 424712e2af72b..e98ef9fc626ab 100644 --- a/stdlib/public/SDK/Dispatch/Dispatch.mm +++ b/stdlib/public/SDK/Dispatch/Dispatch.mm @@ -14,8 +14,6 @@ #include #include -#define DISPATCH_RUNTIME_STDLIB_INTERFACE __attribute__((__visibility__("default"))) - @protocol OS_dispatch_source; @protocol OS_dispatch_source_mach_send; @protocol OS_dispatch_source_mach_recv; @@ -49,59 +47,3 @@ static void _dispatch_overlay_constructor() { } } -#include "swift/Runtime/Config.h" - -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" 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; -} - -#define SOURCE(t) \ - 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(MACH_SEND) -SOURCE(MACH_RECV) -SOURCE(MEMORYPRESSURE) -SOURCE(PROC) -SOURCE(READ) -SOURCE(SIGNAL) -SOURCE(TIMER) -SOURCE(VNODE) -SOURCE(WRITE) diff --git a/stdlib/public/SDK/Dispatch/Dispatch.swift b/stdlib/public/SDK/Dispatch/Dispatch.swift index 72f5991db4729..9ad6b646b256c 100644 --- a/stdlib/public/SDK/Dispatch/Dispatch.swift +++ b/stdlib/public/SDK/Dispatch/Dispatch.swift @@ -11,7 +11,7 @@ //===----------------------------------------------------------------------===// @_exported import Dispatch -import SwiftShims +import _SwiftDispatchOverlayShims /// dispatch_assert diff --git a/stdlib/public/SDK/Dispatch/Queue.swift b/stdlib/public/SDK/Dispatch/Queue.swift index 6556b6408ea6a..7862823873fb5 100644 --- a/stdlib/public/SDK/Dispatch/Queue.swift +++ b/stdlib/public/SDK/Dispatch/Queue.swift @@ -12,7 +12,7 @@ // dispatch/queue.h -import SwiftShims +import _SwiftDispatchOverlayShims public final class DispatchSpecificKey { public init() {} @@ -353,9 +353,3 @@ private func _destructDispatchSpecificValue(ptr: UnsafeMutableRawPointer?) { Unmanaged.fromOpaque(p).release() } } - -@_silgen_name("_swift_dispatch_queue_concurrent") -internal func _swift_dispatch_queue_concurrent() -> __OS_dispatch_queue_attr - -@_silgen_name("_swift_dispatch_get_main_queue") -internal func _swift_dispatch_get_main_queue() -> DispatchQueue diff --git a/stdlib/public/SDK/Dispatch/Source.swift b/stdlib/public/SDK/Dispatch/Source.swift index 32fec65001d7c..2b0d3362db388 100644 --- a/stdlib/public/SDK/Dispatch/Source.swift +++ b/stdlib/public/SDK/Dispatch/Source.swift @@ -11,7 +11,7 @@ //===----------------------------------------------------------------------===// // import Foundation -import SwiftShims +import _SwiftDispatchOverlayShims public extension DispatchSourceProtocol { typealias DispatchSourceHandler = @convention(block) () -> Void @@ -153,56 +153,56 @@ public extension DispatchSource { public class func makeMachSendSource(port: mach_port_t, eventMask: MachSendEvent, queue: DispatchQueue? = nil) -> DispatchSourceMachSend { return __dispatch_source_create( - _swift_dispatch_source_type_mach_send(), UInt(port), eventMask.rawValue, queue) as DispatchSourceMachSend + _swift_dispatch_source_type_MACH_SEND(), UInt(port), eventMask.rawValue, queue) as DispatchSourceMachSend } public class func makeMachReceiveSource(port: mach_port_t, queue: DispatchQueue? = nil) -> DispatchSourceMachReceive { return __dispatch_source_create( - _swift_dispatch_source_type_mach_recv(), UInt(port), 0, queue) as DispatchSourceMachReceive + _swift_dispatch_source_type_MACH_RECV(), UInt(port), 0, queue) as DispatchSourceMachReceive } public class func makeMemoryPressureSource(eventMask: MemoryPressureEvent, queue: DispatchQueue? = nil) -> DispatchSourceMemoryPressure { return __dispatch_source_create( - _swift_dispatch_source_type_memorypressure(), 0, eventMask.rawValue, queue) as DispatchSourceMemoryPressure + _swift_dispatch_source_type_MEMORYPRESSURE(), 0, eventMask.rawValue, queue) as DispatchSourceMemoryPressure } public class func makeProcessSource(identifier: pid_t, eventMask: ProcessEvent, queue: DispatchQueue? = nil) -> DispatchSourceProcess { return __dispatch_source_create( - _swift_dispatch_source_type_proc(), UInt(identifier), eventMask.rawValue, queue) as DispatchSourceProcess + _swift_dispatch_source_type_PROC(), UInt(identifier), eventMask.rawValue, queue) as DispatchSourceProcess } public class func makeReadSource(fileDescriptor: Int32, queue: DispatchQueue? = nil) -> DispatchSourceRead { return __dispatch_source_create( - _swift_dispatch_source_type_read(), UInt(fileDescriptor), 0, queue) as DispatchSourceRead + _swift_dispatch_source_type_READ(), UInt(fileDescriptor), 0, queue) as DispatchSourceRead } public class func makeSignalSource(signal: Int32, queue: DispatchQueue? = nil) -> DispatchSourceSignal { return __dispatch_source_create( - _swift_dispatch_source_type_signal(), UInt(signal), 0, queue) as DispatchSourceSignal + _swift_dispatch_source_type_SIGNAL(), UInt(signal), 0, queue) as DispatchSourceSignal } public class func makeTimerSource(flags: TimerFlags = [], queue: DispatchQueue? = nil) -> DispatchSourceTimer { - return __dispatch_source_create(_swift_dispatch_source_type_timer(), 0, flags.rawValue, queue) as DispatchSourceTimer + return __dispatch_source_create(_swift_dispatch_source_type_TIMER(), 0, flags.rawValue, queue) as DispatchSourceTimer } public class func makeUserDataAddSource(queue: DispatchQueue? = nil) -> DispatchSourceUserDataAdd { - return __dispatch_source_create(_swift_dispatch_source_type_data_add(), 0, 0, queue) as DispatchSourceUserDataAdd + return __dispatch_source_create(_swift_dispatch_source_type_DATA_ADD(), 0, 0, queue) as DispatchSourceUserDataAdd } public class func makeUserDataOrSource(queue: DispatchQueue? = nil) -> DispatchSourceUserDataOr { - return __dispatch_source_create(_swift_dispatch_source_type_data_or(), 0, 0, queue) as DispatchSourceUserDataOr + return __dispatch_source_create(_swift_dispatch_source_type_DATA_OR(), 0, 0, queue) as DispatchSourceUserDataOr } public class func makeFileSystemObjectSource( fileDescriptor: Int32, eventMask: FileSystemEvent, queue: DispatchQueue? = nil) -> DispatchSourceFileSystemObject { return __dispatch_source_create( - _swift_dispatch_source_type_vnode(), UInt(fileDescriptor), eventMask.rawValue, queue) as DispatchSourceFileSystemObject + _swift_dispatch_source_type_VNODE(), UInt(fileDescriptor), eventMask.rawValue, queue) as DispatchSourceFileSystemObject } public class func makeWriteSource(fileDescriptor: Int32, queue: DispatchQueue? = nil) -> DispatchSourceWrite { return __dispatch_source_create( - _swift_dispatch_source_type_write(), UInt(fileDescriptor), 0, queue) as DispatchSourceWrite + _swift_dispatch_source_type_WRITE(), UInt(fileDescriptor), 0, queue) as DispatchSourceWrite } } @@ -331,36 +331,3 @@ public extension DispatchSourceUserDataOr { __dispatch_source_merge_data(self as! DispatchSource, 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_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 - -@_silgen_name("_swift_dispatch_source_type_PROC") -internal func _swift_dispatch_source_type_proc() -> __dispatch_source_type_t - -@_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 - -@_silgen_name("_swift_dispatch_source_type_VNODE") -internal func _swift_dispatch_source_type_vnode() -> __dispatch_source_type_t - -@_silgen_name("_swift_dispatch_source_type_WRITE") -internal func _swift_dispatch_source_type_write() -> __dispatch_source_type_t diff --git a/stdlib/public/SDK/Dispatch/Time.swift b/stdlib/public/SDK/Dispatch/Time.swift index be128bdb13bc7..a30ec77737000 100644 --- a/stdlib/public/SDK/Dispatch/Time.swift +++ b/stdlib/public/SDK/Dispatch/Time.swift @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -import SwiftShims +import _SwiftDispatchOverlayShims public struct DispatchTime : Comparable { public let rawValue: dispatch_time_t diff --git a/stdlib/public/SwiftShims/CMakeLists.txt b/stdlib/public/SwiftShims/CMakeLists.txt index 19932125b8a56..455e554afaad8 100644 --- a/stdlib/public/SwiftShims/CMakeLists.txt +++ b/stdlib/public/SwiftShims/CMakeLists.txt @@ -1,7 +1,6 @@ set(sources AssertionReporting.h CoreFoundationShims.h - DispatchShims.h FoundationShims.h GlobalObjects.h HeapObject.h @@ -15,6 +14,7 @@ set(sources UnicodeShims.h Visibility.h + DispatchOverlayShims.h ObjectiveCOverlayShims.h OSOverlayShims.h SafariServicesOverlayShims.h diff --git a/stdlib/public/SwiftShims/DispatchOverlayShims.h b/stdlib/public/SwiftShims/DispatchOverlayShims.h new file mode 100644 index 0000000000000..77e8abc4d44b9 --- /dev/null +++ b/stdlib/public/SwiftShims/DispatchOverlayShims.h @@ -0,0 +1,213 @@ +//===--- DispatchOverlayShims.h - Compatibility decls -----------*- C++ -*-===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +#ifndef SWIFT_STDLIB_SHIMS_DISPATCHSHIMS_H +#define SWIFT_STDLIB_SHIMS_DISPATCHSHIMS_H + +@import Dispatch; + +#define SWIFT_DISPATCH_RETURNS_RETAINED __attribute__((__ns_returns_retained__)) +#define SWIFT_DISPATCH_NOESCAPE __attribute__((__noescape__)) + +#pragma clang assume_nonnull begin + +#ifdef __cplusplus +namespace swift { extern "C" { +#endif + +typedef void (^__swift_shims_dispatch_block_t)(void); +typedef id __swift_shims_dispatch_data_t; + + +static inline dispatch_queue_attr_t +_swift_dispatch_queue_concurrent(void) { + return DISPATCH_QUEUE_CONCURRENT; +} + +static inline dispatch_queue_t +_swift_dispatch_get_main_queue(void) { + return dispatch_get_main_queue(); +} + +static inline dispatch_data_t +_swift_dispatch_data_empty(void) { + return dispatch_data_empty; +} + +static inline __swift_shims_dispatch_block_t _Nullable +_swift_dispatch_data_destructor_default(void) { + return DISPATCH_DATA_DESTRUCTOR_DEFAULT; +} + +static inline __swift_shims_dispatch_block_t +_swift_dispatch_data_destructor_free(void) { + return _dispatch_data_destructor_free; +} + +static inline __swift_shims_dispatch_block_t +_swift_dispatch_data_destructor_munmap(void) { + return _dispatch_data_destructor_munmap; +} + +#define SWIFT_DISPATCH_SOURCE_TYPE(t) \ + static inline dispatch_source_type_t _swift_dispatch_source_type_##t(void) { \ + return DISPATCH_SOURCE_TYPE_##t; \ + } + +SWIFT_DISPATCH_SOURCE_TYPE(DATA_ADD) +SWIFT_DISPATCH_SOURCE_TYPE(DATA_OR) +SWIFT_DISPATCH_SOURCE_TYPE(MACH_SEND) +SWIFT_DISPATCH_SOURCE_TYPE(MACH_RECV) +SWIFT_DISPATCH_SOURCE_TYPE(MEMORYPRESSURE) +SWIFT_DISPATCH_SOURCE_TYPE(PROC) +SWIFT_DISPATCH_SOURCE_TYPE(READ) +SWIFT_DISPATCH_SOURCE_TYPE(SIGNAL) +SWIFT_DISPATCH_SOURCE_TYPE(TIMER) +SWIFT_DISPATCH_SOURCE_TYPE(VNODE) +SWIFT_DISPATCH_SOURCE_TYPE(WRITE) + + +static inline __swift_shims_dispatch_block_t +_swift_dispatch_block_create_with_qos_class( + dispatch_block_flags_t flags, + qos_class_t qos, + int relative_priority, + __swift_shims_dispatch_block_t _Nonnull block) { + return dispatch_block_create_with_qos_class( + flags, qos, relative_priority, block); +} + +static inline __swift_shims_dispatch_block_t +_swift_dispatch_block_create_noescape( + dispatch_block_flags_t flags, + __swift_shims_dispatch_block_t SWIFT_DISPATCH_NOESCAPE block) { + return dispatch_block_create(flags, block); +} + +static inline int _swift_dispatch_block_wait( + __swift_shims_dispatch_block_t block, + unsigned long long timeout) { + return dispatch_block_wait(block, timeout); +} + +static inline void _swift_dispatch_block_notify( + __swift_shims_dispatch_block_t block, + dispatch_queue_t queue, + __swift_shims_dispatch_block_t notifier) { + dispatch_block_notify(block, queue, notifier); +} + +static inline void _swift_dispatch_block_cancel( + __swift_shims_dispatch_block_t block) { + dispatch_block_cancel(block); +} + +static inline int _swift_dispatch_block_testcancel( + __swift_shims_dispatch_block_t block) { + return dispatch_block_testcancel(block); +} + +static inline void _swift_dispatch_async( + dispatch_queue_t queue, + __swift_shims_dispatch_block_t block) { + dispatch_async(queue, block); +} + +static inline void _swift_dispatch_sync( + dispatch_queue_t queue, + __swift_shims_dispatch_block_t block) { + dispatch_sync(queue, block); +} + +static inline void _swift_dispatch_barrier_async( + dispatch_queue_t queue, + __swift_shims_dispatch_block_t block) { + dispatch_barrier_async(queue, block); +} + +static inline void _swift_dispatch_group_async( + dispatch_group_t group, + dispatch_queue_t queue, + __swift_shims_dispatch_block_t block) { + dispatch_group_async((dispatch_group_t)group, queue, block); +} + +static inline void _swift_dispatch_group_notify( + dispatch_group_t group, + dispatch_queue_t queue, + __swift_shims_dispatch_block_t block) { + dispatch_group_notify(group, queue, block); +} + +static inline void _swift_dispatch_after( + dispatch_time_t when, + dispatch_queue_t queue, + __swift_shims_dispatch_block_t block) { + dispatch_after(when, queue, block); +} + + +static inline void _swift_dispatch_apply_current( + unsigned int iterations, + void SWIFT_DISPATCH_NOESCAPE (^block)(long)) { + dispatch_apply(iterations, (dispatch_queue_t _Nonnull)0, ^(size_t i){ + block((long)i); + }); +} + +SWIFT_DISPATCH_RETURNS_RETAINED +__swift_shims_dispatch_data_t +_swift_dispatch_data_create( + const void *buffer, + size_t size, + dispatch_queue_t _Nullable queue, + __swift_shims_dispatch_block_t _Nullable destructor) { + return dispatch_data_create(buffer, size, queue, destructor); +} + +typedef unsigned int (^__swift_shims_dispatch_data_applier)(__swift_shims_dispatch_data_t, size_t, const void *, size_t); + +unsigned int +_swift_dispatch_data_apply( + __swift_shims_dispatch_data_t data, + __swift_shims_dispatch_data_applier SWIFT_DISPATCH_NOESCAPE applier) { + return dispatch_data_apply(data, ^bool(dispatch_data_t data, size_t off, const void *loc, size_t size){ + return applier(data, off, loc, size); + }); +} + +void _swift_dispatch_source_set_event_handler( + dispatch_source_t source, + __swift_shims_dispatch_block_t _Nullable block) { + dispatch_source_set_event_handler(source, block); +} + +void _swift_dispatch_source_set_cancel_handler( + dispatch_source_t source, + __swift_shims_dispatch_block_t _Nullable block) { + dispatch_source_set_cancel_handler(source, block); +} + +void _swift_dispatch_source_set_registration_handler( + dispatch_source_t source, + __swift_shims_dispatch_block_t _Nullable block) { + dispatch_source_set_registration_handler(source, block); +} + +#ifdef __cplusplus +}} // extern "C", namespace swift +#endif + +#pragma clang assume_nonnull end + +#endif // SWIFT_STDLIB_SHIMS_DISPATCHSHIMS_H + diff --git a/stdlib/public/SwiftShims/DispatchShims.h b/stdlib/public/SwiftShims/DispatchShims.h deleted file mode 100644 index 18e6a9c2327ba..0000000000000 --- a/stdlib/public/SwiftShims/DispatchShims.h +++ /dev/null @@ -1,164 +0,0 @@ -//===--- DispatchShims.h - Compatibility decls. for Dispatch ----*- C++ -*-===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// -// -// Using the Darwin (or Glibc) module in the core stdlib would create a -// circular dependency, so instead we import these declarations as part of -// SwiftShims. -// -//===----------------------------------------------------------------------===// - -#ifndef SWIFT_STDLIB_SHIMS_DISPATCHSHIMS_H -#define SWIFT_STDLIB_SHIMS_DISPATCHSHIMS_H - -#ifdef __OBJC2__ - -#include "SwiftStdint.h" -#include "SwiftStddef.h" -#include "Visibility.h" - -#define SWIFT_DISPATCH_RETURNS_RETAINED __attribute__((__ns_returns_retained__)) -#define SWIFT_DISPATCH_NOESCAPE __attribute__((__noescape__)) -#define SWIFT_DISPATCH_NONNULL _Nonnull -#define SWIFT_DISPATCH_NULLABLE _Nullable -#define SWIFT_DISPATCH_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") -#define SWIFT_DISPATCH_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") - -SWIFT_DISPATCH_ASSUME_NONNULL_BEGIN - -#ifdef __cplusplus -namespace swift { extern "C" { -#endif - -typedef unsigned long __swift_shims_dispatch_block_flags_t; -typedef unsigned int __swift_shims_qos_class_t; -typedef __swift_uint64_t __swift_shims_dispatch_time_t; -typedef void (^__swift_shims_dispatch_block_t)(void); -typedef id __swift_shims_dispatch_queue_t; -typedef id __swift_shims_dispatch_group_t; -typedef id __swift_shims_dispatch_data_t; -typedef id __swift_shims_dispatch_source_t; - -SWIFT_RUNTIME_STDLIB_INTERFACE -SWIFT_DISPATCH_RETURNS_RETAINED -__swift_shims_dispatch_block_t -_swift_dispatch_block_create_with_qos_class( - __swift_shims_dispatch_block_flags_t flags, - __swift_shims_qos_class_t qos, - int relative_priority, - __swift_shims_dispatch_block_t SWIFT_DISPATCH_NONNULL block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -SWIFT_DISPATCH_RETURNS_RETAINED -__swift_shims_dispatch_block_t -_swift_dispatch_block_create_noescape( - __swift_shims_dispatch_block_flags_t flags, - __swift_shims_dispatch_block_t SWIFT_DISPATCH_NOESCAPE block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -int _swift_dispatch_block_wait( - __swift_shims_dispatch_block_t block, - unsigned long long timeout); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_block_notify( - __swift_shims_dispatch_block_t block, - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t notifier); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_block_cancel( - __swift_shims_dispatch_block_t block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -int _swift_dispatch_block_testcancel( - __swift_shims_dispatch_block_t block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_async( - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_sync( - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_barrier_async( - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_group_async( - __swift_shims_dispatch_group_t group, - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_group_notify( - __swift_shims_dispatch_group_t group, - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_after( - __swift_shims_dispatch_time_t when, - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_apply_current( - unsigned int iterations, - void SWIFT_DISPATCH_NOESCAPE (^block)(long)); - -SWIFT_RUNTIME_STDLIB_INTERFACE -SWIFT_DISPATCH_RETURNS_RETAINED -__swift_shims_dispatch_data_t -_swift_dispatch_data_create( - const void *buffer, - __swift_size_t size, - __swift_shims_dispatch_queue_t SWIFT_DISPATCH_NULLABLE queue, - __swift_shims_dispatch_block_t SWIFT_DISPATCH_NULLABLE destructor); - -typedef unsigned int (^__swift_shims_dispatch_data_applier)(__swift_shims_dispatch_data_t, __swift_size_t, const void *, __swift_size_t); - -SWIFT_RUNTIME_STDLIB_INTERFACE -unsigned int -_swift_dispatch_data_apply( - __swift_shims_dispatch_data_t data, - __swift_shims_dispatch_data_applier SWIFT_DISPATCH_NOESCAPE applier); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_source_set_event_handler( - __swift_shims_dispatch_source_t source, - __swift_shims_dispatch_block_t SWIFT_DISPATCH_NULLABLE block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_source_set_cancel_handler( - __swift_shims_dispatch_source_t source, - __swift_shims_dispatch_block_t SWIFT_DISPATCH_NULLABLE block); - -SWIFT_RUNTIME_STDLIB_INTERFACE -void _swift_dispatch_source_set_registration_handler( - __swift_shims_dispatch_source_t source, - __swift_shims_dispatch_block_t SWIFT_DISPATCH_NULLABLE block); - -#ifdef __cplusplus -}} // extern "C", namespace swift -#endif - -SWIFT_DISPATCH_ASSUME_NONNULL_END - -#endif // __OBJC2__ - -#endif // SWIFT_STDLIB_SHIMS_DISPATCHSHIMS_H - diff --git a/stdlib/public/SwiftShims/module.modulemap b/stdlib/public/SwiftShims/module.modulemap index 51c809d913f97..42d451f74c89f 100644 --- a/stdlib/public/SwiftShims/module.modulemap +++ b/stdlib/public/SwiftShims/module.modulemap @@ -1,7 +1,6 @@ module SwiftShims { header "AssertionReporting.h" header "CoreFoundationShims.h" - header "DispatchShims.h" header "FoundationShims.h" header "GlobalObjects.h" header "HeapObject.h" @@ -24,6 +23,10 @@ module SwiftShims { // types and therefore would not strictly need to be present in an installed // Swift. // FIXME: These are not used at all on non-Apple platforms. +module _SwiftDispatchOverlayShims { + header "DispatchOverlayShims.h" +} + module _SwiftObjectiveCOverlayShims { header "ObjectiveCOverlayShims.h" } diff --git a/stdlib/public/stubs/CMakeLists.txt b/stdlib/public/stubs/CMakeLists.txt index 3d021d975d75b..630549f95c6f3 100644 --- a/stdlib/public/stubs/CMakeLists.txt +++ b/stdlib/public/stubs/CMakeLists.txt @@ -7,7 +7,6 @@ set(swift_stubs_sources UnicodeExtendedGraphemeClusters.cpp.gyb) set(swift_stubs_objc_sources Availability.mm - DispatchShims.mm FoundationHelpers.mm OptionalBridgingHelper.mm Reflection.mm diff --git a/stdlib/public/stubs/DispatchShims.mm b/stdlib/public/stubs/DispatchShims.mm deleted file mode 100644 index a584604fc8c4e..0000000000000 --- a/stdlib/public/stubs/DispatchShims.mm +++ /dev/null @@ -1,192 +0,0 @@ -//===--- DispatchShims.mm - Dispatch helper shims -------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// -// -// This file contains shims to refer to framework functions required by the -// standard library. The stdlib cannot directly import these modules without -// introducing circular dependencies. -// -//===----------------------------------------------------------------------===// - -#import -#include "../SwiftShims/DispatchShims.h" - -using namespace swift; - -template struct DestType; - -#define BRIDGE_TYPE(FROM, TO) \ -template <> struct DestType { using type = TO; } - -BRIDGE_TYPE(__swift_shims_dispatch_block_flags_t, dispatch_block_flags_t); -BRIDGE_TYPE(__swift_shims_qos_class_t, qos_class_t); -BRIDGE_TYPE(__swift_shims_dispatch_block_t, dispatch_block_t); -BRIDGE_TYPE(__swift_shims_dispatch_queue_t, dispatch_queue_t); - -template -static typename DestType::type cast(FromTy value) { - return (typename DestType::type) value; -} - -__swift_shims_dispatch_block_t -swift::_swift_dispatch_block_create_with_qos_class( - __swift_shims_dispatch_block_flags_t flags, - __swift_shims_qos_class_t qos, - int relative_priority, - __swift_shims_dispatch_block_t block) -{ - return dispatch_block_create_with_qos_class( - cast(flags), cast(qos), relative_priority, cast(block)); -} - -__swift_shims_dispatch_block_t -swift::_swift_dispatch_block_create_noescape( - __swift_shims_dispatch_block_flags_t flags, - __swift_shims_dispatch_block_t block) -{ - return dispatch_block_create(cast(flags), cast(block)); -} - -int -swift::_swift_dispatch_block_wait( - __swift_shims_dispatch_block_t block, - unsigned long long timeout) -{ - return dispatch_block_wait(block, timeout); -} - -void -swift::_swift_dispatch_block_notify( - __swift_shims_dispatch_block_t block, - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t notifier) -{ - dispatch_block_notify(cast(block), cast(queue), cast(notifier)); -} - -void -swift::_swift_dispatch_block_cancel( - __swift_shims_dispatch_block_t block) -{ - dispatch_block_cancel(cast(block)); -} - -int -swift::_swift_dispatch_block_testcancel( - __swift_shims_dispatch_block_t block) -{ - return dispatch_block_testcancel(cast(block)); -} - -void -swift::_swift_dispatch_async( - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block) -{ - dispatch_async(cast(queue), cast(block)); -} - -void -swift::_swift_dispatch_barrier_async( - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block) -{ - dispatch_barrier_async(cast(queue), cast(block)); -} - -void -swift::_swift_dispatch_group_async( - __swift_shims_dispatch_group_t group, - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block) -{ - dispatch_group_async((dispatch_group_t)group, cast(queue), cast(block)); -} - -void -swift::_swift_dispatch_group_notify( - __swift_shims_dispatch_group_t group, - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block) -{ - dispatch_group_notify((dispatch_group_t)group, cast(queue), cast(block)); -} - -void -swift::_swift_dispatch_sync( - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block) -{ - dispatch_sync(cast(queue), cast(block)); -} - -void -swift::_swift_dispatch_after( - __swift_shims_dispatch_time_t when, - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t block) -{ - dispatch_after((dispatch_time_t)when, cast(queue), cast(block)); -} - -void -swift::_swift_dispatch_apply_current( - unsigned int iterations, - void SWIFT_DISPATCH_NOESCAPE (^block)(long)) -{ - dispatch_apply(iterations, (dispatch_queue_t _Nonnull)0, ^(size_t i){ - block((long)i); - }); -} - -__swift_shims_dispatch_data_t -swift::_swift_dispatch_data_create( - const void *buffer, - __swift_size_t size, - __swift_shims_dispatch_queue_t queue, - __swift_shims_dispatch_block_t destructor) -{ - return dispatch_data_create(buffer, size, cast(queue), cast(destructor)); -} - -unsigned int -swift::_swift_dispatch_data_apply( - __swift_shims_dispatch_data_t data, - __swift_shims_dispatch_data_applier SWIFT_DISPATCH_NOESCAPE applier) -{ - return dispatch_data_apply(data, ^bool(dispatch_data_t data, size_t off, const void *loc, size_t size){ - return applier(data, off, loc, size); - }); -} - -void -swift::_swift_dispatch_source_set_event_handler( - __swift_shims_dispatch_source_t source, - __swift_shims_dispatch_block_t block) -{ - dispatch_source_set_event_handler((dispatch_source_t)source, cast(block)); -} - -void -swift::_swift_dispatch_source_set_cancel_handler( - __swift_shims_dispatch_source_t source, - __swift_shims_dispatch_block_t block) -{ - dispatch_source_set_cancel_handler((dispatch_source_t)source, cast(block)); -} - -void -swift::_swift_dispatch_source_set_registration_handler( - __swift_shims_dispatch_source_t source, - __swift_shims_dispatch_block_t block) -{ - dispatch_source_set_registration_handler((dispatch_source_t)source, cast(block)); -} diff --git a/test/Inputs/clang-importer-sdk/swift-modules/Dispatch.swift b/test/Inputs/clang-importer-sdk/swift-modules/Dispatch.swift new file mode 100644 index 0000000000000..8ee8d33b54602 --- /dev/null +++ b/test/Inputs/clang-importer-sdk/swift-modules/Dispatch.swift @@ -0,0 +1,3 @@ +@_exported import Dispatch // Clang module + +typealias dispatch_block_t = @convention(block) () -> Void diff --git a/test/stdlib/TestData.swift b/test/stdlib/TestData.swift index 2bb9d1029711f..551982680dbf3 100644 --- a/test/stdlib/TestData.swift +++ b/test/stdlib/TestData.swift @@ -12,7 +12,7 @@ // RUN: %target-clang %S/Inputs/FoundationBridge/FoundationBridge.m -c -o %t/FoundationBridgeObjC.o -g // RUN: %target-build-swift %s -I %S/Inputs/FoundationBridge/ -Xlinker %t/FoundationBridgeObjC.o -o %t/TestData -// RUN: %target-run %t/TestData > %t.txt +// RUN: %target-run %t/TestData // REQUIRES: executable_test // REQUIRES: objc_interop