Skip to content

Commit 797df6e

Browse files
committed
Eliminate the _*Indexable protocols.
The various _*Indexable protocols only exist to work around the lack of recursive protocol constraints. Eliminate all of the *_Indexable protocols, collapsing their requirements into the corresponding Collection protocol (e.g., _MutableIndexable —> Collection). This introduces a number of extraneous requirements into the various Collection protocols to work around bugs in associated type inference. Specifically, to work around the lack of "global" inference of associated type witnesses. These hacks were implicitly present in the *Indexable protocols; I've made marked them as ABI FIXMEs here so we can remove them when associated type inference improves. Fixes rdar://problem/21935030 and a number of ABI FIXMEs in the library.
1 parent 42968b2 commit 797df6e

12 files changed

+191
-656
lines changed

stdlib/public/SDK/Dispatch/Data.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable {
299299
}
300300

301301
public struct DispatchDataIterator : IteratorProtocol, Sequence {
302+
public typealias Element = UInt8
302303

303304
/// Create an iterator over the given DispatchData
304305
public init(_data: DispatchData) {

stdlib/public/core/BidirectionalCollection.swift

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,7 @@
1717
/// `BidirectionalCollection` protocol instead, because it has a more complete
1818
/// interface.
1919
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead")
20-
public typealias BidirectionalIndexable = _BidirectionalIndexable
21-
public protocol _BidirectionalIndexable : _Indexable {
22-
// FIXME(ABI)#22 (Recursive Protocol Constraints): there is no reason for this protocol
23-
// to exist apart from missing compiler features that we emulate with it.
24-
// rdar://problem/20531108
25-
//
26-
// This protocol is almost an implementation detail of the standard
27-
// library.
28-
29-
/// Returns the position immediately before the given index.
30-
///
31-
/// - Parameter i: A valid index of the collection. `i` must be greater than
32-
/// `startIndex`.
33-
/// - Returns: The index value immediately before `i`.
34-
func index(before i: Index) -> Index
35-
36-
/// Replaces the given index with its predecessor.
37-
///
38-
/// - Parameter i: A valid index of the collection. `i` must be greater than
39-
/// `startIndex`.
40-
func formIndex(before i: inout Index)
41-
}
20+
public typealias BidirectionalIndexable = BidirectionalCollection
4221

4322
/// A collection that supports backward as well as forward traversal.
4423
///
@@ -65,10 +44,14 @@ public protocol _BidirectionalIndexable : _Indexable {
6544
/// `c.index(before: c.index(after: i)) == i`.
6645
/// - If `i > c.startIndex && i <= c.endIndex`
6746
/// `c.index(after: c.index(before: i)) == i`.
68-
public protocol BidirectionalCollection : _BidirectionalIndexable, Collection
47+
public protocol BidirectionalCollection : Collection
6948
{
49+
// FIXME(ABI): Associated type inference requires this.
50+
associatedtype Element
51+
52+
// FIXME(ABI): Associated type inference requires this.
53+
associatedtype Index
7054

71-
// TODO: swift-3-indexing-model - replaces functionality in BidirectionalIndex
7255
/// Returns the position immediately before the given index.
7356
///
7457
/// - Parameter i: A valid index of the collection. `i` must be greater than
@@ -84,7 +67,7 @@ public protocol BidirectionalCollection : _BidirectionalIndexable, Collection
8467

8568
/// A sequence that can represent a contiguous subrange of the collection's
8669
/// elements.
87-
associatedtype SubSequence: BidirectionalCollection
70+
associatedtype SubSequence : BidirectionalCollection
8871
= BidirectionalSlice<Self>
8972

9073
/// A type that represents the indices that are valid for subscripting the
@@ -147,10 +130,19 @@ public protocol BidirectionalCollection : _BidirectionalIndexable, Collection
147130
/// - Parameter bounds: A range of the collection's indices. The bounds of
148131
/// the range must be valid indices of the collection.
149132
subscript(bounds: Range<Index>) -> SubSequence { get }
133+
134+
// FIXME(ABI): Associated type inference requires this.
135+
subscript(position: Index) -> Element { get }
136+
137+
// FIXME(ABI): Associated type inference requires this.
138+
var startIndex: Index { get }
139+
140+
// FIXME(ABI): Associated type inference requires this.
141+
var endIndex: Index { get }
150142
}
151143

152144
/// Default implementation for bidirectional collections.
153-
extension _BidirectionalIndexable {
145+
extension BidirectionalCollection {
154146

155147
@_inlineable // FIXME(sil-serialize-all)
156148
@inline(__always)

0 commit comments

Comments
 (0)