Skip to content

Commit 29a15ce

Browse files
committed
[Stdlib] Apply SE-0142 to fix ABI FIXME #92, part of ABI FIXME #99.
1 parent d1d4238 commit 29a15ce

15 files changed

+35
-147
lines changed

stdlib/private/StdlibCollectionUnittest/CheckCollectionInstance.swift.gyb

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ public func check${inc.capitalize()}rementable<Instances, BaseCollection>(
6060
) where
6161
Instances : Collection,
6262
BaseCollection : ${protocol},
63-
Instances.Iterator.Element == BaseCollection.Index,
64-
// FIXME(ABI)#83 (Associated Types with where clauses): these constraints should be applied to
65-
// associated types of Collection.
66-
Instances.Indices.Iterator.Element == Instances.Index {
63+
Instances.Iterator.Element == BaseCollection.Index {
6764

6865
checkEquatable(instances, oracle: equalityOracle, ${trace})
6966
for i in instances {
@@ -92,10 +89,7 @@ internal func _checkIncrementalAdvance<Instances, BaseCollection>(
9289
) where
9390
Instances : Collection,
9491
BaseCollection : _Indexable,
95-
Instances.Iterator.Element == BaseCollection.Index,
96-
// FIXME(ABI)#84 (Associated Types with where clauses): these constraints should be applied to
97-
// associated types of Collection.
98-
Instances.Indices.Iterator.Element == Instances.Index {
92+
Instances.Iterator.Element == BaseCollection.Index {
9993
for i in instances {
10094
let d: BaseCollection.IndexDistance = sign > 0 ?
10195
baseCollection.distance(from: i, to: limit) :
@@ -129,10 +123,7 @@ public func checkForwardIndex<Instances, BaseCollection>(
129123
) where
130124
Instances : Collection,
131125
BaseCollection : _Indexable,
132-
Instances.Iterator.Element == BaseCollection.Index,
133-
// FIXME(ABI)#85 (Associated Types with where clauses): these constraints should be applied to
134-
// associated types of Collection.
135-
Instances.Indices.Iterator.Element == Instances.Index {
126+
Instances.Iterator.Element == BaseCollection.Index {
136127

137128
checkIncrementable(instances, of: baseCollection,
138129
equalityOracle: equalityOracle, endIndex: endIndex, ${trace})
@@ -159,10 +150,7 @@ public func checkBidirectionalIndex<Instances, BaseCollection>(
159150
) where
160151
Instances: Collection,
161152
BaseCollection : _BidirectionalIndexable,
162-
Instances.Iterator.Element == BaseCollection.Index,
163-
// FIXME(ABI)#86 (Associated Types with where clauses): these constraints should be applied to
164-
// associated types of Collection.
165-
Instances.Indices.Iterator.Element == Instances.Index {
153+
Instances.Iterator.Element == BaseCollection.Index {
166154

167155
checkForwardIndex(instances, of: baseCollection,
168156
equalityOracle: equalityOracle, endIndex: endIndex)
@@ -199,11 +187,7 @@ public func checkRandomAccessIndex<Instances, Distances, BaseCollection>(
199187
Distances : Collection,
200188
BaseCollection : _RandomAccessIndexable,
201189
Instances.Iterator.Element == BaseCollection.Index,
202-
Distances.Iterator.Element == BaseCollection.IndexDistance,
203-
// FIXME(ABI)#87 (Associated Types with where clauses): these constraints should be applied to
204-
// associated types of Collection.
205-
Instances.Indices.Iterator.Element == Instances.Index,
206-
Distances.Indices.Iterator.Element == Distances.Index {
190+
Distances.Iterator.Element == BaseCollection.IndexDistance {
207191

208192
checkBidirectionalIndex(instances, of: baseCollection,
209193
equalityOracle: { distanceOracle($0, $1) == 0 },
@@ -232,11 +216,7 @@ public func checkAdvancesAndDistances<Instances, Distances, BaseCollection>(
232216
Distances : Collection,
233217
BaseCollection : _Indexable,
234218
Instances.Iterator.Element == BaseCollection.Index,
235-
Distances.Iterator.Element == BaseCollection.IndexDistance,
236-
// FIXME(ABI)#88 (Associated Types with where clauses): these constraints should be applied to
237-
// associated types of Collection.
238-
Instances.Indices.Iterator.Element == Instances.Index,
239-
Distances.Indices.Iterator.Element == Distances.Index {
219+
Distances.Iterator.Element == BaseCollection.IndexDistance {
240220

241221
checkComparable(
242222
instances,
@@ -363,11 +343,7 @@ public func checkOneLevelOf${Traversal}Collection<
363343
${TRACE},
364344
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
365345
sameValue: (${Element}, ${Element}) -> Bool
366-
) where
367-
C.Iterator.Element == ${Element},
368-
// FIXME(ABI) (Associated Types with where clauses): these constraints should be applied to
369-
// associated types of Collection.
370-
C.Indices.Iterator.Element == C.Index {
346+
) where C.Iterator.Element == ${Element} {
371347

372348
// A `Collection` is a multi-pass `Sequence`.
373349
for _ in 0..<3 {
@@ -545,10 +521,7 @@ ${genericParam}, S : ${TraversalCollection}
545521
sameValue: (${Element}, ${Element}) -> Bool
546522
) where
547523
S.Iterator.Element == ${Element},
548-
S.SubSequence : ${TraversalCollection},
549-
S.SubSequence.Iterator.Element == ${Element},
550-
S.SubSequence.Index == S.Index,
551-
S.SubSequence.Indices.Iterator.Element == S.Index {
524+
S.SubSequence : ${TraversalCollection} {
552525

553526
let expectedArray = Array(expected)
554527

@@ -612,8 +585,7 @@ public func checkRangeReplaceable<C, N>(
612585
C : RangeReplaceableCollection,
613586
N : Collection,
614587
C.Iterator.Element : Equatable,
615-
C.Iterator.Element == N.Iterator.Element,
616-
C.Indices.Iterator.Element == C.Index {
588+
C.Iterator.Element == N.Iterator.Element {
617589

618590
typealias A = C
619591

stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,17 +479,9 @@ internal enum _SubSequenceSubscriptOnRangeMode {
479479
C : %(protocol)s,
480480
CollectionWithEquatableElement : %(protocol)s,
481481
%(subseq_as_collection)s
482-
CollectionWithEquatableElement.SubSequence.Iterator.Element
483-
== CollectionWithEquatableElement.Iterator.Element,
484482
C.SubSequence : %(protocol)s,
485-
C.SubSequence.Iterator.Element == C.Iterator.Element,
486-
C.SubSequence.Index == C.Index,
487-
C.SubSequence.Indices.Iterator.Element == C.Index,
488483
C.SubSequence.SubSequence == C.SubSequence,
489484
C.Indices : %(protocol)s,
490-
C.Indices.Iterator.Element == C.Index,
491-
C.Indices.Index == C.Index,
492-
C.Indices.SubSequence == C.Indices,
493485
CollectionWithEquatableElement.Iterator.Element : Equatable
494486
''' % locals()
495487

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public func withInvalidOrderings(_ body: (@escaping (Int, Int) -> Bool) -> Void)
7777
internal func _mapInPlace<C : MutableCollection>(
7878
_ elements: inout C,
7979
_ transform: (C.Iterator.Element) -> C.Iterator.Element
80-
) where C.Indices.Iterator.Element == C.Index {
80+
) {
8181
for i in elements.indices {
8282
elements[i] = transform(elements[i])
8383
}
@@ -122,17 +122,9 @@ extension TestSuite {
122122
collectionIsBidirectional: Bool = false
123123
) where
124124
C.SubSequence : MutableCollection,
125-
C.SubSequence.Iterator.Element == C.Iterator.Element,
126-
C.SubSequence.Index == C.Index,
127-
C.SubSequence.Indices.Iterator.Element == C.Index,
128125
C.SubSequence.SubSequence == C.SubSequence,
129126
C.Indices : Collection,
130-
C.Indices.Iterator.Element == C.Index,
131-
C.Indices.Index == C.Index,
132-
C.Indices.SubSequence == C.Indices,
133127
CollectionWithEquatableElement.Iterator.Element : Equatable,
134-
CollectionWithEquatableElement.SubSequence.Iterator.Element
135-
== CollectionWithEquatableElement.Iterator.Element,
136128
CollectionWithComparableElement.Iterator.Element : Comparable {
137129

138130
var testNamePrefix = testNamePrefix
@@ -793,17 +785,9 @@ self.test("\(testNamePrefix).partition/InvalidOrderings") {
793785
isFixedLengthCollection: Bool
794786
) where
795787
C.SubSequence : BidirectionalCollection & MutableCollection,
796-
C.SubSequence.Iterator.Element == C.Iterator.Element,
797-
C.SubSequence.Index == C.Index,
798-
C.SubSequence.Indices.Iterator.Element == C.Index,
799788
C.SubSequence.SubSequence == C.SubSequence,
800789
C.Indices : BidirectionalCollection,
801-
C.Indices.Iterator.Element == C.Index,
802-
C.Indices.Index == C.Index,
803-
C.Indices.SubSequence == C.Indices,
804790
CollectionWithEquatableElement.Iterator.Element : Equatable,
805-
CollectionWithEquatableElement.SubSequence.Iterator.Element
806-
== CollectionWithEquatableElement.Iterator.Element,
807791
CollectionWithComparableElement.Iterator.Element : Comparable {
808792

809793
var testNamePrefix = testNamePrefix
@@ -948,19 +932,10 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer
948932
isFixedLengthCollection: Bool
949933
) where
950934
C.SubSequence : RandomAccessCollection & MutableCollection,
951-
C.SubSequence.Iterator.Element == C.Iterator.Element,
952-
C.SubSequence.Index == C.Index,
953-
C.SubSequence.Indices.Iterator.Element == C.Index,
954935
C.SubSequence.SubSequence == C.SubSequence,
955936
C.Indices : RandomAccessCollection,
956-
C.Indices.Iterator.Element == C.Index,
957-
C.Indices.Index == C.Index,
958-
C.Indices.SubSequence == C.Indices,
959937
CollectionWithEquatableElement.Iterator.Element : Equatable,
960-
CollectionWithEquatableElement.SubSequence.Iterator.Element
961-
== CollectionWithEquatableElement.Iterator.Element,
962-
CollectionWithComparableElement.Iterator.Element : Comparable,
963-
CollectionWithComparableElement.SubSequence.Indices.Iterator.Element == CollectionWithComparableElement.Index {
938+
CollectionWithComparableElement.Iterator.Element : Comparable {
964939

965940
var testNamePrefix = testNamePrefix
966941

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -463,18 +463,10 @@ extension TestSuite {
463463
collectionIsBidirectional: Bool = false
464464
) where
465465
C.SubSequence : Collection,
466-
C.SubSequence.Iterator.Element == C.Iterator.Element,
467-
C.SubSequence.Index == C.Index,
468-
C.SubSequence.Indices.Iterator.Element == C.Index,
469466
C.SubSequence.SubSequence == C.SubSequence,
470467
C.Indices : Collection,
471-
C.Indices.Iterator.Element == C.Index,
472-
C.Indices.Index == C.Index,
473-
C.Indices.SubSequence == C.Indices,
474468
CollectionWithEquatableElement.Iterator.Element : Equatable,
475-
CollectionWithEquatableElement.SubSequence : Collection,
476-
CollectionWithEquatableElement.SubSequence.Iterator.Element
477-
== CollectionWithEquatableElement.Iterator.Element {
469+
CollectionWithEquatableElement.SubSequence : Collection {
478470

479471
var testNamePrefix = testNamePrefix
480472

@@ -1190,17 +1182,9 @@ self.test("\(testNamePrefix).OperatorPlus") {
11901182
outOfBoundsIndexOffset: Int = 1
11911183
) where
11921184
C.SubSequence : BidirectionalCollection & RangeReplaceableCollection,
1193-
C.SubSequence.Iterator.Element == C.Iterator.Element,
1194-
C.SubSequence.Index == C.Index,
1195-
C.SubSequence.Indices.Iterator.Element == C.Index,
11961185
C.SubSequence.SubSequence == C.SubSequence,
11971186
C.Indices : BidirectionalCollection,
1198-
C.Indices.Iterator.Element == C.Index,
1199-
C.Indices.Index == C.Index,
1200-
C.Indices.SubSequence == C.Indices,
1201-
CollectionWithEquatableElement.Iterator.Element : Equatable,
1202-
CollectionWithEquatableElement.SubSequence.Iterator.Element
1203-
== CollectionWithEquatableElement.Iterator.Element {
1187+
CollectionWithEquatableElement.Iterator.Element : Equatable {
12041188

12051189
var testNamePrefix = testNamePrefix
12061190

@@ -1321,17 +1305,9 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove
13211305
outOfBoundsIndexOffset: Int = 1
13221306
) where
13231307
C.SubSequence : RandomAccessCollection & RangeReplaceableCollection,
1324-
C.SubSequence.Iterator.Element == C.Iterator.Element,
1325-
C.SubSequence.Index == C.Index,
1326-
C.SubSequence.Indices.Iterator.Element == C.Index,
13271308
C.SubSequence.SubSequence == C.SubSequence,
13281309
C.Indices : RandomAccessCollection,
1329-
C.Indices.Iterator.Element == C.Index,
1330-
C.Indices.Index == C.Index,
1331-
C.Indices.SubSequence == C.Indices,
1332-
CollectionWithEquatableElement.Iterator.Element : Equatable,
1333-
CollectionWithEquatableElement.SubSequence.Iterator.Element
1334-
== CollectionWithEquatableElement.Iterator.Element {
1310+
CollectionWithEquatableElement.Iterator.Element : Equatable {
13351311

13361312
var testNamePrefix = testNamePrefix
13371313

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableSliceType.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ extension TestSuite {
3434
) where
3535
C.SubSequence == C,
3636
C.Indices : Collection,
37-
C.Indices.Iterator.Element == C.Index,
38-
C.Indices.Index == C.Index,
39-
C.Indices.SubSequence == C.Indices,
4037
CollectionWithEquatableElement.SubSequence == CollectionWithEquatableElement,
4138
CollectionWithEquatableElement.Iterator.Element : Equatable {
4239

@@ -169,9 +166,6 @@ extension TestSuite {
169166
) where
170167
C.SubSequence == C,
171168
C.Indices : BidirectionalCollection,
172-
C.Indices.Iterator.Element == C.Index,
173-
C.Indices.Index == C.Index,
174-
C.Indices.SubSequence == C.Indices,
175169
CollectionWithEquatableElement.SubSequence == CollectionWithEquatableElement,
176170
CollectionWithEquatableElement.Iterator.Element : Equatable {
177171

@@ -317,9 +311,6 @@ extension TestSuite {
317311
) where
318312
C.SubSequence == C,
319313
C.Indices : RandomAccessCollection,
320-
C.Indices.Iterator.Element == C.Index,
321-
C.Indices.Index == C.Index,
322-
C.Indices.SubSequence == C.Indices,
323314
CollectionWithEquatableElement.SubSequence == CollectionWithEquatableElement,
324315
CollectionWithEquatableElement.Iterator.Element : Equatable {
325316

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ public func expect${Mutable}CollectionType<X : ${Mutable}Collection>(
366366
% if Mutable == '':
367367
X.SubSequence : Collection,
368368
% end
369-
X.SubSequence.Iterator.Element == X.Iterator.Element,
370-
X.SubSequence.Index == X.Index,
371369
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#3 (Recursive Protocol Constraints): can't have this constraint now.
372370
X.SubSequence.SubSequence == X.SubSequence,
373371
X.Indices : Collection {}
@@ -411,10 +409,7 @@ public func expectCollectionAssociatedTypes<X : Collection>(
411409
) where
412410
// FIXME(ABI)#6 (Associated Types with where clauses): there should be no constraints in
413411
// the 'where' clause, all of these should be required by the protocol.
414-
X._Element == X.Iterator.Element,
415412
X.SubSequence : Collection,
416-
X.SubSequence.Iterator.Element == X.Iterator.Element,
417-
X.SubSequence.Index == X.Index,
418413
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#7 (Recursive Protocol Constraints): can't have this constraint now.
419414
X.SubSequence.SubSequence == X.SubSequence,
420415
X.Indices : Collection {}
@@ -431,10 +426,7 @@ public func expectBidirectionalCollectionAssociatedTypes<X : BidirectionalCollec
431426
) where
432427
// FIXME(ABI)#8 (Associated Types with where clauses): there should be no constraints in
433428
// the 'where' clause, all of these should be required by the protocol.
434-
X._Element == X.Iterator.Element,
435429
X.SubSequence : BidirectionalCollection,
436-
X.SubSequence.Iterator.Element == X.Iterator.Element,
437-
X.SubSequence.Index == X.Index,
438430
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#9 (Recursive Protocol Constraints): can't have this constraint now.
439431
X.SubSequence.SubSequence == X.SubSequence,
440432
X.Indices : BidirectionalCollection {}
@@ -451,10 +443,7 @@ public func expectRandomAccessCollectionAssociatedTypes<X : RandomAccessCollecti
451443
) where
452444
// FIXME(ABI)#10 (Associated Types with where clauses): there should be no constraints in
453445
// the 'where' clause, all of these should be required by the protocol.
454-
X._Element == X.Iterator.Element,
455446
X.SubSequence : RandomAccessCollection,
456-
X.SubSequence.Iterator.Element == X.Iterator.Element,
457-
X.SubSequence.Index == X.Index,
458447
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#11 (Recursive Protocol Constraints): can't have this constraint now.
459448
X.SubSequence.SubSequence == X.SubSequence,
460449
X.Indices : RandomAccessCollection {}
@@ -2280,11 +2269,7 @@ public func checkStrideable<Instances : Collection, Strides : Collection>(
22802269
${TRACE}
22812270
) where
22822271
Instances.Iterator.Element : Strideable,
2283-
Instances.Iterator.Element.Stride == Strides.Iterator.Element,
2284-
// FIXME(ABI)#92 (Associated Types with where clauses): these constraints should be applied to
2285-
// associated types of Collection.
2286-
Instances.Indices.Iterator.Element == Instances.Index,
2287-
Strides.Indices.Iterator.Element == Strides.Index {
2272+
Instances.Iterator.Element.Stride == Strides.Iterator.Element {
22882273

22892274
checkComparable(
22902275
instances,

stdlib/public/core/Collection.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ public protocol Collection : _Indexable, Sequence {
646646
/// supplying `IndexingIterator` as its associated `Iterator`
647647
/// type.
648648
associatedtype Iterator = IndexingIterator<Self>
649+
where Self.Iterator.Element == _Element
649650

650651
// FIXME(ABI)#179 (Type checker): Needed here so that the `Iterator` is properly deduced from
651652
// a custom `makeIterator()` function. Otherwise we get an
@@ -660,12 +661,13 @@ public protocol Collection : _Indexable, Sequence {
660661
/// protocol, but it is restated here with stricter constraints. In a
661662
/// collection, the subsequence should also conform to `Collection`.
662663
associatedtype SubSequence : _IndexableBase, Sequence = Slice<Self>
664+
where Self.SubSequence.Index == Index,
665+
Self.Iterator.Element == Self.SubSequence.Iterator.Element
663666
// FIXME(ABI)#98 (Recursive Protocol Constraints):
664667
// FIXME(ABI)#99 (Associated Types with where clauses):
665668
// associatedtype SubSequence : Collection
666669
// where
667-
// Iterator.Element == SubSequence.Iterator.Element,
668-
// SubSequence.Index == Index,
670+
// ,
669671
// SubSequence.Indices == Indices,
670672
// SubSequence.SubSequence == SubSequence
671673
//

stdlib/public/core/ExistentialCollection.swift.gyb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,13 @@ internal class _AnyRandomAccessCollectionBox<Element>
428428
internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Element>
429429
where
430430
S.SubSequence : ${Kind},
431+
% if Kind == 'Sequence':
431432
S.SubSequence.Iterator.Element == S.Iterator.Element,
433+
%end
432434
S.SubSequence.SubSequence == S.SubSequence
433435
% if Kind != 'Sequence':
434436
,
435437
S.SubSequence.Indices : ${Kind},
436-
S.SubSequence.Indices.Index == S.Index,
437438
S.Indices : ${Kind}
438439
% end
439440
{
@@ -1039,13 +1040,10 @@ public struct ${Self}<Element>
10391040
@_inlineable
10401041
public init<C : ${SubProtocol}>(_ base: C)
10411042
where
1042-
C.Iterator.Element == Element,
1043-
10441043
// FIXME(ABI)#101 (Associated Types with where clauses): these constraints should be applied to
10451044
// associated types of Collection.
10461045
C.SubSequence : ${SubProtocol},
10471046
C.SubSequence.Iterator.Element == Element,
1048-
C.SubSequence.Index == C.Index,
10491047
C.SubSequence.Indices : ${SubProtocol},
10501048
C.SubSequence.SubSequence == C.SubSequence,
10511049
C.Indices : ${SubProtocol}

stdlib/public/core/Mirror.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ public struct Mirror {
219219
// FIXME(ABI)#47 (Associated Types with where clauses): these constraints should be applied to
220220
// associated types of Collection.
221221
C.SubSequence : Collection,
222-
C.SubSequence.Iterator.Element == Child,
223222
C.SubSequence.Indices : Collection,
224-
C.SubSequence.Indices.Index == C.Index,
225223
C.SubSequence.SubSequence == C.SubSequence,
226224
C.Indices : Collection {
227225

0 commit comments

Comments
 (0)