@@ -82,24 +82,25 @@ func _canBeClass<T>(_: T.Type) -> Int8 {
82
82
/// Returns the bits of the given instance, interpreted as having the specified
83
83
/// type.
84
84
///
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
88
88
/// include the following:
89
89
///
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
99
100
/// `unsafeBitCast(_:to:)` with class or pointer types; doing so may
100
101
/// introduce undefined behavior.
101
102
///
102
- /// - Warning: Calling this function breaks the guarantees of Swift's type
103
+ /// - Warning: Calling this function breaks the guarantees of the Swift type
103
104
/// system; use with extreme care.
104
105
///
105
106
/// - Parameters:
@@ -656,12 +657,12 @@ func _trueAfterDiagnostics() -> Builtin.Int1 {
656
657
/// particularly when the dynamic type is different from the static type. The
657
658
/// *static type* of a value is the known, compile-time type of the value. The
658
659
/// *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.
660
661
///
661
662
/// In the following code, the `count` variable has the same static and dynamic
662
663
/// 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`.
665
666
///
666
667
/// func printInfo(_ value: Any) {
667
668
/// let type = type(of: value)
@@ -673,7 +674,7 @@ func _trueAfterDiagnostics() -> Builtin.Int1 {
673
674
/// // '5' of type 'Int'
674
675
///
675
676
/// 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
677
678
/// `T`, or an *existential metatype* (`P.Type`) for a protocol or protocol
678
679
/// composition `P`. When the static type of the value passed to `type(of:)`
679
680
/// is constrained to a class or protocol, you can use that metatype to access
@@ -709,19 +710,22 @@ func _trueAfterDiagnostics() -> Builtin.Int1 {
709
710
/// retrieves the overridden value from the `EmojiSmiley` subclass, instead of
710
711
/// the `Smiley` class's original definition.
711
712
///
713
+ /// Finding the Dynamic Type in a Generic Context
714
+ /// =============================================
715
+ ///
712
716
/// Normally, you don't need to be aware of the difference between concrete and
713
717
/// existential metatypes, but calling `type(of:)` can yield unexpected
714
718
/// results in a generic context with a type parameter bound to a protocol. In
715
719
/// a case like this, where a generic parameter `T` is bound to a protocol
716
720
/// `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`.
719
723
///
720
724
/// The following example defines a `printGenericInfo(_:)` function that takes
721
725
/// a generic parameter and declares the `String` type's conformance to a new
722
726
/// protocol `P`. When `printGenericInfo(_:)` is called with a string that has
723
727
/// `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) .
725
729
///
726
730
/// func printGenericInfo<T>(_ value: T) {
727
731
/// let type = type(of: value)
@@ -750,8 +754,8 @@ func _trueAfterDiagnostics() -> Builtin.Int1 {
750
754
/// betterPrintGenericInfo(stringAsP)
751
755
/// // 'Hello!' of type 'String'
752
756
///
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 .
755
759
@_transparent
756
760
@_semantics ( " typechecker.type(of:) " )
757
761
public func type< T, Metatype> ( of value: T ) -> Metatype {
@@ -776,15 +780,15 @@ public func type<T, Metatype>(of value: T) -> Metatype {
776
780
/// whether all the elements in an array match a predicate. The function won't
777
781
/// compile as written, because a lazy collection's `filter(_:)` method
778
782
/// 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.
781
785
///
782
786
/// func allValues(in array: [Int], match predicate: (Int) -> Bool) -> Bool {
783
787
/// return array.lazy.filter { !predicate($0) }.isEmpty
784
788
/// }
785
789
/// // error: closure use of non-escaping parameter 'predicate'...
786
790
///
787
- /// `withoutActuallyEscaping(_:do:)` provides a temporarily- escapable copy of
791
+ /// `withoutActuallyEscaping(_:do:)` provides a temporarily escapable copy of
788
792
/// `predicate` that _can_ be used in a call to the lazy view's `filter(_:)`
789
793
/// method. The second version of `allValues(in:match:)` compiles without
790
794
/// error, with the compiler guaranteeing that the `escapablePredicate`
@@ -816,7 +820,7 @@ public func type<T, Metatype>(of value: T) -> Metatype {
816
820
/// returning. Even though the barrier guarantees that neither closure will
817
821
/// escape the function, the `async(execute:)` method still requires that the
818
822
/// 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
820
824
/// `withoutActuallyEscaping(_:do:)` to get copies of `f` and `g` that can be
821
825
/// passed to `async(execute:)`.
822
826
///
@@ -831,19 +835,19 @@ public func type<T, Metatype>(of value: T) -> Metatype {
831
835
/// }
832
836
/// }
833
837
///
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
835
839
/// during the call to `withoutActuallyEscaping(_:do:)`. It is undefined
836
840
/// behavior for the escapable closure to be stored, referenced, or executed
837
841
/// after the function returns.
838
842
///
839
843
/// - 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
843
847
/// `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.
847
851
@_transparent
848
852
@_semantics ( " typechecker.withoutActuallyEscaping(_:do:) " )
849
853
public func withoutActuallyEscaping< ClosureType, ResultType> (
0 commit comments