Skip to content

Commit 9bd721b

Browse files
committed
[Standard library] Add a bunch of explicit typealiases for associated types.
Type witness inference is failing in a large number of places due to the adoption of conditional conformances in Slice. Add the necessary typealiases to get the standard library to type-check. This is a hack that can be reverted once type witness inference is improved.
1 parent b027247 commit 9bd721b

11 files changed

+20
-5
lines changed

stdlib/public/core/CocoaArray.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import SwiftShims
2929
@_fixed_layout
3030
internal struct _CocoaArrayWrapper : RandomAccessCollection {
3131
typealias Indices = CountableRange<Int>
32+
typealias SubSequence = Slice<_CocoaArrayWrapper>
33+
3234
@_inlineable
3335
@_versioned
3436
internal var startIndex: Int {

stdlib/public/core/DoubleWidth.swift.gyb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ public struct DoubleWidth<Base : FixedWidthInteger> :
177177

178178
@_fixed_layout // FIXME(sil-serialize-all)
179179
public struct Words : Collection {
180+
public typealias Element = UInt
181+
180182
public enum _IndexValue {
181183
case low(Base.Magnitude.Words.Index)
182184
case high(Base.Words.Index)

stdlib/public/core/Mirror.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,8 @@ internal extension Mirror {
564564
@_versioned // FIXME(sil-serialize-all)
565565
internal struct LegacyChildren : RandomAccessCollection {
566566
internal typealias Indices = CountableRange<Int>
567-
567+
internal typealias SubSequence = Slice<LegacyChildren>
568+
568569
@_inlineable // FIXME(sil-serialize-all)
569570
@_versioned // FIXME(sil-serialize-all)
570571
internal init(_ oldMirror: _Mirror) {
@@ -870,6 +871,7 @@ public struct DictionaryLiteral<Key, Value> : ExpressibleByDictionaryLiteral {
870871
/// interoperate with the rest of the standard library.
871872
extension DictionaryLiteral : RandomAccessCollection {
872873
public typealias Indices = CountableRange<Int>
874+
public typealias SubSequence = Slice<DictionaryLiteral>
873875

874876
/// The position of the first element in a nonempty collection.
875877
///

stdlib/public/core/StringCharacterView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ extension String.CharacterView : BidirectionalCollection {
194194
internal var unicodeScalars: UnicodeScalarView {
195195
return UnicodeScalarView(_core, coreOffset: _coreOffset)
196196
}
197-
197+
198+
public typealias Element = Character
198199
public typealias Index = String.Index
199200
public typealias IndexDistance = Int
200201

stdlib/public/core/StringCore.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ public struct _StringCore {
662662
extension _StringCore : RandomAccessCollection {
663663

664664
public typealias Indices = CountableRange<Int>
665-
665+
public typealias SubSequence = _StringCore
666+
666667
@_inlineable // FIXME(sil-serialize-all)
667668
public // @testable
668669
var startIndex: Int {

stdlib/public/core/StringRangeReplaceableCollection.swift.gyb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
extension String : StringProtocol, RangeReplaceableCollection {
13+
extension String : StringProtocol, RangeReplaceableCollection {
14+
public typealias Element = Character
15+
1416
/// A type that represents the number of steps between two `String.Index`
1517
/// values, where one value is reachable from the other.
1618
///

stdlib/public/core/StringUTF16.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ extension String {
104104
CustomStringConvertible,
105105
CustomDebugStringConvertible {
106106

107+
public typealias Element = UTF16.CodeUnit
107108
public typealias Index = String.Index
108109
public typealias IndexDistance = Int
109110

@@ -447,6 +448,7 @@ extension String.UTF16View : CustomPlaygroundQuickLookable {
447448
}
448449

449450
extension String.UTF16View.Indices : BidirectionalCollection {
451+
public typealias Element = String.UTF16View.Index
450452
public typealias Index = String.UTF16View.Index
451453
public typealias IndexDistance = String.UTF16View.IndexDistance
452454
public typealias Indices = String.UTF16View.Indices

stdlib/public/core/StringUTF8.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ extension String {
119119
self._legacyOffsets = (Int8(legacyOffsets.0), Int8(legacyOffsets.1))
120120
}
121121

122+
public typealias Element = UTF8.CodeUnit
122123
public typealias Index = String.Index
123124
public typealias IndexDistance = Int
124125

stdlib/public/core/StringUnicodeScalarView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ extension String {
9595
}
9696
}
9797

98+
public typealias Element = UnicodeScalar
9899
public typealias Index = String.Index
99100
public typealias IndexDistance = Int
100101

stdlib/public/core/Substring.swift.gyb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ extension Substring {
439439
}
440440

441441
extension Substring.${View} : BidirectionalCollection {
442+
public typealias Element = String.${View}.Element
442443
public typealias Index = String.Index
443444
public typealias SubSequence = Substring.${View}
444445

stdlib/public/core/UnicodeScalar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ extension Unicode.Scalar {
418418
}
419419

420420
extension Unicode.Scalar.UTF16View : RandomAccessCollection {
421-
421+
public typealias SubSequence = Slice<Unicode.Scalar.UTF16View>
422422
public typealias Indices = CountableRange<Int>
423423

424424
/// The position of the first code unit.

0 commit comments

Comments
 (0)