Skip to content

Commit 0ebf95b

Browse files
authored
Merge pull request #10209 from natecook1000/nc-fixes-75-3
Documentation edits
2 parents ec45c61 + 825e9d0 commit 0ebf95b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+229
-536
lines changed

stdlib/public/core/Arrays.swift.gyb

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ if True:
169169
/// specific values.
170170
"""
171171
elif Self == 'Array':
172-
SelfDocComment = '''\
172+
SelfDocComment = """\
173173
/// An ordered, random-access collection.
174174
///
175175
/// Arrays are one of the most commonly used data types in an app. You use
@@ -447,9 +447,7 @@ if True:
447447
///
448448
/// - Note: The `ContiguousArray` and `ArraySlice` types are not bridged;
449449
/// instances of those types always have a contiguous block of memory as
450-
/// their storage.
451-
/// - SeeAlso: `ContiguousArray`, `ArraySlice`, `Sequence`, `Collection`,
452-
/// `RangeReplaceableCollection`'''
450+
/// their storage."""
453451
# FIXME: Write about Array up/down-casting.
454452
else:
455453
raise ValueError('Unhandled case: ' + Self)
@@ -620,8 +618,6 @@ public struct ${Self}<Element>
620618
/// - Returns: An index offset by `n` from the index `i`, unless that index
621619
/// would be beyond `limit` in the direction of movement. In that case,
622620
/// the method returns `nil`.
623-
///
624-
/// - SeeAlso: `index(_:offsetBy:)`, `formIndex(_:offsetBy:limitedBy:)`
625621
@_inlineable
626622
public func index(
627623
_ i: Int, offsetBy n: Int, limitedBy limit: Int
@@ -736,10 +732,6 @@ public struct ${Self}<Element>
736732
///
737733
/// - Parameter bounds: A range of integers. The bounds of the range must be
738734
/// valid indices of the array.
739-
%if Self != 'ArraySlice':
740-
///
741-
/// - SeeAlso: `ArraySlice`
742-
%end
743735
@_inlineable
744736
public subscript(bounds: Range<Int>) -> ArraySlice<Element> {
745737
get {
@@ -1683,12 +1675,10 @@ extension ${Self} {
16831675
///
16841676
/// - Parameter body: A closure with an `UnsafeBufferPointer` parameter that
16851677
/// points to the contiguous storage for the array. ${contiguousCaveat} If
1686-
/// `body` has a return value, it is used as the return value for the
1687-
/// `withUnsafeBufferPointer(_:)` method. The pointer argument is valid
1688-
/// only for the duration of the method's execution.
1689-
/// - Returns: The return value of the `body` closure parameter, if any.
1690-
///
1691-
/// - SeeAlso: `withUnsafeMutableBufferPointer`, `UnsafeBufferPointer`
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.
16921682
@_inlineable
16931683
public func withUnsafeBufferPointer<R>(
16941684
_ body: (UnsafeBufferPointer<Element>) throws -> R
@@ -1727,13 +1717,11 @@ extension ${Self} {
17271717
///
17281718
/// - Parameter body: A closure with an `UnsafeMutableBufferPointer`
17291719
/// parameter that points to the contiguous storage for the array.
1730-
/// ${contiguousCaveat} If `body` has a return value, it is used as the
1731-
/// return value for the `withUnsafeMutableBufferPointer(_:)` method. The
1732-
/// pointer argument is valid only for the duration of the method's
1733-
/// execution.
1734-
/// - Returns: The return value of the `body` closure parameter, if any.
1735-
///
1736-
/// - SeeAlso: `withUnsafeBufferPointer`, `UnsafeMutableBufferPointer`
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.
17371725
@_semantics("array.withUnsafeMutableBufferPointer")
17381726
@inline(__always) // Performance: This method should get inlined into the
17391727
// caller such that we can combine the partial apply with the apply in this
@@ -2260,12 +2248,11 @@ extension ${Self} {
22602248
///
22612249
/// - Parameter body: A closure with an `UnsafeMutableRawBufferPointer`
22622250
/// parameter that points to the contiguous storage for the array.
2263-
/// ${contiguousCaveat} If `body` has a return value, it is used as the
2264-
/// return value for the `withUnsafeMutableBytes(_:)` method. The argument
2265-
/// is valid only for the duration of the closure's execution.
2266-
/// - Returns: The return value of the `body` closure parameter, if any.
2267-
///
2268-
/// - SeeAlso: `withUnsafeBytes`, `UnsafeMutableRawBufferPointer`
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.
22692256
@_inlineable
22702257
public mutating func withUnsafeMutableBytes<R>(
22712258
_ body: (UnsafeMutableRawBufferPointer) throws -> R
@@ -2296,12 +2283,10 @@ extension ${Self} {
22962283
///
22972284
/// - Parameter body: A closure with an `UnsafeRawBufferPointer` parameter
22982285
/// that points to the contiguous storage for the array.
2299-
/// ${contiguousCaveat} If `body` has a return value, it is used as the
2300-
/// return value for the `withUnsafeBytes(_:)` method. The argument is
2301-
/// valid only for the duration of the closure's execution.
2302-
/// - Returns: The return value of the `body` closure parameter, if any.
2303-
///
2304-
/// - SeeAlso: `withUnsafeMutableBytes`, `UnsafeRawBufferPointer`
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.
23052290
@_inlineable
23062291
public func withUnsafeBytes<R>(
23072292
_ body: (UnsafeRawBufferPointer) throws -> R
@@ -2360,7 +2345,6 @@ extension Array {
23602345
///
23612346
/// - Complexity: O(*n*) if the array is bridged, where *n* is the length
23622347
/// of the array; otherwise, O(1).
2363-
/// - SeeAlso: `removeLast()`
23642348
@_inlineable
23652349
public mutating func popLast() -> Element? {
23662350
guard !isEmpty else { return nil }
@@ -2375,7 +2359,6 @@ extension ContiguousArray {
23752359
/// otherwise, `nil`.
23762360
///
23772361
/// - Complexity: O(1)
2378-
/// - SeeAlso: `removeLast()`
23792362
@_inlineable
23802363
public mutating func popLast() -> Element? {
23812364
guard !isEmpty else { return nil }

stdlib/public/core/BidirectionalCollection.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ extension BidirectionalCollection where SubSequence == Self {
232232
/// or more elements; otherwise, `nil`.
233233
///
234234
/// - Complexity: O(1).
235-
/// - SeeAlso: `removeLast()`
236235
public mutating func popLast() -> Element? {
237236
guard !isEmpty else { return nil }
238237
let element = last!
@@ -248,7 +247,6 @@ extension BidirectionalCollection where SubSequence == Self {
248247
/// - Returns: The last element of the collection.
249248
///
250249
/// - Complexity: O(1)
251-
/// - SeeAlso: `popLast()`
252250
@discardableResult
253251
public mutating func removeLast() -> Element {
254252
let element = last!

stdlib/public/core/Bool.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ extension Bool : Equatable, Hashable {
145145
/// - Note: The hash value is not guaranteed to be stable across different
146146
/// invocations of the same program. Do not persist the hash value across
147147
/// program runs.
148-
/// - SeeAlso: `Hashable`
149148
@_transparent
150149
public var hashValue: Int {
151150
return self ? 1 : 0
@@ -160,8 +159,8 @@ extension Bool : Equatable, Hashable {
160159
extension Bool : LosslessStringConvertible {
161160
/// Creates a new Boolean value from the given string.
162161
///
163-
/// If `description` is any string other than `"true"` or `"false"`, the
164-
/// 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.
165164
///
166165
/// - Parameter description: A string representation of the Boolean value.
167166
public init?(_ description: String) {

stdlib/public/core/Builtin.swift

Lines changed: 37 additions & 33 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
///
@@ -831,19 +835,19 @@ public func type<T, Metatype>(of value: T) -> Metatype {
831835
/// }
832836
/// }
833837
///
834-
/// - Important: The escapable copy of `closure` passed as `body` is only valid
838+
/// - Important: The escapable copy of `closure` passed to `body` is only valid
835839
/// during the call to `withoutActuallyEscaping(_:do:)`. It is undefined
836840
/// behavior for the escapable closure to be stored, referenced, or executed
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/CString.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ extension String {
143143
/// - Returns: A tuple with the new string and a Boolean value that indicates
144144
/// whether any repairs were made. If `isRepairing` is `false` and an
145145
/// ill-formed sequence is detected, this method returns `nil`.
146-
///
147-
/// - SeeAlso: `UnicodeCodec`
148146
public static func decodeCString<Encoding : _UnicodeEncoding>(
149147
_ cString: UnsafePointer<Encoding.CodeUnit>?,
150148
as encoding: Encoding.Type,

stdlib/public/core/ClosedRange.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ public struct ClosedRangeIterator<Bound> : IteratorProtocol, Sequence
174174
/// bound by floating-point values, see the `ClosedRange` type. If you need to
175175
/// iterate over consecutive floating-point values, see the
176176
/// `stride(from:through:by:)` function.
177-
///
178-
/// - SeeAlso: `CountableRange`, `ClosedRange`, `Range`
179177
@_fixed_layout
180178
public struct CountableClosedRange<Bound> : RandomAccessCollection
181179
where
@@ -373,8 +371,6 @@ public struct CountableClosedRange<Bound> : RandomAccessCollection
373371
/// let lowercaseA = "a"..."a"
374372
/// print(lowercaseA.isEmpty)
375373
/// // Prints "false"
376-
///
377-
/// - SeeAlso: `CountableRange`, `Range`, `CountableClosedRange`
378374
@_fixed_layout
379375
public struct ClosedRange<
380376
Bound : Comparable

0 commit comments

Comments
 (0)