Skip to content

Commit 79a3f9c

Browse files
authored
Merge pull request #11670 from natecook1000/nc-rev-77-2
2 parents e272564 + 4a1b74c commit 79a3f9c

16 files changed

+191
-96
lines changed

stdlib/public/core/Character.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,29 @@
2525
/// // Prints "Length: 8"
2626
///
2727
/// Because each character in a string can be made up of one or more Unicode
28-
/// code points, the number of characters in a string may not match the length
29-
/// of the Unicode code point representation or the length of the string in a
30-
/// particular binary representation.
28+
/// scalar values, the number of characters in a string may not match the
29+
/// length of the Unicode scalar value representation or the length of the
30+
/// string in a particular binary representation.
3131
///
32-
/// print("Unicode code point count: \(greeting.unicodeScalars.count)")
33-
/// // Prints "Unicode code point count: 15"
32+
/// print("Unicode scalar value count: \(greeting.unicodeScalars.count)")
33+
/// // Prints "Unicode scalar value count: 15"
3434
///
3535
/// print("UTF-8 representation count: \(greeting.utf8.count)")
3636
/// // Prints "UTF-8 representation count: 18"
3737
///
38-
/// Every `Character` instance is composed of one or more Unicode code points
38+
/// Every `Character` instance is composed of one or more Unicode scalar values
3939
/// that are grouped together as an *extended grapheme cluster*. The way these
40-
/// code points are grouped is defined by a canonical, localized, or otherwise
41-
/// tailored Unicode segmentation algorithm.
40+
/// scalar values are grouped is defined by a canonical, localized, or
41+
/// otherwise tailored Unicode segmentation algorithm.
4242
///
4343
/// For example, a country's Unicode flag character is made up of two regional
44-
/// indicator code points that correspond to that country's ISO 3166-1 alpha-2
45-
/// code. The alpha-2 code for The United States is "US", so its flag
46-
/// character is made up of the Unicode code points `"\u{1F1FA}"` (REGIONAL
44+
/// indicator scalar values that correspond to that country's ISO 3166-1
45+
/// alpha-2 code. The alpha-2 code for The United States is "US", so its flag
46+
/// character is made up of the Unicode scalar values `"\u{1F1FA}"` (REGIONAL
4747
/// INDICATOR SYMBOL LETTER U) and `"\u{1F1F8}"` (REGIONAL INDICATOR SYMBOL
48-
/// LETTER S). When placed next to each other in a Swift string literal, these
49-
/// two code points are combined into a single grapheme cluster, represented
50-
/// by a `Character` instance in Swift.
48+
/// LETTER S). When placed next to each other in a string literal, these two
49+
/// scalar values are combined into a single grapheme cluster, represented by
50+
/// a `Character` instance in Swift.
5151
///
5252
/// let usFlag: Character = "\u{1F1FA}\u{1F1F8}"
5353
/// print(usFlag)

stdlib/public/core/CompilerProtocols.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,15 @@ public protocol _ExpressibleByBuiltinExtendedGraphemeClusterLiteral
363363
/// A type that can be initialized with a string literal containing a single
364364
/// extended grapheme cluster.
365365
///
366-
/// An *extended grapheme cluster* is a group of one or more Unicode code
367-
/// points that approximates a single user-perceived character. Many
366+
/// An *extended grapheme cluster* is a group of one or more Unicode scalar
367+
/// values that approximates a single user-perceived character. Many
368368
/// individual characters, such as "é", "김", and "🇮🇳", can be made up of
369-
/// multiple Unicode code points. These code points are combined by Unicode's
370-
/// boundary algorithms into extended grapheme clusters.
369+
/// multiple Unicode scalar values. These code points are combined by
370+
/// Unicode's boundary algorithms into extended grapheme clusters.
371371
///
372372
/// The `String`, `StaticString`, and `Character` types conform to the
373-
/// `ExpressibleByExtendedGraphemeClusterLiteral` protocol. You can initialize a
374-
/// variable or constant of any of these types using a string literal that
373+
/// `ExpressibleByExtendedGraphemeClusterLiteral` protocol. You can initialize
374+
/// a variable or constant of any of these types using a string literal that
375375
/// holds a single character.
376376
///
377377
/// let snowflake: Character = "❄︎"
@@ -505,8 +505,8 @@ extension ExpressibleByStringLiteral
505505
/// initialize a type that conforms to `ExpressibleByArrayLiteral` simply by
506506
/// assigning an existing array.
507507
///
508-
/// let anotherSet: Set = employeesArray
509-
/// // error: cannot convert value of type '[String]' to specified type 'Set'
508+
/// let anotherSet: Set = employeesArray
509+
/// // error: cannot convert value of type '[String]' to specified type 'Set'
510510
///
511511
/// Type Inference of Array Literals
512512
/// ================================

