Skip to content

Commit 24821cc

Browse files
authored
Merge pull request #11923 from DougGregor/se-0157-recursive-constraints-stdlib
2 parents 2323991 + 5db9b11 commit 24821cc

37 files changed

+267
-927
lines changed

stdlib/private/StdlibCollectionUnittest/CheckCollectionInstance.swift.gyb

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public struct CollectionMisuseResiliencyChecks {
4040
}
4141

4242
% for inc, protocol, direction, end in (
43-
% ('inc', '_Indexable', 'after', 'end'),
44-
% ('dec', '_BidirectionalIndexable', 'before', 'start')):
43+
% ('inc', 'Collection', 'after', 'end'),
44+
% ('dec', 'BidirectionalCollection', 'before', 'start')):
4545

4646
/// Test that the elements of `instances` satisfy
4747
/// ${'some of ' if inc == 'dec' else ''}the semantic
@@ -88,7 +88,7 @@ internal func _checkIncrementalAdvance<Instances, BaseCollection>(
8888
${TRACE}
8989
) where
9090
Instances : Collection,
91-
BaseCollection : _Indexable,
91+
BaseCollection : Collection,
9292
Instances.Iterator.Element == BaseCollection.Index {
9393
for i in instances {
9494
let d: BaseCollection.IndexDistance = sign > 0 ?
@@ -122,7 +122,7 @@ public func checkForwardIndex<Instances, BaseCollection>(
122122
endIndex: Instances.Iterator.Element, ${TRACE}
123123
) where
124124
Instances : Collection,
125-
BaseCollection : _Indexable,
125+
BaseCollection : Collection,
126126
Instances.Iterator.Element == BaseCollection.Index {
127127

128128
checkIncrementable(instances, of: baseCollection,
@@ -149,7 +149,7 @@ public func checkBidirectionalIndex<Instances, BaseCollection>(
149149
${TRACE}
150150
) where
151151
Instances: Collection,
152-
BaseCollection : _BidirectionalIndexable,
152+
BaseCollection : BidirectionalCollection,
153153
Instances.Iterator.Element == BaseCollection.Index {
154154

155155
checkForwardIndex(instances, of: baseCollection,
@@ -185,7 +185,7 @@ public func checkRandomAccessIndex<Instances, Distances, BaseCollection>(
185185
) where
186186
Instances : Collection,
187187
Distances : Collection,
188-
BaseCollection : _RandomAccessIndexable,
188+
BaseCollection : RandomAccessCollection,
189189
Instances.Iterator.Element == BaseCollection.Index,
190190
Distances.Iterator.Element == BaseCollection.IndexDistance {
191191

@@ -214,7 +214,7 @@ public func checkAdvancesAndDistances<Instances, Distances, BaseCollection>(
214214
) where
215215
Instances : Collection,
216216
Distances : Collection,
217-
BaseCollection : _Indexable,
217+
BaseCollection : Collection,
218218
Instances.Iterator.Element == BaseCollection.Index,
219219
Distances.Iterator.Element == BaseCollection.IndexDistance {
220220

@@ -257,8 +257,7 @@ public func checkCollection<${genericParam}, C : Collection>(
257257
${TRACE},
258258
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
259259
sameValue: (${Element}, ${Element}) -> Bool
260-
) where C.Iterator.Element == ${Element},
261-
C.SubSequence : Collection {
260+
) where C.Iterator.Element == ${Element} {
262261

263262
checkForwardCollection(expected, collection, message(),
264263
stackTrace: stackTrace, showFrame: showFrame, file: file, line: line,
@@ -278,7 +277,6 @@ public func check${Traversal}Collection<
278277
resiliencyChecks: CollectionMisuseResiliencyChecks = .all
279278
) where
280279
C.Iterator.Element == ${Element},
281-
C.SubSequence : ${TraversalCollection},
282280
${Element} : Equatable {
283281

284282
check${Traversal}Collection(
@@ -298,8 +296,7 @@ public func check${Traversal}Collection<
298296
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
299297
sameValue: (${Element}, ${Element}) -> Bool
300298
) where
301-
C.Iterator.Element == ${Element},
302-
C.SubSequence : ${TraversalCollection} {
299+
C.Iterator.Element == ${Element} {
303300

304301
checkOneLevelOf${Traversal}Collection(expected, collection, ${trace},
305302
resiliencyChecks: resiliencyChecks, sameValue: sameValue)
@@ -504,8 +501,7 @@ ${genericParam}, S : ${TraversalCollection}
504501
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
505502
sameValue: (${Element}, ${Element}) -> Bool
506503
) where
507-
S.Iterator.Element == ${Element},
508-
S.SubSequence : ${TraversalCollection} {
504+
S.Iterator.Element == ${Element} {
509505

510506
let expectedArray = Array(expected)
511507

stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,9 @@ 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=''
478474
return '''
479475
C : %(protocol)s,
480476
CollectionWithEquatableElement : %(protocol)s,
481-
%(subseq_as_collection)s
482-
C.SubSequence : %(protocol)s,
483-
C.Indices : %(protocol)s,
484477
CollectionWithEquatableElement.Iterator.Element : Equatable
485478
''' % locals()
486479

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb

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

@@ -776,8 +774,6 @@ self.test("\(testNamePrefix).partition/InvalidOrderings") {
776774
withUnsafeMutableBufferPointerIsSupported: Bool,
777775
isFixedLengthCollection: Bool
778776
) where
779-
C.SubSequence : BidirectionalCollection & MutableCollection,
780-
C.Indices : BidirectionalCollection,
781777
CollectionWithEquatableElement.Iterator.Element : Equatable,
782778
CollectionWithComparableElement.Iterator.Element : Comparable {
783779

@@ -922,8 +918,6 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer
922918
withUnsafeMutableBufferPointerIsSupported: Bool,
923919
isFixedLengthCollection: Bool
924920
) where
925-
C.SubSequence : RandomAccessCollection & MutableCollection,
926-
C.Indices : RandomAccessCollection,
927921
CollectionWithEquatableElement.Iterator.Element : Equatable,
928922
CollectionWithComparableElement.Iterator.Element : Comparable {
929923

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift

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

470467
var testNamePrefix = testNamePrefix
471468

@@ -1180,8 +1177,6 @@ self.test("\(testNamePrefix).OperatorPlus") {
11801177
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
11811178
outOfBoundsIndexOffset: Int = 1
11821179
) where
1183-
C.SubSequence : BidirectionalCollection & RangeReplaceableCollection,
1184-
C.Indices : BidirectionalCollection,
11851180
CollectionWithEquatableElement.Iterator.Element : Equatable {
11861181

11871182
var testNamePrefix = testNamePrefix
@@ -1302,8 +1297,6 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove
13021297
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
13031298
outOfBoundsIndexOffset: Int = 1
13041299
) where
1305-
C.SubSequence : RandomAccessCollection & RangeReplaceableCollection,
1306-
C.Indices : RandomAccessCollection,
13071300
CollectionWithEquatableElement.Iterator.Element : Equatable {
13081301

13091302
var testNamePrefix = testNamePrefix

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableSliceType.swift

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

@@ -165,7 +164,6 @@ extension TestSuite {
165164
outOfBoundsIndexOffset: Int = 1
166165
) where
167166
C.SubSequence == C,
168-
C.Indices : BidirectionalCollection,
169167
CollectionWithEquatableElement.SubSequence == CollectionWithEquatableElement,
170168
CollectionWithEquatableElement.Iterator.Element : Equatable {
171169

@@ -310,7 +308,6 @@ extension TestSuite {
310308
outOfBoundsIndexOffset: Int = 1
311309
) where
312310
C.SubSequence == C,
313-
C.Indices : RandomAccessCollection,
314311
CollectionWithEquatableElement.SubSequence == CollectionWithEquatableElement,
315312
CollectionWithEquatableElement.Iterator.Element : Equatable {
316313

stdlib/private/StdlibCollectionUnittest/CheckSequenceType.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,13 +1536,7 @@ extension TestSuite {
15361536

15371537
resiliencyChecks: CollectionMisuseResiliencyChecks = .all
15381538
) where
1539-
SequenceWithEquatableElement.Iterator.Element : Equatable,
1540-
SequenceWithEquatableElement.SubSequence : Sequence,
1541-
SequenceWithEquatableElement.SubSequence.Iterator.Element
1542-
== SequenceWithEquatableElement.Iterator.Element,
1543-
S.SubSequence : Sequence,
1544-
S.SubSequence.Iterator.Element == S.Iterator.Element,
1545-
S.SubSequence.SubSequence == S.SubSequence {
1539+
SequenceWithEquatableElement.Iterator.Element : Equatable {
15461540

15471541
var testNamePrefix = testNamePrefix
15481542

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -378,25 +378,14 @@ public func expectTrapping<Bound>(
378378
public func expectType<T>(_: T.Type, _ x: inout T) {}
379379
public func expectEqualType<T>(_: T.Type, _: T.Type) {}
380380

381-
public func expectSequenceType<X : Sequence>(_ x: X) -> X
382-
where
383-
X.SubSequence : Sequence,
384-
X.SubSequence.Iterator.Element == X.Iterator.Element,
385-
X.SubSequence.SubSequence == X.SubSequence {
381+
public func expectSequenceType<X : Sequence>(_ x: X) -> X {
386382
return x
387383
}
388384

389385
% for Mutable in ['', 'Mutable']:
390386
public func expect${Mutable}CollectionType<X : ${Mutable}Collection>(
391387
_ x: X.Type
392-
) where
393-
// FIXME(ABI)#2 (Associated Types with where clauses): there should be no constraints in
394-
// the 'where' clause, all of these should be required by the protocol.
395-
% if Mutable == '':
396-
X.SubSequence : Collection,
397-
% end
398-
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#3 (Recursive Protocol Constraints): can't have this constraint now.
399-
X.Indices : Collection {}
388+
) {}
400389
% end
401390

402391
/// A slice is a `Collection` that when sliced returns an instance of
@@ -417,13 +406,7 @@ public func expectSequenceAssociatedTypes<X : Sequence>(
417406
sequenceType: X.Type,
418407
iteratorType: X.Iterator.Type,
419408
subSequenceType: X.SubSequence.Type
420-
) where
421-
// FIXME(ABI)#4 (Associated Types with where clauses): there should be no constraints in
422-
// the 'where' clause, all of these should be required by the protocol.
423-
X.SubSequence : Sequence,
424-
X.SubSequence.Iterator.Element == X.Iterator.Element,
425-
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#5 (Recursive Protocol Constraints): can't have this constraint now.
426-
X.SubSequence.SubSequence == X.SubSequence {}
409+
) {}
427410

428411
/// Check that all associated types of a `Collection` are what we expect them
429412
/// to be.
@@ -434,12 +417,7 @@ public func expectCollectionAssociatedTypes<X : Collection>(
434417
indexType: X.Index.Type,
435418
indexDistanceType: X.IndexDistance.Type,
436419
indicesType: X.Indices.Type
437-
) where
438-
// FIXME(ABI)#6 (Associated Types with where clauses): there should be no constraints in
439-
// the 'where' clause, all of these should be required by the protocol.
440-
X.SubSequence : Collection,
441-
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#7 (Recursive Protocol Constraints): can't have this constraint now.
442-
X.Indices : Collection {}
420+
) {}
443421

444422
/// Check that all associated types of a `BidirectionalCollection` are what we
445423
/// expect them to be.
@@ -450,12 +428,7 @@ public func expectBidirectionalCollectionAssociatedTypes<X : BidirectionalCollec
450428
indexType: X.Index.Type,
451429
indexDistanceType: X.IndexDistance.Type,
452430
indicesType: X.Indices.Type
453-
) where
454-
// FIXME(ABI)#8 (Associated Types with where clauses): there should be no constraints in
455-
// the 'where' clause, all of these should be required by the protocol.
456-
X.SubSequence : BidirectionalCollection,
457-
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#9 (Recursive Protocol Constraints): can't have this constraint now.
458-
X.Indices : BidirectionalCollection {}
431+
) {}
459432

460433
/// Check that all associated types of a `RandomAccessCollection` are what we
461434
/// expect them to be.
@@ -466,12 +439,7 @@ public func expectRandomAccessCollectionAssociatedTypes<X : RandomAccessCollecti
466439
indexType: X.Index.Type,
467440
indexDistanceType: X.IndexDistance.Type,
468441
indicesType: X.Indices.Type
469-
) where
470-
// FIXME(ABI)#10 (Associated Types with where clauses): there should be no constraints in
471-
// the 'where' clause, all of these should be required by the protocol.
472-
X.SubSequence : RandomAccessCollection,
473-
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#11 (Recursive Protocol Constraints): can't have this constraint now.
474-
X.Indices : RandomAccessCollection {}
442+
) {}
475443

476444
public struct AssertionResult : CustomStringConvertible {
477445
init(isPass: Bool) {

stdlib/public/SDK/Dispatch/Data.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable {
299299
}
300300

301301
public struct DispatchDataIterator : IteratorProtocol, Sequence {
302+
public typealias Element = UInt8
302303

303304
/// Create an iterator over the given DispatchData
304305
public init(_data: DispatchData) {

stdlib/public/SDK/Foundation/IndexSet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
371371
public func intersects(integersIn range: CountableClosedRange<Element>) -> Bool { return self.intersects(integersIn: Range(range)) }
372372

373373
// MARK: -
374-
// Indexable
374+
// Collection
375375

376376
public func index(after i: Index) -> Index {
377377
if i.value + 1 == i.extent.upperBound {

stdlib/public/core/ArrayBufferProtocol.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
internal protocol _ArrayBufferProtocol
1717
: MutableCollection, RandomAccessCollection {
1818

19-
associatedtype Indices
20-
// FIXME(ABI) (Revert Where Clauses): Remove this conformance
21-
: RandomAccessCollection
22-
= CountableRange<Int>
19+
associatedtype Indices = CountableRange<Int>
2320

2421
/// Create an empty buffer.
2522
init()

0 commit comments

Comments
 (0)