Skip to content

CoreFoundation: remove private headers from public directory #2395

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 0 additions & 2 deletions CoreFoundation/Base.subproj/SwiftRuntime/CoreFoundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,5 @@
#include <CoreFoundation/CFAttributedString.h>
#include <CoreFoundation/CFNotificationCenter.h>

#include <CoreFoundation/ForSwiftFoundationOnly.h>

#endif /* ! __COREFOUNDATION_COREFOUNDATION__ */

8 changes: 8 additions & 0 deletions CoreFoundation/Base.subproj/module.private.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
framework module CoreFoundation_Private [extern_c] [system] {
umbrella header "ForSwiftFoundationOnly.h"

export *
module * {
export *
}
}
29 changes: 2 additions & 27 deletions CoreFoundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ add_framework(CoreFoundation
CoreFoundation_FRAMEWORK_DIRECTORY
MODULE_MAP
Base.subproj/module.modulemap
Base.subproj/module.private.modulemap
PRIVATE_HEADERS
# Base
Base.subproj/CFAsmMacros.h
Base.subproj/CFInternal.h
Base.subproj/CFKnownLocations.h
Base.subproj/CFLocking.h
Base.subproj/CFLogUtilities.h
Base.subproj/CFPriv.h
Base.subproj/CFOverflow.h
Expand Down Expand Up @@ -185,29 +187,6 @@ add_framework(CoreFoundation
URL.subproj/CFURLPriv.h
URL.subproj/CFURLSessionInterface.h
PUBLIC_HEADERS
# FIXME: PrivateHeaders referenced by public headers
Base.subproj/CFKnownLocations.h
Base.subproj/CFLocking.h
Base.subproj/CFLogUtilities.h
Base.subproj/CFPriv.h
Base.subproj/CFRuntime.h
Base.subproj/ForFoundationOnly.h
Base.subproj/ForSwiftFoundationOnly.h
Locale.subproj/CFCalendar_Internal.h
Locale.subproj/CFDateComponents.h
Locale.subproj/CFDateInterval.h
Locale.subproj/CFLocaleInternal.h
PlugIn.subproj/CFBundlePriv.h
Stream.subproj/CFStreamPriv.h
String.subproj/CFCharacterSetPriv.h
String.subproj/CFRegularExpression.h
String.subproj/CFRunArray.h
StringEncodings.subproj/CFStringEncodingConverter.h
StringEncodings.subproj/CFStringEncodingConverterExt.h
URL.subproj/CFURLPriv.h
URL.subproj/CFURLSessionInterface.h
Locale.subproj/CFDateIntervalFormatter.h

# AppServices
AppServices.subproj/CFNotificationCenter.h
AppServices.subproj/CFUserNotification.h
Expand Down Expand Up @@ -414,8 +393,6 @@ add_framework(CFURLSessionInterface
CFURLSessionInterface_FRAMEWORK_DIRECTORY
MODULE_MAP
URL.subproj/module.modulemap
PRIVATE_HEADERS
URL.subproj/CFURLSessionInterface.h
PUBLIC_HEADERS
URL.subproj/CFURLSessionInterface.h
SOURCES
Expand All @@ -437,8 +414,6 @@ add_framework(CFXMLInterface
CFXMLInterface_FRAMEWORK_DIRECTORY
MODULE_MAP
Parsing.subproj/module.modulemap
PRIVATE_HEADERS
Parsing.subproj/CFXMLInterface.h
PUBLIC_HEADERS
Parsing.subproj/CFXMLInterface.h
SOURCES
Expand Down
144 changes: 72 additions & 72 deletions CoreFoundation/Parsing.subproj/CFXMLInterface.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion CoreFoundation/Parsing.subproj/CFXMLInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ bool _CFXMLGetLengthOfPrefixInQualifiedName(const char *_Nonnull qname, size_t *
// Bridging

struct _NSXMLParserBridge {
struct _NSCFXMLBridge CF;
const struct _NSCFXMLBridge *CF;

_CFXMLInterface _Nullable (*_Nonnull currentParser)(void);
_CFXMLInterfaceParserInput _Nullable (*_Nonnull _xmlExternalEntityWithURL)(_CFXMLInterface /*interface*/, const char * /*url*/, const char * /*identifier*/, _CFXMLInterfaceParserContext /*context*/, _CFXMLInterfaceExternalEntityLoader /*originalLoaderFunction*/);
Expand Down
19 changes: 5 additions & 14 deletions CoreFoundation/cmake/modules/CoreFoundationAddFramework.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ include(CMakeParseArguments)

function(add_framework NAME)
set(options STATIC SHARED)
set(single_value_args MODULE_MAP FRAMEWORK_DIRECTORY)
set(multiple_value_args PRIVATE_HEADERS PUBLIC_HEADERS SOURCES)
set(single_value_args FRAMEWORK_DIRECTORY)
set(multiple_value_args MODULE_MAP PRIVATE_HEADERS PUBLIC_HEADERS SOURCES)
cmake_parse_arguments(AF "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})

set(AF_TYPE)
Expand Down Expand Up @@ -60,18 +60,9 @@ function(add_framework NAME)
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${NAME}.framework)
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
target_compile_options(${NAME}
PRIVATE
-Xclang;-F${CMAKE_BINARY_DIR})
else()
target_compile_options(${NAME}
PRIVATE
-F;${CMAKE_BINARY_DIR})
endif()
target_compile_options(${NAME}
PRIVATE
$<$<OR:$<COMPILE_LANGUAGE:ASM>,$<COMPILE_LANGUAGE:C>>:-I;${CMAKE_BINARY_DIR}/${NAME}.framework/PrivateHeaders>)
target_compile_options(${NAME} PRIVATE
$<$<STREQUAL:${CMAKE_C_SIMULATE_ID},MSVC>:/clang:>-F;${CMAKE_BINARY_DIR}
$<$<OR:$<COMPILE_LANGUAGE:ASM>,$<COMPILE_LANGUAGE:C>>:-I;${CMAKE_BINARY_DIR}/${NAME}.framework/PrivateHeaders>)
add_dependencies(${NAME} ${NAME}_POPULATE_HEADERS)

if(AF_FRAMEWORK_DIRECTORY)
Expand Down
3 changes: 3 additions & 0 deletions Sources/Foundation/Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import CoreFoundation

@_implementationOnly
import CoreFoundation_Private

@_silgen_name("swift_getTypeContextDescriptor")
private func _getTypeContextDescriptor(of cls: AnyClass) -> UnsafeRawPointer

Expand Down
1 change: 1 addition & 0 deletions Sources/Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ target_compile_definitions(Foundation PRIVATE
DEPLOYMENT_RUNTIME_SWIFT)
target_compile_options(Foundation PUBLIC
$<$<BOOL:${ENABLE_TESTING}>:-enable-testing>
"SHELL:-Xcc -DDEPLOYMENT_RUNTIME_SWIFT"
"SHELL:-Xcc -F${CMAKE_BINARY_DIR}")
target_link_libraries(Foundation
PRIVATE
Expand Down
21 changes: 9 additions & 12 deletions Sources/Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ internal func malloc_good_size(_ size: Int) -> Int {

import CoreFoundation

@_implementationOnly
import CoreFoundation_Private

#if os(Windows)
import WinSDK
#endif

internal func __NSDataInvokeDeallocatorUnmap(_ mem: UnsafeMutableRawPointer, _ length: Int) {
#if os(Windows)
UnmapViewOfFile(mem)
Expand Down Expand Up @@ -61,17 +68,10 @@ internal func __NSDataIsCompact(_ data: NSData) -> Bool {

#endif

#if os(Windows)
@usableFromInline @discardableResult
internal func __withStackOrHeapBuffer(_ size: Int, _ block: (UnsafeMutablePointer<_ConditionalAllocationBuffer>) -> Void) -> Bool {
@discardableResult
private func __withStackOrHeapBuffer(_ size: Int, _ block: (UnsafeMutablePointer<_ConditionalAllocationBuffer>) -> Void) -> Bool {
return _withStackOrHeapBuffer(size, block)
}
#else
@inlinable @inline(__always) @discardableResult
internal func __withStackOrHeapBuffer(_ size: Int, _ block: (UnsafeMutablePointer<_ConditionalAllocationBuffer>) -> Void) -> Bool {
return _withStackOrHeapBuffer(size, block)
}
#endif

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

// slightly faster paths for common sequences
@inlinable // This is @inlinable as an important generic funnel point, despite being a non-trivial initializer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove inlineability here?

Copy link
Member Author

@compnerd compnerd Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a cascading effect due to the use of _withStackOrHeapBuffer getting inlined, making this inlinable would expose the @_implementationOnly interface. Of course it is possible something may have changed since.

public init<S: Sequence>(_ elements: S) where S.Element == UInt8 {
// If the sequence is already contiguous, access the underlying raw memory directly.
if let contiguous = elements as? ContiguousBytes {
Expand Down Expand Up @@ -2374,7 +2373,6 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
}
}

@inlinable // This is @inlinable as an important generic funnel point, despite being non-trivial.
public mutating func append<S: Sequence>(contentsOf elements: S) where S.Element == Element {
// If the sequence is already contiguous, access the underlying raw memory directly.
if let contiguous = elements as? ContiguousBytes {
Expand Down Expand Up @@ -2474,7 +2472,6 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
/// - precondition: The bounds of `subrange` must be valid indices of the collection.
/// - parameter subrange: The range in the data to replace.
/// - parameter newElements: The replacement bytes.
@inlinable // This is @inlinable as generic and reasonably small.
public mutating func replaceSubrange<ByteCollection : Collection>(_ subrange: Range<Index>, with newElements: ByteCollection) where ByteCollection.Iterator.Element == Data.Iterator.Element {
let totalCount = Int(newElements.count)
__withStackOrHeapBuffer(totalCount) { conditionalBuffer in
Expand Down
16 changes: 11 additions & 5 deletions Sources/Foundation/DateIntervalFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import CoreFoundation

@_implementationOnly
import CoreFoundation_Private

internal let kCFDateIntervalFormatterNoStyle = CFDateIntervalFormatterStyle.noStyle
internal let kCFDateIntervalFormatterShortStyle = CFDateIntervalFormatterStyle.shortStyle
internal let kCFDateIntervalFormatterMediumStyle = CFDateIntervalFormatterStyle.mediumStyle
Expand Down Expand Up @@ -83,15 +86,18 @@ internal extension _CFDateIntervalFormatterBoundaryStyle {
// DateIntervalFormatter returns nil and NO for all methods in Formatter.

open class DateIntervalFormatter: Formatter {
let core: CFDateIntervalFormatter

let _core: AnyObject
var core: CFDateIntervalFormatter {
unsafeBitCast(_core, to: CFDateIntervalFormatter.self)
}

public override init() {
core = CFDateIntervalFormatterCreate(nil, nil, kCFDateIntervalFormatterShortStyle, kCFDateIntervalFormatterShortStyle)
_core = CFDateIntervalFormatterCreate(nil, nil, kCFDateIntervalFormatterShortStyle, kCFDateIntervalFormatterShortStyle)
super.init()
}

private init(cfFormatter: CFDateIntervalFormatter) {
self.core = cfFormatter
self._core = cfFormatter
super.init()
}

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

super.init(coder: coder)
}
Expand Down
7 changes: 7 additions & 0 deletions Sources/Foundation/FileHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
import CoreFoundation
import Dispatch

@_implementationOnly
import CoreFoundation_Private

#if os(Windows)
import WinSDK
#endif

// FileHandle has a .read(upToCount:) method. Just invoking read() will cause an ambiguity warning. Use _read instead.
// Same with close()/.close().
#if canImport(Darwin)
Expand Down
3 changes: 3 additions & 0 deletions Sources/Foundation/FileManager+POSIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ internal func &(left: UInt32, right: mode_t) -> mode_t {

import CoreFoundation

@_implementationOnly
import CoreFoundation_Private

extension FileManager {
internal func _mountedVolumeURLs(includingResourceValuesForKeys propertyKeys: [URLResourceKey]?, options: VolumeEnumerationOptions = []) -> [URL]? {
var urls: [URL] = []
Expand Down
6 changes: 6 additions & 0 deletions Sources/Foundation/FileManager+Win32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@

import CoreFoundation

@_implementationOnly
import CoreFoundation_Private

#if os(Windows)

import WinSDK

internal func joinPath(prefix: String, suffix: String) -> String {
var pszPath: PWSTR?

Expand Down
3 changes: 3 additions & 0 deletions Sources/Foundation/FileManager+XDG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import CoreFoundation

@_implementationOnly
import CoreFoundation_Private

enum _XDGUserDirectory: String {
case desktop = "DESKTOP"
case download = "DOWNLOAD"
Expand Down
5 changes: 5 additions & 0 deletions Sources/Foundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ fileprivate let UF_HIDDEN: Int32 = 1
#endif

import CoreFoundation

@_implementationOnly
import CoreFoundation_Private

#if os(Windows)
import MSVCRT
import WinSDK
#endif

#if os(Windows)
Expand Down
4 changes: 4 additions & 0 deletions Sources/Foundation/Host.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

import CoreFoundation

#if os(Windows)
import WinSDK
#endif

#if os(Android)
// Android Glibc differs a little with respect to the Linux Glibc.

Expand Down
3 changes: 3 additions & 0 deletions Sources/Foundation/NSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import CoreFoundation

@_implementationOnly
import CoreFoundation_Private

open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCoding, ExpressibleByArrayLiteral {
private let _cfinfo = _CFInfo(typeID: CFArrayGetTypeID())
internal var _storage = [AnyObject]()
Expand Down
19 changes: 13 additions & 6 deletions Sources/Foundation/NSAttributedString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import CoreFoundation

@_implementationOnly
import CoreFoundation_Private

extension NSAttributedString {
public struct Key: RawRepresentable, Equatable, Hashable {
public let rawValue: String
Expand Down Expand Up @@ -50,8 +53,12 @@ open class NSAttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCo

private let _cfinfo = _CFInfo(typeID: CFAttributedStringGetTypeID())
fileprivate var _string: NSString
fileprivate var _attributeArray: CFRunArrayRef


fileprivate let __attributeArray: OpaquePointer
fileprivate var _attributeArray: CFRunArrayRef {
__attributeArray
}

public required init?(coder aDecoder: NSCoder) {
let mutableAttributedString = NSMutableAttributedString(string: "")
guard _NSReadMutableAttributedStringWithCoder(aDecoder, mutableAttributedString: mutableAttributedString) else {
Expand All @@ -60,7 +67,7 @@ open class NSAttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCo

// use the resulting _string and _attributeArray to initialize a new instance, just like init
_string = mutableAttributedString._string
_attributeArray = mutableAttributedString._attributeArray
__attributeArray = mutableAttributedString._attributeArray
}

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

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

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

// use the resulting _string and _attributeArray to initialize a new instance
_string = mutableAttributedString._string
_attributeArray = mutableAttributedString._attributeArray
__attributeArray = mutableAttributedString._attributeArray
}

/// Executes the block for each attribute in the range.
Expand Down
3 changes: 3 additions & 0 deletions Sources/Foundation/NSCFArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import CoreFoundation

@_implementationOnly
import CoreFoundation_Private

internal final class _NSCFArray : NSMutableArray {
deinit {
_CFDeinit(self)
Expand Down
Loading