Skip to content

Commit eaa74f1

Browse files
committed
remove private headers from public directory
Clean up the long standing issue with private headers being pushed into the public headers directory. Add a private modulemap so that we can still access the private headers.
1 parent 4346168 commit eaa74f1

Some content is hidden

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

52 files changed

+328
-183
lines changed

CoreFoundation/Base.subproj/SwiftRuntime/CoreFoundation.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,5 @@
9696
#include <CoreFoundation/CFAttributedString.h>
9797
#include <CoreFoundation/CFNotificationCenter.h>
9898

99-
#include <CoreFoundation/ForSwiftFoundationOnly.h>
100-
10199
#endif /* ! __COREFOUNDATION_COREFOUNDATION__ */
102100

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
framework module CoreFoundation_Private [extern_c] [system] {
2+
umbrella header "ForSwiftFoundationOnly.h"
3+
4+
export *
5+
module * {
6+
export *
7+
}
8+
}

CoreFoundation/CMakeLists.txt

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ add_framework(CoreFoundation
117117
CoreFoundation_FRAMEWORK_DIRECTORY
118118
MODULE_MAP
119119
Base.subproj/module.modulemap
120+
Base.subproj/module.private.modulemap
120121
PRIVATE_HEADERS
121122
# Base
122123
Base.subproj/CFAsmMacros.h
123124
Base.subproj/CFInternal.h
124125
Base.subproj/CFKnownLocations.h
126+
Base.subproj/CFLocking.h
125127
Base.subproj/CFLogUtilities.h
126128
Base.subproj/CFPriv.h
127129
Base.subproj/CFOverflow.h
@@ -185,29 +187,6 @@ add_framework(CoreFoundation
185187
URL.subproj/CFURLPriv.h
186188
URL.subproj/CFURLSessionInterface.h
187189
PUBLIC_HEADERS
188-
# FIXME: PrivateHeaders referenced by public headers
189-
Base.subproj/CFKnownLocations.h
190-
Base.subproj/CFLocking.h
191-
Base.subproj/CFLogUtilities.h
192-
Base.subproj/CFPriv.h
193-
Base.subproj/CFRuntime.h
194-
Base.subproj/ForFoundationOnly.h
195-
Base.subproj/ForSwiftFoundationOnly.h
196-
Locale.subproj/CFCalendar_Internal.h
197-
Locale.subproj/CFDateComponents.h
198-
Locale.subproj/CFDateInterval.h
199-
Locale.subproj/CFLocaleInternal.h
200-
PlugIn.subproj/CFBundlePriv.h
201-
Stream.subproj/CFStreamPriv.h
202-
String.subproj/CFCharacterSetPriv.h
203-
String.subproj/CFRegularExpression.h
204-
String.subproj/CFRunArray.h
205-
StringEncodings.subproj/CFStringEncodingConverter.h
206-
StringEncodings.subproj/CFStringEncodingConverterExt.h
207-
URL.subproj/CFURLPriv.h
208-
URL.subproj/CFURLSessionInterface.h
209-
Locale.subproj/CFDateIntervalFormatter.h
210-
211190
# AppServices
212191
AppServices.subproj/CFNotificationCenter.h
213192
AppServices.subproj/CFUserNotification.h
@@ -404,8 +383,6 @@ add_framework(CFURLSessionInterface
404383
CFURLSessionInterface_FRAMEWORK_DIRECTORY
405384
MODULE_MAP
406385
URL.subproj/module.modulemap
407-
PRIVATE_HEADERS
408-
URL.subproj/CFURLSessionInterface.h
409386
PUBLIC_HEADERS
410387
URL.subproj/CFURLSessionInterface.h
411388
SOURCES
@@ -427,8 +404,6 @@ add_framework(CFXMLInterface
427404
CFXMLInterface_FRAMEWORK_DIRECTORY
428405
MODULE_MAP
429406
Parsing.subproj/module.modulemap
430-
PRIVATE_HEADERS
431-
Parsing.subproj/CFXMLInterface.h
432407
PUBLIC_HEADERS
433408
Parsing.subproj/CFXMLInterface.h
434409
SOURCES

CoreFoundation/Parsing.subproj/CFXMLInterface.c

Lines changed: 72 additions & 72 deletions
Large diffs are not rendered by default.

CoreFoundation/Parsing.subproj/CFXMLInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ bool _CFXMLGetLengthOfPrefixInQualifiedName(const char *_Nonnull qname, size_t *
262262
// Bridging
263263

264264
struct _NSXMLParserBridge {
265-
struct _NSCFXMLBridge CF;
265+
const struct _NSCFXMLBridge *CF;
266266

267267
_CFXMLInterface _Nullable (*_Nonnull currentParser)(void);
268268
_CFXMLInterfaceParserInput _Nullable (*_Nonnull _xmlExternalEntityWithURL)(_CFXMLInterface /*interface*/, const char * /*url*/, const char * /*identifier*/, _CFXMLInterfaceParserContext /*context*/, _CFXMLInterfaceExternalEntityLoader /*originalLoaderFunction*/);

CoreFoundation/cmake/modules/CoreFoundationAddFramework.cmake

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ include(CMakeParseArguments)
33

44
function(add_framework NAME)
55
set(options STATIC SHARED)
6-
set(single_value_args MODULE_MAP FRAMEWORK_DIRECTORY)
7-
set(multiple_value_args PRIVATE_HEADERS PUBLIC_HEADERS SOURCES)
6+
set(single_value_args FRAMEWORK_DIRECTORY)
7+
set(multiple_value_args MODULE_MAP PRIVATE_HEADERS PUBLIC_HEADERS SOURCES)
88
cmake_parse_arguments(AF "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})
99

1010
set(AF_TYPE)
@@ -60,18 +60,9 @@ function(add_framework NAME)
6060
PROPERTIES
6161
LIBRARY_OUTPUT_DIRECTORY
6262
${CMAKE_BINARY_DIR}/${NAME}.framework)
63-
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
64-
target_compile_options(${NAME}
65-
PRIVATE
66-
-Xclang;-F${CMAKE_BINARY_DIR})
67-
else()
68-
target_compile_options(${NAME}
69-
PRIVATE
70-
-F;${CMAKE_BINARY_DIR})
71-
endif()
72-
target_compile_options(${NAME}
73-
PRIVATE
74-
$<$<OR:$<COMPILE_LANGUAGE:ASM>,$<COMPILE_LANGUAGE:C>>:-I;${CMAKE_BINARY_DIR}/${NAME}.framework/PrivateHeaders>)
63+
target_compile_options(${NAME} PRIVATE
64+
$<$<STREQUAL:${CMAKE_C_SIMULATE_ID},MSVC>:/clang:>-F;${CMAKE_BINARY_DIR}
65+
$<$<OR:$<COMPILE_LANGUAGE:ASM>,$<COMPILE_LANGUAGE:C>>:-I;${CMAKE_BINARY_DIR}/${NAME}.framework/PrivateHeaders>)
7566
add_dependencies(${NAME} ${NAME}_POPULATE_HEADERS)
7667

7768
if(AF_FRAMEWORK_DIRECTORY)

Sources/Foundation/Bundle.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
import CoreFoundation
1111

12+
@_implementationOnly
13+
import CoreFoundation_Private
14+
1215
@_silgen_name("swift_getTypeContextDescriptor")
1316
private func _getTypeContextDescriptor(of cls: AnyClass) -> UnsafeRawPointer
1417

Sources/Foundation/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ target_compile_definitions(Foundation PRIVATE
135135
DEPLOYMENT_RUNTIME_SWIFT)
136136
target_compile_options(Foundation PUBLIC
137137
$<$<BOOL:${ENABLE_TESTING}>:-enable-testing>
138+
"SHELL:-Xcc -DDEPLOYMENT_RUNTIME_SWIFT"
138139
"SHELL:-Xcc -F${CMAKE_BINARY_DIR}")
139140
target_link_libraries(Foundation
140141
PRIVATE

Sources/Foundation/Data.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ internal func malloc_good_size(_ size: Int) -> Int {
2121

2222
import CoreFoundation
2323

24+
@_implementationOnly
25+
import CoreFoundation_Private
26+
27+
#if os(Windows)
28+
import WinSDK
29+
#endif
30+
2431
internal func __NSDataInvokeDeallocatorUnmap(_ mem: UnsafeMutableRawPointer, _ length: Int) {
2532
#if os(Windows)
2633
UnmapViewOfFile(mem)
@@ -61,17 +68,10 @@ internal func __NSDataIsCompact(_ data: NSData) -> Bool {
6168

6269
#endif
6370

64-
#if os(Windows)
65-
@usableFromInline @discardableResult
66-
internal func __withStackOrHeapBuffer(_ size: Int, _ block: (UnsafeMutablePointer<_ConditionalAllocationBuffer>) -> Void) -> Bool {
71+
@discardableResult
72+
private func __withStackOrHeapBuffer(_ size: Int, _ block: (UnsafeMutablePointer<_ConditionalAllocationBuffer>) -> Void) -> Bool {
6773
return _withStackOrHeapBuffer(size, block)
6874
}
69-
#else
70-
@inlinable @inline(__always) @discardableResult
71-
internal func __withStackOrHeapBuffer(_ size: Int, _ block: (UnsafeMutablePointer<_ConditionalAllocationBuffer>) -> Void) -> Bool {
72-
return _withStackOrHeapBuffer(size, block)
73-
}
74-
#endif
7575

7676
// Underlying storage representation for medium and large data.
7777
// Inlinability strategy: methods from here should not inline into InlineSlice or LargeSlice unless trivial.
@@ -2083,7 +2083,6 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
20832083
}
20842084

20852085
// slightly faster paths for common sequences
2086-
@inlinable // This is @inlinable as an important generic funnel point, despite being a non-trivial initializer.
20872086
public init<S: Sequence>(_ elements: S) where S.Element == UInt8 {
20882087
// If the sequence is already contiguous, access the underlying raw memory directly.
20892088
if let contiguous = elements as? ContiguousBytes {
@@ -2374,7 +2373,6 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
23742373
}
23752374
}
23762375

2377-
@inlinable // This is @inlinable as an important generic funnel point, despite being non-trivial.
23782376
public mutating func append<S: Sequence>(contentsOf elements: S) where S.Element == Element {
23792377
// If the sequence is already contiguous, access the underlying raw memory directly.
23802378
if let contiguous = elements as? ContiguousBytes {
@@ -2474,7 +2472,6 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
24742472
/// - precondition: The bounds of `subrange` must be valid indices of the collection.
24752473
/// - parameter subrange: The range in the data to replace.
24762474
/// - parameter newElements: The replacement bytes.
2477-
@inlinable // This is @inlinable as generic and reasonably small.
24782475
public mutating func replaceSubrange<ByteCollection : Collection>(_ subrange: Range<Index>, with newElements: ByteCollection) where ByteCollection.Iterator.Element == Data.Iterator.Element {
24792476
let totalCount = Int(newElements.count)
24802477
__withStackOrHeapBuffer(totalCount) { conditionalBuffer in

Sources/Foundation/DateIntervalFormatter.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
import CoreFoundation
1111

12+
@_implementationOnly
13+
import CoreFoundation_Private
14+
1215
internal let kCFDateIntervalFormatterNoStyle = CFDateIntervalFormatterStyle.noStyle
1316
internal let kCFDateIntervalFormatterShortStyle = CFDateIntervalFormatterStyle.shortStyle
1417
internal let kCFDateIntervalFormatterMediumStyle = CFDateIntervalFormatterStyle.mediumStyle
@@ -83,15 +86,18 @@ internal extension _CFDateIntervalFormatterBoundaryStyle {
8386
// DateIntervalFormatter returns nil and NO for all methods in Formatter.
8487

8588
open class DateIntervalFormatter: Formatter {
86-
let core: CFDateIntervalFormatter
87-
89+
let _core: AnyObject
90+
var core: CFDateIntervalFormatter {
91+
unsafeBitCast(_core, to: CFDateIntervalFormatter.self)
92+
}
93+
8894
public override init() {
89-
core = CFDateIntervalFormatterCreate(nil, nil, kCFDateIntervalFormatterShortStyle, kCFDateIntervalFormatterShortStyle)
95+
_core = CFDateIntervalFormatterCreate(nil, nil, kCFDateIntervalFormatterShortStyle, kCFDateIntervalFormatterShortStyle)
9096
super.init()
9197
}
9298

9399
private init(cfFormatter: CFDateIntervalFormatter) {
94-
self.core = cfFormatter
100+
self._core = cfFormatter
95101
super.init()
96102
}
97103

@@ -118,7 +124,7 @@ open class DateIntervalFormatter: Formatter {
118124
cfObject(of: NSLocale.self, from: coder, forKey: "NS.locale"),
119125
cfObject(of: NSCalendar.self, from: coder, forKey: "NS.calendar"),
120126
cfObject(of: NSTimeZone.self, from: coder, forKey: "NS.timeZone"))
121-
self.core = core
127+
self._core = core
122128

123129
super.init(coder: coder)
124130
}

Sources/Foundation/FileHandle.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
import CoreFoundation
1111
import Dispatch
1212

13+
@_implementationOnly
14+
import CoreFoundation_Private
15+
16+
#if os(Windows)
17+
import WinSDK
18+
#endif
19+
1320
// FileHandle has a .read(upToCount:) method. Just invoking read() will cause an ambiguity warning. Use _read instead.
1421
// Same with close()/.close().
1522
#if canImport(Darwin)

Sources/Foundation/FileManager+POSIX.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ internal func &(left: UInt32, right: mode_t) -> mode_t {
1515

1616
import CoreFoundation
1717

18+
@_implementationOnly
19+
import CoreFoundation_Private
20+
1821
extension FileManager {
1922
internal func _mountedVolumeURLs(includingResourceValuesForKeys propertyKeys: [URLResourceKey]?, options: VolumeEnumerationOptions = []) -> [URL]? {
2023
var urls: [URL] = []

Sources/Foundation/FileManager+Win32.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99

1010
import CoreFoundation
1111

12+
@_implementationOnly
13+
import CoreFoundation_Private
14+
1215
#if os(Windows)
16+
17+
import WinSDK
18+
1319
internal func joinPath(prefix: String, suffix: String) -> String {
1420
var pszPath: PWSTR?
1521

Sources/Foundation/FileManager+XDG.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
import CoreFoundation
1111

12+
@_implementationOnly
13+
import CoreFoundation_Private
14+
1215
enum _XDGUserDirectory: String {
1316
case desktop = "DESKTOP"
1417
case download = "DOWNLOAD"

Sources/Foundation/FileManager.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ fileprivate let UF_HIDDEN: Int32 = 1
1616
#endif
1717

1818
import CoreFoundation
19+
20+
@_implementationOnly
21+
import CoreFoundation_Private
22+
1923
#if os(Windows)
2024
import MSVCRT
25+
import WinSDK
2126
#endif
2227

2328
#if os(Windows)

Sources/Foundation/Host.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
import CoreFoundation
1111

12+
#if os(Windows)
13+
import WinSDK
14+
#endif
15+
1216
#if os(Android)
1317
// Android Glibc differs a little with respect to the Linux Glibc.
1418

Sources/Foundation/NSArray.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
import CoreFoundation
1111

12+
@_implementationOnly
13+
import CoreFoundation_Private
14+
1215
open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCoding, ExpressibleByArrayLiteral {
1316
private let _cfinfo = _CFInfo(typeID: CFArrayGetTypeID())
1417
internal var _storage = [AnyObject]()

Sources/Foundation/NSAttributedString.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
import CoreFoundation
1111

12+
@_implementationOnly
13+
import CoreFoundation_Private
14+
1215
extension NSAttributedString {
1316
public struct Key: RawRepresentable, Equatable, Hashable {
1417
public let rawValue: String
@@ -50,8 +53,12 @@ open class NSAttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCo
5053

5154
private let _cfinfo = _CFInfo(typeID: CFAttributedStringGetTypeID())
5255
fileprivate var _string: NSString
53-
fileprivate var _attributeArray: CFRunArrayRef
54-
56+
57+
fileprivate let __attributeArray: OpaquePointer
58+
fileprivate var _attributeArray: CFRunArrayRef {
59+
__attributeArray
60+
}
61+
5562
public required init?(coder aDecoder: NSCoder) {
5663
let mutableAttributedString = NSMutableAttributedString(string: "")
5764
guard _NSReadMutableAttributedStringWithCoder(aDecoder, mutableAttributedString: mutableAttributedString) else {
@@ -60,7 +67,7 @@ open class NSAttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCo
6067

6168
// use the resulting _string and _attributeArray to initialize a new instance, just like init
6269
_string = mutableAttributedString._string
63-
_attributeArray = mutableAttributedString._attributeArray
70+
__attributeArray = mutableAttributedString._attributeArray
6471
}
6572

6673
open func encode(with aCoder: NSCoder) {
@@ -197,7 +204,7 @@ open class NSAttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCo
197204
/// Returns an NSAttributedString object initialized with the characters of a given string and no attribute information.
198205
public init(string: String) {
199206
_string = string._nsObject
200-
_attributeArray = CFRunArrayCreate(kCFAllocatorDefault)
207+
__attributeArray = CFRunArrayCreate(kCFAllocatorDefault)
201208

202209
super.init()
203210
addAttributesToAttributeArray(attrs: nil)
@@ -206,7 +213,7 @@ open class NSAttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCo
206213
/// Returns an NSAttributedString object initialized with a given string and attributes.
207214
public init(string: String, attributes attrs: [NSAttributedString.Key: Any]? = nil) {
208215
_string = string._nsObject
209-
_attributeArray = CFRunArrayCreate(kCFAllocatorDefault)
216+
__attributeArray = CFRunArrayCreate(kCFAllocatorDefault)
210217

211218
super.init()
212219
addAttributesToAttributeArray(attrs: attrs)
@@ -220,7 +227,7 @@ open class NSAttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCo
220227

221228
// use the resulting _string and _attributeArray to initialize a new instance
222229
_string = mutableAttributedString._string
223-
_attributeArray = mutableAttributedString._attributeArray
230+
__attributeArray = mutableAttributedString._attributeArray
224231
}
225232

226233
/// Executes the block for each attribute in the range.

Sources/Foundation/NSCFArray.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
import CoreFoundation
1212

13+
@_implementationOnly
14+
import CoreFoundation_Private
15+
1316
internal final class _NSCFArray : NSMutableArray {
1417
deinit {
1518
_CFDeinit(self)

0 commit comments

Comments
 (0)