diff --git a/docs/Runtime.md b/docs/Runtime.md index 999ce240383..bcac83cac2b 100644 --- a/docs/Runtime.md +++ b/docs/Runtime.md @@ -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 diff --git a/stdlib/public/SDK/Dispatch/Data.swift b/stdlib/public/SDK/Dispatch/Data.swift index c5f038bcf4f..4593d6a3f73 100644 --- a/stdlib/public/SDK/Dispatch/Data.swift +++ b/stdlib/public/SDK/Dispatch/Data.swift @@ -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) diff --git a/stdlib/public/SDK/Foundation/AffineTransform.swift b/stdlib/public/SDK/Foundation/AffineTransform.swift index af25fa15de9..34d7c916f28 100644 --- a/stdlib/public/SDK/Foundation/AffineTransform.swift +++ b/stdlib/public/SDK/Foundation/AffineTransform.swift @@ -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 } diff --git a/stdlib/public/SDK/Foundation/Calendar.swift b/stdlib/public/SDK/Foundation/Calendar.swift index 201adb2671a..af16d204ebc 100644 --- a/stdlib/public/SDK/Foundation/Calendar.swift +++ b/stdlib/public/SDK/Foundation/Calendar.swift @@ -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() diff --git a/stdlib/public/SDK/Foundation/CharacterSet.swift b/stdlib/public/SDK/Foundation/CharacterSet.swift index c27a36b0842..1e9cfa623df 100644 --- a/stdlib/public/SDK/Foundation/CharacterSet.swift +++ b/stdlib/public/SDK/Foundation/CharacterSet.swift @@ -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 } diff --git a/stdlib/public/SDK/Foundation/Data.swift b/stdlib/public/SDK/Foundation/Data.swift index b182792ab6a..d7152447bc9 100644 --- a/stdlib/public/SDK/Foundation/Data.swift +++ b/stdlib/public/SDK/Foundation/Data.swift @@ -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) diff --git a/stdlib/public/SDK/Foundation/Date.swift b/stdlib/public/SDK/Foundation/Date.swift index 4c923332289..bbae2906ef0 100644 --- a/stdlib/public/SDK/Foundation/Date.swift +++ b/stdlib/public/SDK/Foundation/Date.swift @@ -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) diff --git a/stdlib/public/SDK/Foundation/DateComponents.swift b/stdlib/public/SDK/Foundation/DateComponents.swift index e2d5fb625d6..ac8c92fa2f5 100644 --- a/stdlib/public/SDK/Foundation/DateComponents.swift +++ b/stdlib/public/SDK/Foundation/DateComponents.swift @@ -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 } diff --git a/stdlib/public/SDK/Foundation/DateInterval.swift b/stdlib/public/SDK/Foundation/DateInterval.swift index e15ca20ffe8..757a1e8e63e 100644 --- a/stdlib/public/SDK/Foundation/DateInterval.swift +++ b/stdlib/public/SDK/Foundation/DateInterval.swift @@ -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 } diff --git a/stdlib/public/SDK/Foundation/Decimal.swift b/stdlib/public/SDK/Foundation/Decimal.swift index c563c89d637..1b0de335852 100644 --- a/stdlib/public/SDK/Foundation/Decimal.swift +++ b/stdlib/public/SDK/Foundation/Decimal.swift @@ -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) diff --git a/stdlib/public/SDK/Foundation/Foundation.swift b/stdlib/public/SDK/Foundation/Foundation.swift index b270e174bc2..e029ff42be7 100644 --- a/stdlib/public/SDK/Foundation/Foundation.swift +++ b/stdlib/public/SDK/Foundation/Foundation.swift @@ -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 { diff --git a/stdlib/public/SDK/Foundation/IndexPath.swift b/stdlib/public/SDK/Foundation/IndexPath.swift index 9cf5cc420f4..c6388b8730b 100644 --- a/stdlib/public/SDK/Foundation/IndexPath.swift +++ b/stdlib/public/SDK/Foundation/IndexPath.swift @@ -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 } diff --git a/stdlib/public/SDK/Foundation/IndexSet.swift b/stdlib/public/SDK/Foundation/IndexSet.swift index e7cf56fd2eb..03f897eae3d 100644 --- a/stdlib/public/SDK/Foundation/IndexSet.swift +++ b/stdlib/public/SDK/Foundation/IndexSet.swift @@ -852,10 +852,6 @@ private func _toNSRange(_ r : Range) -> NSRange { } extension IndexSet : _ObjectiveCBridgeable { - public static func _isBridgedToObjectiveC() -> Bool { - return true - } - public static func _getObjectiveCType() -> Any.Type { return NSIndexSet.self } diff --git a/stdlib/public/SDK/Foundation/Locale.swift b/stdlib/public/SDK/Foundation/Locale.swift index 9640e3578a4..691a434a7bb 100644 --- a/stdlib/public/SDK/Foundation/Locale.swift +++ b/stdlib/public/SDK/Foundation/Locale.swift @@ -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 diff --git a/stdlib/public/SDK/Foundation/Measurement.swift b/stdlib/public/SDK/Foundation/Measurement.swift index c135efd445b..24731f30aff 100644 --- a/stdlib/public/SDK/Foundation/Measurement.swift +++ b/stdlib/public/SDK/Foundation/Measurement.swift @@ -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) diff --git a/stdlib/public/SDK/Foundation/NSValue.swift b/stdlib/public/SDK/Foundation/NSValue.swift index b35cd95013a..d5b9209d648 100644 --- a/stdlib/public/SDK/Foundation/NSValue.swift +++ b/stdlib/public/SDK/Foundation/NSValue.swift @@ -11,10 +11,6 @@ //===----------------------------------------------------------------------===// extension NSRange : _ObjectiveCBridgeable { - public static func _isBridgedToObjectiveC() -> Bool { - return true - } - public func _bridgeToObjectiveC() -> NSValue { return NSValue(range: self) } diff --git a/stdlib/public/SDK/Foundation/Notification.swift b/stdlib/public/SDK/Foundation/Notification.swift index e1b7d6df998..6a9318f062e 100644 --- a/stdlib/public/SDK/Foundation/Notification.swift +++ b/stdlib/public/SDK/Foundation/Notification.swift @@ -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 } diff --git a/stdlib/public/SDK/Foundation/PersonNameComponents.swift b/stdlib/public/SDK/Foundation/PersonNameComponents.swift index c672580bda1..dd76d4d1496 100644 --- a/stdlib/public/SDK/Foundation/PersonNameComponents.swift +++ b/stdlib/public/SDK/Foundation/PersonNameComponents.swift @@ -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 } diff --git a/stdlib/public/SDK/Foundation/TimeZone.swift b/stdlib/public/SDK/Foundation/TimeZone.swift index 0d052bd29ee..28572fece28 100644 --- a/stdlib/public/SDK/Foundation/TimeZone.swift +++ b/stdlib/public/SDK/Foundation/TimeZone.swift @@ -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 diff --git a/stdlib/public/SDK/Foundation/URL.swift b/stdlib/public/SDK/Foundation/URL.swift index f468b0a1a34..a5d272d589c 100644 --- a/stdlib/public/SDK/Foundation/URL.swift +++ b/stdlib/public/SDK/Foundation/URL.swift @@ -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 diff --git a/stdlib/public/SDK/Foundation/URLComponents.swift b/stdlib/public/SDK/Foundation/URLComponents.swift index 21d6093551a..8236217a51d 100644 --- a/stdlib/public/SDK/Foundation/URLComponents.swift +++ b/stdlib/public/SDK/Foundation/URLComponents.swift @@ -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 } diff --git a/stdlib/public/SDK/Foundation/URLRequest.swift b/stdlib/public/SDK/Foundation/URLRequest.swift index e4b2e9eb97f..ab08b4d47cf 100644 --- a/stdlib/public/SDK/Foundation/URLRequest.swift +++ b/stdlib/public/SDK/Foundation/URLRequest.swift @@ -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 } diff --git a/stdlib/public/SDK/Foundation/UUID.swift b/stdlib/public/SDK/Foundation/UUID.swift index 0add23af62f..fb3bebf6435 100644 --- a/stdlib/public/SDK/Foundation/UUID.swift +++ b/stdlib/public/SDK/Foundation/UUID.swift @@ -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 diff --git a/stdlib/public/core/ArrayBuffer.swift b/stdlib/public/core/ArrayBuffer.swift index 4f1e27fe311..febbef370a0 100644 --- a/stdlib/public/core/ArrayBuffer.swift +++ b/stdlib/public/core/ArrayBuffer.swift @@ -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 } diff --git a/stdlib/public/core/BridgeObjectiveC.swift b/stdlib/public/core/BridgeObjectiveC.swift index b096c6966a2..46406d460ee 100644 --- a/stdlib/public/core/BridgeObjectiveC.swift +++ b/stdlib/public/core/BridgeObjectiveC.swift @@ -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(_ x: T) -> AnyObject? { - if _fastPath(_isClassOrObjCExistential(T.self)) { - return unsafeBitCast(x, to: AnyObject.self) - } - return _bridgeNonVerbatimToObjectiveC(x) -} - -public func _bridgeToObjectiveCUnconditional(_ 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(_ 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(_ 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(_ x: T) -> AnyObject { if _fastPath(_isClassOrObjCExistential(T.self)) { @@ -217,7 +165,6 @@ public func _bridgeAnythingToObjectiveC(_ x: T) -> AnyObject { return _bridgeAnythingNonVerbatimToObjectiveC(x) } -// TODO: This should subsume `_bridgeNonVerbatimToObjectiveC` above. /// COMPILER_INTRINSIC @_silgen_name("_swift_bridgeAnythingNonVerbatimToObjectiveC") public func _bridgeAnythingNonVerbatimToObjectiveC(_ x: T) -> AnyObject @@ -262,8 +209,6 @@ public func _forceBridgeFromObjectiveC_bridgeable ( /// - 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( /// 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.Type) -> Bool { if _fastPath(_isClassOrObjCExistential(T.self)) { return true diff --git a/stdlib/public/core/ContiguousArrayBuffer.swift b/stdlib/public/core/ContiguousArrayBuffer.swift index ff8711e625e..3b6941176a8 100644 --- a/stdlib/public/core/ContiguousArrayBuffer.swift +++ b/stdlib/public/core/ContiguousArrayBuffer.swift @@ -145,7 +145,7 @@ final class _ContiguousArrayStorage : _ContiguousArrayStorage1 { let resultPtr = result.baseAddress let p = __manager._elementPointer for i in 0.. : _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 } diff --git a/stdlib/public/core/HashedCollections.swift.gyb b/stdlib/public/core/HashedCollections.swift.gyb index 719b6b69c7b..fa516c3fca7 100644 --- a/stdlib/public/core/HashedCollections.swift.gyb +++ b/stdlib/public/core/HashedCollections.swift.gyb @@ -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( 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.. 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): diff --git a/stdlib/public/core/ImplicitlyUnwrappedOptional.swift b/stdlib/public/core/ImplicitlyUnwrappedOptional.swift index 8fb76e12e29..f5a0e1f10cd 100644 --- a/stdlib/public/core/ImplicitlyUnwrappedOptional.swift +++ b/stdlib/public/core/ImplicitlyUnwrappedOptional.swift @@ -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) } } diff --git a/stdlib/public/core/NewtypeWrapper.swift.gyb b/stdlib/public/core/NewtypeWrapper.swift.gyb index d9a04b0127e..13097738d75 100644 --- a/stdlib/public/core/NewtypeWrapper.swift.gyb +++ b/stdlib/public/core/NewtypeWrapper.swift.gyb @@ -30,10 +30,6 @@ public func ${op} (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() } diff --git a/stdlib/public/core/Reflection.swift b/stdlib/public/core/Reflection.swift index f59c3a41be2..2bca46bbd42 100644 --- a/stdlib/public/core/Reflection.swift +++ b/stdlib/public/core/Reflection.swift @@ -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? { diff --git a/stdlib/public/runtime/Casting.cpp b/stdlib/public/runtime/Casting.cpp index fbb2f81ec19..7c4af0ca690 100644 --- a/stdlib/public/runtime/Casting.cpp +++ b/stdlib/public/runtime/Casting.cpp @@ -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