[stdlib] Add Sequence.Element, change ExpressibleByArrayLiteral.Element to ArrayLiteralElement (#8990)

* Give Sequence a top-level Element, constrain Iterator to match

* Remove many instances of Iterator.

* Fixed various hard-coded tests

* XFAIL a few tests that need further investigation

* Change assoc type for arrayLiteralConvertible

* Mop up remaining "better expressed as a where clause" warnings

* Fix UnicodeDecoders prototype test

* Fix UIntBuffer

* Fix hard-coded Element identifier in CSDiag

* Fix up more tests

* Account for flatMap changes
This commit is contained in:
Ben Cohen
2017-05-14 06:33:25 -07:00
committed by GitHub
parent 2e275e3a13
commit ea2f64cad2
78 changed files with 503 additions and 500 deletions

View File

@@ -10,14 +10,6 @@
//
//===----------------------------------------------------------------------===//
%{
# We know we will eventually get a Sequence.Element type. Define
# a shorthand that we can use today.
IElement = "Iterator.Element"
}%
//===----------------------------------------------------------------------===//
// last
//===----------------------------------------------------------------------===//
@@ -33,7 +25,7 @@ extension BidirectionalCollection {
/// }
/// // Prints "50"
@_inlineable
public var last: Iterator.Element? {
public var last: Element? {
return isEmpty ? nil : self[index(before: endIndex)]
}
}
@@ -42,7 +34,7 @@ extension BidirectionalCollection {
// index(of:)/index(where:)
//===----------------------------------------------------------------------===//
extension Collection where ${IElement} : Equatable {
extension Collection where Element : Equatable {
/// Returns the first index where the specified value appears in the
/// collection.
///
@@ -64,7 +56,7 @@ extension Collection where ${IElement} : Equatable {
///
/// - SeeAlso: `index(where:)`
@_inlineable
public func index(of element: ${IElement}) -> Index? {
public func index(of element: Element) -> Index? {
if let result = _customIndexOfEquatableElement(element) {
return result
}
@@ -105,7 +97,7 @@ extension Collection {
/// - SeeAlso: `index(of:)`
@_inlineable
public func index(
where predicate: (${IElement}) throws -> Bool
where predicate: (Element) throws -> Bool
) rethrows -> Index? {
var i = self.startIndex
while i != self.endIndex {
@@ -148,7 +140,7 @@ orderingExplanation = """\
extension MutableCollection {
@_inlineable
public mutating func partition(
by belongsInSecondPartition: (${IElement}) throws -> Bool
by belongsInSecondPartition: (Element) throws -> Bool
) rethrows -> Index {
var pivot = startIndex
@@ -177,7 +169,7 @@ extension MutableCollection {
extension MutableCollection where Self : BidirectionalCollection {
@_inlineable
public mutating func partition(
by belongsInSecondPartition: (${IElement}) throws -> Bool
by belongsInSecondPartition: (Element) throws -> Bool
) rethrows -> Index {
let maybeOffset = try _withUnsafeMutableBufferPointerIfSupported {
(baseAddress, count) -> Int in
@@ -233,7 +225,7 @@ extension MutableCollection where Self : BidirectionalCollection {
% sequenceKind = 'sequence' if 'Sequence' in Self else 'collection'
extension ${Self} where Self.Iterator.Element : Comparable {
extension ${Self} where Element : Comparable {
/// Returns the elements of the ${sequenceKind}, sorted.
///
/// You can sort any ${sequenceKind} of elements that conform to the
@@ -263,7 +255,7 @@ extension ${Self} where Self.Iterator.Element : Comparable {
///
/// - SeeAlso: `sorted(by:)`, `sort()`
@_inlineable
public func sorted() -> [Iterator.Element] {
public func sorted() -> [Element] {
var result = ContiguousArray(self)
result.sort()
return Array(result)
@@ -339,8 +331,8 @@ ${orderingExplanation}
@_inlineable
public func sorted(
by areInIncreasingOrder:
(${IElement}, ${IElement}) throws -> Bool
) rethrows -> [Iterator.Element] {
(Element, Element) throws -> Bool
) rethrows -> [Element] {
var result = ContiguousArray(self)
try result.sort(by: areInIncreasingOrder)
return Array(result)
@@ -351,8 +343,7 @@ ${orderingExplanation}
extension MutableCollection
where
Self : RandomAccessCollection,
Self.Iterator.Element : Comparable {
Self : RandomAccessCollection, Element : Comparable {
/// Sorts the collection in place.
///
@@ -455,7 +446,7 @@ ${orderingExplanation}
@_inlineable
public mutating func sort(
by areInIncreasingOrder:
(${IElement}, ${IElement}) throws -> Bool
(Element, Element) throws -> Bool
) rethrows {
let didSortUnsafeBuffer: Void? =
@@ -580,7 +571,7 @@ ${subscriptCommentPost}
extension MutableCollection where Self : RandomAccessCollection {
@available(*, unavailable, message: "call partition(by:)")
public mutating func partition(
isOrderedBefore: (${IElement}, ${IElement}) -> Bool
isOrderedBefore: (Element, Element) -> Bool
) -> Index {
Builtin.unreachable()
}
@@ -588,14 +579,14 @@ extension MutableCollection where Self : RandomAccessCollection {
@available(*, unavailable, message: "slice the collection using the range, and call partition(by:)")
public mutating func partition(
_ range: Range<Index>,
isOrderedBefore: (${IElement}, ${IElement}) -> Bool
isOrderedBefore: (Element, Element) -> Bool
) -> Index {
Builtin.unreachable()
}
}
extension MutableCollection
where Self : RandomAccessCollection, ${IElement} : Comparable {
where Self : RandomAccessCollection, Element : Comparable {
@available(*, unavailable, message: "call partition(by:)")
public mutating func partition() -> Index {
@@ -611,23 +602,22 @@ extension MutableCollection
extension Sequence {
@available(*, unavailable, renamed: "sorted(by:)")
public func sort(
_ isOrderedBefore: (${IElement}, ${IElement}) -> Bool
) -> [${IElement}] {
_ isOrderedBefore: (Element, Element) -> Bool
) -> [Element] {
Builtin.unreachable()
}
}
extension Sequence where ${IElement} : Comparable {
extension Sequence where Element : Comparable {
@available(*, unavailable, renamed: "sorted()")
public func sort() -> [${IElement}] {
public func sort() -> [Element] {
Builtin.unreachable()
}
}
extension MutableCollection
where
Self : RandomAccessCollection,
Self.Iterator.Element : Comparable {
Self : RandomAccessCollection, Element : Comparable {
@available(*, unavailable, renamed: "sort()")
public mutating func sortInPlace() {
@@ -638,15 +628,15 @@ extension MutableCollection
extension MutableCollection where Self : RandomAccessCollection {
@available(*, unavailable, renamed: "sort(by:)")
public mutating func sortInPlace(
_ isOrderedBefore: (${IElement}, ${IElement}) -> Bool
_ isOrderedBefore: (Element, Element) -> Bool
) {
Builtin.unreachable()
}
}
extension Collection where ${IElement} : Equatable {
extension Collection where Element : Equatable {
@available(*, unavailable, renamed: "index(of:)")
public func indexOf(_ element: ${IElement}) -> Index? {
public func indexOf(_ element: Element) -> Index? {
Builtin.unreachable()
}
}
@@ -654,7 +644,7 @@ extension Collection where ${IElement} : Equatable {
extension Collection {
@available(*, unavailable, renamed: "index(where:)")
public func indexOf(
_ predicate: (${IElement}) throws -> Bool
_ predicate: (Element) throws -> Bool
) rethrows -> Index? {
Builtin.unreachable()
}