Skip to content

[Stdlib] For Collections, the SubSequence of a Subsequence is SubSequence #8888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4211,6 +4211,15 @@ static void computeDerivedSameTypeComponents(
assert(componentOf.count(concrete.archetype) > 0);
auto &component = components[componentOf[concrete.archetype]];

// FIXME: Skip self-derived sources. This means our attempts to "stage"
// construction of self-derived sources really don't work, because we
// discover more information later, so we need a more on-line or
// iterative approach.
bool derivedViaConcrete;
if (concrete.source->isSelfDerivedSource(concrete.archetype,
derivedViaConcrete))
continue;

// If it has a better source than we'd seen before for this component,
// keep it.
auto &bestConcreteTypeSource = component.concreteTypeSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ internal enum _SubSequenceSubscriptOnRangeMode {
CollectionWithEquatableElement : %(protocol)s,
%(subseq_as_collection)s
C.SubSequence : %(protocol)s,
C.SubSequence.SubSequence == C.SubSequence,
C.Indices : %(protocol)s,
CollectionWithEquatableElement.Iterator.Element : Equatable
''' % locals()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ extension TestSuite {
collectionIsBidirectional: Bool = false
) where
C.SubSequence : MutableCollection,
C.SubSequence.SubSequence == C.SubSequence,
C.Indices : Collection,
CollectionWithEquatableElement.Iterator.Element : Equatable,
CollectionWithComparableElement.Iterator.Element : Comparable {
Expand Down Expand Up @@ -785,7 +784,6 @@ self.test("\(testNamePrefix).partition/InvalidOrderings") {
isFixedLengthCollection: Bool
) where
C.SubSequence : BidirectionalCollection & MutableCollection,
C.SubSequence.SubSequence == C.SubSequence,
C.Indices : BidirectionalCollection,
CollectionWithEquatableElement.Iterator.Element : Equatable,
CollectionWithComparableElement.Iterator.Element : Comparable {
Expand Down Expand Up @@ -932,7 +930,6 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer
isFixedLengthCollection: Bool
) where
C.SubSequence : RandomAccessCollection & MutableCollection,
C.SubSequence.SubSequence == C.SubSequence,
C.Indices : RandomAccessCollection,
CollectionWithEquatableElement.Iterator.Element : Equatable,
CollectionWithComparableElement.Iterator.Element : Comparable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ extension TestSuite {
collectionIsBidirectional: Bool = false
) where
C.SubSequence : Collection,
C.SubSequence.SubSequence == C.SubSequence,
C.Indices : Collection,
CollectionWithEquatableElement.Iterator.Element : Equatable,
CollectionWithEquatableElement.SubSequence : Collection {
Expand Down Expand Up @@ -1182,7 +1181,6 @@ self.test("\(testNamePrefix).OperatorPlus") {
outOfBoundsIndexOffset: Int = 1
) where
C.SubSequence : BidirectionalCollection & RangeReplaceableCollection,
C.SubSequence.SubSequence == C.SubSequence,
C.Indices : BidirectionalCollection,
CollectionWithEquatableElement.Iterator.Element : Equatable {

Expand Down Expand Up @@ -1305,7 +1303,6 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove
outOfBoundsIndexOffset: Int = 1
) where
C.SubSequence : RandomAccessCollection & RangeReplaceableCollection,
C.SubSequence.SubSequence == C.SubSequence,
C.Indices : RandomAccessCollection,
CollectionWithEquatableElement.Iterator.Element : Equatable {

Expand Down
4 changes: 0 additions & 4 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ public func expect${Mutable}CollectionType<X : ${Mutable}Collection>(
X.SubSequence : Collection,
% end
// X.SubSequence.Indices == X.Indices, // FIXME(ABI)#3 (Recursive Protocol Constraints): can't have this constraint now.
X.SubSequence.SubSequence == X.SubSequence,
X.Indices : Collection {}
% end

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

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

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

public struct AssertionResult : CustomStringConvertible {
Expand Down
5 changes: 2 additions & 3 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -662,14 +662,13 @@ public protocol Collection : _Indexable, Sequence {
/// collection, the subsequence should also conform to `Collection`.
associatedtype SubSequence : _IndexableBase, Sequence = Slice<Self>
where Self.SubSequence.Index == Index,
Self.Iterator.Element == Self.SubSequence.Iterator.Element
Self.Iterator.Element == Self.SubSequence.Iterator.Element,
SubSequence.SubSequence == SubSequence
// FIXME(ABI)#98 (Recursive Protocol Constraints):
// FIXME(ABI)#99 (Associated Types with where clauses):
// associatedtype SubSequence : Collection
// where
// ,
// SubSequence.Indices == Indices,
// SubSequence.SubSequence == SubSequence
//
// (<rdar://problem/20715009> Implement recursive protocol
// constraints)
Expand Down
7 changes: 2 additions & 5 deletions stdlib/public/core/ExistentialCollection.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,11 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Elemen
S.SubSequence : ${Kind},
% if Kind == 'Sequence':
S.SubSequence.Iterator.Element == S.Iterator.Element,
%end
S.SubSequence.SubSequence == S.SubSequence
% if Kind != 'Sequence':
,
% else:
S.SubSequence.Indices : ${Kind},
S.Indices : ${Kind}
% end
% end
{
internal typealias Element = S.Iterator.Element

Expand Down Expand Up @@ -1045,7 +1043,6 @@ public struct ${Self}<Element>
C.SubSequence : ${SubProtocol},
C.SubSequence.Iterator.Element == Element,
C.SubSequence.Indices : ${SubProtocol},
C.SubSequence.SubSequence == C.SubSequence,
C.Indices : ${SubProtocol}
{
// Traversal: ${Traversal}
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/LazyCollection.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ extension ${Self} : ${TraversalCollection} {
///
/// - Complexity: O(1)
@_inlineable
public subscript(bounds: Range<Index>) -> ${Self}<${Slice}<Base>> {
return ${Slice}(base: _base, bounds: bounds).lazy
public subscript(bounds: Range<Index>) -> ${Slice}<${Self}<Base>> {
return ${Slice}(base: self, bounds: bounds)
}

/// A Boolean value indicating whether the collection is empty.
Expand Down
2 changes: 0 additions & 2 deletions stdlib/public/core/Mirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ public struct Mirror {
// associated types of Collection.
C.SubSequence : Collection,
C.SubSequence.Indices : Collection,
C.SubSequence.SubSequence == C.SubSequence,
C.Indices : Collection {

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

self.subjectType = Subject.self
Expand Down