Skip to content

[stdlib][DNM] Remove Sequence.SubSequence #20175

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

Closed
Closed
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
113 changes: 5 additions & 108 deletions stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,12 @@ public class SequenceLog {
// Sequence
public static var makeIterator = TypeIndexed(0)
public static var underestimatedCount = TypeIndexed(0)
public static var map = TypeIndexed(0)
public static var filter = TypeIndexed(0)
public static var forEach = TypeIndexed(0)
public static var dropFirst = TypeIndexed(0)
public static var dropLast = TypeIndexed(0)
public static var dropWhile = TypeIndexed(0)
public static var prefixWhile = TypeIndexed(0)
public static var prefixMaxLength = TypeIndexed(0)
public static var suffixMaxLength = TypeIndexed(0)
public static var split = TypeIndexed(0)
public static var _customContainsEquatableElement = TypeIndexed(0)
public static var _preprocessingPass = TypeIndexed(0)
public static var _copyToContiguousArray = TypeIndexed(0)
Expand All @@ -101,20 +97,15 @@ public class SequenceLog {
public static var successor = TypeIndexed(0)
public static var formSuccessor = TypeIndexed(0)
public static var indices = TypeIndexed(0)
public static var prefixUpTo = TypeIndexed(0)
public static var prefixThrough = TypeIndexed(0)
public static var suffixFrom = TypeIndexed(0)
public static var isEmpty = TypeIndexed(0)
public static var count = TypeIndexed(0)
public static var _customIndexOfEquatableElement = TypeIndexed(0)
public static var first = TypeIndexed(0)
public static var advance = TypeIndexed(0)
public static var advanceLimit = TypeIndexed(0)
public static var distance = TypeIndexed(0)
// BidirectionalCollection
public static var predecessor = TypeIndexed(0)
public static var formPredecessor = TypeIndexed(0)
public static var last = TypeIndexed(0)
// MutableCollection
public static var subscriptIndexSet = TypeIndexed(0)
public static var subscriptRangeSet = TypeIndexed(0)
Expand Down Expand Up @@ -210,7 +201,6 @@ extension LoggingSequence: LoggingType {
extension LoggingSequence: Sequence {
public typealias Element = Base.Element
public typealias Iterator = LoggingIterator<Base.Iterator>
public typealias SubSequence = Base.SubSequence

public func makeIterator() -> Iterator {
SequenceLog.makeIterator[selfType] += 1
Expand All @@ -222,71 +212,6 @@ extension LoggingSequence: Sequence {
return base.underestimatedCount
}

public func map<T>(
_ transform: (Element) throws -> T
) rethrows -> [T] {
SequenceLog.map[selfType] += 1
return try base.map(transform)
}

public func filter(
_ isIncluded: (Element) throws -> Bool
) rethrows -> [Element] {
SequenceLog.filter[selfType] += 1
return try base.filter(isIncluded)
}

public func forEach(_ body: (Element) throws -> Void) rethrows {
SequenceLog.forEach[selfType] += 1
try base.forEach(body)
}

public func dropFirst(_ n: Int) -> SubSequence {
SequenceLog.dropFirst[selfType] += 1
return base.dropFirst(n)
}

public func dropLast(_ n: Int) -> SubSequence {
SequenceLog.dropLast[selfType] += 1
return base.dropLast(n)
}

public func drop(
while predicate: (Element) throws -> Bool
) rethrows -> SubSequence {
SequenceLog.dropWhile[selfType] += 1
return try base.drop(while: predicate)
}

public func prefix(_ maxLength: Int) -> SubSequence {
SequenceLog.prefixMaxLength[selfType] += 1
return base.prefix(maxLength)
}

public func prefix(
while predicate: (Element) throws -> Bool
) rethrows -> SubSequence {
SequenceLog.prefixWhile[selfType] += 1
return try base.prefix(while: predicate)
}

public func suffix(_ maxLength: Int) -> SubSequence {
SequenceLog.suffixMaxLength[selfType] += 1
return base.suffix(maxLength)
}

public func split(
maxSplits: Int = Int.max,
omittingEmptySubsequences: Bool = true,
whereSeparator isSeparator: (Element) throws -> Bool
) rethrows -> [SubSequence] {
SequenceLog.split[selfType] += 1
return try base.split(
maxSplits: maxSplits,
omittingEmptySubsequences: omittingEmptySubsequences,
whereSeparator: isSeparator)
}

public func _customContainsEquatableElement(_ element: Element) -> Bool? {
SequenceLog._customContainsEquatableElement[selfType] += 1
return base._customContainsEquatableElement(element)
Expand Down Expand Up @@ -324,6 +249,7 @@ public typealias LoggingCollection<Base: Collection> = LoggingSequence<Base>
extension LoggingCollection: Collection {
public typealias Index = Base.Index
public typealias Indices = Base.Indices
public typealias SubSequence = Base.SubSequence

public var startIndex: Index {
CollectionLog.startIndex[selfType] += 1
Expand All @@ -336,17 +262,13 @@ extension LoggingCollection: Collection {
}

public subscript(position: Index) -> Element {
get {
CollectionLog.subscriptIndex[selfType] += 1
return base[position]
}
CollectionLog.subscriptIndex[selfType] += 1
return base[position]
}

public subscript(bounds: Range<Index>) -> SubSequence {
get {
CollectionLog.subscriptRange[selfType] += 1
return base[bounds]
}
CollectionLog.subscriptRange[selfType] += 1
return base[bounds]
}

public func _failEarlyRangeCheck(_ index: Index, bounds: Range<Index>) {
Expand Down Expand Up @@ -374,21 +296,6 @@ extension LoggingCollection: Collection {
return base.indices
}

public func prefix(upTo end: Index) -> SubSequence {
CollectionLog.prefixUpTo[selfType] += 1
return base.prefix(upTo: end)
}

public func prefix(through position: Index) -> SubSequence {
CollectionLog.prefixThrough[selfType] += 1
return base.prefix(through: position)
}

public func suffix(from start: Index) -> SubSequence {
CollectionLog.suffixFrom[selfType] += 1
return base.suffix(from: start)
}

public var isEmpty: Bool {
CollectionLog.isEmpty[selfType] += 1
return base.isEmpty
Expand All @@ -406,11 +313,6 @@ extension LoggingCollection: Collection {
return base._customIndexOfEquatableElement(element)
}

public var first: Element? {
CollectionLog.first[selfType] += 1
return base.first
}

public func index(_ i: Index, offsetBy n: Int) -> Index {
CollectionLog.advance[selfType] += 1
return base.index(i, offsetBy: n)
Expand Down Expand Up @@ -443,11 +345,6 @@ extension LoggingBidirectionalCollection: BidirectionalCollection {
BidirectionalCollectionLog.formPredecessor[selfType] += 1
base.formIndex(before: &i)
}

public var last: Element? {
BidirectionalCollectionLog.last[selfType] += 1
return base.last
}
}

public typealias LoggingRandomAccessCollection<Base: RandomAccessCollection>
Expand Down
3 changes: 1 addition & 2 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,7 @@ public func expectMutableSliceType<X : MutableCollection>(
/// to be.
public func expectSequenceAssociatedTypes<X : Sequence>(
sequenceType: X.Type,
iteratorType: X.Iterator.Type,
subSequenceType: X.SubSequence.Type
iteratorType: X.Iterator.Type
) {}

/// Check that all associated types of a `Collection` are what we expect them
Expand Down
14 changes: 0 additions & 14 deletions stdlib/public/core/BidirectionalCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,6 @@ where SubSequence: BidirectionalCollection, Indices: BidirectionalCollection {
/// // c == MyFancyCollection([2, 4, 6, 8, 10])
override var indices: Indices { get }

// TODO: swift-3-indexing-model: tests.
/// The last element of the collection.
///
/// If the collection is empty, the value of this property is `nil`.
///
/// let numbers = [10, 20, 30, 40, 50]
/// if let lastNumber = numbers.last {
/// print(lastNumber)
/// }
/// // Prints "50"
///
/// - Complexity: O(1)
var last: Element? { get }

/// Accesses a contiguous subrange of the collection's elements.
///
/// The accessed slice uses the same indices for the same elements as the
Expand Down
Loading