Skip to content

Commit 0dd1da3

Browse files
committed
[Stdlib] Use SE-0142 to address ABI FIXMEs swiftlang#68, swiftlang#89, swiftlang#90, swiftlang#91.
Address ABI FIXME swiftlang#68 by using same-type constraints directly on an associated type to describe the requirements on the Indices associated type of the Collection protocol. ABI FIXMEs swiftlang#89, swiftlang#90, swiftlang#91 are all in StdlibUnittest, and provoke warnings once swiftlang#68 is fixed, but it's nice to clear them out. Fixes SR-2121.
1 parent b91bd28 commit 0dd1da3

File tree

5 files changed

+28
-57
lines changed

5 files changed

+28
-57
lines changed

Diff for: stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

+7-28
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,7 @@ public func expect${Mutable}CollectionType<X : ${Mutable}Collection>(
370370
X.SubSequence.Index == X.Index,
371371
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#3 (Recursive Protocol Constraints): can't have this constraint now.
372372
X.SubSequence.SubSequence == X.SubSequence,
373-
X.Indices : Collection,
374-
X.Indices.Iterator.Element == X.Index,
375-
X.Indices.Index == X.Index,
376-
X.Indices.SubSequence == X.Indices {}
373+
X.Indices : Collection {}
377374
% end
378375

379376
/// A slice is a `Collection` that when sliced returns an instance of
@@ -420,10 +417,7 @@ public func expectCollectionAssociatedTypes<X : Collection>(
420417
X.SubSequence.Index == X.Index,
421418
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#7 (Recursive Protocol Constraints): can't have this constraint now.
422419
X.SubSequence.SubSequence == X.SubSequence,
423-
X.Indices : Collection,
424-
X.Indices.Iterator.Element == X.Index,
425-
X.Indices.Index == X.Index,
426-
X.Indices.SubSequence == X.Indices {}
420+
X.Indices : Collection {}
427421

428422
/// Check that all associated types of a `BidirectionalCollection` are what we
429423
/// expect them to be.
@@ -443,10 +437,7 @@ public func expectBidirectionalCollectionAssociatedTypes<X : BidirectionalCollec
443437
X.SubSequence.Index == X.Index,
444438
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#9 (Recursive Protocol Constraints): can't have this constraint now.
445439
X.SubSequence.SubSequence == X.SubSequence,
446-
X.Indices : BidirectionalCollection,
447-
X.Indices.Iterator.Element == X.Index,
448-
X.Indices.Index == X.Index,
449-
X.Indices.SubSequence == X.Indices {}
440+
X.Indices : BidirectionalCollection {}
450441

451442
/// Check that all associated types of a `RandomAccessCollection` are what we
452443
/// expect them to be.
@@ -466,10 +457,7 @@ public func expectRandomAccessCollectionAssociatedTypes<X : RandomAccessCollecti
466457
X.SubSequence.Index == X.Index,
467458
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#11 (Recursive Protocol Constraints): can't have this constraint now.
468459
X.SubSequence.SubSequence == X.SubSequence,
469-
X.Indices : RandomAccessCollection,
470-
X.Indices.Iterator.Element == X.Index,
471-
X.Indices.Index == X.Index,
472-
X.Indices.SubSequence == X.Indices {}
460+
X.Indices : RandomAccessCollection {}
473461

474462
public struct AssertionResult : CustomStringConvertible {
475463
init(isPass: Bool) {
@@ -2000,10 +1988,7 @@ public func checkEquatable<Instances : Collection>(
20001988
allowBrokenTransitivity: Bool = false,
20011989
${TRACE}
20021990
) where
2003-
Instances.Iterator.Element : Equatable,
2004-
// FIXME(ABI)#89 (Associated Types with where clauses): these constraints should be applied to
2005-
// associated types of Collection.
2006-
Instances.Indices.Iterator.Element == Instances.Index
1991+
Instances.Iterator.Element : Equatable
20071992
{
20081993
let indices = Array(instances.indices)
20091994
_checkEquatableImpl(
@@ -2096,10 +2081,7 @@ public func checkHashable<Instances : Collection>(
20962081
allowBrokenTransitivity: Bool = false,
20972082
${TRACE}
20982083
) where
2099-
Instances.Iterator.Element : Hashable,
2100-
// FIXME(ABI)#90 (Associated Types with where clauses): these constraints should be applied to
2101-
// associated types of Collection.
2102-
Instances.Indices.Iterator.Element == Instances.Index {
2084+
Instances.Iterator.Element : Hashable {
21032085

21042086
checkEquatable(
21052087
instances,
@@ -2191,10 +2173,7 @@ public func checkComparable<Instances : Collection>(
21912173
oracle: (Instances.Index, Instances.Index) -> ExpectedComparisonResult,
21922174
${TRACE}
21932175
) where
2194-
Instances.Iterator.Element : Comparable,
2195-
// FIXME(ABI)#91 (Associated Types with where clauses): these constraints should be applied to
2196-
// associated types of Collection.
2197-
Instances.Indices.Iterator.Element == Instances.Index {
2176+
Instances.Iterator.Element : Comparable {
21982177

21992178
// Also checks that equality is consistent with comparison and that
22002179
// the oracle obeys the equality laws

Diff for: stdlib/public/core/Collection.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -724,14 +724,13 @@ public protocol Collection : _Indexable, Sequence {
724724
/// A type that represents the indices that are valid for subscripting the
725725
/// collection, in ascending order.
726726
associatedtype Indices : _Indexable, Sequence = DefaultIndices<Self>
727+
where Indices.Iterator.Element == Index,
728+
Indices.Index == Index,
729+
Indices.SubSequence == Indices
727730

728-
// FIXME(ABI)#68 (Associated Types with where clauses):
729731
// FIXME(ABI)#100 (Recursive Protocol Constraints):
730732
// associatedtype Indices : Collection
731733
// where
732-
// Indices.Iterator.Element == Index,
733-
// Indices.Index == Index,
734-
// Indices.SubSequence == Indices
735734
// = DefaultIndices<Self>
736735

737736
/// The indices that are valid for subscripting the collection, in ascending

Diff for: stdlib/public/core/ExistentialCollection.swift.gyb

+3-14
Original file line numberDiff line numberDiff line change
@@ -432,15 +432,9 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Elemen
432432
S.SubSequence.SubSequence == S.SubSequence
433433
% if Kind != 'Sequence':
434434
,
435-
S.SubSequence.Index == S.Index,
436435
S.SubSequence.Indices : ${Kind},
437-
S.SubSequence.Indices.Iterator.Element == S.Index,
438436
S.SubSequence.Indices.Index == S.Index,
439-
S.SubSequence.Indices.SubSequence == S.SubSequence.Indices,
440-
S.Indices : ${Kind},
441-
S.Indices.Iterator.Element == S.Index,
442-
S.Indices.Index == S.Index,
443-
S.Indices.SubSequence == S.Indices
437+
S.Indices : ${Kind}
444438
% end
445439
{
446440
internal typealias Element = S.Iterator.Element
@@ -1053,14 +1047,9 @@ public struct ${Self}<Element>
10531047
C.SubSequence.Iterator.Element == Element,
10541048
C.SubSequence.Index == C.Index,
10551049
C.SubSequence.Indices : ${SubProtocol},
1056-
C.SubSequence.Indices.Iterator.Element == C.Index,
1057-
C.SubSequence.Indices.Index == C.Index,
1058-
C.SubSequence.Indices.SubSequence == C.SubSequence.Indices,
10591050
C.SubSequence.SubSequence == C.SubSequence,
1060-
C.Indices : ${SubProtocol},
1061-
C.Indices.Iterator.Element == C.Index,
1062-
C.Indices.Index == C.Index,
1063-
C.Indices.SubSequence == C.Indices {
1051+
C.Indices : ${SubProtocol}
1052+
{
10641053
// Traversal: ${Traversal}
10651054
// SubTraversal: ${SubTraversal}
10661055
self._box = _${SubProtocol}Box<C>(

Diff for: stdlib/public/core/Mirror.swift

+2-11
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,10 @@ public struct Mirror {
220220
// associated types of Collection.
221221
C.SubSequence : Collection,
222222
C.SubSequence.Iterator.Element == Child,
223-
C.SubSequence.Index == C.Index,
224223
C.SubSequence.Indices : Collection,
225-
C.SubSequence.Indices.Iterator.Element == C.Index,
226224
C.SubSequence.Indices.Index == C.Index,
227-
C.SubSequence.Indices.SubSequence == C.SubSequence.Indices,
228225
C.SubSequence.SubSequence == C.SubSequence,
229-
C.Indices : Collection,
230-
C.Indices.Iterator.Element == C.Index,
231-
C.Indices.Index == C.Index,
232-
C.Indices.SubSequence == C.Indices {
226+
C.Indices : Collection {
233227

234228
self.subjectType = Subject.self
235229
self._makeSuperclassMirror = Mirror._superclassIterator(
@@ -281,10 +275,7 @@ public struct Mirror {
281275
// associated types of Collection.
282276
C.SubSequence : Collection,
283277
C.SubSequence.SubSequence == C.SubSequence,
284-
C.Indices : Collection,
285-
C.Indices.Iterator.Element == C.Index,
286-
C.Indices.Index == C.Index,
287-
C.Indices.SubSequence == C.Indices {
278+
C.Indices : Collection {
288279

289280
self.subjectType = Subject.self
290281
self._makeSuperclassMirror = Mirror._superclassIterator(

Diff for: validation-test/stdlib/CollectionType.swift.gyb

+13
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,19 @@ CollectionTypeTests.test("index(of:)/ContinueSearch") {
734734
}
735735
}
736736

737+
//===----------------------------------------------------------------------===//
738+
// Collection indices types
739+
//===----------------------------------------------------------------------===//
740+
741+
// SR-2121
742+
extension Collection {
743+
func testIndicesElementType() {
744+
for index in self.indices {
745+
_ = self[index]
746+
}
747+
}
748+
}
749+
737750
//===----------------------------------------------------------------------===//
738751
// Collection.split()
739752
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)