Skip to content

Commit c03b14e

Browse files
committed
Revert "Merge pull request swiftlang#9379 from airspeedswift/redundant-where"
95e9681
1 parent 9fa3cec commit c03b14e

File tree

7 files changed

+59
-10
lines changed

7 files changed

+59
-10
lines changed

stdlib/private/StdlibCollectionUnittest/CheckCollectionInstance.swift.gyb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ public func checkCollection<${genericParam}, C : Collection>(
257257
${TRACE},
258258
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
259259
sameValue: (${Element}, ${Element}) -> Bool
260-
) where C.Iterator.Element == ${Element} {
260+
) where C.Iterator.Element == ${Element},
261+
C.SubSequence : Collection {
261262

262263
checkForwardCollection(expected, collection, message(),
263264
stackTrace: stackTrace, showFrame: showFrame, file: file, line: line,
@@ -277,6 +278,7 @@ public func check${Traversal}Collection<
277278
resiliencyChecks: CollectionMisuseResiliencyChecks = .all
278279
) where
279280
C.Iterator.Element == ${Element},
281+
C.SubSequence : ${TraversalCollection},
280282
${Element} : Equatable {
281283

282284
check${Traversal}Collection(
@@ -296,7 +298,8 @@ public func check${Traversal}Collection<
296298
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
297299
sameValue: (${Element}, ${Element}) -> Bool
298300
) where
299-
C.Iterator.Element == ${Element} {
301+
C.Iterator.Element == ${Element},
302+
C.SubSequence : ${TraversalCollection} {
300303

301304
checkOneLevelOf${Traversal}Collection(expected, collection, ${trace},
302305
resiliencyChecks: resiliencyChecks, sameValue: sameValue)
@@ -501,7 +504,8 @@ ${genericParam}, S : ${TraversalCollection}
501504
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
502505
sameValue: (${Element}, ${Element}) -> Bool
503506
) where
504-
S.Iterator.Element == ${Element} {
507+
S.Iterator.Element == ${Element},
508+
S.SubSequence : ${TraversalCollection} {
505509

506510
let expectedArray = Array(expected)
507511

stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,16 @@ internal enum _SubSequenceSubscriptOnRangeMode {
471471
%{
472472
from gyb_stdlib_support import collectionForTraversal
473473
def testConstraints(protocol):
474+
if protocol == 'Collection':
475+
subseq_as_collection = 'CollectionWithEquatableElement.SubSequence : Collection,'
476+
else:
477+
subseq_as_collection=''
474478
return '''
475479
C : %(protocol)s,
476480
CollectionWithEquatableElement : %(protocol)s,
481+
%(subseq_as_collection)s
482+
C.SubSequence : %(protocol)s,
483+
C.Indices : %(protocol)s,
477484
CollectionWithEquatableElement.Iterator.Element : Equatable
478485
''' % locals()
479486

@@ -487,7 +494,6 @@ internal enum _SubSequenceSubscriptOnRangeMode {
487494
[CollectionWithEquatableElement.Iterator.Element]
488495
) -> CollectionWithEquatableElement,
489496

490-
491497
wrapValueIntoEquatable: @escaping (
492498
MinimalEquatableValue) -> CollectionWithEquatableElement.Iterator.Element,
493499

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ extension TestSuite {
121121
isFixedLengthCollection: Bool,
122122
collectionIsBidirectional: Bool = false
123123
) where
124+
C.SubSequence : MutableCollection,
125+
C.Indices : Collection,
124126
CollectionWithEquatableElement.Iterator.Element : Equatable,
125127
CollectionWithComparableElement.Iterator.Element : Comparable {
126128

@@ -781,6 +783,8 @@ self.test("\(testNamePrefix).partition/InvalidOrderings") {
781783
withUnsafeMutableBufferPointerIsSupported: Bool,
782784
isFixedLengthCollection: Bool
783785
) where
786+
C.SubSequence : BidirectionalCollection & MutableCollection,
787+
C.Indices : BidirectionalCollection,
784788
CollectionWithEquatableElement.Iterator.Element : Equatable,
785789
CollectionWithComparableElement.Iterator.Element : Comparable {
786790

@@ -925,6 +929,8 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer
925929
withUnsafeMutableBufferPointerIsSupported: Bool,
926930
isFixedLengthCollection: Bool
927931
) where
932+
C.SubSequence : RandomAccessCollection & MutableCollection,
933+
C.Indices : RandomAccessCollection,
928934
CollectionWithEquatableElement.Iterator.Element : Equatable,
929935
CollectionWithComparableElement.Iterator.Element : Comparable {
930936

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,10 @@ extension TestSuite {
462462
outOfBoundsIndexOffset: Int = 1,
463463
collectionIsBidirectional: Bool = false
464464
) where
465-
CollectionWithEquatableElement.Iterator.Element : Equatable {
465+
C.SubSequence : Collection,
466+
C.Indices : Collection,
467+
CollectionWithEquatableElement.Iterator.Element : Equatable,
468+
CollectionWithEquatableElement.SubSequence : Collection {
466469

467470
var testNamePrefix = testNamePrefix
468471

@@ -1177,6 +1180,8 @@ self.test("\(testNamePrefix).OperatorPlus") {
11771180
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
11781181
outOfBoundsIndexOffset: Int = 1
11791182
) where
1183+
C.SubSequence : BidirectionalCollection & RangeReplaceableCollection,
1184+
C.Indices : BidirectionalCollection,
11801185
CollectionWithEquatableElement.Iterator.Element : Equatable {
11811186

11821187
var testNamePrefix = testNamePrefix
@@ -1297,6 +1302,8 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove
12971302
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
12981303
outOfBoundsIndexOffset: Int = 1
12991304
) where
1305+
C.SubSequence : RandomAccessCollection & RangeReplaceableCollection,
1306+
C.Indices : RandomAccessCollection,
13001307
CollectionWithEquatableElement.Iterator.Element : Equatable {
13011308

13021309
var testNamePrefix = testNamePrefix

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableSliceType.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extension TestSuite {
3333
collectionIsBidirectional: Bool = false
3434
) where
3535
C.SubSequence == C,
36+
C.Indices : Collection,
3637
CollectionWithEquatableElement.SubSequence == CollectionWithEquatableElement,
3738
CollectionWithEquatableElement.Iterator.Element : Equatable {
3839

@@ -164,6 +165,7 @@ extension TestSuite {
164165
outOfBoundsIndexOffset: Int = 1
165166
) where
166167
C.SubSequence == C,
168+
C.Indices : BidirectionalCollection,
167169
CollectionWithEquatableElement.SubSequence == CollectionWithEquatableElement,
168170
CollectionWithEquatableElement.Iterator.Element : Equatable {
169171

@@ -308,6 +310,7 @@ extension TestSuite {
308310
outOfBoundsIndexOffset: Int = 1
309311
) where
310312
C.SubSequence == C,
313+
C.Indices : RandomAccessCollection,
311314
CollectionWithEquatableElement.SubSequence == CollectionWithEquatableElement,
312315
CollectionWithEquatableElement.Iterator.Element : Equatable {
313316

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,14 @@ public func expectSequenceType<X : Sequence>(_ x: X) -> X
376376
% for Mutable in ['', 'Mutable']:
377377
public func expect${Mutable}CollectionType<X : ${Mutable}Collection>(
378378
_ x: X.Type
379-
) { }
379+
) where
380+
// FIXME(ABI)#2 (Associated Types with where clauses): there should be no constraints in
381+
// the 'where' clause, all of these should be required by the protocol.
382+
% if Mutable == '':
383+
X.SubSequence : Collection,
384+
% end
385+
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#3 (Recursive Protocol Constraints): can't have this constraint now.
386+
X.Indices : Collection {}
380387
% end
381388

382389
/// A slice is a `Collection` that when sliced returns an instance of
@@ -414,7 +421,12 @@ public func expectCollectionAssociatedTypes<X : Collection>(
414421
indexType: X.Index.Type,
415422
indexDistanceType: X.IndexDistance.Type,
416423
indicesType: X.Indices.Type
417-
) { }
424+
) where
425+
// FIXME(ABI)#6 (Associated Types with where clauses): there should be no constraints in
426+
// the 'where' clause, all of these should be required by the protocol.
427+
X.SubSequence : Collection,
428+
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#7 (Recursive Protocol Constraints): can't have this constraint now.
429+
X.Indices : Collection {}
418430

419431
/// Check that all associated types of a `BidirectionalCollection` are what we
420432
/// expect them to be.
@@ -425,7 +437,12 @@ public func expectBidirectionalCollectionAssociatedTypes<X : BidirectionalCollec
425437
indexType: X.Index.Type,
426438
indexDistanceType: X.IndexDistance.Type,
427439
indicesType: X.Indices.Type
428-
) { }
440+
) where
441+
// FIXME(ABI)#8 (Associated Types with where clauses): there should be no constraints in
442+
// the 'where' clause, all of these should be required by the protocol.
443+
X.SubSequence : BidirectionalCollection,
444+
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#9 (Recursive Protocol Constraints): can't have this constraint now.
445+
X.Indices : BidirectionalCollection {}
429446

430447
/// Check that all associated types of a `RandomAccessCollection` are what we
431448
/// expect them to be.
@@ -436,7 +453,12 @@ public func expectRandomAccessCollectionAssociatedTypes<X : RandomAccessCollecti
436453
indexType: X.Index.Type,
437454
indexDistanceType: X.IndexDistance.Type,
438455
indicesType: X.Indices.Type
439-
) { }
456+
) where
457+
// FIXME(ABI)#10 (Associated Types with where clauses): there should be no constraints in
458+
// the 'where' clause, all of these should be required by the protocol.
459+
X.SubSequence : RandomAccessCollection,
460+
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#11 (Recursive Protocol Constraints): can't have this constraint now.
461+
X.Indices : RandomAccessCollection {}
440462

441463
public struct AssertionResult : CustomStringConvertible {
442464
init(isPass: Bool) {

stdlib/public/core/Collection.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,8 @@ public struct IndexingIterator<
648648
/// an O(*n*) operation.
649649
public protocol Collection : _Indexable, Sequence
650650
where SubSequence: Collection, Indices: Collection,
651-
SubSequence.Index == Index
651+
SubSequence.Index == Index,
652+
SubSequence.Iterator.Element == Iterator.Element
652653
{
653654
/// A type that represents the number of steps between a pair of
654655
/// indices.

0 commit comments

Comments
 (0)