Skip to content

[stdlib] Take several underscored stdlib functions private #18134

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 8 commits into from
Jul 25, 2018
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
4 changes: 2 additions & 2 deletions benchmark/single-source/OpaqueConsumingUsers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func callFrame4(_ data: Klass, _ user: ConsumingUser) {

@inline(never)
public func run_OpaqueConsumingUsers(_ N: Int) {
let d = data._unsafelyUnwrappedUnchecked
let u = user._unsafelyUnwrappedUnchecked
let d = data.unsafelyUnwrapped
let u = user.unsafelyUnwrapped
for _ in 0..<N*200000 {
callFrame4(d, u)
}
Expand Down
24 changes: 12 additions & 12 deletions benchmark/single-source/Radix2CooleyTukey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ func testDouble(iter: Int) {
let size = doubleSize
let level = Int(log2(Double(doubleN)))

let input_real = double_input_real._unsafelyUnwrappedUnchecked
let input_imag = double_input_imag._unsafelyUnwrappedUnchecked
let output_real = double_output_real._unsafelyUnwrappedUnchecked
let output_imag = double_output_imag._unsafelyUnwrappedUnchecked
let temp_real = double_temp_real._unsafelyUnwrappedUnchecked
let temp_imag = double_temp_imag._unsafelyUnwrappedUnchecked
let input_real = double_input_real.unsafelyUnwrapped
let input_imag = double_input_imag.unsafelyUnwrapped
let output_real = double_output_real.unsafelyUnwrapped
let output_imag = double_output_imag.unsafelyUnwrapped
let temp_real = double_temp_real.unsafelyUnwrapped
let temp_imag = double_temp_imag.unsafelyUnwrapped

for _ in 0..<iter {
memset(UnsafeMutableRawPointer(input_real), 0, size)
Expand Down Expand Up @@ -224,12 +224,12 @@ func testFloat(iter: Int) {
let n = floatN
let size = floatSize

let input_real = float_input_real._unsafelyUnwrappedUnchecked
let input_imag = float_input_imag._unsafelyUnwrappedUnchecked
let output_real = float_output_real._unsafelyUnwrappedUnchecked
let output_imag = float_output_imag._unsafelyUnwrappedUnchecked
let temp_real = float_temp_real._unsafelyUnwrappedUnchecked
let temp_imag = float_temp_imag._unsafelyUnwrappedUnchecked
let input_real = float_input_real.unsafelyUnwrapped
let input_imag = float_input_imag.unsafelyUnwrapped
let output_real = float_output_real.unsafelyUnwrapped
let output_imag = float_output_imag.unsafelyUnwrapped
let temp_real = float_temp_real.unsafelyUnwrapped
let temp_imag = float_temp_imag.unsafelyUnwrapped

let level = Int(log2(Float(n)))

Expand Down
18 changes: 9 additions & 9 deletions benchmark/single-source/StringComparison.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public func setup_StringComparison_ascii() {

@inline(never)
public func run_StringComparison_ascii(_ N: Int) {
let workload = Workload_ascii._unsafelyUnwrappedUnchecked
let workload = Workload_ascii.unsafelyUnwrapped
let tripCount = workload.tripCount
let payload = workload.payload
for _ in 1...tripCount*N {
Expand Down Expand Up @@ -167,7 +167,7 @@ public func setup_StringComparison_latin1() {

@inline(never)
public func run_StringComparison_latin1(_ N: Int) {
let workload = Workload_latin1._unsafelyUnwrappedUnchecked
let workload = Workload_latin1.unsafelyUnwrapped
let tripCount = workload.tripCount
let payload = workload.payload
for _ in 1...tripCount*N {
Expand Down Expand Up @@ -204,7 +204,7 @@ public func setup_StringComparison_fastPrenormal() {

@inline(never)
public func run_StringComparison_fastPrenormal(_ N: Int) {
let workload = Workload_fastPrenormal._unsafelyUnwrappedUnchecked
let workload = Workload_fastPrenormal.unsafelyUnwrapped
let tripCount = workload.tripCount
let payload = workload.payload
for _ in 1...tripCount*N {
Expand Down Expand Up @@ -241,7 +241,7 @@ public func setup_StringComparison_slowerPrenormal() {

@inline(never)
public func run_StringComparison_slowerPrenormal(_ N: Int) {
let workload = Workload_slowerPrenormal._unsafelyUnwrappedUnchecked
let workload = Workload_slowerPrenormal.unsafelyUnwrapped
let tripCount = workload.tripCount
let payload = workload.payload
for _ in 1...tripCount*N {
Expand Down Expand Up @@ -278,7 +278,7 @@ public func setup_StringComparison_nonBMPSlowestPrenormal() {

@inline(never)
public func run_StringComparison_nonBMPSlowestPrenormal(_ N: Int) {
let workload = Workload_nonBMPSlowestPrenormal._unsafelyUnwrappedUnchecked
let workload = Workload_nonBMPSlowestPrenormal.unsafelyUnwrapped
let tripCount = workload.tripCount
let payload = workload.payload
for _ in 1...tripCount*N {
Expand Down Expand Up @@ -315,7 +315,7 @@ public func setup_StringComparison_emoji() {

@inline(never)
public func run_StringComparison_emoji(_ N: Int) {
let workload = Workload_emoji._unsafelyUnwrappedUnchecked
let workload = Workload_emoji.unsafelyUnwrapped
let tripCount = workload.tripCount
let payload = workload.payload
for _ in 1...tripCount*N {
Expand Down Expand Up @@ -352,7 +352,7 @@ public func setup_StringComparison_abnormal() {

@inline(never)
public func run_StringComparison_abnormal(_ N: Int) {
let workload = Workload_abnormal._unsafelyUnwrappedUnchecked
let workload = Workload_abnormal.unsafelyUnwrapped
let tripCount = workload.tripCount
let payload = workload.payload
for _ in 1...tripCount*N {
Expand Down Expand Up @@ -389,7 +389,7 @@ public func setup_StringComparison_zalgo() {

@inline(never)
public func run_StringComparison_zalgo(_ N: Int) {
let workload = Workload_zalgo._unsafelyUnwrappedUnchecked
let workload = Workload_zalgo.unsafelyUnwrapped
let tripCount = workload.tripCount
let payload = workload.payload
for _ in 1...tripCount*N {
Expand Down Expand Up @@ -426,7 +426,7 @@ public func setup_StringComparison_longSharedPrefix() {

@inline(never)
public func run_StringComparison_longSharedPrefix(_ N: Int) {
let workload = Workload_longSharedPrefix._unsafelyUnwrappedUnchecked
let workload = Workload_longSharedPrefix.unsafelyUnwrapped
let tripCount = workload.tripCount
let payload = workload.payload
for _ in 1...tripCount*N {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/StringComparison.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public func setup_StringComparison_${Name}() {

@inline(never)
public func run_StringComparison_${Name}(_ N: Int) {
let workload = Workload_${Name}._unsafelyUnwrappedUnchecked
let workload = Workload_${Name}.unsafelyUnwrapped
let tripCount = workload.tripCount
let payload = workload.payload
for _ in 1...tripCount*N {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibCollectionUnittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add_swift_library(swiftStdlibCollectionUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYP
LoggingWrappers.swift
MinimalCollections.swift
RangeSelection.swift
../../public/core/WriteBackMutableSlice.swift
WriteBackMutableSlice.swift

SWIFT_MODULE_DEPENDS StdlibUnittest
SWIFT_MODULE_DEPENDS_LINUX Glibc
Expand Down
16 changes: 8 additions & 8 deletions stdlib/private/StdlibCollectionUnittest/MinimalCollections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public struct MinimalCollection<T> : Collection {

public func distance(from start: MinimalIndex, to end: MinimalIndex)
-> Int {
_precondition(start <= end,
precondition(start <= end,
"Only BidirectionalCollections can have end come before start")
// FIXME: swift-3-indexing-model: perform a range check properly.
if start != endIndex {
Expand All @@ -718,7 +718,7 @@ public struct MinimalCollection<T> : Collection {
}

public func index(_ i: Index, offsetBy n: Int) -> Index {
_precondition(n >= 0,
precondition(n >= 0,
"Only BidirectionalCollections can be advanced by a negative amount")
// FIXME: swift-3-indexing-model: perform a range check properly.
if i != endIndex {
Expand Down Expand Up @@ -880,7 +880,7 @@ public struct MinimalRangeReplaceableCollection<T> : Collection, RangeReplaceabl

public func distance(from start: MinimalIndex, to end: MinimalIndex)
-> Int {
_precondition(start <= end,
precondition(start <= end,
"Only BidirectionalCollections can have end come before start")
// FIXME: swift-3-indexing-model: perform a range check properly.
if start != endIndex {
Expand All @@ -893,7 +893,7 @@ public struct MinimalRangeReplaceableCollection<T> : Collection, RangeReplaceabl
}

public func index(_ i: Index, offsetBy n: Int) -> Index {
_precondition(n >= 0,
precondition(n >= 0,
"Only BidirectionalCollections can be advanced by a negative amount")
// FIXME: swift-3-indexing-model: perform a range check properly.
if i != endIndex {
Expand Down Expand Up @@ -1130,7 +1130,7 @@ public struct MinimalMutableCollection<T> : Collection, MutableCollection {

public func distance(from start: MinimalIndex, to end: MinimalIndex)
-> Int {
_precondition(start <= end,
precondition(start <= end,
"Only BidirectionalCollections can have end come before start")
// FIXME: swift-3-indexing-model: perform a range check properly.
if start != endIndex {
Expand All @@ -1143,7 +1143,7 @@ public struct MinimalMutableCollection<T> : Collection, MutableCollection {
}

public func index(_ i: Index, offsetBy n: Int) -> Index {
_precondition(n >= 0,
precondition(n >= 0,
"Only BidirectionalCollections can be advanced by a negative amount")
// FIXME: swift-3-indexing-model: perform a range check properly.
if i != endIndex {
Expand Down Expand Up @@ -1313,7 +1313,7 @@ public struct MinimalMutableRangeReplaceableCollection<T> : Collection, MutableC

public func distance(from start: MinimalIndex, to end: MinimalIndex)
-> Int {
_precondition(start <= end,
precondition(start <= end,
"Only BidirectionalCollections can have end come before start")
// FIXME: swift-3-indexing-model: perform a range check properly.
if start != endIndex {
Expand All @@ -1326,7 +1326,7 @@ public struct MinimalMutableRangeReplaceableCollection<T> : Collection, MutableC
}

public func index(_ i: Index, offsetBy n: Int) -> Index {
_precondition(n >= 0,
precondition(n >= 0,
"Only BidirectionalCollections can be advanced by a negative amount")
// FIXME: swift-3-indexing-model: perform a range check properly.
if i != endIndex {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//===--- WriteBackMutableSlice.swift --------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

@inlinable
internal func _writeBackMutableSlice<C, Slice_>(
_ self_: inout C, bounds: Range<C.Index>, slice: Slice_
) where
C : MutableCollection,
Slice_ : Collection,
C.Element == Slice_.Element,
C.Index == Slice_.Index {

self_._failEarlyRangeCheck(bounds, bounds: self_.startIndex..<self_.endIndex)

// FIXME(performance): can we use
// _withUnsafeMutableBufferPointerIfSupported? Would that create inout
// aliasing violations if the newValue points to the same buffer?

var selfElementIndex = bounds.lowerBound
let selfElementsEndIndex = bounds.upperBound
var newElementIndex = slice.startIndex
let newElementsEndIndex = slice.endIndex

while selfElementIndex != selfElementsEndIndex &&
newElementIndex != newElementsEndIndex {

self_[selfElementIndex] = slice[newElementIndex]
self_.formIndex(after: &selfElementIndex)
slice.formIndex(after: &newElementIndex)
}

precondition(
selfElementIndex == selfElementsEndIndex,
"Cannot replace a slice of a MutableCollection with a slice of a smaller size")
precondition(
newElementIndex == newElementsEndIndex,
"Cannot replace a slice of a MutableCollection with a slice of a larger size")
}

6 changes: 3 additions & 3 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ func stopTrackingObjects(_: UnsafePointer<CChar>) -> Int
public final class TestSuite {
public init(_ name: String) {
self.name = name
_precondition(
precondition(
_testNameToIndex[name] == nil,
"test suite with the same name already exists")
_allTestSuites.append(self)
Expand Down Expand Up @@ -1543,12 +1543,12 @@ public final class TestSuite {
}

public func setUp(_ code: @escaping () -> Void) {
_precondition(_testSetUpCode == nil, "set-up code already set")
precondition(_testSetUpCode == nil, "set-up code already set")
_testSetUpCode = code
}

public func tearDown(_ code: @escaping () -> Void) {
_precondition(_testTearDownCode == nil, "tear-down code already set")
precondition(_testTearDownCode == nil, "tear-down code already set")
_testTearDownCode = code
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public func withOverriddenLocaleCurrentLocale<Result>(
guard let oldMethod = class_getClassMethod(
NSLocale.self, #selector(getter: NSLocale.current)) as Optional
else {
_preconditionFailure("Could not find +[Locale currentLocale]")
preconditionFailure("Could not find +[Locale currentLocale]")
}

guard let newMethod = class_getClassMethod(
NSLocale.self, #selector(NSLocale._swiftUnittest_currentLocale)) as Optional
else {
_preconditionFailure("Could not find +[Locale _swiftUnittest_currentLocale]")
preconditionFailure("Could not find +[Locale _swiftUnittest_currentLocale]")
}

precondition(_temporaryLocaleCurrentLocale == nil,
Expand Down
10 changes: 5 additions & 5 deletions stdlib/public/SDK/Accelerate/BNNS.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ extension BNNSImageStackDescriptor {
image_stride: Int,
data_type: BNNSDataType) {

_precondition(data_type != .indexed8,
precondition(data_type != .indexed8,
"Image stacks cannot use the indexed8 data type.")

self.init(width: width,
Expand All @@ -119,7 +119,7 @@ extension BNNSVectorDescriptor {
public init(size: Int,
data_type: BNNSDataType) {

_precondition(data_type != .indexed8,
precondition(data_type != .indexed8,
"Vectors cannot use the indexed8 data type.")

self.init(size: size,
Expand All @@ -137,7 +137,7 @@ extension BNNSLayerData {
data_scale: Float = 1,
data_bias: Float = 0) {

_precondition(data_type != .indexed8,
precondition(data_type != .indexed8,
"This initializer cannot be used with the indexed8 data type; use BNNSLayerData.indexed8 instead.")

self.init(data: data,
Expand Down Expand Up @@ -173,9 +173,9 @@ extension BNNSActivation {
alpha: Float = .nan,
beta: Float = .nan) {
if #available(macOS 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *) {
_precondition(function != .integerLinearSaturate,
precondition(function != .integerLinearSaturate,
"This initializer cannot be used with the integerLinearSaturate activation function; use BNNSActivation.integerLinearSaturate(scale:Int32, offset:Int32, shift:Int32) instead.")
_precondition(function != .integerLinearSaturatePerChannel,
precondition(function != .integerLinearSaturatePerChannel,
"This initializer cannot be used with the integerLinearSaturatePerChannel activation function; use BNNSActivation.integerLinearSaturatePerChannel(scale:UnsafePointer<Int32>, offset:UnsafePointer<Int32>, shift:UnsafePointer<Int32>) instead.")
}
self.init(function: function,
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/SDK/CoreAudio/CoreAudio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension AudioBufferList {
/// - Returns: the size in bytes of an `AudioBufferList` that can hold up to
/// `maximumBuffers` `AudioBuffer`s.
public static func sizeInBytes(maximumBuffers: Int) -> Int {
_precondition(maximumBuffers >= 1,
precondition(maximumBuffers >= 1,
"AudioBufferList should contain at least one AudioBuffer")
return MemoryLayout<AudioBufferList>.size +
(maximumBuffers - 1) * MemoryLayout<AudioBuffer>.stride
Expand All @@ -69,7 +69,7 @@ extension AudioBufferList {
-> UnsafeMutableAudioBufferListPointer {
let byteSize = sizeInBytes(maximumBuffers: maximumBuffers)
let ablMemory = calloc(byteSize, 1)
_precondition(ablMemory != nil,
precondition(ablMemory != nil,
"failed to allocate memory for an AudioBufferList")

let listPtr = ablMemory!.bindMemory(to: AudioBufferList.self, capacity: 1)
Expand Down Expand Up @@ -153,12 +153,12 @@ extension UnsafeMutableAudioBufferListPointer
/// Access an indexed `AudioBuffer` (`mBuffers[i]`).
public subscript(index: Index) -> Element {
get {
_precondition(index >= 0 && index < self.count,
precondition(index >= 0 && index < self.count,
"subscript index out of range")
return (_audioBuffersPointer + index).pointee
}
nonmutating set(newValue) {
_precondition(index >= 0 && index < self.count,
precondition(index >= 0 && index < self.count,
"subscript index out of range")
(_audioBuffersPointer + index).pointee = newValue
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/ExtraStringAPIs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension String.UTF16View.Index {
@available(swift, deprecated: 3.2)
@available(swift, obsoleted: 4.0)
public init(_ offset: Int) {
_precondition(offset >= 0, "Negative UTF16 index offset not allowed")
assert(offset >= 0, "Negative UTF16 index offset not allowed")
self.init(encodedOffset: offset)
}

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/NSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extension Array : _ObjectiveCBridgeable {
/// The provided `NSArray` will be copied to ensure that the copy can
/// not be mutated by other code.
internal init(_cocoaArray: NSArray) {
_sanityCheck(_isBridgedVerbatimToObjectiveC(Element.self),
assert(_isBridgedVerbatimToObjectiveC(Element.self),
"Array can be backed by NSArray only when the element type can be bridged verbatim to Objective-C")
// FIXME: We would like to call CFArrayCreateCopy() to avoid doing an
// objc_msgSend() for instances of CoreFoundation types. We can't do that
Expand Down
Loading