Skip to content

[5.0][Stdlib][Overlays] Rename various classes to avoid conflicting ObjC names. #21433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/AST/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,10 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
}

case DAK_ObjCRuntimeName: {
Printer.printAttrName("@objc");
Printer.printAttrName("@_objcRuntimeName");
Printer << "(";
auto *attr = cast<ObjCRuntimeNameAttr>(this);
Printer << "\"" << attr->Name << "\"";
Printer << attr->Name;
Printer << ")";
break;
}
Expand Down
9 changes: 6 additions & 3 deletions stdlib/public/SDK/AppKit/NSGraphics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ extension NSWindow.Depth {
}

extension NSAnimationEffect {
private class _CompletionHandlerDelegate : NSObject {
// NOTE: older overlays called this class _CompletionHandlerDelegate.
// The two must coexist without a conflicting ObjC class name, so it
// was renamed. The old name must not be used in the new runtime.
private class __CompletionHandlerDelegate : NSObject {
var completionHandler: () -> Void = { }
@objc func animationEffectDidEnd(_ contextInfo: UnsafeMutableRawPointer?) {
completionHandler()
Expand All @@ -190,7 +193,7 @@ extension NSAnimationEffect {
@available(swift 4)
public func show(centeredAt centerLocation: NSPoint, size: NSSize,
completionHandler: @escaping () -> Void = { }) {
let delegate = _CompletionHandlerDelegate()
let delegate = __CompletionHandlerDelegate()
delegate.completionHandler = completionHandler
// Note that the delegate of `__NSShowAnimationEffect` is retained for the
// duration of the animation.
Expand All @@ -199,7 +202,7 @@ extension NSAnimationEffect {
centerLocation,
size,
delegate,
#selector(_CompletionHandlerDelegate.animationEffectDidEnd(_:)),
#selector(__CompletionHandlerDelegate.animationEffectDidEnd(_:)),
nil)
}
}
Expand Down
5 changes: 5 additions & 0 deletions stdlib/public/SDK/Dispatch/Block.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public struct DispatchWorkItemFlags : OptionSet, RawRepresentable {
public static let enforceQoS = DispatchWorkItemFlags(rawValue: 0x20)
}

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

Expand Down
67 changes: 35 additions & 32 deletions stdlib/public/SDK/Foundation/CharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ private func _utfRangeToCFRange(_ inRange : ClosedRange<Unicode.Scalar>) -> CFRa

// MARK: -

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

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

// MARK: -

fileprivate func mutableCopy() -> _CharacterSetStorage {
fileprivate func mutableCopy() -> __CharacterSetStorage {
switch _backing {
case .immutable(let cs):
return _CharacterSetStorage(mutableReference: CFCharacterSetCreateMutableCopy(nil, cs))
return __CharacterSetStorage(mutableReference: CFCharacterSetCreateMutableCopy(nil, cs))
case .mutable(let cs):
return _CharacterSetStorage(mutableReference: CFCharacterSetCreateMutableCopy(nil, cs))
return __CharacterSetStorage(mutableReference: CFCharacterSetCreateMutableCopy(nil, cs))
}
}

Expand Down Expand Up @@ -223,7 +226,7 @@ fileprivate final class _CharacterSetStorage : Hashable {


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

return CharacterSet(_uncopiedStorage: _CharacterSetStorage(mutableReference: copyOfMe))
return CharacterSet(_uncopiedStorage: __CharacterSetStorage(mutableReference: copyOfMe))
}

private func _applyMutation(_ other : _CharacterSetStorage, _ f : (CFMutableCharacterSet, CFCharacterSet) -> ()) {
private func _applyMutation(_ other : __CharacterSetStorage, _ f : (CFMutableCharacterSet, CFCharacterSet) -> ()) {
switch _backing {
case .immutable(let cs):
let r = CFCharacterSetCreateMutableCopy(nil, cs)!
Expand All @@ -267,47 +270,47 @@ fileprivate final class _CharacterSetStorage : Hashable {
fileprivate var inverted : CharacterSet {
switch _backing {
case .immutable(let cs):
return CharacterSet(_uncopiedStorage: _CharacterSetStorage(immutableReference: CFCharacterSetCreateInvertedSet(nil, cs)))
return CharacterSet(_uncopiedStorage: __CharacterSetStorage(immutableReference: CFCharacterSetCreateInvertedSet(nil, cs)))
case .mutable(let cs):
// Even if input is mutable, the result is immutable
return CharacterSet(_uncopiedStorage: _CharacterSetStorage(immutableReference: CFCharacterSetCreateInvertedSet(nil, cs)))
return CharacterSet(_uncopiedStorage: __CharacterSetStorage(immutableReference: CFCharacterSetCreateInvertedSet(nil, cs)))
}
}

fileprivate func union(_ other: _CharacterSetStorage) -> CharacterSet {
return _CharacterSetStorage._apply(self, other, CFCharacterSetUnion)
fileprivate func union(_ other: __CharacterSetStorage) -> CharacterSet {
return __CharacterSetStorage._apply(self, other, CFCharacterSetUnion)
}

fileprivate func formUnion(_ other: _CharacterSetStorage) {
fileprivate func formUnion(_ other: __CharacterSetStorage) {
_applyMutation(other, CFCharacterSetUnion)
}

fileprivate func intersection(_ other: _CharacterSetStorage) -> CharacterSet {
return _CharacterSetStorage._apply(self, other, CFCharacterSetIntersect)
fileprivate func intersection(_ other: __CharacterSetStorage) -> CharacterSet {
return __CharacterSetStorage._apply(self, other, CFCharacterSetIntersect)
}

fileprivate func formIntersection(_ other: _CharacterSetStorage) {
fileprivate func formIntersection(_ other: __CharacterSetStorage) {
_applyMutation(other, CFCharacterSetIntersect)
}

fileprivate func subtracting(_ other: _CharacterSetStorage) -> CharacterSet {
fileprivate func subtracting(_ other: __CharacterSetStorage) -> CharacterSet {
return intersection(other.inverted._storage)
}

fileprivate func subtract(_ other: _CharacterSetStorage) {
fileprivate func subtract(_ other: __CharacterSetStorage) {
_applyMutation(other.inverted._storage, CFCharacterSetIntersect)
}

fileprivate func symmetricDifference(_ other: _CharacterSetStorage) -> CharacterSet {
fileprivate func symmetricDifference(_ other: __CharacterSetStorage) -> CharacterSet {
return union(other).subtracting(intersection(other))
}

fileprivate func formSymmetricDifference(_ other: _CharacterSetStorage) {
fileprivate func formSymmetricDifference(_ other: __CharacterSetStorage) {
// This feels like cheating
_backing = symmetricDifference(other)._storage._backing
}

fileprivate func isSuperset(of other: _CharacterSetStorage) -> Bool {
fileprivate func isSuperset(of other: __CharacterSetStorage) -> Bool {
switch _backing {
case .immutable(let cs):
switch other._backing {
Expand Down Expand Up @@ -363,43 +366,43 @@ fileprivate final class _CharacterSetStorage : Hashable {
public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgebra {
public typealias ReferenceType = NSCharacterSet

fileprivate var _storage : _CharacterSetStorage
fileprivate var _storage : __CharacterSetStorage

// MARK: Init methods

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

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

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

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

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

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

fileprivate init(_bridged characterSet: __shared NSCharacterSet) {
_storage = _CharacterSetStorage(immutableReference: characterSet.copy() as! CFCharacterSet)
_storage = __CharacterSetStorage(immutableReference: characterSet.copy() as! CFCharacterSet)
}

fileprivate init(_uncopiedImmutableReference characterSet: CFCharacterSet) {
_storage = _CharacterSetStorage(immutableReference: characterSet)
_storage = __CharacterSetStorage(immutableReference: characterSet)
}

fileprivate init(_uncopiedStorage : _CharacterSetStorage) {
fileprivate init(_uncopiedStorage : __CharacterSetStorage) {
_storage = _uncopiedStorage
}

fileprivate init(_builtIn: __shared CFCharacterSetPredefinedSet) {
_storage = _CharacterSetStorage(immutableReference: CFCharacterSetGetPredefined(_builtIn))
_storage = __CharacterSetStorage(immutableReference: CFCharacterSetGetPredefined(_builtIn))
}

// MARK: Static functions
Expand Down
Loading