stdlib/public/core/Dump.swift

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// Dumps an object's contents using its mirror to the specified output stream.
13+
/// Dumps the given object's contents using its mirror to the specified output
14+
/// stream.
15+
///
16+
/// - Parameters:
17+
/// - value: The value to output to the `target` stream.
18+
/// - target: The stream to use for writing the contents of `value`.
19+
/// - name: A label to use when writing the contents of `value`. When `nil`
20+
/// is passed, the label is omitted. The default is `nil`.
21+
/// - indent: The number of spaces to use as an indent for each line of the
22+
/// output. The default is `0`.
23+
/// - maxDepth: The maximum depth to descend when writing the contents of a
24+
/// value that has nested components. The default is `Int.max`.
25+
/// - maxItems: The maximum number of elements for which to write the full
26+
/// contents. The default is `Int.max`.
27+
/// - Returns: The instance passed as `value`.
1428
@discardableResult
1529
@_semantics("optimize.sil.specialize.generic.never")
1630
public func dump<T, TargetStream : TextOutputStream>(
@@ -36,7 +50,19 @@ public func dump<T, TargetStream : TextOutputStream>(
3650
return value
3751
}
3852

39-
/// Dumps an object's contents using its mirror to standard output.
53+
/// Dumps the given object's contents using its mirror to standard output.
54+
///
55+
/// - Parameters:
56+
/// - value: The value to output to the `target` stream.
57+
/// - name: A label to use when writing the contents of `value`. When `nil`
58+
/// is passed, the label is omitted. The default is `nil`.
59+
/// - indent: The number of spaces to use as an indent for each line of the
60+
/// output. The default is `0`.
61+
/// - maxDepth: The maximum depth to descend when writing the contents of a
62+
/// value that has nested components. The default is `Int.max`.
63+
/// - maxItems: The maximum number of elements for which to write the full
64+
/// contents. The default is `Int.max`.
65+
/// - Returns: The instance passed as `value`.
4066
@discardableResult
4167
@_semantics("optimize.sil.specialize.generic.never")
4268
public func dump<T>(

stdlib/public/core/Integers.swift.gyb

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extension ExpressibleByIntegerLiteral
8888
}
8989

9090
//===----------------------------------------------------------------------===//
91-
//===--- Documentation Helpers --------------------------------------------===//
91+
//===--- Operator Documentation -------------------------------------------===//
9292
//===----------------------------------------------------------------------===//
9393

9494
%{
@@ -1587,6 +1587,20 @@ extension BinaryInteger {
15871587
return it.next() ?? 0
15881588
}
15891589

1590+
/// Returns the quotient and remainder of this value divided by the given
1591+
/// value.
1592+
///
1593+
/// Use this method to calculate the quotient and remainder of a division at
1594+
/// the same time.
1595+
///
1596+
/// let x = 1_000_000
1597+
/// let (q, r) = x.quotientAndRemainder(dividingBy: 933)
1598+
/// // q == 1071
1599+
/// // r == 757
1600+
///
1601+
/// - Parameter rhs: The value to divide this value by.
1602+
/// - Returns: A tuple containing the quotient and remainder of this value
1603+
/// divided by `rhs`.
15901604
public func quotientAndRemainder(dividingBy rhs: Self)
15911605
-> (quotient: Self, remainder: Self) {
15921606
return (self / rhs, self % rhs)
@@ -2007,8 +2021,8 @@ ${overflowOperationComment(x.operator)}
20072021
/// - Parameter other: The value to multiply this value by.
20082022
/// - Returns: A tuple containing the high and low parts of the result of
20092023
/// multiplying this value and `other`.
2010-
// FIXME(integers): figure out how to return DoubleWidth<Self>
20112024
func multipliedFullWidth(by other: Self) -> (high: Self, low: Self.Magnitude)
2025+
// FIXME(integers): figure out how to return DoubleWidth<Self>
20122026

20132027
/// Returns a tuple containing the quotient and remainder of dividing the
20142028
/// given value by this value.
@@ -2113,6 +2127,11 @@ extension FixedWidthInteger {
21132127
@_inlineable
21142128
public var bitWidth: Int { return Self.bitWidth }
21152129

2130+
/// Creates an integer from its little-endian representation, changing the
2131+
/// byte order if necessary.
2132+
///
2133+
/// - Parameter value: A value to use as the little-endian representation of
2134+
/// the new integer.
21162135
public init(littleEndian value: Self) {
21172136
#if _endian(little)
21182137
self = value
@@ -2121,6 +2140,11 @@ extension FixedWidthInteger {
21212140
#endif
21222141
}
21232142

2143+
/// Creates an integer from its big-endian representation, changing the byte
2144+
/// order if necessary.
2145+
///
2146+
/// - Parameter value: A value to use as the big-endian representation of the
2147+
/// new integer.
21242148
public init(bigEndian value: Self) {
21252149
#if _endian(big)
21262150
self = value
@@ -2129,6 +2153,11 @@ extension FixedWidthInteger {
21292153
#endif
21302154
}
21312155

2156+
/// The little-endian representation of this integer.
2157+
///
2158+
/// If necessary, the byte order of this value is reversed from the typical
2159+
/// byte order of this integer type. On a little-endian platform, for any
2160+
/// integer `x`, `x == x.littleEndian`.
21322161
public var littleEndian: Self {
21332162
#if _endian(little)
21342163
return self
@@ -2137,6 +2166,11 @@ extension FixedWidthInteger {
21372166
#endif
21382167
}
21392168

2169+
/// The big-endian representation of this integer.
2170+
///
2171+
/// If necessary, the byte order of this value is reversed from the typical
2172+
/// byte order of this integer type. On a big-endian platform, for any
2173+
/// integer `x`, `x == x.bigEndian`.
21402174
public var bigEndian: Self {
21412175
#if _endian(big)
21422176
return self
@@ -2552,6 +2586,25 @@ extension UnsignedInteger {
25522586
}
25532587

25542588
extension UnsignedInteger where Self : FixedWidthInteger {
2589+
/// Creates a new instance from the given integer.
2590+
///
2591+
/// Use this initializer to convert from another integer type when you know
2592+
/// the value is within the bounds of this type. Passing a value that can't
2593+
/// be represented in this type results in a runtime error.
2594+
///
2595+
/// In the following example, the constant `y` is successfully created from
2596+
/// `x`, an `Int` instance with a value of `100`. Because the `Int8` type
2597+
/// can represent `127` at maximum, the attempt to create `z` with a value
2598+
/// of `1000` results in a runtime error.
2599+
///
2600+
/// let x = 100
2601+
/// let y = Int8(x)
2602+
/// // y == 100
2603+
/// let z = Int8(x * 10)
2604+
/// // Error: Not enough bits to represent the given value
2605+
///
2606+
/// - Parameter source: A value to convert to this type of integer. The value
2607+
/// passed as `source` must be representable in this type.
25552608
@_semantics("optimize.sil.specialize.generic.partial.never")
25562609
@inline(__always)
25572610
public init<T : BinaryInteger>(_ source: T) {
@@ -2646,6 +2699,25 @@ extension SignedInteger {
26462699
}
26472700

26482701
extension SignedInteger where Self : FixedWidthInteger {
2702+
/// Creates a new instance from the given integer.
2703+
///
2704+
/// Use this initializer to convert from another integer type when you know
2705+
/// the value is within the bounds of this type. Passing a value that can't
2706+
/// be represented in this type results in a runtime error.
2707+
///
2708+
/// In the following example, the constant `y` is successfully created from
2709+
/// `x`, an `Int` instance with a value of `100`. Because the `Int8` type
2710+
/// can represent `127` at maximum, the attempt to create `z` with a value
2711+
/// of `1000` results in a runtime error.
2712+
///
2713+
/// let x = 100
2714+
/// let y = Int8(x)
2715+
/// // y == 100
2716+
/// let z = Int8(x * 10)
2717+
/// // Error: Not enough bits to represent the given value
2718+
///
2719+
/// - Parameter source: A value to convert to this type of integer. The value
2720+
/// passed as `source` must be representable in this type.
26492721
@_semantics("optimize.sil.specialize.generic.partial.never")
26502722
@inline(__always)
26512723
public init<T : BinaryInteger>(_ source: T) {
@@ -3154,9 +3226,9 @@ ${assignmentOperatorComment(x.operator, True)}
31543226
/// - Parameter other: The value to multiply this value by.
31553227
/// - Returns: A tuple containing the high and low parts of the result of
31563228
/// multiplying this value and `other`.
3157-
// FIXME(integers): tests
31583229
public func multipliedFullWidth(by other: ${Self})
3159-
-> (high: ${Self}, low: ${Self}.Magnitude) {
3230+
-> (high: ${Self}, low: ${Self}.Magnitude) {
3231+
// FIXME(integers): tests
31603232
% # 128 bit types are not provided by the 32-bit LLVM
31613233
% if word_bits == 32 and bits == 64:
31623234
// FIXME(integers): implement
@@ -3186,10 +3258,10 @@ ${assignmentOperatorComment(x.operator, True)}
31863258
/// sign, if the type is signed.
31873259
/// - Returns: A tuple containing the quotient and remainder of `dividend`
31883260
/// divided by this value.
3189-
// FIXME(integers): tests
31903261
public func dividingFullWidth(
31913262
_ dividend: (high: ${Self}, low: ${Self}.Magnitude)
31923263
) -> (quotient: ${Self}, remainder: ${Self}) {
3264+
// FIXME(integers): tests
31933265
% # 128 bit types are not provided by the 32-bit LLVM
31943266
% #if word_bits == 32 and bits == 64:
31953267
% if bits == 64:

stdlib/public/core/Optional.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public enum Optional<Wrapped> : ExpressibleByNilLiteral {
179179
/// let possibleNumber: Int? = Int("42")
180180
/// let nonOverflowingSquare = possibleNumber.flatMap { x -> Int? in
181181
/// let (result, overflowed) = x.multipliedReportingOverflow(by: x)
182-
/// return overflowed == .overflow ? nil : result
182+
/// return overflowed ? nil : result
183183
/// }
184184
/// print(nonOverflowingSquare)
185185
/// // Prints "Optional(1764)"

stdlib/public/core/Range.swift.gyb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// A type which can be used to slice a collection. A `RangeExpression` can
14-
/// convert itself to a `Range<Bound>` of indices within a given collection;
15-
/// the collection can then slice itself with that `Range`.
13+
/// A type that can be used to slice a collection.
14+
///
15+
/// A type that conforms to `RangeExpression` can convert itself to a
16+
/// `Range<Bound>` of indices within a given collection.
1617
public protocol RangeExpression {
18+
/// The type for which the expression describes a range.
1719
associatedtype Bound: Comparable
20+
1821
/// Returns the range of indices within the given collection described by
1922
/// this range expression.
2023
///
@@ -61,6 +64,12 @@ public protocol RangeExpression {
6164
to collection: C
6265
) -> Range<Bound> where C.Index == Bound
6366

67+
/// Returns a Boolean value indicating whether the given element is contained
68+
/// within the range expression.
69+
///
70+
/// - Parameter element: The element to check for containment.
71+
/// - Returns: `true` if `element` is contained in the range expression;
72+
/// otherwise, `false`.
6473
func contains(_ element: Bound) -> Bool
6574
}
6675

stdlib/public/core/StaticString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public struct StaticString
219219
}
220220

221221
/// Creates an instance initialized to a single character that is made up of
222-
/// one or more Unicode code points.
222+
/// one or more Unicode scalar values.
223223
///
224224
/// Do not call this initializer directly. It may be used by the compiler
225225
/// when you initialize a static string using an extended grapheme cluster.

stdlib/public/core/String.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ extension String {
363363
///
364364
/// let banner = """
365365
/// __,
366-
/// ( o /) _/_
366+
/// ( o /) _/_
367367
/// `. , , , , // /
368368
/// (___)(_(_/_(_ //_ (__
369369
/// /)
@@ -393,9 +393,9 @@ extension String {
393393
/// print(cafe1 == cafe2)
394394
/// // Prints "true"
395395
///
396-
/// The Unicode code point `"\u{301}"` modifies the preceding character to
396+
/// The Unicode scalar value `"\u{301}"` modifies the preceding character to
397397
/// include an accent, so `"e\u{301}"` has the same canonical representation
398-
/// as the single Unicode code point `"é"`.
398+
/// as the single Unicode scalar value `"é"`.
399399
///
400400
/// Basic string operations are not sensitive to locale settings, ensuring that
401401
/// string comparisons and other operations always have a single, stable
@@ -407,10 +407,10 @@ extension String {
407407
///
408408
/// A string is a collection of *extended grapheme clusters*, which approximate
409409
/// human-readable characters. Many individual characters, such as "é", "김",
410-
/// and "🇮🇳", can be made up of multiple Unicode code points. These code points
411-
/// are combined by Unicode's boundary algorithms into extended grapheme
412-
/// clusters, represented by the Swift `Character` type. Each element of a
413-
/// string is represented by a `Character` instance.
410+
/// and "🇮🇳", can be made up of multiple Unicode scalar values. These scalar
411+
/// values are combined by Unicode's boundary algorithms into extended
412+
/// grapheme clusters, represented by the Swift `Character` type. Each element
413+
/// of a string is represented by a `Character` instance.
414414
///
415415
/// For example, to retrieve the first word of a longer string, you can search
416416
/// for a space and then create a substring from a prefix of the string up to
@@ -468,9 +468,9 @@ extension String {
468468
///
469469
/// The `unicodeScalars` view's elements comprise each Unicode scalar value in
470470
/// the `cafe` string. In particular, because `cafe` was declared using the
471-
/// decomposed form of the `"é"` character, `unicodeScalars` contains the code
472-
/// points for both the letter `"e"` (101) and the accent character `"´"`
473-
/// (769).
471+
/// decomposed form of the `"é"` character, `unicodeScalars` contains the
472+
/// scalar values for both the letter `"e"` (101) and the accent character
473+
/// `"´"` (769).
474474
///
475475
/// UTF-16 View
476476
/// -----------

stdlib/public/core/StringCharacterView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ extension String {
2929
///
3030
/// In Swift, every string provides a view of its contents as characters. In
3131
/// this view, many individual characters---for example, "é", "김", and
32-
/// "🇮🇳"---can be made up of multiple Unicode code points. These code points
33-
/// are combined by Unicode's boundary algorithms into *extended grapheme
34-
/// clusters*, represented by the `Character` type. Each element of a
35-
/// `CharacterView` collection is a `Character` instance.
32+
/// "🇮🇳"---can be made up of multiple Unicode scalar values. These scalar
33+
/// values are combined by Unicode's boundary algorithms into *extended
34+
/// grapheme clusters*, represented by the `Character` type. Each element of
35+
/// a `CharacterView` collection is a `Character` instance.
3636
///
3737
/// let flowers = "Flowers 💐"
3838
/// for c in flowers.characters {

0 commit comments

Comments
 (0)