Skip to content

Commit bc3d278

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 653c070 commit bc3d278

Some content is hidden

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

49 files changed

+238
-84
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 & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ add_framework(CoreFoundation
114114
CoreFoundation_FRAMEWORK_DIRECTORY
115115
MODULE_MAP
116116
Base.subproj/module.modulemap
117+
Base.subproj/module.private.modulemap
117118
PRIVATE_HEADERS
118119
# Base
119120
Base.subproj/CFAsmMacros.h
120121
Base.subproj/CFInternal.h
121122
Base.subproj/CFKnownLocations.h
123+
Base.subproj/CFLocking.h
122124
Base.subproj/CFLogUtilities.h
123125
Base.subproj/CFPriv.h
124126
Base.subproj/CFOverflow.h
@@ -182,29 +184,6 @@ add_framework(CoreFoundation
182184
URL.subproj/CFURLPriv.h
183185
URL.subproj/CFURLSessionInterface.h
184186
PUBLIC_HEADERS
185-
# FIXME: PrivateHeaders referenced by public headers
186-
Base.subproj/CFKnownLocations.h
187-
Base.subproj/CFLocking.h
188-
Base.subproj/CFLogUtilities.h
189-
Base.subproj/CFPriv.h
190-
Base.subproj/CFRuntime.h
191-
Base.subproj/ForFoundationOnly.h
192-
Base.subproj/ForSwiftFoundationOnly.h
193-
Locale.subproj/CFCalendar_Internal.h
194-
Locale.subproj/CFDateComponents.h
195-
Locale.subproj/CFDateInterval.h
196-
Locale.subproj/CFLocaleInternal.h
197-
PlugIn.subproj/CFBundlePriv.h
198-
Stream.subproj/CFStreamPriv.h
199-
String.subproj/CFCharacterSetPriv.h
200-
String.subproj/CFRegularExpression.h
201-
String.subproj/CFRunArray.h
202-
StringEncodings.subproj/CFStringEncodingConverter.h
203-
StringEncodings.subproj/CFStringEncodingConverterExt.h
204-
URL.subproj/CFURLPriv.h
205-
URL.subproj/CFURLSessionInterface.h
206-
Locale.subproj/CFDateIntervalFormatter.h
207-
208187
# AppServices
209188
AppServices.subproj/CFNotificationCenter.h
210189
AppServices.subproj/CFUserNotification.h

CoreFoundation/cmake/modules/CoreFoundationAddFramework.cmake

Lines changed: 3 additions & 11 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,17 +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()
7263
target_compile_options(${NAME}
7364
PRIVATE
65+
$<$<STREQUAL:${CMAKE_C_SIMULATE_ID},MSVC>:/clang:>-F;${CMAKE_BINARY_DIR}
7466
$<$<OR:$<COMPILE_LANGUAGE:ASM>,$<COMPILE_LANGUAGE:C>>:-I;${CMAKE_BINARY_DIR}/${NAME}.framework/PrivateHeaders>)
7567
add_dependencies(${NAME} ${NAME}_POPULATE_HEADERS)
7668

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

Foundation/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ add_library(Foundation
138138
UUID.swift)
139139
target_compile_definitions(Foundation PRIVATE
140140
DEPLOYMENT_RUNTIME_SWIFT)
141+
target_compile_options(Foundation PRIVATE
142+
"SHELL:-Xcc -DDEPLOYMENT_RUNTIME_SWIFT")
141143
target_compile_options(Foundation PUBLIC
142144
"SHELL:-Xcc -F${CMAKE_BINARY_DIR}")
143145
target_compile_options(Foundation PRIVATE
@@ -212,6 +214,8 @@ add_library(FoundationNetworking
212214
target_compile_definitions(FoundationNetworking PRIVATE
213215
DEPLOYMENT_RUNTIME_SWIFT
214216
NS_BUILDING_FOUNDATION_NETWORKING)
217+
target_compile_options(FoundationNetworking PRIVATE
218+
"SHELL:-Xcc -DDEPLOYMENT_RUNTIME_SWIFT")
215219
target_compile_options(FoundationNetworking PUBLIC
216220
"SHELL:-Xcc -F${CMAKE_BINARY_DIR}")
217221
if(ENABLE_TESTING)
@@ -238,6 +242,8 @@ add_library(FoundationXML
238242
XMLParser.swift)
239243
target_compile_definitions(FoundationXML PRIVATE
240244
DEPLOYMENT_RUNTIME_SWIFT)
245+
target_compile_options(FoundationXML PRIVATE
246+
"SHELL:-Xcc -DDEPLOYMENT_RUNTIME_SWIFT")
241247
target_compile_options(FoundationXML PUBLIC
242248
"SHELL:-Xcc -F${CMAKE_BINARY_DIR}")
243249
if(ENABLE_TESTING)

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

Foundation/DateIntervalFormatter.swift

Lines changed: 10 additions & 4 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
#if _runtime(_ObjC)
1316
internal let kCFDateIntervalFormatterNoStyle = CFDateIntervalFormatterStyle.noStyle
1417
internal let kCFDateIntervalFormatterShortStyle = CFDateIntervalFormatterStyle.shortStyle
@@ -85,15 +88,18 @@ internal extension _CFDateIntervalFormatterBoundaryStyle {
8588
// DateIntervalFormatter returns nil and NO for all methods in Formatter.
8689

8790
open class DateIntervalFormatter: Formatter {
88-
let core: CFDateIntervalFormatter
91+
let _core: AnyObject
92+
let core: CFDateIntervalFormatter {
93+
unsafeBitCast(_core, to: CFDateIntervalFormatter.self)
94+
}
8995

9096
public override init() {
91-
core = CFDateIntervalFormatterCreate(nil, nil, kCFDateIntervalFormatterShortStyle, kCFDateIntervalFormatterShortStyle)
97+
_core = CFDateIntervalFormatterCreate(nil, nil, kCFDateIntervalFormatterShortStyle, kCFDateIntervalFormatterShortStyle)
9298
super.init()
9399
}
94100

95101
private init(cfFormatter: CFDateIntervalFormatter) {
96-
self.core = cfFormatter
102+
self._core = cfFormatter
97103
super.init()
98104
}
99105

@@ -120,7 +126,7 @@ open class DateIntervalFormatter: Formatter {
120126
cfObject(of: NSLocale.self, from: coder, forKey: "NS.locale"),
121127
cfObject(of: NSCalendar.self, from: coder, forKey: "NS.calendar"),
122128
cfObject(of: NSTimeZone.self, from: coder, forKey: "NS.timeZone"))
123-
self.core = core
129+
self._core = core
124130

125131
super.init(coder: coder)
126132
}

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+
#if os(Windows)
14+
import WinSDK
15+
#endif
16+
17+
@_implementationOnly
18+
import CoreFoundation_Private
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)

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] = []

Foundation/FileManager+Win32.swift

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

1010
import CoreFoundation
1111

12+
@_implementationOnly
13+
import CoreFoundation_Private
14+
1215
#if os(Windows)
16+
import WinSDK
17+
1318
internal func joinPath(prefix: String, suffix: String) -> String {
1419
var pszPath: PWSTR?
1520
_ = prefix.withCString(encodedAs: UTF16.self) { prefix in

Foundation/FileManager.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ fileprivate let UF_HIDDEN: Int32 = 1
1616
#endif
1717

1818
import CoreFoundation
19+
1920
#if os(Windows)
20-
import MSVCRT
21+
import WinSDK
2122
#endif
2223

24+
@_implementationOnly
25+
import CoreFoundation_Private
26+
2327
open class FileManager : NSObject {
2428

2529
/* Returns the default singleton instance.

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"

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

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]()

Foundation/NSAttributedString.swift

Lines changed: 12 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
extension NSAttributedString {
1316
public struct Key: RawRepresentable, Equatable, Hashable {
1417
public let rawValue: String
@@ -50,7 +53,11 @@ 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
56+
57+
fileprivate var __attributeArray: OpaquePointer
58+
fileprivate var _attributeArray: CFRunArrayRef {
59+
return unsafeBitCast(__attributeArray, to: CFRunArrayRef.self)
60+
}
5461

5562
public required init?(coder aDecoder: NSCoder) {
5663
let mutableAttributedString = NSMutableAttributedString(string: "")
@@ -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.

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)

Foundation/NSCFDictionary.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 _NSCFDictionary : NSMutableDictionary {
1417
deinit {
1518
_CFDeinit(self)

Foundation/NSCFSet.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 _NSCFSet : NSMutableSet {
1417
deinit {
1518
_CFDeinit(self)

0 commit comments

Comments
 (0)