Skip to content

Commit 5d17b31

Browse files
authored
Merge pull request #11249 from natecook1000/nc-rev-77-1
[stdlib] Documentation revisions
2 parents 25ac930 + 8329ca9 commit 5d17b31

21 files changed

+1426
-271
lines changed

stdlib/public/core/Builtin.swift

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,26 @@ public func _unsafeReferenceCast<T, U>(_ x: T, to: U.Type) -> U {
246246
return Builtin.castReference(x)
247247
}
248248

249-
/// - returns: `x as T`.
249+
/// Returns the given instance cast unconditionally to the specified type.
250250
///
251-
/// - Precondition: `x is T`. In particular, in -O builds, no test is
252-
/// performed to ensure that `x` actually has dynamic type `T`.
251+
/// The instance passed as `x` must be an instance of type `T`.
253252
///
254-
/// - Warning: Trades safety for performance. Use `unsafeDowncast`
255-
/// only when `x as! T` has proven to be a performance problem and you
256-
/// are confident that, always, `x is T`. It is better than an
257-
/// `unsafeBitCast` because it's more restrictive, and because
258-
/// checking is still performed in debug builds.
253+
/// Use this function instead of `unsafeBitcast(_:to:)` because this function
254+
/// is more restrictive and still performs a check in debug builds. In -O
255+
/// builds, no test is performed to ensure that `x` actually has the dynamic
256+
/// type `T`.
257+
///
258+
/// - Warning: This function trades safety for performance. Use
259+
/// `unsafeDowncast(_:to:)` only when you are confident that `x is T` always
260+
/// evaluates to `true`, and only after `x as! T` has proven to be a
261+
/// performance problem.
262+
///
263+
/// - Parameters:
264+
/// - x: An instance to cast to type `T`.
265+
/// - type: The type `T` to which `x` is cast.
266+
/// - Returns: The instance `x`, cast to type `T`.
259267
@_transparent
260-
public func unsafeDowncast<T : AnyObject>(_ x: AnyObject, to: T.Type) -> T {
268+
public func unsafeDowncast<T : AnyObject>(_ x: AnyObject, to type: T.Type) -> T {
261269
_debugPrecondition(x is T, "invalid unsafeDowncast")
262270
return Builtin.castReference(x)
263271
}
@@ -337,7 +345,6 @@ func swift_class_getInstanceExtents(_ theClass: AnyClass)
337345
func swift_objc_class_unknownGetInstanceExtents(_ theClass: AnyClass)
338346
-> (negative: UInt, positive: UInt)
339347

340-
/// - Returns:
341348
@inline(__always)
342349
internal func _class_getInstancePositiveExtentSize(_ theClass: AnyClass) -> Int {
343350
#if _runtime(_ObjC)

stdlib/public/core/Codable.swift

Lines changed: 69 additions & 73 deletions
Large diffs are not rendered by default.

stdlib/public/core/Collection.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -445,18 +445,6 @@ public struct IndexingIterator<
445445
/// corresponding element. In the example above, `firstSpace` is used to
446446
/// extract the prefix that contains elements up to that index.
447447
///
448-
/// You can pass only valid indices to collection operations. You can find a
449-
/// complete set of a collection's valid indices by starting with the
450-
/// collection's `startIndex` property and finding every successor up to, and
451-
/// including, the `endIndex` property. All other values of the `Index` type,
452-
/// such as the `startIndex` property of a different collection, are invalid
453-
/// indices for this collection.
454-
///
455-
/// Saved indices may become invalid as a result of mutating operations. For
456-
/// more information about index invalidation in mutable collections, see the
457-
/// reference for the `MutableCollection` and `RangeReplaceableCollection`
458-
/// protocols, as well as for the specific type you're using.
459-
///
460448
/// Accessing Individual Elements
461449
/// =============================
462450
///
@@ -481,6 +469,18 @@ public struct IndexingIterator<
481469
/// print(text.first)
482470
/// // Prints "Optional("B")"
483471
///
472+
/// You can pass only valid indices to collection operations. You can find a
473+
/// complete set of a collection's valid indices by starting with the
474+
/// collection's `startIndex` property and finding every successor up to, and
475+
/// including, the `endIndex` property. All other values of the `Index` type,
476+
/// such as the `startIndex` property of a different collection, are invalid
477+
/// indices for this collection.
478+
///
479+
/// Saved indices may become invalid as a result of mutating operations. For
480+
/// more information about index invalidation in mutable collections, see the
481+
/// reference for the `MutableCollection` and `RangeReplaceableCollection`
482+
/// protocols, as well as for the specific type you're using.
483+
///
484484
/// Accessing Slices of a Collection
485485
/// ================================
486486
///

stdlib/public/core/CompilerProtocols.swift

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -673,30 +673,8 @@ public protocol ExpressibleByDictionaryLiteral {
673673
/// Conforming to the ExpressibleByStringInterpolation Protocol
674674
/// ===========================================================
675675
///
676-
/// To use string interpolation to initialize instances of your custom type,
677-
/// implement the required initializers for `ExpressibleByStringInterpolation`
678-
/// conformance. String interpolation is a multiple-step initialization
679-
/// process. When you use string interpolation, the following steps occur:
680-
///
681-
/// 1. The string literal is broken into pieces. Each segment of the string
682-
/// literal before, between, and after any included expressions, along with
683-
/// the individual expressions themselves, are passed to the
684-
/// `init(stringInterpolationSegment:)` initializer.
685-
/// 2. The results of those calls are passed to the
686-
/// `init(stringInterpolation:)` initializer in the order in which they
687-
/// appear in the string literal.
688-
///
689-
/// In other words, initializing the `message` constant in the example above
690-
/// using string interpolation is equivalent to the following code:
691-
///
692-
/// let message = String(stringInterpolation:
693-
/// String(stringInterpolationSegment: "One cookie: $"),
694-
/// String(stringInterpolationSegment: price),
695-
/// String(stringInterpolationSegment: ", "),
696-
/// String(stringInterpolationSegment: number),
697-
/// String(stringInterpolationSegment: " cookies: $"),
698-
/// String(stringInterpolationSegment: price * number),
699-
/// String(stringInterpolationSegment: "."))
676+
/// The `ExpressibleByStringInterpolation` protocol is deprecated. Do not add
677+
/// new conformances to the protocol.
700678
@available(*, deprecated, message: "it will be replaced or redesigned in Swift 4.0. Instead of conforming to 'ExpressibleByStringInterpolation', consider adding an 'init(_:String)'")
701679
public typealias ExpressibleByStringInterpolation = _ExpressibleByStringInterpolation
702680
public protocol _ExpressibleByStringInterpolation {

0 commit comments

Comments
 (0)