Skip to content

Commit 577e04d

Browse files
authored
Merge pull request #21331 from mikeash/rename-avoid-objc-conflicts
[Stdlib][Overlays] Rename various classes to avoid conflicting ObjC names.
2 parents 8b9c943 + a2cd889 commit 577e04d

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

+587
-348
lines changed

lib/AST/Attr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,10 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
552552
}
553553

554554
case DAK_ObjCRuntimeName: {
555-
Printer.printAttrName("@objc");
555+
Printer.printAttrName("@_objcRuntimeName");
556556
Printer << "(";
557557
auto *attr = cast<ObjCRuntimeNameAttr>(this);
558-
Printer << "\"" << attr->Name << "\"";
558+
Printer << attr->Name;
559559
Printer << ")";
560560
break;
561561
}

stdlib/public/Darwin/AppKit/NSGraphics.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ extension NSWindow.Depth {
181181
}
182182

183183
extension NSAnimationEffect {
184-
private class _CompletionHandlerDelegate : NSObject {
184+
// NOTE: older overlays called this class _CompletionHandlerDelegate.
185+
// The two must coexist without a conflicting ObjC class name, so it
186+
// was renamed. The old name must not be used in the new runtime.
187+
private class __CompletionHandlerDelegate : NSObject {
185188
var completionHandler: () -> Void = { }
186189
@objc func animationEffectDidEnd(_ contextInfo: UnsafeMutableRawPointer?) {
187190
completionHandler()
@@ -190,7 +193,7 @@ extension NSAnimationEffect {
190193
@available(swift 4)
191194
public func show(centeredAt centerLocation: NSPoint, size: NSSize,
192195
completionHandler: @escaping () -> Void = { }) {
193-
let delegate = _CompletionHandlerDelegate()
196+
let delegate = __CompletionHandlerDelegate()
194197
delegate.completionHandler = completionHandler
195198
// Note that the delegate of `__NSShowAnimationEffect` is retained for the
196199
// duration of the animation.
@@ -199,7 +202,7 @@ extension NSAnimationEffect {
199202
centerLocation,
200203
size,
201204
delegate,
202-
#selector(_CompletionHandlerDelegate.animationEffectDidEnd(_:)),
205+
#selector(__CompletionHandlerDelegate.animationEffectDidEnd(_:)),
203206
nil)
204207
}
205208
}

stdlib/public/Darwin/Dispatch/Block.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ public struct DispatchWorkItemFlags : OptionSet, RawRepresentable {
3434
public static let enforceQoS = DispatchWorkItemFlags(rawValue: 0x20)
3535
}
3636

37+
// NOTE: older overlays had Dispatch.DispatchWorkItem as the ObjC name.
38+
// The two must coexist, so it was renamed. The old name must not be
39+
// used in the new runtime. _TtC8Dispatch17_DispatchWorkItem is the
40+
// mangled name for Dispatch._DispatchWorkItem.
3741
@available(macOS 10.10, iOS 8.0, *)
42+
@_objcRuntimeName(_TtC8Dispatch17_DispatchWorkItem)
3843
public class DispatchWorkItem {
3944
internal var _block: _DispatchBlock
4045

stdlib/public/Darwin/Foundation/CharacterSet.swift

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ private func _utfRangeToCFRange(_ inRange : ClosedRange<Unicode.Scalar>) -> CFRa
2929

3030
// MARK: -
3131

32-
fileprivate final class _CharacterSetStorage : Hashable {
32+
// NOTE: older overlays called this class _CharacterSetStorage.
33+
// The two must coexist without a conflicting ObjC class name, so it
34+
// was renamed. The old name must not be used in the new runtime.
35+
fileprivate final class __CharacterSetStorage : Hashable {
3336
fileprivate enum Backing {
3437
case immutable(CFCharacterSet)
3538
case mutable(CFMutableCharacterSet)
@@ -58,7 +61,7 @@ fileprivate final class _CharacterSetStorage : Hashable {
5861
}
5962
}
6063

61-
fileprivate static func ==(lhs : _CharacterSetStorage, rhs : _CharacterSetStorage) -> Bool {
64+
fileprivate static func ==(lhs : __CharacterSetStorage, rhs : __CharacterSetStorage) -> Bool {
6265
switch (lhs._backing, rhs._backing) {
6366
case (.immutable(let cs1), .immutable(let cs2)):
6467
return CFEqual(cs1, cs2)
@@ -73,12 +76,12 @@ fileprivate final class _CharacterSetStorage : Hashable {
7376

7477
// MARK: -
7578

76-
fileprivate func mutableCopy() -> _CharacterSetStorage {
79+
fileprivate func mutableCopy() -> __CharacterSetStorage {
7780
switch _backing {
7881
case .immutable(let cs):
79-
return _CharacterSetStorage(mutableReference: CFCharacterSetCreateMutableCopy(nil, cs))
82+
return __CharacterSetStorage(mutableReference: CFCharacterSetCreateMutableCopy(nil, cs))
8083
case .mutable(let cs):
81-
return _CharacterSetStorage(mutableReference: CFCharacterSetCreateMutableCopy(nil, cs))
84+
return __CharacterSetStorage(mutableReference: CFCharacterSetCreateMutableCopy(nil, cs))
8285
}
8386
}
8487

@@ -223,7 +226,7 @@ fileprivate final class _CharacterSetStorage : Hashable {
223226

224227

225228
// When the underlying collection does not have a method to return new CharacterSets with changes applied, so we will copy and apply here
226-
private static func _apply(_ lhs : _CharacterSetStorage, _ rhs : _CharacterSetStorage, _ f : (CFMutableCharacterSet, CFCharacterSet) -> ()) -> CharacterSet {
229+
private static func _apply(_ lhs : __CharacterSetStorage, _ rhs : __CharacterSetStorage, _ f : (CFMutableCharacterSet, CFCharacterSet) -> ()) -> CharacterSet {
227230
let copyOfMe : CFMutableCharacterSet
228231
switch lhs._backing {
229232
case .immutable(let cs):
@@ -239,10 +242,10 @@ fileprivate final class _CharacterSetStorage : Hashable {
239242
f(copyOfMe, cs)
240243
}
241244

242-
return CharacterSet(_uncopiedStorage: _CharacterSetStorage(mutableReference: copyOfMe))
245+
return CharacterSet(_uncopiedStorage: __CharacterSetStorage(mutableReference: copyOfMe))
243246
}
244247

245-
private func _applyMutation(_ other : _CharacterSetStorage, _ f : (CFMutableCharacterSet, CFCharacterSet) -> ()) {
248+
private func _applyMutation(_ other : __CharacterSetStorage, _ f : (CFMutableCharacterSet, CFCharacterSet) -> ()) {
246249
switch _backing {
247250
case .immutable(let cs):
248251
let r = CFCharacterSetCreateMutableCopy(nil, cs)!
@@ -267,47 +270,47 @@ fileprivate final class _CharacterSetStorage : Hashable {
267270
fileprivate var inverted : CharacterSet {
268271
switch _backing {
269272
case .immutable(let cs):
270-
return CharacterSet(_uncopiedStorage: _CharacterSetStorage(immutableReference: CFCharacterSetCreateInvertedSet(nil, cs)))
273+
return CharacterSet(_uncopiedStorage: __CharacterSetStorage(immutableReference: CFCharacterSetCreateInvertedSet(nil, cs)))
271274
case .mutable(let cs):
272275
// Even if input is mutable, the result is immutable
273-
return CharacterSet(_uncopiedStorage: _CharacterSetStorage(immutableReference: CFCharacterSetCreateInvertedSet(nil, cs)))
276+
return CharacterSet(_uncopiedStorage: __CharacterSetStorage(immutableReference: CFCharacterSetCreateInvertedSet(nil, cs)))
274277
}
275278
}
276279

277-
fileprivate func union(_ other: _CharacterSetStorage) -> CharacterSet {
278-
return _CharacterSetStorage._apply(self, other, CFCharacterSetUnion)
280+
fileprivate func union(_ other: __CharacterSetStorage) -> CharacterSet {
281+
return __CharacterSetStorage._apply(self, other, CFCharacterSetUnion)
279282
}
280283

281-
fileprivate func formUnion(_ other: _CharacterSetStorage) {
284+
fileprivate func formUnion(_ other: __CharacterSetStorage) {
282285
_applyMutation(other, CFCharacterSetUnion)
283286
}
284287

285-
fileprivate func intersection(_ other: _CharacterSetStorage) -> CharacterSet {
286-
return _CharacterSetStorage._apply(self, other, CFCharacterSetIntersect)
288+
fileprivate func intersection(_ other: __CharacterSetStorage) -> CharacterSet {
289+
return __CharacterSetStorage._apply(self, other, CFCharacterSetIntersect)
287290
}
288291

289-
fileprivate func formIntersection(_ other: _CharacterSetStorage) {
292+
fileprivate func formIntersection(_ other: __CharacterSetStorage) {
290293
_applyMutation(other, CFCharacterSetIntersect)
291294
}
292295

293-
fileprivate func subtracting(_ other: _CharacterSetStorage) -> CharacterSet {
296+
fileprivate func subtracting(_ other: __CharacterSetStorage) -> CharacterSet {
294297
return intersection(other.inverted._storage)
295298
}
296299

297-
fileprivate func subtract(_ other: _CharacterSetStorage) {
300+
fileprivate func subtract(_ other: __CharacterSetStorage) {
298301
_applyMutation(other.inverted._storage, CFCharacterSetIntersect)
299302
}
300303

301-
fileprivate func symmetricDifference(_ other: _CharacterSetStorage) -> CharacterSet {
304+
fileprivate func symmetricDifference(_ other: __CharacterSetStorage) -> CharacterSet {
302305
return union(other).subtracting(intersection(other))
303306
}
304307

305-
fileprivate func formSymmetricDifference(_ other: _CharacterSetStorage) {
308+
fileprivate func formSymmetricDifference(_ other: __CharacterSetStorage) {
306309
// This feels like cheating
307310
_backing = symmetricDifference(other)._storage._backing
308311
}
309312

310-
fileprivate func isSuperset(of other: _CharacterSetStorage) -> Bool {
313+
fileprivate func isSuperset(of other: __CharacterSetStorage) -> Bool {
311314
switch _backing {
312315
case .immutable(let cs):
313316
switch other._backing {
@@ -363,43 +366,43 @@ fileprivate final class _CharacterSetStorage : Hashable {
363366
public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgebra {
364367
public typealias ReferenceType = NSCharacterSet
365368

366-
fileprivate var _storage : _CharacterSetStorage
369+
fileprivate var _storage : __CharacterSetStorage
367370

368371
// MARK: Init methods
369372

370373
/// Initialize an empty instance.
371374
public init() {
372375
// It's unlikely that we are creating an empty character set with no intention to mutate it
373-
_storage = _CharacterSetStorage(mutableReference: CFCharacterSetCreateMutable(nil))
376+
_storage = __CharacterSetStorage(mutableReference: CFCharacterSetCreateMutable(nil))
374377
}
375378

376379
/// Initialize with a range of integers.
377380
///
378381
/// It is the caller's responsibility to ensure that the values represent valid `Unicode.Scalar` values, if that is what is desired.
379382
public init(charactersIn range: Range<Unicode.Scalar>) {
380-
_storage = _CharacterSetStorage(immutableReference: CFCharacterSetCreateWithCharactersInRange(nil, _utfRangeToCFRange(range)))
383+
_storage = __CharacterSetStorage(immutableReference: CFCharacterSetCreateWithCharactersInRange(nil, _utfRangeToCFRange(range)))
381384
}
382385

383386
/// Initialize with a closed range of integers.
384387
///
385388
/// It is the caller's responsibility to ensure that the values represent valid `Unicode.Scalar` values, if that is what is desired.
386389
public init(charactersIn range: ClosedRange<Unicode.Scalar>) {
387-
_storage = _CharacterSetStorage(immutableReference: CFCharacterSetCreateWithCharactersInRange(nil, _utfRangeToCFRange(range)))
390+
_storage = __CharacterSetStorage(immutableReference: CFCharacterSetCreateWithCharactersInRange(nil, _utfRangeToCFRange(range)))
388391
}
389392

390393
/// Initialize with the characters in the given string.
391394
///
392395
/// - parameter string: The string content to inspect for characters.
393396
public init(charactersIn string: __shared String) {
394-
_storage = _CharacterSetStorage(immutableReference: CFCharacterSetCreateWithCharactersInString(nil, string as CFString))
397+
_storage = __CharacterSetStorage(immutableReference: CFCharacterSetCreateWithCharactersInString(nil, string as CFString))
395398
}
396399

397400
/// Initialize with a bitmap representation.
398401
///
399402
/// This method is useful for creating a character set object with data from a file or other external data source.
400403
/// - parameter data: The bitmap representation.
401404
public init(bitmapRepresentation data: __shared Data) {
402-
_storage = _CharacterSetStorage(immutableReference: CFCharacterSetCreateWithBitmapRepresentation(nil, data as CFData))
405+
_storage = __CharacterSetStorage(immutableReference: CFCharacterSetCreateWithBitmapRepresentation(nil, data as CFData))
403406
}
404407

405408
/// Initialize with the contents of a file.
@@ -409,26 +412,26 @@ public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgeb
409412
public init?(contentsOfFile file: __shared String) {
410413
do {
411414
let data = try Data(contentsOf: URL(fileURLWithPath: file), options: .mappedIfSafe)
412-
_storage = _CharacterSetStorage(immutableReference: CFCharacterSetCreateWithBitmapRepresentation(nil, data as CFData))
415+
_storage = __CharacterSetStorage(immutableReference: CFCharacterSetCreateWithBitmapRepresentation(nil, data as CFData))
413416
} catch {
414417
return nil
415418
}
416419
}
417420

418421
fileprivate init(_bridged characterSet: __shared NSCharacterSet) {
419-
_storage = _CharacterSetStorage(immutableReference: characterSet.copy() as! CFCharacterSet)
422+
_storage = __CharacterSetStorage(immutableReference: characterSet.copy() as! CFCharacterSet)
420423
}
421424

422425
fileprivate init(_uncopiedImmutableReference characterSet: CFCharacterSet) {
423-
_storage = _CharacterSetStorage(immutableReference: characterSet)
426+
_storage = __CharacterSetStorage(immutableReference: characterSet)
424427
}
425428

426-
fileprivate init(_uncopiedStorage : _CharacterSetStorage) {
429+
fileprivate init(_uncopiedStorage : __CharacterSetStorage) {
427430
_storage = _uncopiedStorage
428431
}
429432

430433
fileprivate init(_builtIn: __shared CFCharacterSetPredefinedSet) {
431-
_storage = _CharacterSetStorage(immutableReference: CFCharacterSetGetPredefined(_builtIn))
434+
_storage = __CharacterSetStorage(immutableReference: CFCharacterSetGetPredefined(_builtIn))
432435
}
433436

434437
// MARK: Static functions

0 commit comments

Comments
 (0)