Skip to content

Commit 399193f

Browse files
author
Dave Abrahams
authored
Merge pull request swiftlang#9847 from apple/eliminate-_Element
[stdlib] Eliminate _Element
2 parents 35df359 + 02fdc0a commit 399193f

10 files changed

+30
-35
lines changed

stdlib/public/SDK/Dispatch/Data.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public struct DispatchDataIterator : IteratorProtocol, Sequence {
315315

316316
/// Advance to the next element and return it, or `nil` if no next
317317
/// element exists.
318-
public mutating func next() -> DispatchData._Element? {
318+
public mutating func next() -> DispatchData.Element? {
319319
if _position == _count { return nil }
320320
let element = _ptr.load(fromByteOffset: _position, as: UInt8.self)
321321
_position = _position + 1

stdlib/public/core/Collection.swift

+7-11
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,7 @@ public protocol _IndexableBase {
5858
/// If the collection is empty, `endIndex` is equal to `startIndex`.
5959
var endIndex: Index { get }
6060

61-
// The declaration of _Element and subscript here is a trick used to
62-
// break a cyclic conformance/deduction that Swift can't handle. We
63-
// need something other than a Collection.Element that can
64-
// be used as IndexingIterator<T>'s Element. Here we arrange for
65-
// the Collection itself to have an Element type that's deducible from
66-
// its subscript. Ideally we'd like to constrain this Element to be the same
67-
// as Collection.Element (see below), but we have no way of
68-
// expressing it today.
69-
associatedtype _Element
61+
associatedtype Element
7062

7163
/// Accesses the element at the specified position.
7264
///
@@ -87,7 +79,7 @@ public protocol _IndexableBase {
8779
/// `endIndex` property.
8880
///
8981
/// - Complexity: O(1)
90-
subscript(position: Index) -> _Element { get }
82+
subscript(position: Index) -> Element { get }
9183

9284
// WORKAROUND: rdar://25214066
9385
// FIXME(ABI)#178 (Type checker)
@@ -422,7 +414,7 @@ public struct IndexingIterator<
422414
/// exists; otherwise, `nil`.
423415
@_inlineable
424416
@inline(__always)
425-
public mutating func next() -> Elements._Element? {
417+
public mutating func next() -> Elements.Element? {
426418
if _position == _elements.endIndex { return nil }
427419
let element = _elements[_position]
428420
_elements.formIndex(after: &_position)
@@ -1978,3 +1970,7 @@ extension Collection where Element : Equatable {
19781970
@available(*, unavailable, message: "PermutationGenerator has been removed in Swift 3")
19791971
public struct PermutationGenerator<C : Collection, Indices : Sequence> {}
19801972

1973+
extension _IndexableBase {
1974+
@available(swift, deprecated: 3.2, renamed: "Element")
1975+
public typealias _Element = Element
1976+
}

stdlib/public/core/MutableCollection.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public protocol _MutableIndexable : _Indexable {
6767
/// - Parameter position: The position of the element to access. `position`
6868
/// must be a valid index of the collection that is not equal to the
6969
/// `endIndex` property.
70-
subscript(position: Index) -> _Element { get set }
70+
subscript(position: Index) -> Element { get set }
7171

7272
/// Accesses a contiguous subrange of the collection's elements.
7373
///

stdlib/public/core/RangeReplaceableCollection.swift.gyb

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ public protocol _RangeReplaceableIndexable : _Indexable {
4949
/// - repeatedValue: The element to repeat.
5050
/// - count: The number of times to repeat the value passed in the
5151
/// `repeating` parameter. `count` must be zero or greater.
52-
init(repeating repeatedValue: _Element, count: Int)
52+
init(repeating repeatedValue: Element, count: Int)
5353

5454
/// Creates a new instance of a collection containing the elements of a
5555
/// sequence.
5656
///
5757
/// - Parameter elements: The sequence of elements for the new collection.
5858
/// `elements` must be finite.
59-
init<S : Sequence>(_ elements: S) where S.Element == _Element
59+
init<S : Sequence>(_ elements: S) where S.Element == Element
6060

6161
/// Replaces the specified subrange of elements with the given collection.
6262
///
@@ -97,7 +97,7 @@ public protocol _RangeReplaceableIndexable : _Indexable {
9797
mutating func replaceSubrange<C>(
9898
_ subrange: Range<Index>,
9999
with newElements: C
100-
) where C : Collection, C.Element == _Element
100+
) where C : Collection, C.Element == Element
101101

102102
/// Inserts a new element into the collection at the specified position.
103103
///
@@ -121,7 +121,7 @@ public protocol _RangeReplaceableIndexable : _Indexable {
121121
/// valid index into the collection.
122122
///
123123
/// - Complexity: O(*n*), where *n* is the length of the collection.
124-
mutating func insert(_ newElement: _Element, at i: Index)
124+
mutating func insert(_ newElement: Element, at i: Index)
125125

126126
/// Inserts the elements of a sequence into the collection at the specified
127127
/// position.
@@ -152,7 +152,7 @@ public protocol _RangeReplaceableIndexable : _Indexable {
152152
/// `newElements`.
153153
mutating func insert<S : Collection>(
154154
contentsOf newElements: S, at i: Index
155-
) where S.Element == _Element
155+
) where S.Element == Element
156156

157157
/// Removes and returns the element at the specified position.
158158
///
@@ -175,7 +175,7 @@ public protocol _RangeReplaceableIndexable : _Indexable {
175175
///
176176
/// - Complexity: O(*n*), where *n* is the length of the collection.
177177
@discardableResult
178-
mutating func remove(at i: Index) -> _Element
178+
mutating func remove(at i: Index) -> Element
179179

180180
/// Removes the specified subrange of elements from the collection.
181181
///

stdlib/public/core/Reverse.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public struct _ReverseIndexingIterator<
5252

5353
@_inlineable
5454
@inline(__always)
55-
public mutating func next() -> Elements._Element? {
55+
public mutating func next() -> Elements.Element? {
5656
guard _fastPath(_position != _elements.startIndex) else { return nil }
5757
_position = _elements.index(before: _position)
5858
return _elements[_position]

stdlib/public/core/Slice.swift.gyb

+7-7
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
131131
return _endIndex
132132
}
133133

134-
public subscript(index: Index) -> Base._Element {
134+
public subscript(index: Index) -> Base.Element {
135135
get {
136136
_failEarlyRangeCheck(index, bounds: startIndex..<endIndex)
137137
return _base[index]
@@ -223,7 +223,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
223223
self._endIndex = _base.endIndex
224224
}
225225

226-
public init(repeating repeatedValue: Base._Element, count: Int) {
226+
public init(repeating repeatedValue: Base.Element, count: Int) {
227227
self._base = Base(repeating: repeatedValue, count: count)
228228
self._startIndex = _base.startIndex
229229
self._endIndex = _base.endIndex
@@ -232,7 +232,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
232232
public init<S>(_ elements: S)
233233
where
234234
S : Sequence,
235-
S.Element == Base._Element {
235+
S.Element == Base.Element {
236236

237237
self._base = Base(elements)
238238
self._startIndex = _base.startIndex
@@ -243,7 +243,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
243243
_ subRange: Range<Index>, with newElements: C
244244
) where
245245
C : Collection,
246-
C.Element == Base._Element {
246+
C.Element == Base.Element {
247247

248248
// FIXME: swift-3-indexing-model: range check.
249249
% if Traversal == 'Forward':
@@ -280,7 +280,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
280280
% end
281281
}
282282

283-
public mutating func insert(_ newElement: Base._Element, at i: Index) {
283+
public mutating func insert(_ newElement: Base.Element, at i: Index) {
284284
// FIXME: swift-3-indexing-model: range check.
285285
% if Traversal == 'Forward':
286286
let sliceOffset: IndexDistance =
@@ -311,7 +311,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
311311
public mutating func insert<S>(contentsOf newElements: S, at i: Index)
312312
where
313313
S : Collection,
314-
S.Element == Base._Element {
314+
S.Element == Base.Element {
315315

316316
// FIXME: swift-3-indexing-model: range check.
317317
% if Traversal == 'Forward':
@@ -344,7 +344,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
344344
% end
345345
}
346346

347-
public mutating func remove(at i: Index) -> Base._Element {
347+
public mutating func remove(at i: Index) -> Base.Element {
348348
// FIXME: swift-3-indexing-model: range check.
349349
% if Traversal == 'Forward':
350350
let sliceOffset: IndexDistance =

stdlib/public/core/WriteBackMutableSlice.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal func _writeBackMutableSlice<C, Slice_>(
1717
) where
1818
C : MutableCollection,
1919
Slice_ : Collection,
20-
C._Element == Slice_.Element,
20+
C.Element == Slice_.Element,
2121
C.Index == Slice_.Index {
2222

2323
self_._failEarlyRangeCheck(bounds, bounds: self_.startIndex..<self_.endIndex)

test/Prototypes/UnicodeDecoders.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ extension Unicode {
3939
struct DefaultScalarView<
4040
CodeUnits: BidirectionalCollection,
4141
Encoding: Unicode.Encoding
42-
> where CodeUnits.Element == Encoding.CodeUnit,
43-
CodeUnits._Element == CodeUnits.Element {
42+
> where CodeUnits.Element == Encoding.CodeUnit {
4443
var codeUnits: CodeUnits
4544
init(
4645
_ codeUnits: CodeUnits,

test/SILGen/foreach.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func trivialStructBreak(_ xx: [Int]) {
117117
// CHECK: br [[LOOP_DEST:bb[0-9]+]]
118118
//
119119
// CHECK: [[LOOP_DEST]]:
120-
// CHECK: [[FUNC_REF:%.*]] = function_ref @_T0s16IndexingIteratorV4next8_ElementQzSgyF : $@convention(method)
120+
// CHECK: [[FUNC_REF:%.*]] = function_ref @_T0s16IndexingIteratorV4next7ElementQzSgyF : $@convention(method)
121121
// CHECK: [[GET_ELT_STACK:%.*]] = alloc_stack $Optional<Int>
122122
// CHECK: [[WRITE:%.*]] = begin_access [modify] [unknown] [[PROJECT_ITERATOR_BOX]] : $*IndexingIterator<Array<Int>>
123123
// CHECK: apply [[FUNC_REF]]<[Int]>([[GET_ELT_STACK]], [[WRITE]])
@@ -223,7 +223,7 @@ func existentialBreak(_ xx: [P]) {
223223
// CHECK: br [[LOOP_DEST:bb[0-9]+]]
224224
//
225225
// CHECK: [[LOOP_DEST]]:
226-
// CHECK: [[FUNC_REF:%.*]] = function_ref @_T0s16IndexingIteratorV4next8_ElementQzSgyF : $@convention(method)
226+
// CHECK: [[FUNC_REF:%.*]] = function_ref @_T0s16IndexingIteratorV4next7ElementQzSgyF : $@convention(method)
227227
// CHECK: [[WRITE:%.*]] = begin_access [modify] [unknown] [[PROJECT_ITERATOR_BOX]] : $*IndexingIterator<Array<P>> // users: %16, %15
228228
// CHECK: apply [[FUNC_REF]]<[P]>([[ELT_STACK]], [[WRITE]])
229229
// CHECK: switch_enum_addr [[ELT_STACK]] : $*Optional<P>, case #Optional.some!enumelt.1: [[SOME_BB:bb[0-9]+]], case #Optional.none!enumelt: [[NONE_BB:bb[0-9]+]]
@@ -388,7 +388,7 @@ func genericStructBreak<T>(_ xx: [GenericStruct<T>]) {
388388
// CHECK: br [[LOOP_DEST:bb[0-9]+]]
389389
//
390390
// CHECK: [[LOOP_DEST]]:
391-
// CHECK: [[FUNC_REF:%.*]] = function_ref @_T0s16IndexingIteratorV4next8_ElementQzSgyF : $@convention(method)
391+
// CHECK: [[FUNC_REF:%.*]] = function_ref @_T0s16IndexingIteratorV4next7ElementQzSgyF : $@convention(method)
392392
// CHECK: [[WRITE:%.*]] = begin_access [modify] [unknown] [[PROJECT_ITERATOR_BOX]] : $*IndexingIterator<Array<GenericStruct<T>>>
393393
// CHECK: apply [[FUNC_REF]]<[GenericStruct<T>]>([[ELT_STACK]], [[WRITE]])
394394
// CHECK: switch_enum_addr [[ELT_STACK]] : $*Optional<GenericStruct<T>>, case #Optional.some!enumelt.1: [[SOME_BB:bb[0-9]+]], case #Optional.none!enumelt: [[NONE_BB:bb[0-9]+]]

test/SILOptimizer/prespecialize.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// function_ref specialized Collection<A where ...>.makeIterator() -> IndexingIterator<A>
1414
// CHECK: function_ref @_T0s10CollectionPssAARzs16IndexingIteratorVyxG0C0RtzlE04makeC0AEyFs14CountableRangeVySiG_Tgq5
1515
//
16-
// function_ref specialized IndexingIterator.next() -> A._Element?
17-
// CHECK: function_ref @_T0s16IndexingIteratorV4next8_ElementQzSgyFs14CountableRangeVySiG_Tgq5
16+
// function_ref specialized IndexingIterator.next() -> A.Element?
17+
// CHECK: function_ref @_T0s16IndexingIteratorV4next7ElementQzSgyFs14CountableRangeVySiG_Tgq5
1818
//
1919
// Look for generic specialization <Swift.Int> of Swift.Array.subscript.getter : (Swift.Int) -> A
2020
// CHECK: function_ref {{@_T0Sa9subscriptxSicfgSi_Tgq5|@_TTSg5Si___TFSaap9subscriptFSix}}

0 commit comments

Comments
 (0)