Skip to content

[5.7][SE-0358][stdlib] Adopt primary associated types #59694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
2 changes: 1 addition & 1 deletion stdlib/public/Concurrency/Clock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Swift
/// For more information about specific clocks see `ContinuousClock` and
/// `SuspendingClock`.
@available(SwiftStdlib 5.7, *)
public protocol Clock: Sendable {
public protocol Clock<Duration>: Sendable {
associatedtype Duration
associatedtype Instant: InstantProtocol where Instant.Duration == Duration

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/BidirectionalCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/// Valid indices are exactly those indices that are reachable from the
/// collection's `startIndex` by repeated applications of `index(after:)`, up
/// to, and including, the `endIndex`.
public protocol BidirectionalCollection: Collection
public protocol BidirectionalCollection<Element>: Collection
where SubSequence: BidirectionalCollection, Indices: BidirectionalCollection {
// FIXME: Only needed for associated type inference.
override associatedtype Element
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ extension IndexingIterator: Sendable
/// or bidirectional collection must traverse the entire collection to count
/// the number of contained elements, accessing its `count` property is an
/// O(*n*) operation.
public protocol Collection: Sequence {
public protocol Collection<Element>: Sequence {
// FIXME: ideally this would be in MigrationSupport.swift, but it needs
// to be on the protocol instead of as an extension
@available(*, deprecated/*, obsoleted: 5.0*/, message: "all index distances are now of type Int")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/CompilerProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
/// // Prints "false"
/// print(allowedMoves.rawValue & Directions.right.rawValue)
/// // Prints "0"
public protocol RawRepresentable {
public protocol RawRepresentable<RawValue> {
/// The raw type that can be used to represent all values of the conforming
/// type.
///
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Identifiable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/// lifetime of an object. If an object has a stronger notion of identity, it
/// may be appropriate to provide a custom implementation.
@available(SwiftStdlib 5.1, *)
public protocol Identifiable {
public protocol Identifiable<ID> {

/// A type representing the stable identity of the entity associated with
/// an instance.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Instant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// A type that defines a specific point in time for a given `Clock`.
@available(SwiftStdlib 5.7, *)
public protocol InstantProtocol: Comparable, Hashable, Sendable {
public protocol InstantProtocol<Duration>: Comparable, Hashable, Sendable {
associatedtype Duration: DurationProtocol
func advanced(by duration: Duration) -> Self
func duration(to other: Self) -> Duration
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/LazyCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//

public protocol LazyCollectionProtocol: Collection, LazySequenceProtocol
where Elements: Collection { }
public protocol LazyCollectionProtocol: Collection, LazySequenceProtocol
where Elements: Collection {}

extension LazyCollectionProtocol {
// Lazy things are already lazy
Expand Down
7 changes: 2 additions & 5 deletions stdlib/public/core/LazySequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,8 @@ public protocol LazySequenceProtocol: Sequence {
/// A sequence containing the same elements as this one, possibly with
/// a simpler type.
///
/// When implementing lazy operations, wrapping `elements` instead
/// of `self` can prevent result types from growing an extra
/// `LazySequence` layer. For example,
///
/// _prext_ example needed
/// When implementing lazy operations, wrapping `elements` instead of `self`
/// can prevent result types from growing an extra `LazySequence` layer.
///
/// Note: this property need not be implemented by conforming types,
/// it has a default implementation in a protocol extension that
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/MutableCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
/// // Must be equivalent to:
/// a[i] = x
/// let y = x
public protocol MutableCollection: Collection
public protocol MutableCollection<Element>: Collection
where SubSequence: MutableCollection
{
// FIXME: Associated type inference requires these.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/RandomAccessCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/// collection, either the index for your custom type must conform to the
/// `Strideable` protocol or you must implement the `index(_:offsetBy:)` and
/// `distance(from:to:)` methods with O(1) efficiency.
public protocol RandomAccessCollection: BidirectionalCollection
public protocol RandomAccessCollection<Element>: BidirectionalCollection
where SubSequence: RandomAccessCollection, Indices: RandomAccessCollection
{
// FIXME: Associated type inference requires these.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Range.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
///
/// A type that conforms to `RangeExpression` can convert itself to a
/// `Range<Bound>` of indices within a given collection.
public protocol RangeExpression {
public protocol RangeExpression<Bound> {
/// The type for which the expression describes a range.
associatedtype Bound: Comparable

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/RangeReplaceableCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
/// `replaceSubrange(_:with:)` with an empty collection for the `newElements`
/// parameter. You can override any of the protocol's required methods to
/// provide your own custom implementation.
public protocol RangeReplaceableCollection: Collection
where SubSequence: RangeReplaceableCollection {
public protocol RangeReplaceableCollection<Element>: Collection
where SubSequence: RangeReplaceableCollection {
// FIXME: Associated type inference requires this.
override associatedtype SubSequence

Expand Down
12 changes: 7 additions & 5 deletions stdlib/public/core/SIMDVector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ public protocol SIMDScalar {
}

/// A SIMD vector of a fixed number of elements.
public protocol SIMD: SIMDStorage,
Codable,
Hashable,
CustomStringConvertible,
ExpressibleByArrayLiteral {
public protocol SIMD<Scalar>:
SIMDStorage,
Codable,
Hashable,
CustomStringConvertible,
ExpressibleByArrayLiteral
{
/// The mask type resulting from pointwise comparisons of this vector type.
associatedtype MaskStorage: SIMD
where MaskStorage.Scalar: FixedWidthInteger & SignedInteger
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
/// // Prints "3..."
/// // Prints "2..."
/// // Prints "1..."
public protocol IteratorProtocol {
public protocol IteratorProtocol<Element> {
/// The type of element traversed by the iterator.
associatedtype Element

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

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/SetAlgebra.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
/// - `x.isStrictSuperset(of: y)` if and only if
/// `x.isSuperset(of: y) && x != y`
/// - `x.isStrictSubset(of: y)` if and only if `x.isSubset(of: y) && x != y`
public protocol SetAlgebra: Equatable, ExpressibleByArrayLiteral {
public protocol SetAlgebra<Element>: Equatable, ExpressibleByArrayLiteral {
/// A type for which the conforming type provides a containment test.
associatedtype Element

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Stride.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
/// `Stride` type's implementations. If a type conforming to `Strideable` is
/// its own `Stride` type, it must provide concrete implementations of the
/// two operators to avoid infinite recursion.
public protocol Strideable: Comparable {
public protocol Strideable<Stride>: Comparable {
/// A type that represents the distance between two values.
associatedtype Stride: SignedNumeric, Comparable

Expand Down