Skip to content

Commit 668b9db

Browse files
committed
[stdlib] Apply tail style "where" clause to stdlib/public/core
1 parent 06d8455 commit 668b9db

29 files changed

+485
-562
lines changed

stdlib/public/core/ArrayBufferProtocol.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ public protocol _ArrayBufferProtocol
7171
///
7272
/// - Precondition: This buffer is backed by a uniquely-referenced
7373
/// `_ContiguousArrayBuffer`.
74-
mutating func replace<C : Collection where C.Iterator.Element == Element>(
74+
mutating func replace<C>(
7575
subRange: Range<Int>,
7676
with newCount: Int,
7777
elementsOf newValues: C
78-
)
78+
) where C : Collection, C.Iterator.Element == Element
7979

8080
/// Returns a `_SliceBuffer` containing the elements in `bounds`.
8181
subscript(bounds: Range<Int>) -> _SliceBuffer<Element> { get }
@@ -131,13 +131,11 @@ extension _ArrayBufferProtocol where Index == Int {
131131
return firstElementAddress
132132
}
133133

134-
public mutating func replace<
135-
C : Collection where C.Iterator.Element == Element
136-
>(
134+
public mutating func replace<C>(
137135
subRange: Range<Int>,
138136
with newCount: Int,
139137
elementsOf newValues: C
140-
) {
138+
) where C : Collection, C.Iterator.Element == Element {
141139
_sanityCheck(startIndex == 0, "_SliceBuffer should override this function.")
142140
let oldCount = self.count
143141
let eraseCount = subRange.count

stdlib/public/core/ArrayType.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ protocol _ArrayProtocol
4545
mutating func reserveCapacity(_ minimumCapacity: Int)
4646

4747
/// Operator form of `append(contentsOf:)`.
48-
func += <
49-
S : Sequence where S.Iterator.Element == Iterator.Element
50-
>(lhs: inout Self, rhs: S)
48+
func += <S : Sequence>(lhs: inout Self, rhs: S)
49+
where S.Iterator.Element == Iterator.Element
5150

5251
/// Insert `newElement` at index `i`.
5352
///

stdlib/public/core/Arrays.swift.gyb

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,9 +1024,9 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
10241024
/// // Prints "["Gold", "Cerise", "Magenta", "Vermillion"]"
10251025
///
10261026
/// - Parameter s: The sequence of elements to turn into an array.
1027-
public init<
1028-
S : Sequence where S.Iterator.Element == Element
1029-
>(_ s: S) {
1027+
public init<S : Sequence>(_ s: S)
1028+
where S.Iterator.Element == Element {
1029+
10301030
self = ${Self}(_Buffer(s._copyToNativeArrayBuffer(),
10311031
shiftedToStartIndex: 0))
10321032
}
@@ -1275,11 +1275,8 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
12751275
/// - Parameter newElements: The elements to append to the array.
12761276
///
12771277
/// - Complexity: O(*n*), where *n* is the length of the resulting array.
1278-
public mutating func append<
1279-
S : Sequence
1280-
where
1281-
S.Iterator.Element == Element
1282-
>(contentsOf newElements: S) {
1278+
public mutating func append<S : Sequence>(contentsOf newElements: S)
1279+
where S.Iterator.Element == Element {
12831280
let oldCount = self.count
12841281
let capacity = self.capacity
12851282
let newCount = oldCount + newElements.underestimatedCount
@@ -1309,11 +1306,9 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
13091306
/// - Parameter newElements: The elements to append to the array.
13101307
///
13111308
/// - Complexity: O(*n*), where *n* is the length of the resulting array.
1312-
public mutating func append<
1313-
C : Collection
1314-
where
1315-
C.Iterator.Element == Element
1316-
>(contentsOf newElements: C) {
1309+
public mutating func append<C : Collection>(contentsOf newElements: C)
1310+
where C.Iterator.Element == Element {
1311+
13171312
let newElementsCount = numericCast(newElements.count) as Int
13181313

13191314
let oldCount = self.count
@@ -1624,14 +1619,17 @@ internal struct _InitializeMemoryFromCollection<
16241619

16251620
// FIXME(ABI): add argument labels.
16261621
@inline(never)
1627-
internal func _arrayOutOfPlaceReplace<
1628-
B : _ArrayBufferProtocol, C : Collection
1629-
where
1622+
internal func _arrayOutOfPlaceReplace<B, C>(
1623+
_ source: inout B,
1624+
_ bounds: Range<Int>,
1625+
_ newValues: C,
1626+
_ insertCount: Int
1627+
) where
1628+
B : _ArrayBufferProtocol,
1629+
C : Collection,
16301630
C.Iterator.Element == B.Element,
1631-
B.Index == Int
1632-
>(
1633-
_ source: inout B, _ bounds: Range<Int>, _ newValues: C, _ insertCount: Int
1634-
) {
1631+
B.Index == Int {
1632+
16351633
let growth = insertCount - bounds.count
16361634
let newCount = source.count + growth
16371635
var newBuffer = _forceCreateUniqueMutableBuffer(
@@ -1694,11 +1692,10 @@ extension ${Self} {
16941692
/// array with an empty collection; otherwise, O(*n*), where *n* is the
16951693
/// length of the array.
16961694
@_semantics("array.mutate_unknown")
1697-
public mutating func replaceSubrange<
1698-
C: Collection where C.Iterator.Element == _Buffer.Element
1699-
>(
1700-
_ subrange: Range<Int>, with newElements: C
1701-
) {
1695+
public mutating func replaceSubrange<C>(
1696+
_ subrange: Range<Int>,
1697+
with newElements: C
1698+
) where C : Collection, C.Iterator.Element == _Buffer.Element {
17021699
_precondition(subrange.lowerBound >= self._buffer.startIndex,
17031700
"${Self} replace: subrange start is negative")
17041701

@@ -1839,17 +1836,18 @@ internal protocol _PointerFunction {
18391836
/// As an optimization, may move elements out of source rather than
18401837
/// copying when it isUniquelyReferenced.
18411838
@inline(never)
1842-
internal func _arrayOutOfPlaceUpdate<
1843-
_Buffer : _ArrayBufferProtocol, Initializer : _PointerFunction
1844-
where Initializer.Element == _Buffer.Element,
1845-
_Buffer.Index == Int
1846-
>(
1839+
internal func _arrayOutOfPlaceUpdate<_Buffer, Initializer>(
18471840
_ source: inout _Buffer,
18481841
_ dest: inout _ContiguousArrayBuffer<_Buffer.Element>,
18491842
_ headCount: Int, // Count of initial source elements to copy/move
18501843
_ newCount: Int, // Number of new elements to insert
18511844
_ initializeNewElements: Initializer
1852-
) {
1845+
) where
1846+
_Buffer : _ArrayBufferProtocol,
1847+
Initializer : _PointerFunction,
1848+
Initializer.Element == _Buffer.Element,
1849+
_Buffer.Index == Int {
1850+
18531851
_sanityCheck(headCount >= 0)
18541852
_sanityCheck(newCount >= 0)
18551853

@@ -1931,11 +1929,12 @@ internal struct _IgnorePointer<T> : _PointerFunction {
19311929

19321930
@_versioned
19331931
@inline(never)
1934-
internal func _outlinedMakeUniqueBuffer<
1935-
_Buffer : _ArrayBufferProtocol where _Buffer.Index == Int
1936-
>(
1932+
internal func _outlinedMakeUniqueBuffer<_Buffer>(
19371933
_ buffer: inout _Buffer, bufferCount: Int
1938-
) {
1934+
) where
1935+
_Buffer : _ArrayBufferProtocol,
1936+
_Buffer.Index == Int {
1937+
19391938
if _fastPath(
19401939
buffer.requestUniqueMutableBackingBuffer(minimumCapacity: bufferCount) != nil) {
19411940
return
@@ -1946,11 +1945,12 @@ internal func _outlinedMakeUniqueBuffer<
19461945
_arrayOutOfPlaceUpdate(&buffer, &newBuffer, bufferCount, 0, _IgnorePointer())
19471946
}
19481947

1949-
internal func _arrayReserve<
1950-
_Buffer : _ArrayBufferProtocol where _Buffer.Index == Int
1951-
>(
1948+
internal func _arrayReserve<_Buffer>(
19521949
_ buffer: inout _Buffer, _ minimumCapacity: Int
1953-
) {
1950+
) where
1951+
_Buffer : _ArrayBufferProtocol,
1952+
_Buffer.Index == Int {
1953+
19541954
let count = buffer.count
19551955
let requiredCapacity = max(count, minimumCapacity)
19561956

@@ -1967,29 +1967,28 @@ internal func _arrayReserve<
19671967
}
19681968

19691969
public // SPI(Foundation)
1970-
func _extractOrCopyToNativeArrayBuffer<
1971-
Buffer : _ArrayBufferProtocol
1970+
func _extractOrCopyToNativeArrayBuffer<Buffer>(
1971+
_ source: Buffer
1972+
) -> _ContiguousArrayBuffer<Buffer.Iterator.Element>
19721973
where
1973-
Buffer.Iterator.Element == Buffer.Element
1974-
>(_ source: Buffer)
1975-
-> _ContiguousArrayBuffer<Buffer.Iterator.Element>
1976-
{
1974+
Buffer : _ArrayBufferProtocol,
1975+
Buffer.Iterator.Element == Buffer.Element {
1976+
19771977
if let n = source.requestNativeBuffer() {
19781978
return n
19791979
}
19801980
return _copyCollectionToNativeArrayBuffer(source)
19811981
}
19821982

19831983
/// Append items from `newItems` to `buffer`.
1984-
internal func _arrayAppendSequence<
1984+
internal func _arrayAppendSequence<Buffer, S>(
1985+
_ buffer: inout Buffer, _ newItems: S
1986+
) where
19851987
Buffer : _ArrayBufferProtocol,
1986-
S : Sequence
1987-
where
1988+
S : Sequence,
19881989
S.Iterator.Element == Buffer.Element,
1989-
Buffer.Index == Int
1990-
>(
1991-
_ buffer: inout Buffer, _ newItems: S
1992-
) {
1990+
Buffer.Index == Int {
1991+
19931992
var stream = newItems.makeIterator()
19941993
var nextItem = stream.next()
19951994

@@ -2161,18 +2160,16 @@ extension ${Self} {
21612160
}
21622161

21632162
@available(*, unavailable, renamed: "replaceSubrange")
2164-
public mutating func replaceRange<
2165-
C : Collection where C.Iterator.Element == _Buffer.Element
2166-
>(_ subRange: Range<Int>, with newElements: C) {
2163+
public mutating func replaceRange<C>(
2164+
_ subRange: Range<Int>,
2165+
with newElements: C
2166+
) where C : Collection, C.Iterator.Element == _Buffer.Element {
21672167
Builtin.unreachable()
21682168
}
21692169

21702170
@available(*, unavailable, renamed: "append(contentsOf:)")
2171-
public mutating func appendContentsOf<
2172-
S : Sequence
2173-
where
2174-
S.Iterator.Element == Element
2175-
>(_ newElements: S) {
2171+
public mutating func appendContentsOf<S : Sequence>(_ newElements: S)
2172+
where S.Iterator.Element == Element {
21762173
Builtin.unreachable()
21772174
}
21782175
}

stdlib/public/core/ClosedRange.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@
1313
// FIXME: swift-3-indexing-model: Generalize all tests to check both
1414
// [Closed]Range and [Closed]CountableRange.
1515

16-
// WORKAROUND rdar://25214598 - should be Bound : Strideable
17-
internal enum _ClosedRangeIndexRepresentation<
18-
Bound : Comparable where Bound : _Strideable, Bound.Stride : Integer
19-
> {
16+
internal enum _ClosedRangeIndexRepresentation<Bound>
17+
where
18+
// WORKAROUND rdar://25214598 - should be Bound : Strideable
19+
Bound : protocol<_Strideable, Comparable>,
20+
Bound.Stride : Integer {
2021
case pastEnd
2122
case inRange(Bound)
2223
}
2324

2425
// FIXME(ABI)(compiler limitation): should be a nested type in
2526
// `ClosedRange`.
2627
/// A position in a `CountableClosedRange` instance.
27-
public struct ClosedRangeIndex<
28+
public struct ClosedRangeIndex<Bound> : Comparable
29+
where
2830
// WORKAROUND rdar://25214598 - should be Bound : Strideable
29-
Bound : Comparable where Bound : _Strideable, Bound.Stride : Integer
3031
// swift-3-indexing-model: should conform to _Strideable, otherwise
3132
// CountableClosedRange is not interchangeable with CountableRange in all
3233
// contexts.
33-
> : Comparable {
34+
Bound : protocol<_Strideable, Comparable>,
35+
Bound.Stride : Integer {
3436
/// Creates the "past the end" position.
3537
internal init() { _value = .pastEnd }
3638

@@ -101,11 +103,11 @@ public func < <B>(lhs: ClosedRangeIndex<B>, rhs: ClosedRangeIndex<B>) -> Bool {
101103

102104
// WORKAROUND: needed because of rdar://25584401
103105
/// An iterator over the elements of a `CountableClosedRange` instance.
104-
public struct ClosedRangeIterator<
105-
Bound : protocol<_Strideable, Comparable>
106+
public struct ClosedRangeIterator<Bound> : IteratorProtocol, Sequence
106107
where
107-
Bound.Stride : SignedInteger
108-
> : IteratorProtocol, Sequence {
108+
// WORKAROUND rdar://25214598 - should be just Bound : Strideable
109+
Bound : protocol<_Strideable, Comparable>,
110+
Bound.Stride : SignedInteger {
109111

110112
internal init(_range r: CountableClosedRange<Bound>) {
111113
_nextResult = r.lowerBound
@@ -175,12 +177,11 @@ public struct ClosedRangeIterator<
175177
/// `stride(from:through:by:)` function.
176178
///
177179
/// - SeeAlso: `CountableRange`, `ClosedRange`, `Range`
178-
public struct CountableClosedRange<
179-
// WORKAROUND rdar://25214598 - should be just Bound : Strideable
180-
Bound : protocol<_Strideable, Comparable>
180+
public struct CountableClosedRange<Bound> : RandomAccessCollection
181181
where
182-
Bound.Stride : SignedInteger
183-
> : RandomAccessCollection {
182+
// WORKAROUND rdar://25214598 - should be just Bound : Strideable
183+
Bound : protocol<_Strideable, Comparable>,
184+
Bound.Stride : SignedInteger {
184185

185186
/// The range's lower bound.
186187
public let lowerBound: Bound
@@ -387,14 +388,13 @@ public func ... <Bound : Comparable> (minimum: Bound, maximum: Bound)
387388
/// - minimum: The lower bound for the range.
388389
/// - maximum: The upper bound for the range.
389390
@_transparent
390-
public func ... <
391-
// WORKAROUND rdar://25214598 - should be just Bound : Strideable
392-
Bound : protocol<_Strideable, Comparable>
393-
where
394-
Bound.Stride : SignedInteger
395-
> (
391+
public func ... <Bound> (
396392
minimum: Bound, maximum: Bound
397-
) -> CountableClosedRange<Bound> {
393+
) -> CountableClosedRange<Bound>
394+
where
395+
// WORKAROUND rdar://25214598 - should be just Bound : Strideable
396+
Bound : protocol<_Strideable, Comparable>,
397+
Bound.Stride : SignedInteger {
398398
// FIXME: swift-3-indexing-model: tests for traps.
399399
_precondition(
400400
minimum <= maximum, "Can't form Range with upperBound < lowerBound")

stdlib/public/core/CompilerProtocols.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,8 @@ public protocol RawRepresentable {
195195
/// - Parameters:
196196
/// - lhs: A raw-representable instance.
197197
/// - rhs: A second raw-representable instance.
198-
public func == <
199-
T : RawRepresentable where T.RawValue : Equatable
200-
>(lhs: T, rhs: T) -> Bool {
198+
public func == <T : RawRepresentable>(lhs: T, rhs: T) -> Bool
199+
where T.RawValue : Equatable {
201200
return lhs.rawValue == rhs.rawValue
202201
}
203202

@@ -206,9 +205,8 @@ public func == <
206205
/// - Parameters:
207206
/// - lhs: A raw-representable instance.
208207
/// - rhs: A second raw-representable instance.
209-
public func != <
210-
T : RawRepresentable where T.RawValue : Equatable
211-
>(lhs: T, rhs: T) -> Bool {
208+
public func != <T : RawRepresentable>(lhs: T, rhs: T) -> Bool
209+
where T.RawValue : Equatable {
212210
return lhs.rawValue != rhs.rawValue
213211
}
214212

@@ -219,9 +217,8 @@ public func != <
219217
/// - Parameters:
220218
/// - lhs: A raw-representable instance.
221219
/// - rhs: A second raw-representable instance.
222-
public func != <
223-
T : Equatable where T : RawRepresentable, T.RawValue : Equatable
224-
>(lhs: T, rhs: T) -> Bool {
220+
public func != <T : Equatable>(lhs: T, rhs: T) -> Bool
221+
where T : RawRepresentable, T.RawValue : Equatable {
225222
return lhs.rawValue != rhs.rawValue
226223
}
227224

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,10 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
495495
}
496496

497497
/// Append the elements of `rhs` to `lhs`.
498-
public func += <
499-
Element, C : Collection where C.Iterator.Element == Element
500-
> (lhs: inout _ContiguousArrayBuffer<Element>, rhs: C) {
498+
public func += <Element, C : Collection>(
499+
lhs: inout _ContiguousArrayBuffer<Element>, rhs: C
500+
) where C.Iterator.Element == Element {
501+
501502
let oldCount = lhs.count
502503
let newCount = oldCount + numericCast(rhs.count)
503504

0 commit comments

Comments
 (0)