Skip to content

Commit 825e9d0

Browse files
committed
[stdlib] More documentation revisions / consistency fixes.
1 parent b7af9bf commit 825e9d0

16 files changed

+213
-203
lines changed

stdlib/public/core/Arrays.swift.gyb

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,10 +1675,10 @@ extension ${Self} {
16751675
///
16761676
/// - Parameter body: A closure with an `UnsafeBufferPointer` parameter that
16771677
/// points to the contiguous storage for the array. ${contiguousCaveat} If
1678-
/// `body` has a return value, it is used as the return value for the
1679-
/// `withUnsafeBufferPointer(_:)` method. The pointer argument is valid
1680-
/// only for the duration of the method's execution.
1681-
/// - Returns: The return value of the `body` closure parameter, if any.
1678+
/// `body` has a return value, that value is also used as the return value
1679+
/// for the `withUnsafeBufferPointer(_:)` method. The pointer argument is
1680+
/// valid only for the duration of the method's execution.
1681+
/// - Returns: The return value, if any, of the `body` closure parameter.
16821682
@_inlineable
16831683
public func withUnsafeBufferPointer<R>(
16841684
_ body: (UnsafeBufferPointer<Element>) throws -> R
@@ -1717,11 +1717,11 @@ extension ${Self} {
17171717
///
17181718
/// - Parameter body: A closure with an `UnsafeMutableBufferPointer`
17191719
/// parameter that points to the contiguous storage for the array.
1720-
/// ${contiguousCaveat} If `body` has a return value, it is used as the
1721-
/// return value for the `withUnsafeMutableBufferPointer(_:)` method. The
1722-
/// pointer argument is valid only for the duration of the method's
1723-
/// execution.
1724-
/// - Returns: The return value of the `body` closure parameter, if any.
1720+
/// ${contiguousCaveat} If `body` has a return value, that value is also
1721+
/// used as the return value for the `withUnsafeMutableBufferPointer(_:)`
1722+
/// method. The pointer argument is valid only for the duration of the
1723+
/// method's execution.
1724+
/// - Returns: The return value, if any, of the `body` closure parameter.
17251725
@_semantics("array.withUnsafeMutableBufferPointer")
17261726
@inline(__always) // Performance: This method should get inlined into the
17271727
// caller such that we can combine the partial apply with the apply in this
@@ -2248,10 +2248,11 @@ extension ${Self} {
22482248
///
22492249
/// - Parameter body: A closure with an `UnsafeMutableRawBufferPointer`
22502250
/// parameter that points to the contiguous storage for the array.
2251-
/// ${contiguousCaveat} If `body` has a return value, it is used as the
2252-
/// return value for the `withUnsafeMutableBytes(_:)` method. The argument
2253-
/// is valid only for the duration of the closure's execution.
2254-
/// - Returns: The return value of the `body` closure parameter, if any.
2251+
/// ${contiguousCaveat} If `body` has a return value, that value is also
2252+
/// used as the return value for the `withUnsafeMutableBytes(_:)` method.
2253+
/// The argument is valid only for the duration of the closure's
2254+
/// execution.
2255+
/// - Returns: The return value, if any, of the `body` closure parameter.
22552256
@_inlineable
22562257
public mutating func withUnsafeMutableBytes<R>(
22572258
_ body: (UnsafeMutableRawBufferPointer) throws -> R
@@ -2282,10 +2283,10 @@ extension ${Self} {
22822283
///
22832284
/// - Parameter body: A closure with an `UnsafeRawBufferPointer` parameter
22842285
/// that points to the contiguous storage for the array.
2285-
/// ${contiguousCaveat} If `body` has a return value, it is used as the
2286-
/// return value for the `withUnsafeBytes(_:)` method. The argument is
2287-
/// valid only for the duration of the closure's execution.
2288-
/// - Returns: The return value of the `body` closure parameter, if any.
2286+
/// ${contiguousCaveat} If `body` has a return value, that value is also
2287+
/// used as the return value for the `withUnsafeBytes(_:)` method. The
2288+
/// argument is valid only for the duration of the closure's execution.
2289+
/// - Returns: The return value, if any, of the `body` closure parameter.
22892290
@_inlineable
22902291
public func withUnsafeBytes<R>(
22912292
_ body: (UnsafeRawBufferPointer) throws -> R

stdlib/public/core/Bool.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ extension Bool : Equatable, Hashable {
159159
extension Bool : LosslessStringConvertible {
160160
/// Creates a new Boolean value from the given string.
161161
///
162-
/// If `description` is any string other than `"true"` or `"false"`, the
163-
/// result is `nil`. This initializer is case sensitive.
162+
/// If the `description` value is any string other than `"true"` or
163+
/// `"false"`, the result is `nil`. This initializer is case sensitive.
164164
///
165165
/// - Parameter description: A string representation of the Boolean value.
166166
public init?(_ description: String) {

stdlib/public/core/Builtin.swift

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,25 @@ func _canBeClass<T>(_: T.Type) -> Int8 {
8282
/// Returns the bits of the given instance, interpreted as having the specified
8383
/// type.
8484
///
85-
/// Only use this function to convert the instance passed as `x` to a
86-
/// layout-compatible type when the conversion is not possible through other
87-
/// means. Common conversions that are supported by the standard library
85+
/// Use this function only to convert the instance passed as `x` to a
86+
/// layout-compatible type when conversion through other means is not
87+
/// possible. Common conversions supported by the Swift standard library
8888
/// include the following:
8989
///
90-
/// - To convert an integer value from one type to another, use an initializer
91-
/// or the `numericCast(_:)` function.
92-
/// - To perform a bitwise conversion of an integer value to a different type,
93-
/// use an `init(bitPattern:)` or `init(truncatingBitPattern:)` initializer.
94-
/// - To convert between a pointer and an integer value with that bit pattern,
95-
/// or vice versa, use the `init(bitPattern:)` initializer for the
96-
/// destination type.
97-
/// - To perform a reference cast, use the casting operators (`as`, `as!`, or
98-
/// `as?`) or the `unsafeDowncast(_:to:)` function. Do not use
90+
/// - Value conversion from one integer type to another. Use the destination
91+
/// type's initializer or the `numericCast(_:)` function.
92+
/// - Bitwise conversion from one integer type to another. Use the destination
93+
/// type's `init(extendingOrTruncating:)` or `init(bitPattern:)`
94+
/// initializer.
95+
/// - Conversion from a pointer to an integer value with the bit pattern of the
96+
/// pointer's address in memory, or vice versa. Use the `init(bitPattern:)`
97+
/// initializer for the destination type.
98+
/// - Casting an instance of a reference type. Use the casting operators (`as`,
99+
/// `as!`, or `as?`) or the `unsafeDowncast(_:to:)` function. Do not use
99100
/// `unsafeBitCast(_:to:)` with class or pointer types; doing so may
100101
/// introduce undefined behavior.
101102
///
102-
/// - Warning: Calling this function breaks the guarantees of Swift's type
103+
/// - Warning: Calling this function breaks the guarantees of the Swift type
103104
/// system; use with extreme care.
104105
///
105106
/// - Parameters:
@@ -656,12 +657,12 @@ func _trueAfterDiagnostics() -> Builtin.Int1 {
656657
/// particularly when the dynamic type is different from the static type. The
657658
/// *static type* of a value is the known, compile-time type of the value. The
658659
/// *dynamic type* of a value is the value's actual type at run-time, which
659-
/// may be nested inside its concrete type.
660+
/// can be nested inside its concrete type.
660661
///
661662
/// In the following code, the `count` variable has the same static and dynamic
662663
/// type: `Int`. When `count` is passed to the `printInfo(_:)` function,
663-
/// however, the `value` parameter has a static type of `Any`, the type
664-
/// declared for the parameter, and a dynamic type of `Int`.
664+
/// however, the `value` parameter has a static type of `Any` (the type
665+
/// declared for the parameter) and a dynamic type of `Int`.
665666
///
666667
/// func printInfo(_ value: Any) {
667668
/// let type = type(of: value)
@@ -673,7 +674,7 @@ func _trueAfterDiagnostics() -> Builtin.Int1 {
673674
/// // '5' of type 'Int'
674675
///
675676
/// The dynamic type returned from `type(of:)` is a *concrete metatype*
676-
/// (`T.Type`) for a class, structure, enumeration, or other non-protocol type
677+
/// (`T.Type`) for a class, structure, enumeration, or other nonprotocol type
677678
/// `T`, or an *existential metatype* (`P.Type`) for a protocol or protocol
678679
/// composition `P`. When the static type of the value passed to `type(of:)`
679680
/// is constrained to a class or protocol, you can use that metatype to access
@@ -709,19 +710,22 @@ func _trueAfterDiagnostics() -> Builtin.Int1 {
709710
/// retrieves the overridden value from the `EmojiSmiley` subclass, instead of
710711
/// the `Smiley` class's original definition.
711712
///
713+
/// Finding the Dynamic Type in a Generic Context
714+
/// =============================================
715+
///
712716
/// Normally, you don't need to be aware of the difference between concrete and
713717
/// existential metatypes, but calling `type(of:)` can yield unexpected
714718
/// results in a generic context with a type parameter bound to a protocol. In
715719
/// a case like this, where a generic parameter `T` is bound to a protocol
716720
/// `P`, the type parameter is not statically known to be a protocol type in
717-
/// the body of the generic function, so `type(of:)` can only produce the
718-
/// concrete metatype `P.Protocol`.
721+
/// the body of the generic function. As a result, `type(of:)` can only
722+
/// produce the concrete metatype `P.Protocol`.
719723
///
720724
/// The following example defines a `printGenericInfo(_:)` function that takes
721725
/// a generic parameter and declares the `String` type's conformance to a new
722726
/// protocol `P`. When `printGenericInfo(_:)` is called with a string that has
723727
/// `P` as its static type, the call to `type(of:)` returns `P.self` instead
724-
/// of the dynamic type inside the parameter, `String.self`.
728+
/// of `String.self` (the dynamic type inside the parameter).
725729
///
726730
/// func printGenericInfo<T>(_ value: T) {
727731
/// let type = type(of: value)
@@ -750,8 +754,8 @@ func _trueAfterDiagnostics() -> Builtin.Int1 {
750754
/// betterPrintGenericInfo(stringAsP)
751755
/// // 'Hello!' of type 'String'
752756
///
753-
/// - Parameter value: The value to find the dynamic type of.
754-
/// - Returns: The dynamic type, which is a value of metatype type.
757+
/// - Parameter value: The value for which to find the dynamic type.
758+
/// - Returns: The dynamic type, which is a metatype instance.
755759
@_transparent
756760
@_semantics("typechecker.type(of:)")
757761
public func type<T, Metatype>(of value: T) -> Metatype {
@@ -776,15 +780,15 @@ public func type<T, Metatype>(of value: T) -> Metatype {
776780
/// whether all the elements in an array match a predicate. The function won't
777781
/// compile as written, because a lazy collection's `filter(_:)` method
778782
/// requires an escaping closure. The lazy collection isn't persisted, so the
779-
/// `predicate` closure won't actually escape the body of the function, but
780-
/// even so it can't be used in this way.
783+
/// `predicate` closure won't actually escape the body of the function;
784+
/// nevertheless, it can't be used in this way.
781785
///
782786
/// func allValues(in array: [Int], match predicate: (Int) -> Bool) -> Bool {
783787
/// return array.lazy.filter { !predicate($0) }.isEmpty
784788
/// }
785789
/// // error: closure use of non-escaping parameter 'predicate'...
786790
///
787-
/// `withoutActuallyEscaping(_:do:)` provides a temporarily-escapable copy of
791+
/// `withoutActuallyEscaping(_:do:)` provides a temporarily escapable copy of
788792
/// `predicate` that _can_ be used in a call to the lazy view's `filter(_:)`
789793
/// method. The second version of `allValues(in:match:)` compiles without
790794
/// error, with the compiler guaranteeing that the `escapablePredicate`
@@ -816,7 +820,7 @@ public func type<T, Metatype>(of value: T) -> Metatype {
816820
/// returning. Even though the barrier guarantees that neither closure will
817821
/// escape the function, the `async(execute:)` method still requires that the
818822
/// closures passed be marked as `@escaping`, so the first version of the
819-
/// function does not compile. To resolve this, you can use
823+
/// function does not compile. To resolve these errors, you can use
820824
/// `withoutActuallyEscaping(_:do:)` to get copies of `f` and `g` that can be
821825
/// passed to `async(execute:)`.
822826
///
@@ -837,13 +841,13 @@ public func type<T, Metatype>(of value: T) -> Metatype {
837841
/// after the function returns.
838842
///
839843
/// - Parameters:
840-
/// - closure: A non-escaping closure value that will be made escapable for
841-
/// the duration of the execution of the `body` closure. If `body` has a
842-
/// return value, it is used as the return value for the
844+
/// - closure: A nonescaping closure value that is made escapable for the
845+
/// duration of the execution of the `body` closure. If `body` has a
846+
/// return value, that value is also used as the return value for the
843847
/// `withoutActuallyEscaping(_:do:)` function.
844-
/// - body: A closure that will be immediately executed, receiving an
845-
/// escapable copy of `closure` as an argument.
846-
/// - Returns: The return value of the `body` closure, if any.
848+
/// - body: A closure that is executed immediately with an escapable copy of
849+
/// `closure` as its argument.
850+
/// - Returns: The return value, if any, of the `body` closure.
847851
@_transparent
848852
@_semantics("typechecker.withoutActuallyEscaping(_:do:)")
849853
public func withoutActuallyEscaping<ClosureType, ResultType>(

stdlib/public/core/Collection.swift

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -420,20 +420,18 @@ public struct IndexingIterator<
420420
}
421421

422422
/// A sequence whose elements can be traversed multiple times,
423-
/// nondestructively, and accessed by indexed subscript.
423+
/// nondestructively, and accessed by an indexed subscript.
424424
///
425425
/// Collections are used extensively throughout the standard library. When you
426-
/// use arrays, dictionaries, views of a string's contents and other types,
427-
/// you benefit from the operations that the `Collection` protocol declares
428-
/// and implements.
429-
///
430-
/// In addition to the methods that collections inherit from the `Sequence`
426+
/// use arrays, dictionaries, and other collections, you benefit from the
427+
/// operations that the `Collection` protocol declares and implements. In
428+
/// addition to the operations that collections inherit from the `Sequence`
431429
/// protocol, you gain access to methods that depend on accessing an element
432-
/// at a specific position when using a collection.
430+
/// at a specific position in a collection.
433431
///
434-
/// For example, if you want to print only the first word in a string, search
435-
/// for the index of the first space, and then create a subsequence up to that
436-
/// position.
432+
/// For example, if you want to print only the first word in a string, you can
433+
/// search for the index of the first space, and then create a substring up to
434+
/// that position.
437435
///
438436
/// let text = "Buffalo buffalo buffalo buffalo."
439437
/// if let firstSpace = text.index(of: " ") {
@@ -454,17 +452,18 @@ public struct IndexingIterator<
454452
/// such as the `startIndex` property of a different collection, are invalid
455453
/// indices for this collection.
456454
///
457-
/// Saved indices may become invalid as a result of mutating operations; for
455+
/// Saved indices may become invalid as a result of mutating operations. For
458456
/// more information about index invalidation in mutable collections, see the
459457
/// reference for the `MutableCollection` and `RangeReplaceableCollection`
460458
/// protocols, as well as for the specific type you're using.
461459
///
462460
/// Accessing Individual Elements
463461
/// =============================
464462
///
465-
/// You can access an element of a collection through its subscript with any
466-
/// valid index except the collection's `endIndex` property, a "past the end"
467-
/// index that does not correspond with any element of the collection.
463+
/// You can access an element of a collection through its subscript by using
464+
/// any valid index except the collection's `endIndex` property. This property
465+
/// is a "past the end" index that does not correspond with any element of the
466+
/// collection.
468467
///
469468
/// Here's an example of accessing the first character in a string through its
470469
/// subscript:
@@ -545,7 +544,7 @@ public struct IndexingIterator<
545544
/// A slice inherits the value or reference semantics of its base collection.
546545
/// That is, when working with a slice of a mutable collection that has value
547546
/// semantics, such as an array, mutating the original collection triggers a
548-
/// copy of that collection, and does not affect the contents of the slice.
547+
/// copy of that collection and does not affect the contents of the slice.
549548
///
550549
/// For example, if you update the last element of the `absences` array from
551550
/// `0` to `2`, the `secondHalf` slice is unchanged.
@@ -560,11 +559,12 @@ public struct IndexingIterator<
560559
/// =======================
561560
///
562561
/// Although a sequence can be consumed as it is traversed, a collection is
563-
/// guaranteed to be multipass: Any element may be repeatedly accessed by
562+
/// guaranteed to be *multipass*: Any element can be repeatedly accessed by
564563
/// saving its index. Moreover, a collection's indices form a finite range of
565-
/// the positions of the collection's elements. This guarantees the safety of
566-
/// operations that depend on a sequence being finite, such as checking to see
567-
/// whether a collection contains an element.
564+
/// the positions of the collection's elements. The fact that all collections
565+
/// are finite guarantees the safety of many sequence operations, such as
566+
/// using the `contains(_:)` method to test whether a collection includes an
567+
/// element.
568568
///
569569
/// Iterating over the elements of a collection by their positions yields the
570570
/// same elements in the same order as iterating over that collection using
@@ -598,31 +598,31 @@ public struct IndexingIterator<
598598
/// elements, make sure that its type conforms to the `Collection` protocol in
599599
/// order to give a more useful and more efficient interface for sequence and
600600
/// collection operations. To add `Collection` conformance to your type, you
601-
/// must declare at least the four following requirements:
601+
/// must declare at least the following requirements:
602602
///
603-
/// - the `startIndex` and `endIndex` properties,
604-
/// - a subscript that provides at least read-only access to your type's
605-
/// elements, and
606-
/// - the `index(after:)` method for advancing an index into your collection.
603+
/// - The `startIndex` and `endIndex` properties
604+
/// - A subscript that provides at least read-only access to your type's
605+
/// elements
606+
/// - The `index(after:)` method for advancing an index into your collection
607607
///
608608
/// Expected Performance
609609
/// ====================
610610
///
611611
/// Types that conform to `Collection` are expected to provide the `startIndex`
612612
/// and `endIndex` properties and subscript access to elements as O(1)
613-
/// operations. Types that are not able to guarantee that expected performance
614-
/// must document the departure, because many collection operations depend on
615-
/// O(1) subscripting performance for their own performance guarantees.
613+
/// operations. Types that are not able to guarantee this performance must
614+
/// document the departure, because many collection operations depend on O(1)
615+
/// subscripting performance for their own performance guarantees.
616616
///
617617
/// The performance of some collection operations depends on the type of index
618618
/// that the collection provides. For example, a random-access collection,
619-
/// which can measure the distance between two indices in O(1) time, will be
620-
/// able to calculate its `count` property in O(1) time. Conversely, because a
621-
/// forward or bidirectional collection must traverse the entire collection to
622-
/// count the number of contained elements, accessing its `count` property is
623-
/// an O(*n*) operation.
624-
public protocol Collection : _Indexable, Sequence
625-
// FIXME(ABI) (Revert Where Clauses): Restore these
619+
/// which can measure the distance between two indices in O(1) time, can
620+
/// calculate its `count` property in O(1) time. Conversely, because a forward
621+
/// or bidirectional collection must traverse the entire collection to count
622+
/// the number of contained elements, accessing its `count` property is an
623+
/// O(*n*) operation.
624+
public protocol Collection : _Indexable, Sequence
625+
// FIXME(ABI) (Revert Where Clauses): Restore these
626626
// where SubSequence: Collection, Indices: Collection,
627627
{
628628
/// A type that represents the number of steps between a pair of

0 commit comments

Comments
 (0)