Skip to content

Commit c196667

Browse files
committed
[stdlib] Remove non-obvious conditional Hashable conformances
This removes Hashable conformance for types that do not already implement Equatable: - CollectionOfOne - AnyCollection - DictionaryLiteral
1 parent fd0c387 commit c196667

File tree

6 files changed

+0
-108
lines changed

6 files changed

+0
-108
lines changed

stdlib/public/core/CollectionOfOne.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,6 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
136136
}
137137
}
138138

139-
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
140-
extension CollectionOfOne : Equatable where Element : Equatable {
141-
@_inlineable // FIXME(sil-serialize-all)
142-
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
143-
public static func == (lhs: CollectionOfOne, rhs: CollectionOfOne) -> Bool {
144-
return lhs._element == rhs._element
145-
}
146-
}
147-
148-
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
149-
extension CollectionOfOne : Hashable where Element : Hashable {
150-
@_inlineable // FIXME(sil-serialize-all)
151-
public var hashValue: Int {
152-
return _element.hashValue
153-
}
154-
}
155-
156139
extension CollectionOfOne : CustomDebugStringConvertible {
157140
/// A textual representation of `self`, suitable for debugging.
158141
@_inlineable // FIXME(sil-serialize-all)

stdlib/public/core/EmptyCollection.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,5 @@ extension EmptyCollection : Equatable {
173173
}
174174
}
175175

176-
extension EmptyCollection : Hashable {
177-
@_inlineable // FIXME(sil-serialize-all)
178-
public var hashValue: Int {
179-
return 0
180-
}
181-
}
182-
183176
// @available(*, deprecated, renamed: "EmptyCollection.Iterator")
184177
public typealias EmptyIterator<T> = EmptyCollection<T>.Iterator

stdlib/public/core/ExistentialCollection.swift.gyb

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,30 +1243,3 @@ extension ${Self}: _AnyCollectionProtocol {
12431243
}
12441244
}
12451245
% end
1246-
1247-
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
1248-
extension AnyCollection : Equatable where Element : Equatable {
1249-
@_inlineable // FIXME(sil-serialize-all)
1250-
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
1251-
public static func == (
1252-
lhs: AnyCollection<Element>, rhs: AnyCollection<Element>
1253-
) -> Bool {
1254-
if lhs.count != rhs.count {
1255-
return false
1256-
}
1257-
return lhs.elementsEqual(rhs)
1258-
}
1259-
}
1260-
1261-
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
1262-
extension AnyCollection : Hashable where Element : Hashable {
1263-
@_inlineable // FIXME(sil-serialize-all)
1264-
public var hashValue: Int {
1265-
// FIXME(ABI)#177: <rdar://problem/18915294> Cache AnyCollection<T> hashValue
1266-
var result = 0
1267-
for element in self {
1268-
result = _combineHashValues(result, element.hashValue)
1269-
}
1270-
return result
1271-
}
1272-
}

stdlib/public/core/Mirror.swift

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -761,35 +761,6 @@ extension DictionaryLiteral : RandomAccessCollection {
761761
}
762762
}
763763

764-
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
765-
extension DictionaryLiteral: Equatable where Key: Equatable, Value: Equatable {
766-
@_inlineable // FIXME(sil-serialize-all)
767-
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
768-
public static func == (
769-
lhs: DictionaryLiteral<Key, Value>, rhs: DictionaryLiteral<Key, Value>
770-
) -> Bool {
771-
if lhs.count != rhs.count {
772-
return false
773-
}
774-
return lhs.elementsEqual(rhs, by: ==)
775-
}
776-
}
777-
778-
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
779-
extension DictionaryLiteral: Hashable where Key: Hashable, Value: Hashable {
780-
@_inlineable // FIXME(sil-serialize-all)
781-
public var hashValue: Int {
782-
// FIXME(ABI)#177: <rdar://problem/18915294> Issue applies to DictionaryLiteral too
783-
var result = 0
784-
for element in self {
785-
let elementHashValue =
786-
_combineHashValues(element.key.hashValue, element.value.hashValue)
787-
result = _combineHashValues(result, elementHashValue)
788-
}
789-
return result
790-
}
791-
}
792-
793764
extension String {
794765
/// Creates a string representing the given value.
795766
///

test/stdlib/DictionaryLiteral.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,3 @@ expectType(DictionaryLiteral<String, NSObject>.self, &hetero1)
5454

5555
var hetero2: DictionaryLiteral = ["a": 1 as NSNumber, "b": "Foo" as NSString]
5656
expectType(DictionaryLiteral<String, NSObject>.self, &hetero2)
57-
58-
let instances: [DictionaryLiteral<Int, String>] = [
59-
[1: "a", 1: "a", 2: "b"],
60-
[1: "a", 2: "b", 1: "a"],
61-
[2: "b", 1: "a", 1: "a"],
62-
[1: "a", 1: "a", 1: "a"]
63-
]
64-
checkEquatable(instances, oracle: { $0 == $1 })
65-
checkHashable(instances, equalityOracle: { $0 == $1 })

validation-test/stdlib/Lazy.swift.gyb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,6 @@ LazyTestSuite.test("CollectionOfOne/{CustomDebugStringConvertible,CustomReflecta
209209
c)
210210
}
211211

212-
LazyTestSuite.test("CollectionOfOne/Equatable") {
213-
let c = CollectionOfOne<Int>(42)
214-
let d = CollectionOfOne<Int>(43)
215-
let instances = [ c, d ]
216-
checkEquatable(instances, oracle: { $0 == $1 })
217-
}
218-
219-
LazyTestSuite.test("CollectionOfOne/Hashable") {
220-
let c = CollectionOfOne<Int>(42)
221-
let d = CollectionOfOne<Int>(43)
222-
let instances = [ c, d ]
223-
checkHashable(instances, equalityOracle: { $0 == $1 })
224-
}
225-
226212
//===----------------------------------------------------------------------===//
227213
// EmptyCollection
228214
//===----------------------------------------------------------------------===//
@@ -257,11 +243,6 @@ LazyTestSuite.test("EmptyCollection/Equatable") {
257243
checkEquatable(instances, oracle: { $0 == $1 })
258244
}
259245

260-
LazyTestSuite.test("EmptyCollection/Equatable") {
261-
let instances = [ EmptyCollection<OpaqueValue<Int>>() ]
262-
checkHashable(instances, equalityOracle: { $0 == $1 })
263-
}
264-
265246
LazyTestSuite.test("EmptyCollection/AssociatedTypes") {
266247
typealias Subject = EmptyCollection<OpaqueValue<Int>>
267248
expectRandomAccessCollectionAssociatedTypes(

0 commit comments

Comments
 (0)