Skip to content

[Foundation] Import shims with @implementationOnly #28918

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
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/Calendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import _SwiftFoundationOverlayShims
@_implementationOnly import _SwiftFoundationOverlayShims

/**
`Calendar` encapsulates information about systems of reckoning time in which the beginning, length, and divisions of a year are defined. It provides information about the calendar and support for calendrical computations such as determining the range of a given calendrical unit and adding units to a given absolute time.
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/Darwin/Foundation/CharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

@_exported import Foundation // Clang module
import CoreFoundation
import _SwiftCoreFoundationOverlayShims
import _SwiftFoundationOverlayShims
@_implementationOnly import _SwiftCoreFoundationOverlayShims
@_implementationOnly import _SwiftFoundationOverlayShims

private func _utfRangeToCFRange(_ inRange : Range<Unicode.Scalar>) -> CFRange {
return CFRange(
Expand Down
303 changes: 172 additions & 131 deletions stdlib/public/Darwin/Foundation/Data.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@_exported import Foundation // Clang module
import CoreFoundation
import _SwiftCoreFoundationOverlayShims
@_implementationOnly import _SwiftCoreFoundationOverlayShims

/**
`Date` represents a single point in time.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/DateInterval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import _SwiftCoreFoundationOverlayShims
@_implementationOnly import _SwiftCoreFoundationOverlayShims

/// DateInterval represents a closed date interval in the form of [startDate, endDate]. It is possible for the start and end dates to be the same with a duration of 0. DateInterval does not support reverse intervals i.e. intervals where the duration is less than 0 and the end date occurs earlier in time than the start date.
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/Decimal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import _SwiftCoreFoundationOverlayShims
@_implementationOnly import _SwiftCoreFoundationOverlayShims

extension Decimal {
public typealias RoundingMode = NSDecimalNumber.RoundingMode
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import _SwiftFoundationOverlayShims
@_implementationOnly import _SwiftFoundationOverlayShims

extension FileManager {
/*
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/IndexPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import _SwiftFoundationOverlayShims
@_implementationOnly import _SwiftFoundationOverlayShims

/**
`IndexPath` represents the path to a specific node in a tree of nested array collections.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/IndexSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import _SwiftFoundationOverlayShims
@_implementationOnly import _SwiftFoundationOverlayShims

extension IndexSet.Index {
public static func ==(lhs: IndexSet.Index, rhs: IndexSet.Index) -> Bool {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/Locale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import _SwiftFoundationOverlayShims
@_implementationOnly import _SwiftFoundationOverlayShims

/**
`Locale` encapsulates information about linguistic, cultural, and technological conventions and standards. Examples of information encapsulated by a locale include the symbol used for the decimal separator in numbers and the way dates are formatted.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/Measurement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import CoreFoundation
#else
@_exported import Foundation // Clang module
import _SwiftCoreFoundationOverlayShims
@_implementationOnly import _SwiftCoreFoundationOverlayShims
#endif

/// A `Measurement` is a model type that holds a `Double` value associated with a `Unit`.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/NSCoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import _SwiftFoundationOverlayShims
@_implementationOnly import _SwiftFoundationOverlayShims

//===----------------------------------------------------------------------===//
// NSCoder
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/NSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import _SwiftFoundationOverlayShims
@_implementationOnly import _SwiftFoundationOverlayShims

// We don't check for NSCopying here for performance reasons. We would
// just crash anyway, and NSMutableDictionary will still do that when
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/NSError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@_exported import Foundation // Clang module
import CoreFoundation
import Darwin
import _SwiftFoundationOverlayShims
@_implementationOnly import _SwiftFoundationOverlayShims

//===----------------------------------------------------------------------===//
// NSError (as an out parameter).
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/NSUndoManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import _SwiftFoundationOverlayShims
@_implementationOnly import _SwiftFoundationOverlayShims

extension UndoManager {
@available(*, unavailable, renamed: "registerUndo(withTarget:handler:)")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/TimeZone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import _SwiftFoundationOverlayShims
@_implementationOnly import _SwiftFoundationOverlayShims

/**
`TimeZone` defines the behavior of a time zone. Time zone values represent geopolitical regions. Consequently, these values have names for these regions. Time zone values also represent a temporal offset, either plus or minus, from Greenwich Mean Time (GMT) and an abbreviation (such as PST for Pacific Standard Time).
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Darwin/Foundation/UUID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@_exported import Foundation // Clang module
import Darwin.uuid
import _SwiftCoreFoundationOverlayShims
@_implementationOnly import _SwiftCoreFoundationOverlayShims

/// Represents UUID strings, which can be used to uniquely identify types, interfaces, and other items.
@available(macOS 10.8, iOS 6.0, *)
Expand Down
38 changes: 0 additions & 38 deletions stdlib/public/SwiftShims/FoundationOverlayShims.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,6 @@
#import "NSTimeZoneShims.h"
#import "NSUndoManagerShims.h"

typedef struct {
void *_Nonnull memory;
size_t capacity;
_Bool onStack;
} _ConditionalAllocationBuffer;

static inline _Bool _resizeConditionalAllocationBuffer(_ConditionalAllocationBuffer *_Nonnull buffer, size_t amt) {
size_t amount = malloc_good_size(amt);
if (amount <= buffer->capacity) { return true; }
void *newMemory;
if (buffer->onStack) {
newMemory = malloc(amount);
if (newMemory == NULL) { return false; }
memcpy(newMemory, buffer->memory, buffer->capacity);
buffer->onStack = false;
} else {
newMemory = realloc(buffer->memory, amount);
if (newMemory == NULL) { return false; }
}
if (newMemory == NULL) { return false; }
buffer->memory = newMemory;
buffer->capacity = amount;
return true;
}

static inline _Bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((noescape)) ^ _Nonnull applier)(_ConditionalAllocationBuffer *_Nonnull)) {
_ConditionalAllocationBuffer buffer;
buffer.capacity = malloc_good_size(amount);
buffer.onStack = (pthread_main_np() != 0 ? buffer.capacity < 2048 : buffer.capacity < 512);
buffer.memory = buffer.onStack ? alloca(buffer.capacity) : malloc(buffer.capacity);
if (buffer.memory == NULL) { return false; }
applier(&buffer);
if (!buffer.onStack) {
free(buffer.memory);
}
return true;
}

@protocol _NSKVOCompatibilityShim <NSObject>
+ (void)_noteProcessHasUsedKVOSwiftOverlay;
@end