Skip to content

Commit 798edb9

Browse files
committed
[Runtime][Stdlib][Overlays] Rename various Objective-C classes and methods that would conflict when loading old Swift libraries into a process alongside ABI-stable libraries.
rdar://problem/35768222
1 parent c94bc1d commit 798edb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+275
-275
lines changed

docs/SIL.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ typed, so aliasing of classes is constrained by the type system as follows:
16661666
A violation of the above aliasing rules only results in undefined
16671667
behavior if the aliasing references are dereferenced within Swift code.
16681668
For example,
1669-
``_SwiftNativeNS[Array|Dictionary|String]`` classes alias with
1669+
``__SwiftNativeNS[Array|Dictionary|String]`` classes alias with
16701670
``NS[Array|Dictionary|String]`` classes even though they are not
16711671
statically related. Since Swift never directly accesses stored
16721672
properties on the Foundation classes, this aliasing does not pose a

include/swift/Remote/MetadataReader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class MetadataReader {
309309
// error existential with NSError-compatible layout.
310310
std::string ObjCClassName;
311311
if (readObjCClassName(*MetadataAddress, ObjCClassName)) {
312-
if (ObjCClassName == "_SwiftNativeNSError")
312+
if (ObjCClassName == "__SwiftNativeNSError")
313313
isObjC = true;
314314
} else {
315315
// Otherwise, we can check to see if this is a class metadata with the

lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ bool COWArrayOpt::checkSafeArrayElementUse(SILInstruction *UseInst,
753753
// %57 = load %56 : $*Builtin.BridgeObject from Array<Int>
754754
// %58 = unchecked_ref_cast %57 : $Builtin.BridgeObject to
755755
// $_ContiguousArray
756-
// %59 = unchecked_ref_cast %58 : $_ContiguousArrayStorageBase to
756+
// %59 = unchecked_ref_cast %58 : $__ContiguousArrayStorageBase to
757757
// $Builtin.NativeObject
758758
// %60 = struct_extract %53 : $UnsafeMutablePointer<Int>,
759759
// #UnsafeMutablePointer

stdlib/private/StdlibUnittestFoundationExtras/StdlibUnittestFoundationExtras.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal var _temporaryLocaleCurrentLocale: NSLocale?
1818

1919
extension NSLocale {
2020
@objc
21-
public class func _swiftUnittest_currentLocale() -> NSLocale {
21+
public class func __swiftUnittest_currentLocale() -> NSLocale {
2222
return _temporaryLocaleCurrentLocale!
2323
}
2424
}
@@ -34,9 +34,9 @@ public func withOverriddenLocaleCurrentLocale<Result>(
3434
}
3535

3636
guard let newMethod = class_getClassMethod(
37-
NSLocale.self, #selector(NSLocale._swiftUnittest_currentLocale)) as Optional
37+
NSLocale.self, #selector(NSLocale.__swiftUnittest_currentLocale)) as Optional
3838
else {
39-
preconditionFailure("Could not find +[Locale _swiftUnittest_currentLocale]")
39+
preconditionFailure("Could not find +[Locale __swiftUnittest_currentLocale]")
4040
}
4141

4242
precondition(_temporaryLocaleCurrentLocale == nil,

stdlib/public/SDK/Foundation/Data.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -929,20 +929,20 @@ internal final class _DataStorage {
929929

930930
switch _backing {
931931
case .swift:
932-
return _NSSwiftData(backing: self, range: range)
932+
return __NSSwiftData(backing: self, range: range)
933933
case .immutable(let d):
934934
guard range.lowerBound == 0 && range.upperBound == _length else {
935-
return _NSSwiftData(backing: self, range: range)
935+
return __NSSwiftData(backing: self, range: range)
936936
}
937937
return d
938938
case .mutable(let d):
939939
guard range.lowerBound == 0 && range.upperBound == _length else {
940-
return _NSSwiftData(backing: self, range: range)
940+
return __NSSwiftData(backing: self, range: range)
941941
}
942942
return d
943943
case .customReference(let d):
944944
guard range.lowerBound == 0 && range.upperBound == d.length else {
945-
return _NSSwiftData(backing: self, range: range)
945+
return __NSSwiftData(backing: self, range: range)
946946
}
947947
return d
948948
case .customMutableReference(let d):
@@ -966,7 +966,7 @@ internal final class _DataStorage {
966966
}
967967
}
968968

969-
internal class _NSSwiftData : NSData {
969+
internal class __NSSwiftData : NSData {
970970
var _backing: _DataStorage!
971971
var _range: Range<Data.Index>!
972972

stdlib/public/SDK/Foundation/NSDictionary.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ extension NSDictionary : Sequence {
173173
// Bridging subscript.
174174
@objc
175175
public subscript(key: Any) -> Any? {
176-
@objc(_swift_objectForKeyedSubscript:)
176+
@objc(__swift_objectForKeyedSubscript:)
177177
get {
178178
// Deliberately avoid the subscript operator in case the dictionary
179179
// contains non-copyable keys. This is rare since NSMutableDictionary
@@ -193,11 +193,11 @@ extension NSDictionary : Sequence {
193193
extension NSMutableDictionary {
194194
// Bridging subscript.
195195
@objc override public subscript(key: Any) -> Any? {
196-
@objc(_swift_objectForKeyedSubscript:)
196+
@objc(__swift_objectForKeyedSubscript:)
197197
get {
198198
return self.object(forKey: key)
199199
}
200-
@objc(_swift_setObject:forKeyedSubscript:)
200+
@objc(__swift_setObject:forKeyedSubscript:)
201201
set {
202202
// FIXME: Unfortunate that the `NSCopying` check has to be done at
203203
// runtime.
@@ -218,7 +218,7 @@ extension NSDictionary {
218218
/// - Returns: An initialized dictionary--which might be different
219219
/// than the original receiver--containing the keys and values
220220
/// found in `otherDictionary`.
221-
@objc(_swiftInitWithDictionary_NSDictionary:)
221+
@objc(__swiftInitWithDictionary_NSDictionary:)
222222
public convenience init(dictionary otherDictionary: NSDictionary) {
223223
// FIXME(performance)(compiler limitation): we actually want to do just
224224
// `self = otherDictionary.copy()`, but Swift does not have factory

stdlib/public/SDK/Foundation/NSObject.swift

+29-29
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,34 @@ public protocol NSKeyValueObservingCustomization : NSObjectProtocol {
3535

3636
fileprivate extension NSObject {
3737

38-
@objc class func _old_unswizzled_automaticallyNotifiesObservers(forKey key: String?) -> Bool {
38+
@objc class func __old_unswizzled_automaticallyNotifiesObservers(forKey key: String?) -> Bool {
3939
fatalError("Should never be reached")
4040
}
4141

42-
@objc class func _old_unswizzled_keyPathsForValuesAffectingValue(forKey key: String?) -> Set<String> {
42+
@objc class func __old_unswizzled_keyPathsForValuesAffectingValue(forKey key: String?) -> Set<String> {
4343
fatalError("Should never be reached")
4444
}
4545

4646
}
4747

48-
@objc private class _KVOKeyPathBridgeMachinery : NSObject {
48+
@objc private class __KVOKeyPathBridgeMachinery : NSObject {
4949
@nonobjc static var keyPathTable: [String : AnyKeyPath] = {
5050
/*
5151
Move all our methods into place. We want the following:
52-
_KVOKeyPathBridgeMachinery's automaticallyNotifiesObserversForKey:, and keyPathsForValuesAffectingValueForKey: methods replaces NSObject's versions of them
52+
__KVOKeyPathBridgeMachinery's automaticallyNotifiesObserversForKey:, and keyPathsForValuesAffectingValueForKey: methods replaces NSObject's versions of them
5353
NSObject's automaticallyNotifiesObserversForKey:, and keyPathsForValuesAffectingValueForKey: methods replace NSObject's _old_unswizzled_* methods
54-
NSObject's _old_unswizzled_* methods replace _KVOKeyPathBridgeMachinery's methods, and are never invoked
54+
NSObject's _old_unswizzled_* methods replace __KVOKeyPathBridgeMachinery's methods, and are never invoked
5555
*/
5656
let rootClass: AnyClass = NSObject.self
57-
let bridgeClass: AnyClass = _KVOKeyPathBridgeMachinery.self
57+
let bridgeClass: AnyClass = __KVOKeyPathBridgeMachinery.self
5858

5959
let dependentSel = #selector(NSObject.keyPathsForValuesAffectingValue(forKey:))
6060
let rootDependentImpl = class_getClassMethod(rootClass, dependentSel)!
6161
let bridgeDependentImpl = class_getClassMethod(bridgeClass, dependentSel)!
6262
method_exchangeImplementations(rootDependentImpl, bridgeDependentImpl) // NSObject <-> Us
6363

6464
let originalDependentImpl = class_getClassMethod(bridgeClass, dependentSel)! //we swizzled it onto this class, so this is actually NSObject's old implementation
65-
let originalDependentSel = #selector(NSObject._old_unswizzled_keyPathsForValuesAffectingValue(forKey:))
65+
let originalDependentSel = #selector(NSObject.__old_unswizzled_keyPathsForValuesAffectingValue(forKey:))
6666
let dummyDependentImpl = class_getClassMethod(rootClass, originalDependentSel)!
6767
method_exchangeImplementations(originalDependentImpl, dummyDependentImpl) // NSObject's original version <-> NSObject's _old_unswizzled_ version
6868

@@ -72,7 +72,7 @@ fileprivate extension NSObject {
7272
method_exchangeImplementations(rootAutoImpl, bridgeAutoImpl) // NSObject <-> Us
7373

7474
let originalAutoImpl = class_getClassMethod(bridgeClass, autoSel)! //we swizzled it onto this class, so this is actually NSObject's old implementation
75-
let originalAutoSel = #selector(NSObject._old_unswizzled_automaticallyNotifiesObservers(forKey:))
75+
let originalAutoSel = #selector(NSObject.__old_unswizzled_automaticallyNotifiesObservers(forKey:))
7676
let dummyAutoImpl = class_getClassMethod(rootClass, originalAutoSel)!
7777
method_exchangeImplementations(originalAutoImpl, dummyAutoImpl) // NSObject's original version <-> NSObject's _old_unswizzled_ version
7878

@@ -83,62 +83,62 @@ fileprivate extension NSObject {
8383

8484
@nonobjc fileprivate static func _bridgeKeyPath(_ keyPath:AnyKeyPath) -> String {
8585
guard let keyPathString = keyPath._kvcKeyPathString else { fatalError("Could not extract a String from KeyPath \(keyPath)") }
86-
_KVOKeyPathBridgeMachinery.keyPathTableLock.lock()
87-
defer { _KVOKeyPathBridgeMachinery.keyPathTableLock.unlock() }
88-
_KVOKeyPathBridgeMachinery.keyPathTable[keyPathString] = keyPath
86+
__KVOKeyPathBridgeMachinery.keyPathTableLock.lock()
87+
defer { __KVOKeyPathBridgeMachinery.keyPathTableLock.unlock() }
88+
__KVOKeyPathBridgeMachinery.keyPathTable[keyPathString] = keyPath
8989
return keyPathString
9090
}
9191

9292
@nonobjc fileprivate static func _bridgeKeyPath(_ keyPath:String?) -> AnyKeyPath? {
9393
guard let keyPath = keyPath else { return nil }
94-
_KVOKeyPathBridgeMachinery.keyPathTableLock.lock()
95-
defer { _KVOKeyPathBridgeMachinery.keyPathTableLock.unlock() }
96-
let path = _KVOKeyPathBridgeMachinery.keyPathTable[keyPath]
94+
__KVOKeyPathBridgeMachinery.keyPathTableLock.lock()
95+
defer { __KVOKeyPathBridgeMachinery.keyPathTableLock.unlock() }
96+
let path = __KVOKeyPathBridgeMachinery.keyPathTable[keyPath]
9797
return path
9898
}
9999

100100
@objc override class func automaticallyNotifiesObservers(forKey key: String) -> Bool {
101101
//This is swizzled so that it's -[NSObject automaticallyNotifiesObserversForKey:]
102-
if let customizingSelf = self as? NSKeyValueObservingCustomization.Type, let path = _KVOKeyPathBridgeMachinery._bridgeKeyPath(key) {
102+
if let customizingSelf = self as? NSKeyValueObservingCustomization.Type, let path = __KVOKeyPathBridgeMachinery._bridgeKeyPath(key) {
103103
return customizingSelf.automaticallyNotifiesObservers(for: path)
104104
} else {
105-
return self._old_unswizzled_automaticallyNotifiesObservers(forKey: key) //swizzled to be NSObject's original implementation
105+
return self.__old_unswizzled_automaticallyNotifiesObservers(forKey: key) //swizzled to be NSObject's original implementation
106106
}
107107
}
108108

109109
@objc override class func keyPathsForValuesAffectingValue(forKey key: String?) -> Set<String> {
110110
//This is swizzled so that it's -[NSObject keyPathsForValuesAffectingValueForKey:]
111-
if let customizingSelf = self as? NSKeyValueObservingCustomization.Type, let path = _KVOKeyPathBridgeMachinery._bridgeKeyPath(key!) {
111+
if let customizingSelf = self as? NSKeyValueObservingCustomization.Type, let path = __KVOKeyPathBridgeMachinery._bridgeKeyPath(key!) {
112112
let resultSet = customizingSelf.keyPathsAffectingValue(for: path)
113113
return Set(resultSet.lazy.map {
114114
guard let str = $0._kvcKeyPathString else { fatalError("Could not extract a String from KeyPath \($0)") }
115115
return str
116116
})
117117
} else {
118-
return self._old_unswizzled_keyPathsForValuesAffectingValue(forKey: key) //swizzled to be NSObject's original implementation
118+
return self.__old_unswizzled_keyPathsForValuesAffectingValue(forKey: key) //swizzled to be NSObject's original implementation
119119
}
120120
}
121121
}
122122

123123
func _bridgeKeyPathToString(_ keyPath:AnyKeyPath) -> String {
124-
return _KVOKeyPathBridgeMachinery._bridgeKeyPath(keyPath)
124+
return __KVOKeyPathBridgeMachinery._bridgeKeyPath(keyPath)
125125
}
126126

127127
func _bridgeStringToKeyPath(_ keyPath:String) -> AnyKeyPath? {
128-
return _KVOKeyPathBridgeMachinery._bridgeKeyPath(keyPath)
128+
return __KVOKeyPathBridgeMachinery._bridgeKeyPath(keyPath)
129129
}
130130

131-
public class NSKeyValueObservation : NSObject {
131+
public class _NSKeyValueObservation : NSObject {
132132

133133
@nonobjc weak var object : NSObject?
134134
@nonobjc let callback : (NSObject, NSKeyValueObservedChange<Any>) -> Void
135135
@nonobjc let path : String
136136

137137
//workaround for <rdar://problem/31640524> Erroneous (?) error when using bridging in the Foundation overlay
138-
@nonobjc static var swizzler : NSKeyValueObservation? = {
139-
let bridgeClass: AnyClass = NSKeyValueObservation.self
138+
@nonobjc static var swizzler : _NSKeyValueObservation? = {
139+
let bridgeClass: AnyClass = _NSKeyValueObservation.self
140140
let observeSel = #selector(NSObject.observeValue(forKeyPath:of:change:context:))
141-
let swapSel = #selector(NSKeyValueObservation._swizzle_me_observeValue(forKeyPath:of:change:context:))
141+
let swapSel = #selector(_NSKeyValueObservation._swizzle_me_observeValue(forKeyPath:of:change:context:))
142142
let rootObserveImpl = class_getInstanceMethod(bridgeClass, observeSel)
143143
let swapObserveImpl = class_getInstanceMethod(bridgeClass, swapSel)
144144
method_exchangeImplementations(rootObserveImpl, swapObserveImpl)
@@ -147,7 +147,7 @@ public class NSKeyValueObservation : NSObject {
147147

148148
fileprivate init(object: NSObject, keyPath: AnyKeyPath, callback: @escaping (NSObject, NSKeyValueObservedChange<Any>) -> Void) {
149149
path = _bridgeKeyPathToString(keyPath)
150-
let _ = NSKeyValueObservation.swizzler
150+
let _ = _NSKeyValueObservation.swizzler
151151
self.object = object
152152
self.callback = callback
153153
}
@@ -156,7 +156,7 @@ public class NSKeyValueObservation : NSObject {
156156
object?.addObserver(self, forKeyPath: path, options: options, context: nil)
157157
}
158158

159-
///invalidate() will be called automatically when an NSKeyValueObservation is deinited
159+
///invalidate() will be called automatically when an _NSKeyValueObservation is deinited
160160
@objc public func invalidate() {
161161
object?.removeObserver(self, forKeyPath: path, context: nil)
162162
object = nil
@@ -181,13 +181,13 @@ public class NSKeyValueObservation : NSObject {
181181

182182
extension _KeyValueCodingAndObserving {
183183

184-
///when the returned NSKeyValueObservation is deinited or invalidated, it will stop observing
184+
///when the returned _NSKeyValueObservation is deinited or invalidated, it will stop observing
185185
public func observe<Value>(
186186
_ keyPath: KeyPath<Self, Value>,
187187
options: NSKeyValueObservingOptions = [],
188188
changeHandler: @escaping (Self, NSKeyValueObservedChange<Value>) -> Void)
189-
-> NSKeyValueObservation {
190-
let result = NSKeyValueObservation(object: self as! NSObject, keyPath: keyPath) { (obj, change) in
189+
-> _NSKeyValueObservation {
190+
let result = _NSKeyValueObservation(object: self as! NSObject, keyPath: keyPath) { (obj, change) in
191191
let notification = NSKeyValueObservedChange(kind: change.kind,
192192
newValue: change.newValue as? Value,
193193
oldValue: change.oldValue as? Value,

stdlib/public/SDK/SpriteKit/SpriteKit.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public typealias SKColor = UIColor
2424
// this class only exists to allow AnyObject lookup of _copyImageData
2525
// since that method only exists in a private header in SpriteKit, the lookup
2626
// mechanism by default fails to accept it as a valid AnyObject call
27-
@objc class _SpriteKitMethodProvider : NSObject {
27+
@objc class __SpriteKitMethodProvider : NSObject {
2828
override init() { preconditionFailure("don't touch me") }
2929
@objc func _copyImageData() -> NSData! { return nil }
3030
}

stdlib/public/core/Array.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ extension Array {
17611761
_ source: AnyObject
17621762
) -> Array? {
17631763
// If source is deferred, we indirect to get its native storage
1764-
let maybeNative = (source as? _SwiftDeferredNSArray)?._nativeStorage ?? source
1764+
let maybeNative = (source as? __SwiftDeferredNSArray)?._nativeStorage ?? source
17651765

17661766
return (maybeNative as? _ContiguousArrayStorage<Element>).map {
17671767
Array(_ContiguousArrayBuffer($0))

stdlib/public/core/ArrayBuffer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SwiftShims
2020

2121
@usableFromInline
2222
internal typealias _ArrayBridgeStorage
23-
= _BridgeStorage<_ContiguousArrayStorageBase, _NSArrayCore>
23+
= _BridgeStorage<__ContiguousArrayStorageBase, _NSArrayCore>
2424

2525
@usableFromInline
2626
@_fixed_layout

stdlib/public/core/BridgeObjectiveC.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ protocol _NSSwiftValue: class {
596596
}
597597

598598
@usableFromInline
599-
internal class _SwiftValue {
599+
internal class __SwiftValue {
600600
@usableFromInline
601601
let value: Any
602602

@@ -606,7 +606,7 @@ internal class _SwiftValue {
606606
}
607607

608608
@usableFromInline
609-
static let null = _SwiftValue(Optional<Any>.none as Any)
609+
static let null = __SwiftValue(Optional<Any>.none as Any)
610610
}
611611

612612
// Internal stdlib SPI
@@ -623,7 +623,7 @@ public func swift_unboxFromSwiftValueWithType<T>(
623623
}
624624
}
625625

626-
if let box = source as? _SwiftValue {
626+
if let box = source as? __SwiftValue {
627627
if let value = box.value as? T {
628628
result.initialize(to: value)
629629
return true
@@ -644,7 +644,7 @@ public func _swiftValueConformsTo<T>(_ type: T.Type) -> Bool {
644644
if let foundationType = _foundationSwiftValueType {
645645
return foundationType is T.Type
646646
} else {
647-
return _SwiftValue.self is T.Type
647+
return __SwiftValue.self is T.Type
648648
}
649649
}
650650

@@ -665,14 +665,14 @@ extension Optional: _Unwrappable {
665665
}
666666
}
667667

668-
private let _foundationSwiftValueType = _typeByName("Foundation._SwiftValue") as? _NSSwiftValue.Type
668+
private let _foundationSwiftValueType = _typeByName("Foundation.__SwiftValue") as? _NSSwiftValue.Type
669669

670670
@usableFromInline
671671
internal var _nullPlaceholder: AnyObject {
672672
if let foundationType = _foundationSwiftValueType {
673673
return foundationType.null
674674
} else {
675-
return _SwiftValue.null
675+
return __SwiftValue.null
676676
}
677677
}
678678

@@ -681,7 +681,7 @@ func _makeSwiftValue(_ value: Any) -> AnyObject {
681681
if let foundationType = _foundationSwiftValueType {
682682
return foundationType.init(value)
683683
} else {
684-
return _SwiftValue(value)
684+
return __SwiftValue(value)
685685
}
686686
}
687687

0 commit comments

Comments
 (0)