Skip to content

[stdlib] Remove additional customization points #19995

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
64 changes: 4 additions & 60 deletions stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ 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)
Expand All @@ -101,20 +98,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 @@ -222,25 +214,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)
Expand Down Expand Up @@ -336,17 +309,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 +343,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 +360,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 +392,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
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
121 changes: 1 addition & 120 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -477,108 +477,6 @@ public protocol Collection: Sequence where SubSequence: Collection {
/// // c == MyFancyCollection([2, 4, 6, 8, 10])
var indices: Indices { get }

/// Returns a subsequence from the start of the collection up to, but not
/// including, the specified position.
///
/// The resulting subsequence *does not include* the element at the position
/// `end`. The following example searches for the index of the number `40`
/// in an array of integers, and then prints the prefix of the array up to,
/// but not including, that index:
///
/// let numbers = [10, 20, 30, 40, 50, 60]
/// if let i = numbers.firstIndex(of: 40) {
/// print(numbers.prefix(upTo: i))
/// }
/// // Prints "[10, 20, 30]"
///
/// Passing the collection's starting index as the `end` parameter results in
/// an empty subsequence.
///
/// print(numbers.prefix(upTo: numbers.startIndex))
/// // Prints "[]"
///
/// Using the `prefix(upTo:)` method is equivalent to using a partial
/// half-open range as the collection's subscript. The subscript notation is
/// preferred over `prefix(upTo:)`.
///
/// if let i = numbers.firstIndex(of: 40) {
/// print(numbers[..<i])
/// }
/// // Prints "[10, 20, 30]"
///
/// - Parameter end: The "past the end" index of the resulting subsequence.
/// `end` must be a valid index of the collection.
/// - Returns: A subsequence up to, but not including, the `end` position.
///
/// - Complexity: O(1)
__consuming func prefix(upTo end: Index) -> SubSequence

/// Returns a subsequence from the specified position to the end of the
/// collection.
///
/// The following example searches for the index of the number `40` in an
/// array of integers, and then prints the suffix of the array starting at
/// that index:
///
/// let numbers = [10, 20, 30, 40, 50, 60]
/// if let i = numbers.firstIndex(of: 40) {
/// print(numbers.suffix(from: i))
/// }
/// // Prints "[40, 50, 60]"
///
/// Passing the collection's `endIndex` as the `start` parameter results in
/// an empty subsequence.
///
/// print(numbers.suffix(from: numbers.endIndex))
/// // Prints "[]"
///
/// Using the `suffix(from:)` method is equivalent to using a partial range
/// from the index as the collection's subscript. The subscript notation is
/// preferred over `suffix(from:)`.
///
/// if let i = numbers.firstIndex(of: 40) {
/// print(numbers[i...])
/// }
/// // Prints "[40, 50, 60]"
///
/// - Parameter start: The index at which to start the resulting subsequence.
/// `start` must be a valid index of the collection.
/// - Returns: A subsequence starting at the `start` position.
///
/// - Complexity: O(1)
__consuming func suffix(from start: Index) -> SubSequence

/// Returns a subsequence from the start of the collection through the
/// specified position.
///
/// The resulting subsequence *includes* the element at the position `end`.
/// The following example searches for the index of the number `40` in an
/// array of integers, and then prints the prefix of the array up to, and
/// including, that index:
///
/// let numbers = [10, 20, 30, 40, 50, 60]
/// if let i = numbers.firstIndex(of: 40) {
/// print(numbers.prefix(through: i))
/// }
/// // Prints "[10, 20, 30, 40]"
///
/// Using the `prefix(through:)` method is equivalent to using a partial
/// closed range as the collection's subscript. The subscript notation is
/// preferred over `prefix(through:)`.
///
/// if let i = numbers.firstIndex(of: 40) {
/// print(numbers[...i])
/// }
/// // Prints "[10, 20, 30, 40]"
///
/// - Parameter end: The index of the last element to include in the
/// resulting subsequence. `end` must be a valid index of the collection
/// that is not equal to the `endIndex` property.
/// - Returns: A subsequence up to, and including, the `end` position.
///
/// - Complexity: O(1)
__consuming func prefix(through position: Index) -> SubSequence

/// A Boolean value indicating whether the collection is empty.
///
/// When you need to check whether your collection is empty, use the
Expand Down Expand Up @@ -632,22 +530,6 @@ public protocol Collection: Sequence where SubSequence: Collection {
/// - Complexity: Hopefully less than O(`count`).
func _customLastIndexOfEquatableElement(_ element: Element) -> Index??

// FIXME(move-only types): `first` might not be implementable by collections
// with move-only elements, since they would need to be able to somehow form
// a temporary `Optional<Element>` value from a non-optional Element without
// modifying the collection.

/// The first 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 firstNumber = numbers.first {
/// print(firstNumber)
/// }
/// // Prints "10"
var first: Element? { get }

/// Returns an index that is the specified distance from the given index.
///
/// The following example obtains an index advanced four positions from a
Expand Down Expand Up @@ -1346,8 +1228,7 @@ extension Collection {
@inlinable
public __consuming func dropFirst(_ k: Int) -> SubSequence {
_precondition(k >= 0, "Can't drop a negative number of elements from a collection")
let start = index(startIndex,
offsetBy: k, limitedBy: endIndex) ?? endIndex
let start = index(startIndex, offsetBy: k, limitedBy: endIndex) ?? endIndex
return self[start..<endIndex]
}

Expand Down
13 changes: 0 additions & 13 deletions stdlib/public/core/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -728,19 +728,6 @@ extension Dictionary: Collection {
public var isEmpty: Bool {
return count == 0
}

/// The first element of the dictionary.
///
/// The first element of the dictionary is not necessarily the first element
/// added to the dictionary. Don't expect any particular ordering of
/// dictionary elements.
///
/// If the dictionary is empty, the value of this property is `nil`.
@inlinable
public var first: Element? {
var it = makeIterator()
return it.next()
}
}

extension Dictionary {
Expand Down
24 changes: 0 additions & 24 deletions stdlib/public/core/ExistentialCollection.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,6 @@ internal class _AnyRandomAccessCollectionBox<Element>
func _customLastIndexOfEquatableElement(element: Element) -> Index??
*/

@inlinable // FIXME(sil-serialize-all)
internal var _first: Element? { _abstract() }

@inlinable
internal init(
_startIndex: _AnyIndexBox,
Expand Down Expand Up @@ -385,8 +382,6 @@ internal class _AnyRandomAccessCollectionBox<Element>
internal func _index(before i: _AnyIndexBox) -> _AnyIndexBox { _abstract() }
@inlinable
internal func _formIndex(before i: _AnyIndexBox) { _abstract() }
@inlinable
internal var _last: Element? { _abstract() }
% end
}

Expand Down Expand Up @@ -617,11 +612,6 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Element>
return numericCast(_base.count)
}

@inlinable
internal override var _first: Element? {
return _base.first
}

% if Kind in ['BidirectionalCollection', 'RandomAccessCollection']:
@inlinable
internal override func _index(before position: _AnyIndexBox) -> _AnyIndexBox {
Expand All @@ -636,10 +626,6 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Element>
fatalError("Index type mismatch!")
}

@inlinable
internal override var _last: Element? {
return _base.last
}
% end

% end
Expand Down Expand Up @@ -1118,11 +1104,6 @@ extension ${Self}: ${SelfProtocol} {
return _box._count
}

@inlinable
public var first: Element? {
return _box._first
}

% if Traversal == 'Bidirectional' or Traversal == 'RandomAccess':
@inlinable
public func index(before i: Index) -> Index {
Expand All @@ -1138,11 +1119,6 @@ extension ${Self}: ${SelfProtocol} {
i = index(before: i)
}
}

@inlinable
public var last: Element? {
return _box._last
}
% end
}

Expand Down
11 changes: 0 additions & 11 deletions stdlib/public/core/LazyCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ extension LazyCollection : Collection {
return _base._customLastIndexOfEquatableElement(element)
}

/// Returns the first element of `self`, or `nil` if `self` is empty.
@inlinable
public var first: Element? {
return _base.first
}

// TODO: swift-3-indexing-model - add docs
@inlinable
public func index(_ i: Index, offsetBy n: Int) -> Index {
Expand Down Expand Up @@ -235,11 +229,6 @@ extension LazyCollection : BidirectionalCollection
public func index(before i: Index) -> Index {
return _base.index(before: i)
}

@inlinable
public var last: Element? {
return _base.last
}
}

extension LazyCollection : RandomAccessCollection
Expand Down
Loading