Skip to content

Commit 583d567

Browse files
authored
Merge pull request #8888 from DougGregor/the-subsequence-of-my-subsequence
[Stdlib] For Collections, the SubSequence of a Subsequence is SubSequence
2 parents 49daaea + 13f6c79 commit 583d567

File tree

9 files changed

+15
-23
lines changed

9 files changed

+15
-23
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,6 +4211,15 @@ static void computeDerivedSameTypeComponents(
42114211
assert(componentOf.count(concrete.archetype) > 0);
42124212
auto &component = components[componentOf[concrete.archetype]];
42134213

4214+
// FIXME: Skip self-derived sources. This means our attempts to "stage"
4215+
// construction of self-derived sources really don't work, because we
4216+
// discover more information later, so we need a more on-line or
4217+
// iterative approach.
4218+
bool derivedViaConcrete;
4219+
if (concrete.source->isSelfDerivedSource(concrete.archetype,
4220+
derivedViaConcrete))
4221+
continue;
4222+
42144223
// If it has a better source than we'd seen before for this component,
42154224
// keep it.
42164225
auto &bestConcreteTypeSource = component.concreteTypeSource;

stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ internal enum _SubSequenceSubscriptOnRangeMode {
480480
CollectionWithEquatableElement : %(protocol)s,
481481
%(subseq_as_collection)s
482482
C.SubSequence : %(protocol)s,
483-
C.SubSequence.SubSequence == C.SubSequence,
484483
C.Indices : %(protocol)s,
485484
CollectionWithEquatableElement.Iterator.Element : Equatable
486485
''' % locals()

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ extension TestSuite {
122122
collectionIsBidirectional: Bool = false
123123
) where
124124
C.SubSequence : MutableCollection,
125-
C.SubSequence.SubSequence == C.SubSequence,
126125
C.Indices : Collection,
127126
CollectionWithEquatableElement.Iterator.Element : Equatable,
128127
CollectionWithComparableElement.Iterator.Element : Comparable {
@@ -785,7 +784,6 @@ self.test("\(testNamePrefix).partition/InvalidOrderings") {
785784
isFixedLengthCollection: Bool
786785
) where
787786
C.SubSequence : BidirectionalCollection & MutableCollection,
788-
C.SubSequence.SubSequence == C.SubSequence,
789787
C.Indices : BidirectionalCollection,
790788
CollectionWithEquatableElement.Iterator.Element : Equatable,
791789
CollectionWithComparableElement.Iterator.Element : Comparable {
@@ -932,7 +930,6 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer
932930
isFixedLengthCollection: Bool
933931
) where
934932
C.SubSequence : RandomAccessCollection & MutableCollection,
935-
C.SubSequence.SubSequence == C.SubSequence,
936933
C.Indices : RandomAccessCollection,
937934
CollectionWithEquatableElement.Iterator.Element : Equatable,
938935
CollectionWithComparableElement.Iterator.Element : Comparable {

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ extension TestSuite {
463463
collectionIsBidirectional: Bool = false
464464
) where
465465
C.SubSequence : Collection,
466-
C.SubSequence.SubSequence == C.SubSequence,
467466
C.Indices : Collection,
468467
CollectionWithEquatableElement.Iterator.Element : Equatable,
469468
CollectionWithEquatableElement.SubSequence : Collection {
@@ -1182,7 +1181,6 @@ self.test("\(testNamePrefix).OperatorPlus") {
11821181
outOfBoundsIndexOffset: Int = 1
11831182
) where
11841183
C.SubSequence : BidirectionalCollection & RangeReplaceableCollection,
1185-
C.SubSequence.SubSequence == C.SubSequence,
11861184
C.Indices : BidirectionalCollection,
11871185
CollectionWithEquatableElement.Iterator.Element : Equatable {
11881186

@@ -1305,7 +1303,6 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove
13051303
outOfBoundsIndexOffset: Int = 1
13061304
) where
13071305
C.SubSequence : RandomAccessCollection & RangeReplaceableCollection,
1308-
C.SubSequence.SubSequence == C.SubSequence,
13091306
C.Indices : RandomAccessCollection,
13101307
CollectionWithEquatableElement.Iterator.Element : Equatable {
13111308

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ public func expect${Mutable}CollectionType<X : ${Mutable}Collection>(
367367
X.SubSequence : Collection,
368368
% end
369369
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#3 (Recursive Protocol Constraints): can't have this constraint now.
370-
X.SubSequence.SubSequence == X.SubSequence,
371370
X.Indices : Collection {}
372371
% end
373372

@@ -411,7 +410,6 @@ public func expectCollectionAssociatedTypes<X : Collection>(
411410
// the 'where' clause, all of these should be required by the protocol.
412411
X.SubSequence : Collection,
413412
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#7 (Recursive Protocol Constraints): can't have this constraint now.
414-
X.SubSequence.SubSequence == X.SubSequence,
415413
X.Indices : Collection {}
416414

417415
/// Check that all associated types of a `BidirectionalCollection` are what we
@@ -428,7 +426,6 @@ public func expectBidirectionalCollectionAssociatedTypes<X : BidirectionalCollec
428426
// the 'where' clause, all of these should be required by the protocol.
429427
X.SubSequence : BidirectionalCollection,
430428
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#9 (Recursive Protocol Constraints): can't have this constraint now.
431-
X.SubSequence.SubSequence == X.SubSequence,
432429
X.Indices : BidirectionalCollection {}
433430

434431
/// Check that all associated types of a `RandomAccessCollection` are what we
@@ -445,7 +442,6 @@ public func expectRandomAccessCollectionAssociatedTypes<X : RandomAccessCollecti
445442
// the 'where' clause, all of these should be required by the protocol.
446443
X.SubSequence : RandomAccessCollection,
447444
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#11 (Recursive Protocol Constraints): can't have this constraint now.
448-
X.SubSequence.SubSequence == X.SubSequence,
449445
X.Indices : RandomAccessCollection {}
450446

451447
public struct AssertionResult : CustomStringConvertible {

stdlib/public/core/Collection.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,13 @@ public protocol Collection : _Indexable, Sequence {
662662
/// collection, the subsequence should also conform to `Collection`.
663663
associatedtype SubSequence : _IndexableBase, Sequence = Slice<Self>
664664
where Self.SubSequence.Index == Index,
665-
Self.Iterator.Element == Self.SubSequence.Iterator.Element
665+
Self.Iterator.Element == Self.SubSequence.Iterator.Element,
666+
SubSequence.SubSequence == SubSequence
666667
// FIXME(ABI)#98 (Recursive Protocol Constraints):
667668
// FIXME(ABI)#99 (Associated Types with where clauses):
668669
// associatedtype SubSequence : Collection
669670
// where
670-
// ,
671671
// SubSequence.Indices == Indices,
672-
// SubSequence.SubSequence == SubSequence
673672
//
674673
// (<rdar://problem/20715009> Implement recursive protocol
675674
// constraints)

stdlib/public/core/ExistentialCollection.swift.gyb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,11 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Elemen
430430
S.SubSequence : ${Kind},
431431
% if Kind == 'Sequence':
432432
S.SubSequence.Iterator.Element == S.Iterator.Element,
433-
%end
434433
S.SubSequence.SubSequence == S.SubSequence
435-
% if Kind != 'Sequence':
436-
,
434+
% else:
437435
S.SubSequence.Indices : ${Kind},
438436
S.Indices : ${Kind}
439-
% end
437+
% end
440438
{
441439
internal typealias Element = S.Iterator.Element
442440

@@ -1045,7 +1043,6 @@ public struct ${Self}<Element>
10451043
C.SubSequence : ${SubProtocol},
10461044
C.SubSequence.Iterator.Element == Element,
10471045
C.SubSequence.Indices : ${SubProtocol},
1048-
C.SubSequence.SubSequence == C.SubSequence,
10491046
C.Indices : ${SubProtocol}
10501047
{
10511048
// Traversal: ${Traversal}

stdlib/public/core/LazyCollection.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ extension ${Self} : ${TraversalCollection} {
163163
///
164164
/// - Complexity: O(1)
165165
@_inlineable
166-
public subscript(bounds: Range<Index>) -> ${Self}<${Slice}<Base>> {
167-
return ${Slice}(base: _base, bounds: bounds).lazy
166+
public subscript(bounds: Range<Index>) -> ${Slice}<${Self}<Base>> {
167+
return ${Slice}(base: self, bounds: bounds)
168168
}
169169

170170
/// A Boolean value indicating whether the collection is empty.

stdlib/public/core/Mirror.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ public struct Mirror {
220220
// associated types of Collection.
221221
C.SubSequence : Collection,
222222
C.SubSequence.Indices : Collection,
223-
C.SubSequence.SubSequence == C.SubSequence,
224223
C.Indices : Collection {
225224

226225
self.subjectType = Subject.self
@@ -272,7 +271,6 @@ public struct Mirror {
272271
// FIXME(ABI)#48 (Associated Types with where clauses): these constraints should be applied to
273272
// associated types of Collection.
274273
C.SubSequence : Collection,
275-
C.SubSequence.SubSequence == C.SubSequence,
276274
C.Indices : Collection {
277275

278276
self.subjectType = Subject.self

0 commit comments

Comments
 (0)