Skip to content

Commit b4c08de

Browse files
committed
stdlib: SetIndex and DictionaryIndex can now be nested types of Set and Dictionary
Resolves ABI FIXME swiftlang#34 and <rdar://problem/17002096>.
1 parent 1f20fd6 commit b4c08de

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,6 @@ public struct Set<Element : Hashable> :
453453
internal typealias _VariantBuffer = _VariantSetBuffer<Element>
454454
internal typealias _NativeBuffer = _NativeSetBuffer<Element>
455455

456-
/// The index type for subscripting the set.
457-
public typealias Index = SetIndex<Element>
458-
459456
internal var _variantBuffer: _VariantBuffer
460457

461458
/// Creates a new, empty set with at least the specified number of elements'
@@ -1642,9 +1639,6 @@ public struct Dictionary<Key : Hashable, Value> :
16421639
/// key-value pair.
16431640
public typealias Element = (key: Key, value: Value)
16441641

1645-
/// The index type of a dictionary.
1646-
public typealias Index = DictionaryIndex<Key, Value>
1647-
16481642
internal var _variantBuffer: _VariantBuffer
16491643

16501644
/// Creates an empty dictionary.
@@ -4705,6 +4699,7 @@ internal enum ${Self}IndexRepresentation<${TypeParametersDecl}> {
47054699
case _cocoa(_CocoaIndex)
47064700
}
47074701

4702+
extension ${Self} {
47084703
%{
47094704
if Self == 'Set':
47104705
SubscriptingWithIndexDoc = """\
@@ -4726,12 +4721,7 @@ elif Self == 'Dictionary':
47264721
}%
47274722

47284723
${SubscriptingWithIndexDoc}
4729-
public struct ${Self}Index<${TypeParametersDecl}> :
4730-
Comparable {
4731-
// FIXME(ABI)#34 (Nesting types in generics): `DictionaryIndex` and `SetIndex` should
4732-
// be nested types (Dictionary.Index and Set.Index).
4733-
// rdar://problem/17002096
4734-
4724+
public struct Index : Comparable {
47354725
// Index for native buffer is efficient. Index for bridged NS${Self} is
47364726
// not, because neither NSEnumerator nor fast enumeration support moving
47374727
// backwards. Even if they did, there is another issue: NSEnumerator does
@@ -4750,12 +4740,12 @@ public struct ${Self}Index<${TypeParametersDecl}> :
47504740
internal var _value: ${Self}IndexRepresentation<${TypeParameters}>
47514741

47524742
@_versioned
4753-
internal static func _native(_ index: _NativeIndex) -> ${Self}Index {
4743+
internal static func _native(_ index: _NativeIndex) -> Index {
47544744
return ${Self}Index(_value: ._native(index))
47554745
}
47564746
#if _runtime(_ObjC)
47574747
@_versioned
4758-
internal static func _cocoa(_ index: _CocoaIndex) -> ${Self}Index {
4748+
internal static func _cocoa(_ index: _CocoaIndex) -> Index {
47594749
return ${Self}Index(_value: ._cocoa(index))
47604750
}
47614751
#endif
@@ -4789,10 +4779,15 @@ public struct ${Self}Index<${TypeParametersDecl}> :
47894779
#endif
47904780
}
47914781

4792-
extension ${Self}Index {
4782+
}
4783+
4784+
public typealias ${Self}Index<${TypeParametersDecl}> =
4785+
${Self}<${TypeParameters}>.Index
4786+
4787+
extension ${Self}.Index {
47934788
public static func == (
4794-
lhs: ${Self}Index<${TypeParameters}>,
4795-
rhs: ${Self}Index<${TypeParameters}>
4789+
lhs: ${Self}<${TypeParameters}>.Index,
4790+
rhs: ${Self}<${TypeParameters}>.Index
47964791
) -> Bool {
47974792
if _fastPath(lhs._guaranteedNative) {
47984793
return lhs._nativeIndex == rhs._nativeIndex
@@ -4813,8 +4808,8 @@ extension ${Self}Index {
48134808
}
48144809

48154810
public static func < (
4816-
lhs: ${Self}Index<${TypeParameters}>,
4817-
rhs: ${Self}Index<${TypeParameters}>
4811+
lhs: ${Self}<${TypeParameters}>.Index,
4812+
rhs: ${Self}<${TypeParameters}>.Index
48184813
) -> Bool {
48194814
if _fastPath(lhs._guaranteedNative) {
48204815
return lhs._nativeIndex < rhs._nativeIndex

0 commit comments

Comments
 (0)