mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: Remove _isBridgedToObjectiveC from _ObjectiveCBridgeable.
All generic bridgeable types can bridge for all their instantiations now. Removing this ferrets out some now-unnecessary traps that check for unbridgeable parameter types.
This commit is contained in:
@@ -251,7 +251,6 @@ process start and the function returns.
|
||||
should be implementable in the standard library now.
|
||||
|
||||
```
|
||||
0000000000003b60 T _swift_bridgeNonVerbatimFromObjectiveC
|
||||
0000000000003c80 T _swift_bridgeNonVerbatimFromObjectiveCConditional
|
||||
00000000000037e0 T _swift_bridgeNonVerbatimToObjectiveC
|
||||
00000000000039c0 T _swift_getBridgedNonVerbatimObjectiveCType
|
||||
|
||||
@@ -262,10 +262,6 @@ public struct DispatchDataIterator : IteratorProtocol, Sequence {
|
||||
}
|
||||
|
||||
extension DispatchData {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> __DispatchData {
|
||||
return unsafeBitCast(__wrapped, to: __DispatchData.self)
|
||||
|
||||
@@ -264,10 +264,6 @@ extension AffineTransform : ReferenceConvertible, Hashable, CustomStringConverti
|
||||
}
|
||||
|
||||
extension AffineTransform : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public static func _getObjectiveCType() -> Any.Type {
|
||||
return NSAffineTransform.self
|
||||
}
|
||||
|
||||
@@ -1082,10 +1082,6 @@ public struct Calendar : CustomStringConvertible, CustomDebugStringConvertible,
|
||||
}
|
||||
|
||||
extension Calendar : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSCalendar {
|
||||
return _handle._copiedReference()
|
||||
|
||||
@@ -439,10 +439,6 @@ public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgeb
|
||||
|
||||
// MARK: Objective-C Bridging
|
||||
extension CharacterSet : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public static func _getObjectiveCType() -> Any.Type {
|
||||
return NSCharacterSet.self
|
||||
}
|
||||
|
||||
@@ -678,10 +678,6 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
|
||||
|
||||
/// Provides bridging functionality for struct Data to class NSData and vice-versa.
|
||||
extension Data : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSData {
|
||||
return unsafeBitCast(_wrapped, to: NSData.self)
|
||||
|
||||
@@ -229,10 +229,6 @@ public struct Date : ReferenceConvertible, Comparable, Equatable, CustomStringCo
|
||||
}
|
||||
|
||||
extension Date : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSDate {
|
||||
return NSDate(timeIntervalSinceReferenceDate: _time)
|
||||
|
||||
@@ -292,10 +292,6 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
|
||||
// MARK: - Bridging
|
||||
|
||||
extension DateComponents : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public static func _getObjectiveCType() -> Any.Type {
|
||||
return NSDateComponents.self
|
||||
}
|
||||
|
||||
@@ -183,10 +183,6 @@ public struct DateInterval : ReferenceConvertible, Comparable, Hashable {
|
||||
|
||||
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
|
||||
extension DateInterval : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public static func _getObjectiveCType() -> Any.Type {
|
||||
return NSDateInterval.self
|
||||
}
|
||||
|
||||
@@ -436,10 +436,6 @@ extension Decimal : CustomStringConvertible {
|
||||
}
|
||||
|
||||
extension Decimal : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSDecimalNumber {
|
||||
return NSDecimalNumber(decimal: self)
|
||||
|
||||
@@ -86,10 +86,6 @@ extension String {
|
||||
}
|
||||
|
||||
extension String : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSString {
|
||||
// This method should not do anything extra except calling into the
|
||||
@@ -132,10 +128,6 @@ extension String : _ObjectiveCBridgeable {
|
||||
// back to a specific numeric type requires a cast.
|
||||
// FIXME: Incomplete list of types.
|
||||
extension Int : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public init(_ number: NSNumber) {
|
||||
self = number.intValue
|
||||
}
|
||||
@@ -168,10 +160,6 @@ extension Int : _ObjectiveCBridgeable {
|
||||
}
|
||||
|
||||
extension UInt : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public init(_ number: NSNumber) {
|
||||
self = number.uintValue
|
||||
}
|
||||
@@ -204,10 +192,6 @@ extension UInt : _ObjectiveCBridgeable {
|
||||
}
|
||||
|
||||
extension Float : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public init(_ number: NSNumber) {
|
||||
self = number.floatValue
|
||||
}
|
||||
@@ -240,10 +224,6 @@ extension Float : _ObjectiveCBridgeable {
|
||||
}
|
||||
|
||||
extension Double : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public init(_ number: NSNumber) {
|
||||
self = number.doubleValue
|
||||
}
|
||||
@@ -276,10 +256,6 @@ extension Double : _ObjectiveCBridgeable {
|
||||
}
|
||||
|
||||
extension Bool: _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public init(_ number: NSNumber) {
|
||||
self = number.boolValue
|
||||
}
|
||||
@@ -313,10 +289,6 @@ extension Bool: _ObjectiveCBridgeable {
|
||||
|
||||
// CGFloat bridging.
|
||||
extension CGFloat : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public init(_ number: NSNumber) {
|
||||
self.native = CGFloat.NativeType(number)
|
||||
}
|
||||
@@ -408,10 +380,6 @@ extension Array : _ObjectiveCBridgeable {
|
||||
unsafeBitCast(_cocoaArray.copy() as AnyObject, to: _NSArrayCore.self))
|
||||
}
|
||||
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return Swift._isBridgedToObjectiveC(Element.self)
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSArray {
|
||||
return unsafeBitCast(self._buffer._asCocoaArray() as AnyObject, to: NSArray.self)
|
||||
@@ -570,11 +538,6 @@ extension Dictionary : _ObjectiveCBridgeable {
|
||||
return result != nil
|
||||
}
|
||||
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return Swift._isBridgedToObjectiveC(Key.self) &&
|
||||
Swift._isBridgedToObjectiveC(Value.self)
|
||||
}
|
||||
|
||||
public static func _unconditionallyBridgeFromObjectiveC(
|
||||
_ d: NSDictionary?
|
||||
) -> Dictionary {
|
||||
@@ -850,10 +813,6 @@ extension Set : _ObjectiveCBridgeable {
|
||||
})
|
||||
return builder.take()
|
||||
}
|
||||
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return Swift._isBridgedToObjectiveC(Element.self)
|
||||
}
|
||||
}
|
||||
|
||||
extension NSDictionary : Sequence {
|
||||
|
||||
@@ -209,10 +209,6 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
|
||||
}
|
||||
|
||||
extension IndexPath : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public static func _getObjectiveCType() -> Any.Type {
|
||||
return NSIndexPath.self
|
||||
}
|
||||
|
||||
@@ -852,10 +852,6 @@ private func _toNSRange(_ r : Range<IndexSet.Element>) -> NSRange {
|
||||
}
|
||||
|
||||
extension IndexSet : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public static func _getObjectiveCType() -> Any.Type {
|
||||
return NSIndexSet.self
|
||||
}
|
||||
|
||||
@@ -441,10 +441,6 @@ public struct Locale : CustomStringConvertible, CustomDebugStringConvertible, Ha
|
||||
|
||||
|
||||
extension Locale : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSLocale {
|
||||
return _wrapped
|
||||
|
||||
@@ -253,10 +253,6 @@ extension Measurement {
|
||||
|
||||
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
|
||||
extension Measurement : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSMeasurement {
|
||||
return NSMeasurement(doubleValue: value, unit: unit)
|
||||
|
||||
@@ -11,10 +11,6 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension NSRange : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public func _bridgeToObjectiveC() -> NSValue {
|
||||
return NSValue(range: self)
|
||||
}
|
||||
|
||||
@@ -95,10 +95,6 @@ public struct Notification : ReferenceConvertible, Equatable, Hashable {
|
||||
}
|
||||
|
||||
extension Notification : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public static func _getObjectiveCType() -> Any.Type {
|
||||
return NSNotification.self
|
||||
}
|
||||
|
||||
@@ -87,10 +87,6 @@ public struct PersonNameComponents : ReferenceConvertible, Hashable, Equatable,
|
||||
|
||||
@available(OSX 10.11, iOS 9.0, *)
|
||||
extension PersonNameComponents : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public static func _getObjectiveCType() -> Any.Type {
|
||||
return NSPersonNameComponents.self
|
||||
}
|
||||
|
||||
@@ -230,10 +230,6 @@ public struct TimeZone : CustomStringConvertible, CustomDebugStringConvertible,
|
||||
}
|
||||
|
||||
extension TimeZone : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSTimeZone {
|
||||
// _wrapped is immutable
|
||||
|
||||
@@ -1124,10 +1124,6 @@ public struct URL : ReferenceConvertible, CustomStringConvertible, Equatable {
|
||||
}
|
||||
|
||||
extension URL : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSURL {
|
||||
return _url
|
||||
|
||||
@@ -316,10 +316,6 @@ public struct URLComponents : ReferenceConvertible, Hashable, CustomStringConver
|
||||
}
|
||||
|
||||
extension URLComponents : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public static func _getObjectiveCType() -> Any.Type {
|
||||
return NSURLComponents.self
|
||||
}
|
||||
@@ -384,10 +380,6 @@ public struct URLQueryItem : ReferenceConvertible, Hashable, Equatable, CustomSt
|
||||
|
||||
@available(OSX 10.10, iOS 8.0, *)
|
||||
extension URLQueryItem : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public static func _getObjectiveCType() -> Any.Type {
|
||||
return NSURLQueryItem.self
|
||||
}
|
||||
|
||||
@@ -247,10 +247,6 @@ public struct URLRequest : ReferenceConvertible, CustomStringConvertible, Equata
|
||||
}
|
||||
|
||||
extension URLRequest : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public static func _getObjectiveCType() -> Any.Type {
|
||||
return NSURLRequest.self
|
||||
}
|
||||
|
||||
@@ -107,10 +107,6 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
|
||||
}
|
||||
|
||||
extension UUID : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSUUID {
|
||||
return reference
|
||||
|
||||
@@ -112,13 +112,8 @@ extension _ArrayBuffer {
|
||||
|
||||
/// Convert to an NSArray.
|
||||
///
|
||||
/// - Precondition: `_isBridgedToObjectiveC(Element.self)`.
|
||||
/// O(1) if the element type is bridged verbatim, O(N) otherwise.
|
||||
/// O(1) if the element type is bridged verbatim, O(N) otherwise.
|
||||
public func _asCocoaArray() -> _NSArrayCore {
|
||||
_sanityCheck(
|
||||
_isBridgedToObjectiveC(Element.self),
|
||||
"Array element type is not bridged to Objective-C")
|
||||
|
||||
return _fastPath(_isNative) ? _native._asCocoaArray() : _nonNative
|
||||
}
|
||||
|
||||
|
||||
@@ -19,14 +19,6 @@
|
||||
public protocol _ObjectiveCBridgeable {
|
||||
associatedtype _ObjectiveCType : AnyObject
|
||||
|
||||
/// Returns `true` iff instances of `Self` can be converted to
|
||||
/// Objective-C. Even if this method returns `true`, a given
|
||||
/// instance of `Self._ObjectiveCType` may, or may not, convert
|
||||
/// successfully to `Self`; for example, an `NSArray` will only
|
||||
/// convert successfully to `[String]` if it contains only
|
||||
/// `NSString`s.
|
||||
static func _isBridgedToObjectiveC() -> Bool
|
||||
|
||||
/// Convert `self` to Objective-C.
|
||||
func _bridgeToObjectiveC() -> _ObjectiveCType
|
||||
|
||||
@@ -91,6 +83,13 @@ public protocol _ObjectiveCBridgeable {
|
||||
-> Self
|
||||
}
|
||||
|
||||
// TODO: stub for unit testing purposes
|
||||
extension _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
//===--- Bridging for metatypes -------------------------------------------===//
|
||||
|
||||
/// A stand-in for a value of metatype type.
|
||||
@@ -106,10 +105,6 @@ public struct _BridgeableMetatype: _ObjectiveCBridgeable {
|
||||
|
||||
public typealias _ObjectiveCType = AnyObject
|
||||
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public func _bridgeToObjectiveC() -> AnyObject {
|
||||
return value
|
||||
}
|
||||
@@ -149,66 +144,19 @@ public struct _BridgeableMetatype: _ObjectiveCBridgeable {
|
||||
// implementations.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Attempt to convert `x` to its Objective-C representation.
|
||||
///
|
||||
/// - If `T` is a class type, it is always bridged verbatim, the function
|
||||
/// returns `x`;
|
||||
///
|
||||
/// - otherwise, `T` conforms to `_ObjectiveCBridgeable`:
|
||||
/// + if `T._isBridgedToObjectiveC()` returns `false`, then the
|
||||
/// result is empty;
|
||||
/// + otherwise, returns the result of `x._bridgeToObjectiveC()`;
|
||||
///
|
||||
/// - otherwise, the result is empty.
|
||||
public func _bridgeToObjectiveC<T>(_ x: T) -> AnyObject? {
|
||||
if _fastPath(_isClassOrObjCExistential(T.self)) {
|
||||
return unsafeBitCast(x, to: AnyObject.self)
|
||||
}
|
||||
return _bridgeNonVerbatimToObjectiveC(x)
|
||||
}
|
||||
|
||||
public func _bridgeToObjectiveCUnconditional<T>(_ x: T) -> AnyObject {
|
||||
let optResult: AnyObject? = _bridgeToObjectiveC(x)
|
||||
_precondition(optResult != nil,
|
||||
"value failed to bridge from Swift type to a Objective-C type")
|
||||
return optResult!
|
||||
}
|
||||
|
||||
/// Same as `_bridgeToObjectiveCUnconditional`, but autoreleases the
|
||||
/// return value if `T` is bridged non-verbatim.
|
||||
func _bridgeToObjectiveCUnconditionalAutorelease<T>(_ x: T) -> AnyObject
|
||||
{
|
||||
if _fastPath(_isClassOrObjCExistential(T.self)) {
|
||||
return unsafeBitCast(x, to: AnyObject.self)
|
||||
}
|
||||
guard let bridged = _bridgeNonVerbatimToObjectiveC(x) else {
|
||||
_preconditionFailure(
|
||||
"Dictionary key failed to bridge from Swift type to a Objective-C type")
|
||||
}
|
||||
|
||||
_autorelease(bridged)
|
||||
return bridged
|
||||
}
|
||||
|
||||
@_silgen_name("_swift_bridgeNonVerbatimToObjectiveC")
|
||||
func _bridgeNonVerbatimToObjectiveC<T>(_ x: T) -> AnyObject?
|
||||
|
||||
/// Bridge an arbitrary value to an Objective-C object.
|
||||
///
|
||||
/// - If `T` is a class type, it is always bridged verbatim, the function
|
||||
/// returns `x`;
|
||||
///
|
||||
/// - otherwise, `T` conforms to `_ObjectiveCBridgeable`:
|
||||
/// + if `T._isBridgedToObjectiveC()` returns `false`, then
|
||||
/// we fall back to boxing (below);
|
||||
/// + otherwise, returns the result of `x._bridgeToObjectiveC()`;
|
||||
/// - otherwise, if `T` conforms to `_ObjectiveCBridgeable`,
|
||||
/// returns the result of `x._bridgeToObjectiveC()`;
|
||||
///
|
||||
/// - otherwise, we use **boxing** to bring the value into Objective-C.
|
||||
/// The value is wrapped in an instance of a private Objective-C class
|
||||
/// that is `id`-compatible and dynamically castable back to the type of
|
||||
/// the boxed value, but is otherwise opaque.
|
||||
///
|
||||
/// TODO: This should subsume `_bridgeToObjectiveC` above.
|
||||
/// COMPILER_INTRINSIC
|
||||
public func _bridgeAnythingToObjectiveC<T>(_ x: T) -> AnyObject {
|
||||
if _fastPath(_isClassOrObjCExistential(T.self)) {
|
||||
@@ -217,7 +165,6 @@ public func _bridgeAnythingToObjectiveC<T>(_ x: T) -> AnyObject {
|
||||
return _bridgeAnythingNonVerbatimToObjectiveC(x)
|
||||
}
|
||||
|
||||
// TODO: This should subsume `_bridgeNonVerbatimToObjectiveC` above.
|
||||
/// COMPILER_INTRINSIC
|
||||
@_silgen_name("_swift_bridgeAnythingNonVerbatimToObjectiveC")
|
||||
public func _bridgeAnythingNonVerbatimToObjectiveC<T>(_ x: T) -> AnyObject
|
||||
@@ -262,8 +209,6 @@ public func _forceBridgeFromObjectiveC_bridgeable<T:_ObjectiveCBridgeable> (
|
||||
/// - if the dynamic type of `x` is `T` or a subclass of it, it is bridged
|
||||
/// verbatim, the function returns `x`;
|
||||
/// - otherwise, if `T` conforms to `_ObjectiveCBridgeable`:
|
||||
/// + if `T._isBridgedToObjectiveC()` returns `false`, then the result is
|
||||
/// empty;
|
||||
/// + otherwise, if the dynamic type of `x` is not `T._ObjectiveCType`
|
||||
/// or a subclass of it, the result is empty;
|
||||
/// + otherwise, returns the result of
|
||||
@@ -319,8 +264,7 @@ func _bridgeNonVerbatimFromObjectiveCConditional<T>(
|
||||
/// representation.
|
||||
///
|
||||
/// - If `T` is a class type, returns `true`;
|
||||
/// - otherwise, if `T` conforms to `_ObjectiveCBridgeable`, returns
|
||||
/// `T._isBridgedToObjectiveC()`.
|
||||
/// - otherwise, returns whether `T` conforms to `_ObjectiveCBridgeable`.
|
||||
public func _isBridgedToObjectiveC<T>(_: T.Type) -> Bool {
|
||||
if _fastPath(_isClassOrObjCExistential(T.self)) {
|
||||
return true
|
||||
|
||||
@@ -145,7 +145,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
|
||||
let resultPtr = result.baseAddress
|
||||
let p = __manager._elementPointer
|
||||
for i in 0..<count {
|
||||
(resultPtr + i).initialize(to: _bridgeToObjectiveCUnconditional(p[i]))
|
||||
(resultPtr + i).initialize(to: _bridgeAnythingToObjectiveC(p[i]))
|
||||
}
|
||||
_fixLifetime(__manager)
|
||||
return result
|
||||
@@ -428,9 +428,6 @@ struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
|
||||
///
|
||||
/// - Complexity: O(1).
|
||||
public func _asCocoaArray() -> _NSArrayCore {
|
||||
_sanityCheck(
|
||||
_isBridgedToObjectiveC(Element.self),
|
||||
"Array element type is not bridged to Objective-C")
|
||||
if count == 0 {
|
||||
return _emptyArrayStorage
|
||||
}
|
||||
|
||||
@@ -1184,7 +1184,7 @@ extension Set {
|
||||
var i = lhsNative.startIndex
|
||||
while i != endIndex {
|
||||
let key = lhsNative.assertingGet(i)
|
||||
let bridgedKey: AnyObject = _bridgeToObjectiveCUnconditional(key)
|
||||
let bridgedKey: AnyObject = _bridgeAnythingToObjectiveC(key)
|
||||
let optRhsValue: AnyObject? = rhsCocoa.maybeGet(bridgedKey)
|
||||
if let rhsValue = optRhsValue {
|
||||
if key == _forceBridgeFromObjectiveC(rhsValue, Element.self) {
|
||||
@@ -1301,10 +1301,8 @@ public func _setBridgeToObjectiveC<SwiftValue, ObjCValue>(
|
||||
if valueBridgesDirectly {
|
||||
bridgedMember = unsafeBitCast(member, to: ObjCValue.self)
|
||||
} else {
|
||||
let bridged: AnyObject? = _bridgeToObjectiveC(member)
|
||||
_precondition(bridged != nil,
|
||||
"set member cannot be bridged to Objective-C")
|
||||
bridgedMember = unsafeBitCast(bridged!, to: ObjCValue.self)
|
||||
let bridged: AnyObject = _bridgeAnythingToObjectiveC(member)
|
||||
bridgedMember = unsafeBitCast(bridged, to: ObjCValue.self)
|
||||
}
|
||||
result.insert(bridgedMember)
|
||||
}
|
||||
@@ -2109,7 +2107,7 @@ extension Dictionary where Key : Equatable, Value : Equatable {
|
||||
while index != endIndex {
|
||||
let (key, value) = lhsNative.assertingGet(index)
|
||||
let optRhsValue: AnyObject? =
|
||||
rhsCocoa.maybeGet(_bridgeToObjectiveCUnconditional(key))
|
||||
rhsCocoa.maybeGet(_bridgeAnythingToObjectiveC(key))
|
||||
// TODO: swift-3-indexing-model: change 'if' into 'guard'.
|
||||
if let rhsValue = optRhsValue {
|
||||
if value == _forceBridgeFromObjectiveC(rhsValue, Value.self) {
|
||||
@@ -2245,9 +2243,8 @@ public func _dictionaryBridgeToObjectiveC<
|
||||
if keyBridgesDirectly {
|
||||
bridgedKey = unsafeBitCast(key, to: ObjCKey.self)
|
||||
} else {
|
||||
let bridged: AnyObject? = _bridgeToObjectiveC(key)
|
||||
_precondition(bridged != nil, "dictionary key cannot be bridged to Objective-C")
|
||||
bridgedKey = unsafeBitCast(bridged!, to: ObjCKey.self)
|
||||
let bridged: AnyObject = _bridgeAnythingToObjectiveC(key)
|
||||
bridgedKey = unsafeBitCast(bridged, to: ObjCKey.self)
|
||||
}
|
||||
|
||||
// Bridge the value
|
||||
@@ -2255,10 +2252,8 @@ public func _dictionaryBridgeToObjectiveC<
|
||||
if valueBridgesDirectly {
|
||||
bridgedValue = unsafeBitCast(value, to: ObjCValue.self)
|
||||
} else {
|
||||
let bridged: AnyObject? = _bridgeToObjectiveC(value)
|
||||
_precondition(bridged != nil,
|
||||
"dictionary value cannot be bridged to Objective-C")
|
||||
bridgedValue = unsafeBitCast(bridged!, to: ObjCValue.self)
|
||||
let bridged: AnyObject? = _bridgeAnythingToObjectiveC(value)
|
||||
bridgedValue = unsafeBitCast(bridged, to: ObjCValue.self)
|
||||
}
|
||||
|
||||
result[bridgedKey] = bridgedValue
|
||||
@@ -3410,11 +3405,11 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
// Bridge everything.
|
||||
for i in 0..<nativeStorage.capacity {
|
||||
if nativeStorage.isInitializedEntry(at: i) {
|
||||
let key = _bridgeToObjectiveCUnconditional(nativeStorage.key(at: i))
|
||||
let key = _bridgeAnythingToObjectiveC(nativeStorage.key(at: i))
|
||||
%if Self == 'Set':
|
||||
bridged.initializeKey(key, at: i)
|
||||
%elif Self == 'Dictionary':
|
||||
let val = _bridgeToObjectiveCUnconditional(nativeStorage.value(at: i))
|
||||
let val = _bridgeAnythingToObjectiveC(nativeStorage.value(at: i))
|
||||
bridged.initializeKey(key, value: val, at: i)
|
||||
%end
|
||||
}
|
||||
@@ -3433,9 +3428,9 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
AnyObject {
|
||||
if _fastPath(_isClassOrObjCExistential(Key.self)) {
|
||||
%if Self == 'Set':
|
||||
return _bridgeToObjectiveCUnconditional(nativeStorage.assertingGet(i))
|
||||
return _bridgeAnythingToObjectiveC(nativeStorage.assertingGet(i))
|
||||
%elif Self == 'Dictionary':
|
||||
return _bridgeToObjectiveCUnconditional(nativeStorage.assertingGet(i).0)
|
||||
return _bridgeAnythingToObjectiveC(nativeStorage.assertingGet(i).0)
|
||||
%end
|
||||
}
|
||||
bridgeEverything()
|
||||
@@ -3451,7 +3446,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
internal func _getBridgedValue(_ i: _Native${Self}Index<${TypeParameters}>) ->
|
||||
AnyObject {
|
||||
if _fastPath(_isClassOrObjCExistential(Value.self)) {
|
||||
return _bridgeToObjectiveCUnconditional(nativeStorage.assertingGet(i))
|
||||
return _bridgeAnythingToObjectiveC(nativeStorage.assertingGet(i))
|
||||
}
|
||||
bridgeEverything()
|
||||
return bridgedNativeStorage.assertingGet(i.offset)
|
||||
@@ -3462,7 +3457,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
internal func _getBridgedValue(_ i: _Native${Self}Index<${TypeParameters}>)
|
||||
-> AnyObject {
|
||||
if _fastPath(_isClassOrObjCExistential(Value.self)) {
|
||||
return _bridgeToObjectiveCUnconditional(nativeStorage.assertingGet(i).1)
|
||||
return _bridgeAnythingToObjectiveC(nativeStorage.assertingGet(i).1)
|
||||
}
|
||||
bridgeEverything()
|
||||
return bridgedNativeStorage.assertingGet(i.offset).1
|
||||
@@ -3952,7 +3947,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
|
||||
return nil
|
||||
case .cocoa(let cocoaStorage):
|
||||
#if _runtime(_ObjC)
|
||||
let anyObjectKey: AnyObject = _bridgeToObjectiveCUnconditional(key)
|
||||
let anyObjectKey: AnyObject = _bridgeAnythingToObjectiveC(key)
|
||||
if let cocoaIndex = cocoaStorage.index(forKey: anyObjectKey) {
|
||||
return ._cocoa(cocoaIndex)
|
||||
}
|
||||
@@ -4001,7 +3996,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
|
||||
case .cocoa(let cocoaStorage):
|
||||
#if _runtime(_ObjC)
|
||||
// FIXME: This assumes that Key and Value are bridged verbatim.
|
||||
let anyObjectKey: AnyObject = _bridgeToObjectiveCUnconditional(key)
|
||||
let anyObjectKey: AnyObject = _bridgeAnythingToObjectiveC(key)
|
||||
let anyObjectValue: AnyObject = cocoaStorage.assertingGet(anyObjectKey)
|
||||
return _forceBridgeFromObjectiveC(anyObjectValue, Value.self)
|
||||
#else
|
||||
@@ -4016,7 +4011,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
|
||||
internal static func maybeGetFromCocoaStorage(
|
||||
_ cocoaStorage : CocoaStorage, forKey key: Key
|
||||
) -> Value? {
|
||||
let anyObjectKey: AnyObject = _bridgeToObjectiveCUnconditional(key)
|
||||
let anyObjectKey: AnyObject = _bridgeAnythingToObjectiveC(key)
|
||||
if let anyObjectValue = cocoaStorage.maybeGet(anyObjectKey) {
|
||||
return _forceBridgeFromObjectiveC(anyObjectValue, Value.self)
|
||||
}
|
||||
@@ -4322,7 +4317,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
|
||||
return nativeRemoveObject(forKey: key)
|
||||
case .cocoa(let cocoaStorage):
|
||||
#if _runtime(_ObjC)
|
||||
let anyObjectKey: AnyObject = _bridgeToObjectiveCUnconditional(key)
|
||||
let anyObjectKey: AnyObject = _bridgeAnythingToObjectiveC(key)
|
||||
if cocoaStorage.maybeGet(anyObjectKey) == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -5033,13 +5028,6 @@ extension ${Self} {
|
||||
public func _bridgeToObjectiveCImpl() -> _NS${Self}Core {
|
||||
switch _variantStorage {
|
||||
case _Variant${Self}Storage.native(let nativeOwner):
|
||||
%if Self == 'Set':
|
||||
_precondition(_isBridgedToObjectiveC(Element.self),
|
||||
"Key is not bridged to Objective-C")
|
||||
%elif Self == 'Dictionary':
|
||||
_precondition(_isBridgedToObjectiveC(Value.self),
|
||||
"Value is not bridged to Objective-C")
|
||||
%end
|
||||
return nativeOwner as _Native${Self}StorageOwner<${TypeParameters}>
|
||||
|
||||
case _Variant${Self}Storage.cocoa(let cocoaStorage):
|
||||
|
||||
@@ -71,7 +71,7 @@ extension ImplicitlyUnwrappedOptional : _ObjectiveCBridgeable {
|
||||
_preconditionFailure("attempt to bridge an implicitly unwrapped optional containing nil")
|
||||
|
||||
case .some(let x):
|
||||
return Swift._bridgeToObjectiveC(x)!
|
||||
return Swift._bridgeAnythingToObjectiveC(x)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,6 @@ public func ${op} <T: _SwiftNewtypeWrapper>(lhs: T, rhs: T) -> Bool
|
||||
|
||||
#if _runtime(_ObjC)
|
||||
extension _SwiftNewtypeWrapper where Self.RawValue : _ObjectiveCBridgeable {
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
return Self.RawValue._isBridgedToObjectiveC()
|
||||
}
|
||||
|
||||
public func _bridgeToObjectiveC() -> Self.RawValue._ObjectiveCType {
|
||||
return rawValue._bridgeToObjectiveC()
|
||||
}
|
||||
|
||||
@@ -510,7 +510,7 @@ public func _swift_ClassMirror_quickLookObject(_: _MagicMirrorData) -> AnyObject
|
||||
func _swift_isKind(_ object: AnyObject, of: AnyObject) -> Bool
|
||||
|
||||
func _isKind(_ object: AnyObject, of: String) -> Bool {
|
||||
return _swift_isKind(object, of: _bridgeToObjectiveC(of)!)
|
||||
return _swift_isKind(object, of: _bridgeAnythingToObjectiveC(of))
|
||||
}
|
||||
|
||||
func _getClassPlaygroundQuickLook(_ object: AnyObject) -> PlaygroundQuickLook? {
|
||||
|
||||
@@ -2516,11 +2516,6 @@ struct _ObjectiveCBridgeableWitnessTable {
|
||||
const Metadata *parentMetadata,
|
||||
const _ObjectiveCBridgeableWitnessTable *witnessTable);
|
||||
|
||||
// class func _isBridgedToObjectiveC() -> bool
|
||||
bool (*isBridgedToObjectiveC)(
|
||||
const Metadata *value, const Metadata *T,
|
||||
const _ObjectiveCBridgeableWitnessTable *witnessTable);
|
||||
|
||||
// func _bridgeToObjectiveC() -> _ObjectiveCType
|
||||
HeapObject *(*bridgeToObjectiveC)(
|
||||
OpaqueValue *self, const Metadata *Self,
|
||||
@@ -2561,12 +2556,6 @@ static bool _dynamicCastValueToClassViaObjCBridgeable(
|
||||
const Metadata *targetType,
|
||||
const _ObjectiveCBridgeableWitnessTable *srcBridgeWitness,
|
||||
DynamicCastFlags flags) {
|
||||
// Check whether the source is bridged to Objective-C.
|
||||
if (!srcBridgeWitness->isBridgedToObjectiveC(srcType, srcType,
|
||||
srcBridgeWitness)) {
|
||||
return _fail(src, srcType, targetType, flags);
|
||||
}
|
||||
|
||||
// Bridge the source value to an object.
|
||||
auto srcBridgedObject =
|
||||
srcBridgeWitness->bridgeToObjectiveC(src, srcType, srcBridgeWitness);
|
||||
@@ -2604,12 +2593,6 @@ static bool _dynamicCastValueToClassExistentialViaObjCBridgeable(
|
||||
const ExistentialTypeMetadata *targetType,
|
||||
const _ObjectiveCBridgeableWitnessTable *srcBridgeWitness,
|
||||
DynamicCastFlags flags) {
|
||||
// Check whether the source is bridged to Objective-C.
|
||||
if (!srcBridgeWitness->isBridgedToObjectiveC(srcType, srcType,
|
||||
srcBridgeWitness)) {
|
||||
return _fail(src, srcType, targetType, flags);
|
||||
}
|
||||
|
||||
// Bridge the source value to an object.
|
||||
auto srcBridgedObject =
|
||||
srcBridgeWitness->bridgeToObjectiveC(src, srcType, srcBridgeWitness);
|
||||
@@ -2646,12 +2629,6 @@ static bool _dynamicCastClassToValueViaObjCBridgeable(
|
||||
const Metadata *targetType,
|
||||
const _ObjectiveCBridgeableWitnessTable *targetBridgeWitness,
|
||||
DynamicCastFlags flags) {
|
||||
// Check whether the target is bridged to Objective-C.
|
||||
if (!targetBridgeWitness->isBridgedToObjectiveC(targetType, targetType,
|
||||
targetBridgeWitness)) {
|
||||
return _fail(src, srcType, targetType, flags);
|
||||
}
|
||||
|
||||
// Determine the class type to which the target value type is bridged.
|
||||
auto targetBridgedClass =
|
||||
targetBridgeWitness->ObjectiveCType(targetType, targetBridgeWitness);
|
||||
@@ -2772,12 +2749,6 @@ static id bridgeAnythingNonVerbatimToObjectiveC(OpaqueValue *src,
|
||||
}
|
||||
|
||||
if (auto srcBridgeWitness = findBridgeWitness(srcType)) {
|
||||
// Check whether the source is bridged to Objective-C.
|
||||
if (!srcBridgeWitness->isBridgedToObjectiveC(srcType, srcType,
|
||||
srcBridgeWitness)) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Bridge the source value to an object.
|
||||
auto srcBridgedObject =
|
||||
srcBridgeWitness->bridgeToObjectiveC(src, srcType, srcBridgeWitness);
|
||||
@@ -2850,30 +2821,6 @@ findBridgeWitness(const Metadata *T) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/// \param value passed at +1, consumed.
|
||||
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
|
||||
extern "C" HeapObject *_swift_bridgeNonVerbatimToObjectiveC(
|
||||
OpaqueValue *value, const Metadata *T
|
||||
) {
|
||||
assert(!swift_isClassOrObjCExistentialTypeImpl(T));
|
||||
|
||||
if (const auto *bridgeWitness = findBridgeWitness(T)) {
|
||||
if (!bridgeWitness->isBridgedToObjectiveC(T, T, bridgeWitness)) {
|
||||
// Witnesses take 'self' at +0, so we still need to consume the +1 argument.
|
||||
T->vw_destroy(value);
|
||||
return nullptr;
|
||||
}
|
||||
auto result = bridgeWitness->bridgeToObjectiveC(value, T, bridgeWitness);
|
||||
// Witnesses take 'self' at +0, so we still need to consume the +1 argument.
|
||||
T->vw_destroy(value);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Consume the +1 argument.
|
||||
T->vw_destroy(value);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
|
||||
extern "C" const Metadata *_swift_getBridgedNonVerbatimObjectiveCType(
|
||||
const Metadata *value, const Metadata *T
|
||||
@@ -2987,8 +2934,7 @@ extern "C" bool _swift_isBridgedNonVerbatimToObjectiveC(
|
||||
assert(!swift_isClassOrObjCExistentialTypeImpl(T));
|
||||
|
||||
auto bridgeWitness = findBridgeWitness(T);
|
||||
return bridgeWitness && bridgeWitness->isBridgedToObjectiveC(value, T,
|
||||
bridgeWitness);
|
||||
return (bool)bridgeWitness;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user