Skip to content

Commit c6148cf

Browse files
committed
Foundation: make some functions more visible
These ivars and functions are referenced elsewhere in Foundation. We were previously relying on the compiler exporting functions more aggressively which would ensure that these were emitted even when not meant to be used outside of the current module. This marks these interfaces as `internal` to ensure that references from other source files are emitted with more aggressive internalization by the compiler.
1 parent cc90ac5 commit c6148cf

File tree

7 files changed

+51
-50
lines changed

7 files changed

+51
-50
lines changed

Sources/Foundation/NSCharacterSet.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ fileprivate extension String {
6262

6363
open class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
6464
typealias CFType = CFCharacterSet
65-
private var _base = _CFInfo(typeID: CFCharacterSetGetTypeID())
66-
private var _hashValue = UInt(0) // CFHashCode
67-
private var _buffer: UnsafeMutableRawPointer? = nil
68-
private var _length = Int(0) // CFIndex
69-
private var _annex: UnsafeMutableRawPointer? = nil
65+
internal var _base = _CFInfo(typeID: CFCharacterSetGetTypeID())
66+
internal var _hashValue = UInt(0) // CFHashCode
67+
internal var _buffer: UnsafeMutableRawPointer? = nil
68+
internal var _length = Int(0) // CFIndex
69+
internal var _annex: UnsafeMutableRawPointer? = nil
7070

7171
internal var _cfObject: CFType {
7272
return unsafeBitCast(self, to: CFType.self)

Sources/Foundation/NSCoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ open class NSCoder : NSObject {
745745
_hasFailed = true
746746
}
747747

748-
internal private(set) var _hasFailed = false
748+
internal var _hasFailed = false
749749

750750
open internal(set) var decodingFailurePolicy: NSCoder.DecodingFailurePolicy = .raiseException
751751

Sources/Foundation/NSData.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extension NSData {
5656
}
5757
}
5858

59-
private final class _NSDataDeallocator {
59+
internal final class _NSDataDeallocator {
6060
var handler: (UnsafeMutableRawPointer, Int) -> Void = {_,_ in }
6161
}
6262

@@ -70,12 +70,12 @@ private let __kCFDontDeallocate: CFOptionFlags = 4
7070
open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
7171
typealias CFType = CFData
7272

73-
private var _base = _CFInfo(typeID: CFDataGetTypeID())
74-
private var _length: Int = 0 // CFIndex
75-
private var _capacity: Int = 0 // CFIndex
76-
private var _deallocator: UnsafeMutableRawPointer? = nil // for CF only
77-
private var _deallocHandler: _NSDataDeallocator? = _NSDataDeallocator() // for Swift
78-
private var _bytes: UnsafeMutablePointer<UInt8>? = nil
73+
internal var _base = _CFInfo(typeID: CFDataGetTypeID())
74+
internal var _length: Int = 0 // CFIndex
75+
internal var _capacity: Int = 0 // CFIndex
76+
internal var _deallocator: UnsafeMutableRawPointer? = nil // for CF only
77+
internal var _deallocHandler: _NSDataDeallocator? = _NSDataDeallocator() // for Swift
78+
internal var _bytes: UnsafeMutablePointer<UInt8>? = nil
7979

8080
internal final var _cfObject: CFType {
8181
if type(of: self) === NSData.self || type(of: self) === NSMutableData.self {
@@ -112,7 +112,7 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
112112
}
113113
}
114114

115-
fileprivate init(bytes: UnsafeMutableRawPointer?, length: Int, copy: Bool = false, deallocator: ((UnsafeMutableRawPointer, Int) -> Void)? = nil) {
115+
internal init(bytes: UnsafeMutableRawPointer?, length: Int, copy: Bool = false, deallocator: ((UnsafeMutableRawPointer, Int) -> Void)? = nil) {
116116
super.init()
117117
_init(bytes: bytes, length: length, copy: copy, deallocator: deallocator)
118118
}

Sources/Foundation/NSDictionary.swift

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@
1414
import Dispatch
1515
#endif
1616

17+
fileprivate func getDescription(of object: Any) -> String? {
18+
switch object {
19+
case let nsArray as NSArray:
20+
return nsArray.description(withLocale: nil, indent: 1)
21+
case let nsDecimalNumber as NSDecimalNumber:
22+
return nsDecimalNumber.description(withLocale: nil)
23+
case let nsDate as NSDate:
24+
return nsDate.description(with: nil)
25+
case let nsOrderedSet as NSOrderedSet:
26+
return nsOrderedSet.description(withLocale: nil)
27+
case let nsSet as NSSet:
28+
return nsSet.description(withLocale: nil)
29+
case let nsDictionary as NSDictionary:
30+
return nsDictionary.description(withLocale: nil)
31+
case let hashableObject as Dictionary<AnyHashable, Any>:
32+
return hashableObject._nsObject.description(withLocale: nil, indent: 1)
33+
default:
34+
return nil
35+
}
36+
}
37+
38+
1739
open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCoding, ExpressibleByDictionaryLiteral {
1840
private let _cfinfo = _CFInfo(typeID: CFDictionaryGetTypeID())
1941
internal var _storage: [NSObject: AnyObject]
@@ -299,27 +321,6 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
299321
return description(withLocale: nil)
300322
}
301323

302-
private func getDescription(of object: Any) -> String? {
303-
switch object {
304-
case let nsArray as NSArray:
305-
return nsArray.description(withLocale: nil, indent: 1)
306-
case let nsDecimalNumber as NSDecimalNumber:
307-
return nsDecimalNumber.description(withLocale: nil)
308-
case let nsDate as NSDate:
309-
return nsDate.description(with: nil)
310-
case let nsOrderedSet as NSOrderedSet:
311-
return nsOrderedSet.description(withLocale: nil)
312-
case let nsSet as NSSet:
313-
return nsSet.description(withLocale: nil)
314-
case let nsDictionary as NSDictionary:
315-
return nsDictionary.description(withLocale: nil)
316-
case let hashableObject as Dictionary<AnyHashable, Any>:
317-
return hashableObject._nsObject.description(withLocale: nil, indent: 1)
318-
default:
319-
return nil
320-
}
321-
}
322-
323324
open var descriptionInStringsFileFormat: String {
324325
var lines = [String]()
325326
for key in self.allKeys {

Sources/Foundation/NSNumber.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ extension NSNumber : ExpressibleByFloatLiteral, ExpressibleByIntegerLiteral, Exp
594594

595595
}
596596

597-
private struct CFSInt128Struct {
597+
internal struct CFSInt128Struct {
598598
var high: Int64
599599
var low: UInt64
600600
}
@@ -606,8 +606,8 @@ fileprivate func cast<T, U>(_ t: T) -> U {
606606
open class NSNumber : NSValue {
607607
typealias CFType = CFNumber
608608
// This layout MUST be the same as CFNumber so that they are bridgeable
609-
private var _base = _CFInfo(typeID: CFNumberGetTypeID())
610-
private var _pad: UInt64 = 0
609+
internal var _base = _CFInfo(typeID: CFNumberGetTypeID())
610+
internal var _pad: UInt64 = 0
611611

612612
internal final var _cfObject: CFType {
613613
return unsafeBitCast(self, to: CFType.self)
@@ -903,7 +903,7 @@ open class NSNumber : NSValue {
903903
return .init(truncatingIfNeeded: value.low)
904904
}
905905

906-
private var int128Value: CFSInt128Struct {
906+
internal var int128Value: CFSInt128Struct {
907907
var value = CFSInt128Struct(high: 0, low: 0)
908908
CFNumberGetValue(_cfObject, kCFNumberSInt128Type, &value)
909909
return value

Sources/Foundation/NSObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ open class NSObject : NSObjectProtocol, Equatable, Hashable {
367367
// Please note:
368368
// the following methods are not overridable in swift-corelibs-foundation.
369369

370-
private class var nsObjectSuperclass: NSObject.Type? {
370+
internal class var nsObjectSuperclass: NSObject.Type? {
371371
// Pretend that {Swift,}Foundation.NSObject is the top of the class hierarchy.
372372
// On Darwin, avoids dipping into the class hierarchy that exists above this class,
373373
// which is ultimately rooted in the ObjC NSObject class.

Sources/Foundation/Progress.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ import Dispatch
3030
*/
3131
open class Progress : NSObject {
3232

33-
private weak var _parent : Progress?
34-
private var _children : Set<Progress>
35-
private var _selfFraction : _ProgressFraction
36-
private var _childFraction : _ProgressFraction
37-
private var _userInfo : [ProgressUserInfoKey : Any]
33+
internal weak var _parent : Progress?
34+
internal var _children : Set<Progress>
35+
internal var _selfFraction : _ProgressFraction
36+
internal var _childFraction : _ProgressFraction
37+
internal var _userInfo : [ProgressUserInfoKey : Any]
3838

3939
// This is set once, but after initialization
40-
private var _portionOfParent : Int64
40+
internal var _portionOfParent : Int64
4141

4242
static private var _tsdKey = "_Foundation_CurrentProgressKey"
4343

@@ -167,7 +167,7 @@ open class Progress : NSObject {
167167
}
168168
}
169169

170-
private func _setParent(_ parent: Progress, portion: Int64) {
170+
internal func _setParent(_ parent: Progress, portion: Int64) {
171171
_parent = parent
172172
_portionOfParent = portion
173173

@@ -416,18 +416,18 @@ open class Progress : NSObject {
416416
// MARK: -
417417
// MARK: Implementation of unit counts
418418

419-
private var _overallFraction : _ProgressFraction {
419+
internal var _overallFraction : _ProgressFraction {
420420
return _selfFraction + _childFraction
421421
}
422422

423-
private func _addCompletedUnitCount(_ unitCount : Int64) {
423+
internal func _addCompletedUnitCount(_ unitCount : Int64) {
424424
let old = _overallFraction
425425
_selfFraction.completed += unitCount
426426
let new = _overallFraction
427427
_updateFractionCompleted(from: old, to: new)
428428
}
429429

430-
private func _updateFractionCompleted(from: _ProgressFraction, to: _ProgressFraction) {
430+
internal func _updateFractionCompleted(from: _ProgressFraction, to: _ProgressFraction) {
431431
if from != to {
432432
_parent?._updateChild(self, from: from, to: to, portion: _portionOfParent)
433433
}

0 commit comments

Comments
 (0)