Skip to content

Commit 66a2a6e

Browse files
authored
Merge pull request #59694 from lorentey/adopt-primary-associated-types-5.7
[5.7][SE-0358][stdlib] Adopt primary associated types
2 parents c770b19 + 6efa6a1 commit 66a2a6e

16 files changed

+26
-27
lines changed

stdlib/public/Concurrency/Clock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Swift
3131
/// For more information about specific clocks see `ContinuousClock` and
3232
/// `SuspendingClock`.
3333
@available(SwiftStdlib 5.7, *)
34-
public protocol Clock: Sendable {
34+
public protocol Clock<Duration>: Sendable {
3535
associatedtype Duration
3636
associatedtype Instant: InstantProtocol where Instant.Duration == Duration
3737

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/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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public protocol LazyCollectionProtocol: Collection, LazySequenceProtocol
14-
where Elements: Collection { }
13+
public protocol LazyCollectionProtocol: Collection, LazySequenceProtocol
14+
where Elements: Collection {}
1515

1616
extension LazyCollectionProtocol {
1717
// Lazy things are already lazy

stdlib/public/core/LazySequence.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,8 @@ public protocol LazySequenceProtocol: Sequence {
138138
/// A sequence containing the same elements as this one, possibly with
139139
/// a simpler type.
140140
///
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
141+
/// When implementing lazy operations, wrapping `elements` instead of `self`
142+
/// can prevent result types from growing an extra `LazySequence` layer.
146143
///
147144
/// Note: this property need not be implemented by conforming types,
148145
/// 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/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
@@ -72,11 +72,13 @@ public protocol SIMDScalar {
7272
}
7373

7474
/// A SIMD vector of a fixed number of elements.
75-
public protocol SIMD: SIMDStorage,
76-
Codable,
77-
Hashable,
78-
CustomStringConvertible,
79-
ExpressibleByArrayLiteral {
75+
public protocol SIMD<Scalar>:
76+
SIMDStorage,
77+
Codable,
78+
Hashable,
79+
CustomStringConvertible,
80+
ExpressibleByArrayLiteral
81+
{
8082
/// The mask type resulting from pointwise comparisons of this vector type.
8183
associatedtype MaskStorage: SIMD
8284
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)