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

0 commit comments

Comments
 (0)