Skip to content

Commit ca6c6b1

Browse files
[stdlib] Cleanup DefaultIndices, delete dead code (#13952)
* Remove a bunch of Default(Bidirectional|RandomAccess)Indices usage from stdlib and test * Remove some DefaultRandomAccessIndices and IndexDistance usage from Foundation * Remove no-longer-used internal type in Existentials.swift * Get rid of indicesForTraversal
1 parent 3de0d14 commit ca6c6b1

16 files changed

+13
-103
lines changed

stdlib/public/SDK/Dispatch/Data.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import _SwiftDispatchOverlayShims
1515
public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable {
1616
public typealias Iterator = DispatchDataIterator
1717
public typealias Index = Int
18-
public typealias Indices = DefaultRandomAccessIndices<DispatchData>
18+
public typealias Indices = DefaultIndices<DispatchData>
1919

2020
public static let empty: DispatchData = DispatchData(data: _swift_dispatch_data_empty())
2121

stdlib/public/SDK/Foundation/IndexPath.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
2222
public typealias ReferenceType = NSIndexPath
2323
public typealias Element = Int
2424
public typealias Index = Array<Int>.Index
25-
public typealias Indices = DefaultRandomAccessIndices<IndexPath>
25+
public typealias Indices = DefaultIndices<IndexPath>
2626

2727
fileprivate enum Storage : ExpressibleByArrayLiteral {
2828
typealias Element = Int

stdlib/public/SDK/Foundation/IndexSet.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
656656
}
657657

658658
/// For a positive delta, shifts the indexes in [index, INT_MAX] to the right, thereby inserting an "empty space" [index, delta], for a negative delta, shifts the indexes in [index, INT_MAX] to the left, thereby deleting the indexes in the range [index - delta, delta].
659-
public mutating func shift(startingAt integer: Element, by delta: IndexSet.IndexDistance) {
659+
public mutating func shift(startingAt integer: Element, by delta: Int) {
660660
_applyMutation { $0.shiftIndexesStarting(at: integer, by: delta) }
661661
}
662662

stdlib/public/core/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ set(SWIFTLIB_ESSENTIAL
5353
EmptyCollection.swift
5454
Equatable.swift
5555
ErrorType.swift
56-
Existential.swift
5756
Filter.swift
5857
FixedArray.swift.gyb
5958
FlatMap.swift

stdlib/public/core/Existential.swift

-71
This file was deleted.

stdlib/public/core/ExistentialCollection.swift.gyb

+1-3
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,7 @@ public struct ${Self}<Element> {
10401040
}
10411041

10421042
extension ${Self}: ${SelfProtocol} {
1043-
public typealias Indices
1044-
= Default${Traversal.replace('Forward', '')}Indices<${Self}>
1045-
1043+
public typealias Indices = DefaultIndices<${Self}>
10461044
public typealias Iterator = AnyIterator<Element>
10471045
public typealias Index = AnyIndex
10481046
public typealias SubSequence = ${Self}<Element>

stdlib/public/core/GroupInfo.json

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"SequenceAlgorithms.swift",
6161
"RangeReplaceableCollection.swift",
6262
"Indices.swift",
63-
"Existential.swift",
6463
"WriteBackMutableSlice.swift",
6564
"UnfoldSequence.swift",
6665
"UIntBuffer.swift",

stdlib/public/core/UIntBuffer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ extension _UIntBuffer : BidirectionalCollection {
129129
}
130130

131131
extension _UIntBuffer : RandomAccessCollection {
132-
public typealias Indices = DefaultRandomAccessIndices<_UIntBuffer>
132+
public typealias Indices = DefaultIndices<_UIntBuffer>
133133

134134
@_inlineable // FIXME(sil-serialize-all)
135135
@inline(__always)

test/Prototypes/Algorithms.swift.gyb

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import StdlibUnittest
2424
from gyb_stdlib_support import (
2525
TRAVERSALS,
2626
collectionForTraversal,
27-
defaultIndicesForTraversal,
2827
)
2928

3029
}%

utils/gyb_stdlib_support.py

-12
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,6 @@ def protocolsForCollectionFeatures(traversal, mutable, rangeReplaceable): # noq
3939
protocols.append('RangeReplaceableCollection')
4040
return protocols
4141

42-
43-
def defaultIndicesForTraversal(traversal): # noqa (N802)
44-
if traversal == 'Forward':
45-
return 'DefaultIndices'
46-
elif traversal == 'Bidirectional':
47-
return 'DefaultBidirectionalIndices'
48-
elif traversal == 'RandomAccess':
49-
return 'DefaultRandomAccessIndices'
50-
else:
51-
raise ValueError("Unknown traversal %r" % traversal)
52-
53-
5442
def documentationNameForTraversal(traversal): # noqa (N802)
5543
if traversal == 'Forward':
5644
return 'collection'

validation-test/compiler_crashers_2_fixed/0080-rdar30442622.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protocol AnyCodeUnits_ {
1414

1515
struct AnyCodeUnits : RandomAccessCollection, AnyCodeUnits_ {
1616
let me: AnyCodeUnits_
17-
typealias Indices = DefaultRandomAccessIndices<AnyCodeUnits>
17+
typealias Indices = DefaultIndices<AnyCodeUnits>
1818
var startIndex: Int64 { return me.startIndex }
1919
var endIndex: Int64 { return me.endIndex }
2020
func index(after i: Index) -> Index { return me.index(after: i) }

validation-test/compiler_crashers_2_fixed/0109-sr4737.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ extension _UIntBuffer : BidirectionalCollection {
133133
}
134134

135135
extension _UIntBuffer : RandomAccessCollection {
136-
public typealias Indices = DefaultRandomAccessIndices<_UIntBuffer>
136+
public typealias Indices = DefaultIndices<_UIntBuffer>
137137

138138
@inline(__always)
139139
public func index(_ i: Index, offsetBy n: Int) -> Index {

validation-test/stdlib/CollectionType.swift.gyb

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
% import os.path
99
% import gyb
10-
% from gyb_stdlib_support import TRAVERSALS, collectionForTraversal, defaultIndicesForTraversal
10+
% from gyb_stdlib_support import TRAVERSALS, collectionForTraversal
1111

1212
import StdlibUnittest
1313
import StdlibCollectionUnittest
@@ -829,7 +829,6 @@ func ==(lhs: FatalIndex, rhs: FatalIndex) -> Bool { fatalError() }
829829
% for Traversal in TRAVERSALS:
830830
% Collection = collectionForTraversal(Traversal)
831831
% Self = 'Fatal' + Collection
832-
% Indices = defaultIndicesForTraversal(Traversal)
833832

834833
struct ${Self}<T> : ${Collection} {
835834
var startIndex: FatalIndex { fatalError() }
@@ -848,7 +847,7 @@ CollectionTypeTests.test("AssociatedTypes/${Collection}") {
848847
iteratorType: IndexingIterator<C>.self,
849848
subSequenceType: Slice<C>.self,
850849
indexType: FatalIndex.self,
851-
indicesType: ${Indices}<C>.self)
850+
indicesType: DefaultIndices<C>.self)
852851
}
853852
% end
854853

validation-test/stdlib/Range.swift.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ CountableClosedRangeTestSuite.test("AssociatedTypes") {
770770
iteratorType: IndexingIterator<Collection>.self,
771771
subSequenceType: RandomAccessSlice<Collection>.self,
772772
indexType: ClosedRangeIndex<MinimalStrideableValue>.self,
773-
indicesType: DefaultRandomAccessIndices<Collection>.self)
773+
indicesType: DefaultIndices<Collection>.self)
774774
}
775775

776776
var MiscTestSuite = TestSuite("Misc")

validation-test/stdlib/Slice.swift.gyb

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
%{
66
from gyb_stdlib_support import (
77
TRAVERSALS,
8-
defaultIndicesForTraversal,
98
collectionTypeName
109
)
1110
}%

validation-test/stdlib/String.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ StringTests.test("AssociatedTypes-UTF8View") {
6666
iteratorType: View.Iterator.self,
6767
subSequenceType: Substring.UTF8View.self,
6868
indexType: View.Index.self,
69-
indicesType: DefaultBidirectionalIndices<View>.self)
69+
indicesType: DefaultIndices<View>.self)
7070
}
7171

7272
StringTests.test("AssociatedTypes-UTF16View") {
@@ -86,7 +86,7 @@ StringTests.test("AssociatedTypes-UnicodeScalarView") {
8686
iteratorType: View.Iterator.self,
8787
subSequenceType: Substring.UnicodeScalarView.self,
8888
indexType: View.Index.self,
89-
indicesType: DefaultBidirectionalIndices<View>.self)
89+
indicesType: DefaultIndices<View>.self)
9090
}
9191

9292
StringTests.test("AssociatedTypes-CharacterView") {
@@ -96,7 +96,7 @@ StringTests.test("AssociatedTypes-CharacterView") {
9696
iteratorType: IndexingIterator<View>.self,
9797
subSequenceType: View.self,
9898
indexType: View.Index.self,
99-
indicesType: DefaultBidirectionalIndices<View>.self)
99+
indicesType: DefaultIndices<View>.self)
100100
}
101101

102102
func checkUnicodeScalarViewIteration(

0 commit comments

Comments
 (0)