Skip to content

Commit 7a7ebd8

Browse files
committed
[stdlib] Adopt primary associated types in the stdlib
1 parent 6a08f14 commit 7a7ebd8

17 files changed

+31
-30
lines changed

stdlib/public/core/BidirectionalCollection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
/// Valid indices are exactly those indices that are reachable from the
4040
/// collection's `startIndex` by repeated applications of `index(after:)`, up
4141
/// to, and including, the `endIndex`.
42-
public protocol BidirectionalCollection: Collection
42+
public protocol BidirectionalCollection<Element>: Collection
4343
where SubSequence: BidirectionalCollection, Indices: BidirectionalCollection {
4444
// FIXME: Only needed for associated type inference.
4545
override associatedtype Element

stdlib/public/core/Codable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public protocol Decoder {
183183
///
184184
/// Encoders should provide types conforming to
185185
/// `KeyedEncodingContainerProtocol` for their format.
186-
public protocol KeyedEncodingContainerProtocol {
186+
public protocol KeyedEncodingContainerProtocol<Key> {
187187
associatedtype Key: CodingKey
188188

189189
/// The path of coding keys taken to get to this point in encoding.
@@ -938,7 +938,7 @@ public struct KeyedEncodingContainer<K: CodingKey> :
938938
///
939939
/// Decoders should provide types conforming to `UnkeyedDecodingContainer` for
940940
/// their format.
941-
public protocol KeyedDecodingContainerProtocol {
941+
public protocol KeyedDecodingContainerProtocol<Key> {
942942
associatedtype Key: CodingKey
943943

944944
/// The path of coding keys taken to get to this point in decoding.

stdlib/public/core/Collection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ extension IndexingIterator: Sendable
335335
/// or bidirectional collection must traverse the entire collection to count
336336
/// the number of contained elements, accessing its `count` property is an
337337
/// O(*n*) operation.
338-
public protocol Collection: Sequence {
338+
public protocol Collection<Element>: Sequence {
339339
// FIXME: ideally this would be in MigrationSupport.swift, but it needs
340340
// to be on the protocol instead of as an extension
341341
@available(*, deprecated/*, obsoleted: 5.0*/, message: "all index distances are now of type Int")

stdlib/public/core/CompilerProtocols.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
/// // Prints "false"
9999
/// print(allowedMoves.rawValue & Directions.right.rawValue)
100100
/// // Prints "0"
101-
public protocol RawRepresentable {
101+
public protocol RawRepresentable<RawValue> {
102102
/// The raw type that can be used to represent all values of the conforming
103103
/// type.
104104
///

stdlib/public/core/Identifiable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
/// lifetime of an object. If an object has a stronger notion of identity, it
4040
/// may be appropriate to provide a custom implementation.
4141
@available(SwiftStdlib 5.1, *)
42-
public protocol Identifiable {
42+
public protocol Identifiable<ID> {
4343

4444
/// A type representing the stable identity of the entity associated with
4545
/// an instance.

stdlib/public/core/Instant.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// A type that defines a specific point in time for a given `Clock`.
1414
@available(SwiftStdlib 5.7, *)
15-
public protocol InstantProtocol: Comparable, Hashable, Sendable {
15+
public protocol InstantProtocol<Duration>: Comparable, Hashable, Sendable {
1616
associatedtype Duration: DurationProtocol
1717
func advanced(by duration: Duration) -> Self
1818
func duration(to other: Self) -> Duration

stdlib/public/core/LazyCollection.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public protocol LazyCollectionProtocol: Collection, LazySequenceProtocol
14-
where Elements: Collection { }
13+
public protocol LazyCollectionProtocol<Elements>
14+
: Collection, LazySequenceProtocol
15+
where Elements: Collection {}
1516

1617
extension LazyCollectionProtocol {
1718
// Lazy things are already lazy

stdlib/public/core/LazySequence.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@
128128
/// and discards the resulting array. Instead, use `reduce` for summing
129129
/// operations, or `forEach` or a `for`-`in` loop for operations with side
130130
/// effects.
131-
public protocol LazySequenceProtocol: Sequence {
131+
public protocol LazySequenceProtocol<Elements>: Sequence
132+
where Elements.Element == Element {
132133
/// A `Sequence` that can contain the same elements as this one,
133134
/// possibly with a simpler type.
134135
///
@@ -138,11 +139,8 @@ public protocol LazySequenceProtocol: Sequence {
138139
/// A sequence containing the same elements as this one, possibly with
139140
/// a simpler type.
140141
///
141-
/// When implementing lazy operations, wrapping `elements` instead
142-
/// of `self` can prevent result types from growing an extra
143-
/// `LazySequence` layer. For example,
144-
///
145-
/// _prext_ example needed
142+
/// When implementing lazy operations, wrapping `elements` instead of `self`
143+
/// can prevent result types from growing an extra `LazySequence` layer.
146144
///
147145
/// Note: this property need not be implemented by conforming types,
148146
/// it has a default implementation in a protocol extension that

stdlib/public/core/MutableCollection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
/// // Must be equivalent to:
5858
/// a[i] = x
5959
/// let y = x
60-
public protocol MutableCollection: Collection
60+
public protocol MutableCollection<Element>: Collection
6161
where SubSequence: MutableCollection
6262
{
6363
// FIXME: Associated type inference requires these.

stdlib/public/core/OptionSet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
/// print("Add more to your cart for free priority shipping!")
8484
/// }
8585
/// // Prints "You've earned free priority shipping!"
86-
public protocol OptionSet: SetAlgebra, RawRepresentable {
86+
public protocol OptionSet<Element>: SetAlgebra, RawRepresentable {
8787
// We can't constrain the associated Element type to be the same as
8888
// Self, but we can do almost as well with a default and a
8989
// constrained extension

stdlib/public/core/RandomAccessCollection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/// collection, either the index for your custom type must conform to the
3131
/// `Strideable` protocol or you must implement the `index(_:offsetBy:)` and
3232
/// `distance(from:to:)` methods with O(1) efficiency.
33-
public protocol RandomAccessCollection: BidirectionalCollection
33+
public protocol RandomAccessCollection<Element>: BidirectionalCollection
3434
where SubSequence: RandomAccessCollection, Indices: RandomAccessCollection
3535
{
3636
// FIXME: Associated type inference requires these.

stdlib/public/core/Range.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
///
1515
/// A type that conforms to `RangeExpression` can convert itself to a
1616
/// `Range<Bound>` of indices within a given collection.
17-
public protocol RangeExpression {
17+
public protocol RangeExpression<Bound> {
1818
/// The type for which the expression describes a range.
1919
associatedtype Bound: Comparable
2020

stdlib/public/core/RangeReplaceableCollection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
/// `replaceSubrange(_:with:)` with an empty collection for the `newElements`
6262
/// parameter. You can override any of the protocol's required methods to
6363
/// provide your own custom implementation.
64-
public protocol RangeReplaceableCollection: Collection
65-
where SubSequence: RangeReplaceableCollection {
64+
public protocol RangeReplaceableCollection<Element>: Collection
65+
where SubSequence: RangeReplaceableCollection {
6666
// FIXME: Associated type inference requires this.
6767
override associatedtype SubSequence
6868

stdlib/public/core/SIMDVector.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ public protocol SIMDScalar {
7171
}
7272

7373
/// A SIMD vector of a fixed number of elements.
74-
public protocol SIMD: SIMDStorage,
75-
Codable,
76-
Hashable,
77-
CustomStringConvertible,
78-
ExpressibleByArrayLiteral {
74+
public protocol SIMD<Scalar>:
75+
SIMDStorage,
76+
Codable,
77+
Hashable,
78+
CustomStringConvertible,
79+
ExpressibleByArrayLiteral
80+
{
7981
/// The mask type resulting from pointwise comparisons of this vector type.
8082
associatedtype MaskStorage: SIMD
8183
where MaskStorage.Scalar: FixedWidthInteger & SignedInteger

stdlib/public/core/Sequence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
/// // Prints "3..."
175175
/// // Prints "2..."
176176
/// // Prints "1..."
177-
public protocol IteratorProtocol {
177+
public protocol IteratorProtocol<Element> {
178178
/// The type of element traversed by the iterator.
179179
associatedtype Element
180180

@@ -322,7 +322,7 @@ public protocol IteratorProtocol {
322322
/// makes no other requirements about element access, so routines that
323323
/// traverse a sequence should be considered O(*n*) unless documented
324324
/// otherwise.
325-
public protocol Sequence {
325+
public protocol Sequence<Element> {
326326
/// A type representing the sequence's elements.
327327
associatedtype Element
328328

stdlib/public/core/SetAlgebra.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
/// - `x.isStrictSuperset(of: y)` if and only if
5353
/// `x.isSuperset(of: y) && x != y`
5454
/// - `x.isStrictSubset(of: y)` if and only if `x.isSubset(of: y) && x != y`
55-
public protocol SetAlgebra: Equatable, ExpressibleByArrayLiteral {
55+
public protocol SetAlgebra<Element>: Equatable, ExpressibleByArrayLiteral {
5656
/// A type for which the conforming type provides a containment test.
5757
associatedtype Element
5858

stdlib/public/core/Stride.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
/// `Stride` type's implementations. If a type conforming to `Strideable` is
9797
/// its own `Stride` type, it must provide concrete implementations of the
9898
/// two operators to avoid infinite recursion.
99-
public protocol Strideable: Comparable {
99+
public protocol Strideable<Stride>: Comparable {
100100
/// A type that represents the distance between two values.
101101
associatedtype Stride: SignedNumeric, Comparable
102102

0 commit comments

Comments
 (0)