Skip to content

Commit c7334cd

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 7d6a9be commit c7334cd

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.
@@ -4702,6 +4696,7 @@ internal enum ${Self}IndexRepresentation<${TypeParametersDecl}> {
47024696
case _cocoa(_CocoaIndex)
47034697
}
47044698

4699+
extension ${Self} {
47054700
%{
47064701
if Self == 'Set':
47074702
SubscriptingWithIndexDoc = """\
@@ -4723,12 +4718,7 @@ elif Self == 'Dictionary':
47234718
}%
47244719

47254720
${SubscriptingWithIndexDoc}
4726-
public struct ${Self}Index<${TypeParametersDecl}> :
4727-
Comparable {
4728-
// FIXME(ABI)#34 (Nesting types in generics): `DictionaryIndex` and `SetIndex` should
4729-
// be nested types (Dictionary.Index and Set.Index).
4730-
// rdar://problem/17002096
4731-
4721+
public struct Index : Comparable {
47324722
// Index for native buffer is efficient. Index for bridged NS${Self} is
47334723
// not, because neither NSEnumerator nor fast enumeration support moving
47344724
// backwards. Even if they did, there is another issue: NSEnumerator does
@@ -4747,12 +4737,12 @@ public struct ${Self}Index<${TypeParametersDecl}> :
47474737
internal var _value: ${Self}IndexRepresentation<${TypeParameters}>
47484738

47494739
@_versioned
4750-
internal static func _native(_ index: _NativeIndex) -> ${Self}Index {
4740+
internal static func _native(_ index: _NativeIndex) -> Index {
47514741
return ${Self}Index(_value: ._native(index))
47524742
}
47534743
#if _runtime(_ObjC)
47544744
@_versioned
4755-
internal static func _cocoa(_ index: _CocoaIndex) -> ${Self}Index {
4745+
internal static func _cocoa(_ index: _CocoaIndex) -> Index {
47564746
return ${Self}Index(_value: ._cocoa(index))
47574747
}
47584748
#endif
@@ -4786,10 +4776,15 @@ public struct ${Self}Index<${TypeParametersDecl}> :
47864776
#endif
47874777
}
47884778

4789-
extension ${Self}Index {
4779+
}
4780+
4781+
public typealias ${Self}Index<${TypeParametersDecl}> =
4782+
${Self}<${TypeParameters}>.Index
4783+
4784+
extension ${Self}.Index {
47904785
public static func == (
4791-
lhs: ${Self}Index<${TypeParameters}>,
4792-
rhs: ${Self}Index<${TypeParameters}>
4786+
lhs: ${Self}<${TypeParameters}>.Index,
4787+
rhs: ${Self}<${TypeParameters}>.Index
47934788
) -> Bool {
47944789
if _fastPath(lhs._guaranteedNative) {
47954790
return lhs._nativeIndex == rhs._nativeIndex
@@ -4810,8 +4805,8 @@ extension ${Self}Index {
48104805
}
48114806

48124807
public static func < (
4813-
lhs: ${Self}Index<${TypeParameters}>,
4814-
rhs: ${Self}Index<${TypeParameters}>
4808+
lhs: ${Self}<${TypeParameters}>.Index,
4809+
rhs: ${Self}<${TypeParameters}>.Index
48154810
) -> Bool {
48164811
if _fastPath(lhs._guaranteedNative) {
48174812
return lhs._nativeIndex < rhs._nativeIndex

0 commit comments

Comments
 (0)