Skip to content

Commit 78ba5d5

Browse files
author
Max Moiseev
committed
[stdlib] Requires in comments changed to Precondition
1 parent 40b1a0b commit 78ba5d5

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

+219
-219
lines changed

stdlib/private/StdlibUnittest/LifetimeTracked.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class LifetimeTracked : ForwardIndex, CustomStringConvertible {
3232

3333
/// Returns the next consecutive value after `self`.
3434
///
35-
/// Requires: the next value is representable.
35+
/// Precondition: the next value is representable.
3636
public func successor() -> LifetimeTracked {
3737
return LifetimeTracked(self.value.successor())
3838
}

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ public func checkForwardIndex<
18821882
/// to generate equality expectations from pairs of positions in
18831883
/// `instances`.
18841884
///
1885-
/// - Preconditions:
1885+
/// - Precondition:
18861886
/// - all elements of `instances` are reachable from `startIndex`.
18871887
/// - `endIndex` is reachable from all elements of `instances`.
18881888
public func checkBidirectionalIndex<
@@ -1915,7 +1915,7 @@ public func checkBidirectionalIndex<
19151915
/// about the results of `advanced(by:)` and `distance(to:)` from pairs of
19161916
/// positions in `instances` and `distances`.
19171917
///
1918-
/// - Preconditions:
1918+
/// - Precondition:
19191919
/// - all elements of `instances` are reachable from `startIndex`.
19201920
/// - `endIndex` is reachable from all elements of `instances`.
19211921
public func checkRandomAccessIndex<

stdlib/public/core/ArrayBuffer.swift

+7-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct _ArrayBuffer<Element> : _ArrayBufferProtocol {
3535

3636
/// Returns an `_ArrayBuffer<U>` containing the same elements.
3737
///
38-
/// - Requires: The elements actually have dynamic type `U`, and `U`
38+
/// - Precondition: The elements actually have dynamic type `U`, and `U`
3939
/// is a class or `@objc` existential.
4040
@warn_unused_result
4141
internal func cast<U>(toBufferOf _: U.Type) -> _ArrayBuffer<U> {
@@ -51,7 +51,8 @@ public struct _ArrayBuffer<Element> : _ArrayBufferProtocol {
5151
/// Returns an `_ArrayBuffer<U>` containing the same elements,
5252
/// deferring checking each element's `U`-ness until it is accessed.
5353
///
54-
/// - Requires: `U` is a class or `@objc` existential derived from `Element`.
54+
/// - Precondition: `U` is a class or `@objc` existential derived from
55+
/// `Element`.
5556
@warn_unused_result
5657
internal func downcast<U>(
5758
toBufferWithDeferredTypeCheckOf _: U.Type
@@ -410,7 +411,7 @@ extension _ArrayBuffer {
410411
/// Call `body(p)`, where `p` is an `UnsafeMutableBufferPointer`
411412
/// over the underlying contiguous storage.
412413
///
413-
/// - Requires: Such contiguous storage exists or the buffer is empty.
414+
/// - Precondition: Such contiguous storage exists or the buffer is empty.
414415
public mutating func withUnsafeMutableBufferPointer<R>(
415416
@noescape body: (UnsafeMutableBufferPointer<Element>) throws -> R
416417
) rethrows -> R {
@@ -430,7 +431,7 @@ extension _ArrayBuffer {
430431

431432
/// An object that keeps the elements stored in this buffer alive.
432433
///
433-
/// - Requires: This buffer is backed by a `_ContiguousArrayBuffer`.
434+
/// - Precondition: This buffer is backed by a `_ContiguousArrayBuffer`.
434435
public var nativeOwner: AnyObject {
435436
_sanityCheck(_isNative, "Expect a native array")
436437
return _native._storage
@@ -490,7 +491,7 @@ extension _ArrayBuffer {
490491

491492
/// Our native representation.
492493
///
493-
/// - Requires: `_isNative`.
494+
/// - Precondition: `_isNative`.
494495
var _native: NativeBuffer {
495496
return NativeBuffer(
496497
_isClassOrObjCExistential(Element.self)
@@ -499,7 +500,7 @@ extension _ArrayBuffer {
499500

500501
/// Fast access to the native representation.
501502
///
502-
/// - Requires: `_isNativeTypeChecked`.
503+
/// - Precondition: `_isNativeTypeChecked`.
503504
var _nativeTypeChecked: NativeBuffer {
504505
return NativeBuffer(_storage.nativeInstance_noSpareBits)
505506
}

stdlib/public/core/ArrayBufferProtocol.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public protocol _ArrayBufferProtocol : MutableCollection {
6666
/// Replace the given `subRange` with the first `newCount` elements of
6767
/// the given collection.
6868
///
69-
/// - Requires: This buffer is backed by a uniquely-referenced
69+
/// - Precondition: This buffer is backed by a uniquely-referenced
7070
/// `_ContiguousArrayBuffer`.
7171
mutating func replace<C : Collection where C.Iterator.Element == Element>(
7272
subRange subRange: Range<Int>,
@@ -87,7 +87,7 @@ public protocol _ArrayBufferProtocol : MutableCollection {
8787
/// Call `body(p)`, where `p` is an `UnsafeMutableBufferPointer`
8888
/// over the underlying contiguous storage.
8989
///
90-
/// - Requires: Such contiguous storage exists or the buffer is empty.
90+
/// - Precondition: Such contiguous storage exists or the buffer is empty.
9191
mutating func withUnsafeMutableBufferPointer<R>(
9292
@noescape body: (UnsafeMutableBufferPointer<Element>) throws -> R
9393
) rethrows -> R

stdlib/public/core/ArrayCast.swift

+4-5
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ internal enum _BridgeStyle {
4040

4141
/// Implements `source as! [TargetElement]`.
4242
///
43-
/// - Requires: At least one of `SourceElement` and `TargetElement` is a
44-
/// class type or ObjC existential. May trap for other "valid" inputs
45-
/// when `TargetElement` is not bridged verbatim, if an element can't
46-
/// be converted.
43+
/// - Precondition: At least one of `SourceElement` and `TargetElement` is a
44+
/// class type or ObjC existential. May trap for other "valid" inputs when
45+
/// `TargetElement` is not bridged verbatim, if an element can't be converted.
4746
public func _arrayForceCast<SourceElement, TargetElement>(
4847
source: Array<SourceElement>
4948
) -> Array<TargetElement> {
@@ -181,7 +180,7 @@ ElementwiseBridging:
181180
/// `source` to a `TargetElement` and return the resulting array, or
182181
/// return `nil` if any element fails to convert.
183182
///
184-
/// - Requires: `SourceElement` is a class or ObjC existential type.
183+
/// - Precondition: `SourceElement` is a class or ObjC existential type.
185184
/// O(n), because each element must be checked.
186185
public func _arrayConditionalCast<SourceElement, TargetElement>(
187186
source: [SourceElement]

stdlib/public/core/ArrayType.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protocol _ArrayProtocol
5555
///
5656
/// - Complexity: O(`self.count`).
5757
///
58-
/// - Requires: `i <= count`.
58+
/// - Precondition: `i <= count`.
5959
mutating func insert(newElement: Iterator.Element, at i: Int)
6060

6161
/// Remove and return the element at the given index.
@@ -64,7 +64,7 @@ protocol _ArrayProtocol
6464
///
6565
/// - Complexity: Worst case O(N).
6666
///
67-
/// - Requires: `count > index`.
67+
/// - Precondition: `count > index`.
6868
mutating func remove(at index: Int) -> Iterator.Element
6969

7070
//===--- implementation detail -----------------------------------------===//

stdlib/public/core/Arrays.swift.gyb

+7-7
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,14 @@ public struct ${Self}<Element>
300300
return _buffer.capacity
301301
}
302302

303-
/// - Requires: The array has a native buffer.
303+
/// - Precondition: The array has a native buffer.
304304
@warn_unused_result
305305
@_semantics("array.owner")
306306
internal func _getOwnerWithSemanticLabel_native() -> Builtin.NativeObject {
307307
return Builtin.castToNativeObject(_buffer.nativeOwner)
308308
}
309309

310-
/// - Requires: The array has a native buffer.
310+
/// - Precondition: The array has a native buffer.
311311
@warn_unused_result
312312
@inline(__always)
313313
internal func _getOwner_native() -> Builtin.NativeObject {
@@ -453,7 +453,7 @@ extension ${Self} : ArrayLiteralConvertible {
453453
///
454454
/// This function is referenced by the compiler to allocate array literals.
455455
///
456-
/// - Requires: `storage` is `_ContiguousArrayStorage`.
456+
/// - Precondition: `storage` is `_ContiguousArrayStorage`.
457457
@warn_unused_result
458458
@inline(__always)
459459
public // COMPILER_INTRINSIC
@@ -556,7 +556,7 @@ extension ${Self} : _ArrayProtocol {
556556
/// given `storage`, and a pointer to uninitialized memory for the
557557
/// first element.
558558
///
559-
/// - Requires: `storage is _ContiguousArrayStorage`.
559+
/// - Precondition: `storage is _ContiguousArrayStorage`.
560560
@warn_unused_result
561561
@_semantics("array.uninitialized")
562562
internal static func _adoptStorage(
@@ -715,7 +715,7 @@ extension ${Self} : _ArrayProtocol {
715715

716716
/// Remove and return the last element in O(1).
717717
///
718-
/// - Requires: `!isEmpty`.
718+
/// - Precondition: `!isEmpty`.
719719
public mutating func removeLast() -> Element {
720720
_precondition(count > 0, "can't removeLast from an empty ${Self}")
721721
let i = count
@@ -728,7 +728,7 @@ extension ${Self} : _ArrayProtocol {
728728

729729
/// Insert `newElement` at index `i`.
730730
///
731-
/// - Requires: `i <= count`.
731+
/// - Precondition: `i <= count`.
732732
///
733733
/// - Complexity: O(`self.count`).
734734
public mutating func insert(newElement: Element, at i: Int) {
@@ -1324,7 +1324,7 @@ public func != <Element : Equatable>(
13241324
/// Returns an `Array<Base>` containing the same elements as `a` in
13251325
/// O(1).
13261326
///
1327-
/// - Requires: `Base` is a base class or base `@objc` protocol (such
1327+
/// - Precondition: `Base` is a base class or base `@objc` protocol (such
13281328
/// as `AnyObject`) of `Derived`.
13291329
@warn_unused_result
13301330
public func _arrayUpCast<Derived, Base>(a: Array<Derived>) -> Array<Base> {

stdlib/public/core/BridgeObjectiveC.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
356356

357357
/// Access the `Pointee` instance referenced by `self`.
358358
///
359-
/// - Requires: the pointee has been initialized with an instance of
360-
/// type `Pointee`.
359+
/// - Precondition: the pointee has been initialized with an instance of type
360+
/// `Pointee`.
361361
public var pointee: Pointee {
362362
/// Retrieve the value the pointer points to.
363363
@_transparent get {
@@ -389,7 +389,7 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
389389
/// Access the `i`th element of the raw array pointed to by
390390
/// `self`.
391391
///
392-
/// - Requires: `self != nil`.
392+
/// - Precondition: `self != nil`.
393393
public subscript(i: Int) -> Pointee {
394394
@_transparent
395395
get {

stdlib/public/core/Builtin.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public func _unsafeReferenceCast<T, U>(x: T, to: U.Type) -> U {
220220

221221
/// - returns: `x as T`.
222222
///
223-
/// - Requires: `x is T`. In particular, in -O builds, no test is
223+
/// - Precondition: `x is T`. In particular, in -O builds, no test is
224224
/// performed to ensure that `x` actually has dynamic type `T`.
225225
///
226226
/// - Warning: Trades safety for performance. Use `unsafeDowncast`
@@ -397,7 +397,7 @@ internal func _isObjCTaggedPointer(x: AnyObject) -> Bool {
397397
/// Reference-counting and other operations on this
398398
/// object will have access to the knowledge that it is native.
399399
///
400-
/// - Requires: `bits & _objectPointerIsObjCBit == 0`,
400+
/// - Precondition: `bits & _objectPointerIsObjCBit == 0`,
401401
/// `bits & _objectPointerSpareBits == bits`.
402402
@inline(__always)
403403
@warn_unused_result
@@ -426,7 +426,7 @@ func _makeObjCBridgeObject(
426426
/// Create a `BridgeObject` around the given `object` with the
427427
/// given spare bits.
428428
///
429-
/// - Requires:
429+
/// - Precondition:
430430
///
431431
/// 1. `bits & _objectPointerSpareBits == bits`
432432
/// 2. if `object` is a tagged pointer, `bits == 0`. Otherwise,

stdlib/public/core/CString.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extension String {
2222
/// If `cString` contains ill-formed UTF-8 code unit sequences, replaces them
2323
/// with replacement characters (U+FFFD).
2424
///
25-
/// - Requires: `cString != nil`
25+
/// - Precondition: `cString != nil`
2626
public init(cString: UnsafePointer<CChar>) {
2727
_precondition(cString != nil, "cString must not be nil")
2828
self = String.decodeCString(UnsafePointer(cString), as: UTF8.self,
@@ -35,7 +35,7 @@ extension String {
3535
/// Does not try to repair ill-formed UTF-8 code unit sequences, fails if any
3636
/// such sequences are found.
3737
///
38-
/// - Requires: `cString != nil`
38+
/// - Precondition: `cString != nil`
3939
public init?(validatingUTF8 cString: UnsafePointer<CChar>) {
4040
_precondition(cString != nil, "cString must not be nil")
4141
guard let (result, _) = String.decodeCString(

stdlib/public/core/Character.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public struct Character :
7979

8080
/// Create an instance from a single-character `String`.
8181
///
82-
/// - Requires: `s` contains exactly one extended grapheme cluster.
82+
/// - Precondition: `s` contains exactly one extended grapheme cluster.
8383
public init(_ s: String) {
8484
// The small representation can accept up to 8 code units as long
8585
// as the last one is a continuation. Since the high bit of the
@@ -161,7 +161,7 @@ public struct Character :
161161

162162
/// Access the code unit at `position`.
163163
///
164-
/// - Requires: `position` is a valid position in `self` and
164+
/// - Precondition: `position` is a valid position in `self` and
165165
/// `position != endIndex`.
166166
subscript(position: Int) -> UTF8.CodeUnit {
167167
_sanityCheck(position >= 0)
@@ -233,7 +233,7 @@ public struct Character :
233233

234234
/// Access the code unit at `position`.
235235
///
236-
/// - Requires: `position` is a valid position in `self` and
236+
/// - Precondition: `position` is a valid position in `self` and
237237
/// `position != endIndex`.
238238
subscript(position: Int) -> UTF16.CodeUnit {
239239
_sanityCheck(position >= 0)

0 commit comments

Comments
 (0)