mirror of
https://github.com/apple/swift-collections
synced 2026-11-22 04:20:40 +00:00
[BasicContainers, DequeModule] Clean up Equatable/Hashable conformances
Make sure all types conditionally conform to Equatable/Hashable, even if their contents happen to be noncopyable.
This commit is contained in:
14 files changed
+95
-38
No files matched your search
@@ -25,9 +25,13 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
#if compiler(>=6.4)
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension RigidArray: Equatable where Element: Equatable & ~Copyable {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidArray where Element: Equatable & ~Copyable {
|
||||
@inlinable
|
||||
public static func ==(
|
||||
left: borrowing Self,
|
||||
|
||||
@@ -17,13 +17,28 @@
|
||||
import InternalCollectionsUtilities
|
||||
#endif
|
||||
|
||||
#if compiler(>=6.4)
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension RigidArray: Hashable where Element: Hashable & ~Copyable {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidArray /*: Hashable */ where Element: Hashable /* & ~Copyable */ {
|
||||
extension RigidArray where Element: Hashable & ~Copyable {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(self.count)
|
||||
self.span._hashContents(into: &hasher)
|
||||
}
|
||||
}
|
||||
#else
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidArray where Element: Hashable {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(self.count)
|
||||
self.span._hashContents(into: &hasher)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -20,7 +20,7 @@ import ContainersPreview
|
||||
#if compiler(>=6.4) && UnstableHashedContainers
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDictionary {
|
||||
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
|
||||
@inlinable
|
||||
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
||||
self._keys.isTriviallyIdentical(to: other._keys)
|
||||
@@ -29,7 +29,7 @@ extension RigidDictionary {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDictionary {
|
||||
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
|
||||
@inlinable
|
||||
public func isEqual(
|
||||
to other: borrowing Self,
|
||||
@@ -56,8 +56,11 @@ extension RigidDictionary {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension RigidDictionary: Equatable where Key: ~Copyable, Value: Equatable & ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDictionary: Equatable where Value: Equatable {
|
||||
extension RigidDictionary where Key: ~Copyable, Value: Equatable & ~Copyable {
|
||||
@inlinable
|
||||
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
|
||||
left.isEqual(to: right, by: ==)
|
||||
|
||||
@@ -18,8 +18,12 @@ import ContainersPreview
|
||||
|
||||
#if compiler(>=6.4) && UnstableHashedContainers
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension RigidDictionary: Hashable where Value: Hashable & ~Copyable {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDictionary: Hashable where Value: Hashable { // Should be Hashable
|
||||
extension RigidDictionary where Value: Hashable & ~Copyable {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
var commutativeHash = 0
|
||||
|
||||
@@ -20,7 +20,7 @@ import ContainersPreview
|
||||
#if compiler(>=6.4) && UnstableHashedContainers
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidSet {
|
||||
extension RigidSet where Element: ~Copyable {
|
||||
@inlinable
|
||||
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
||||
self._members == other._members
|
||||
@@ -28,12 +28,11 @@ extension RigidSet {
|
||||
}
|
||||
}
|
||||
|
||||
#if UnstableContainersPreview
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension RigidSet: Equatable {}
|
||||
extension RigidSet: Equatable where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidSet {
|
||||
extension RigidSet where Element: ~Copyable {
|
||||
@inlinable
|
||||
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
|
||||
if left.isTriviallyIdentical(to: right) { return true }
|
||||
@@ -54,5 +53,3 @@ extension RigidSet {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -19,10 +19,10 @@ import ContainersPreview
|
||||
#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension RigidSet: Hashable {}
|
||||
extension RigidSet: Hashable where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidSet {
|
||||
extension RigidSet where Element: ~Copyable {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
// Generate a seed from a snapshot of the hasher. This makes members' hash
|
||||
@@ -42,7 +42,7 @@ extension RigidSet {
|
||||
let next = it.nextSpan_()
|
||||
var i = 0
|
||||
while i < next.count {
|
||||
hash ^= next[i]._rawHashValue(seed: seed)
|
||||
hash ^= next[unchecked: i]._rawHashValue(seed: seed)
|
||||
i &+= 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,13 @@ extension UniqueArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
#if compiler(>=6.4)
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension UniqueArray: Equatable where Element: Equatable & ~Copyable {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray where Element: Equatable & ~Copyable {
|
||||
@inlinable
|
||||
public static func ==(
|
||||
left: borrowing Self,
|
||||
|
||||
@@ -13,16 +13,30 @@
|
||||
|
||||
#if compiler(>=6.2)
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray /*: Hashable */ where Element: Hashable /* & ~Copyable */ {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(self.count)
|
||||
let span = self.span
|
||||
for i in 0 ..< count {
|
||||
hasher.combine(span[unchecked: i])
|
||||
}
|
||||
}
|
||||
#if !COLLECTIONS_SINGLE_MODULE
|
||||
import InternalCollectionsUtilities
|
||||
#endif
|
||||
|
||||
#if compiler(>=6.4)
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension UniqueArray: Hashable where Element: Hashable & ~Copyable {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray where Element: Hashable & ~Copyable {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
self._storage.hash(into: &hasher)
|
||||
}
|
||||
}
|
||||
#else
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray where Element: Hashable {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
self._storage.hash(into: &hasher)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -20,7 +20,7 @@ import ContainersPreview
|
||||
#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueSet {
|
||||
extension UniqueSet where Element: ~Copyable {
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
||||
@@ -29,10 +29,10 @@ extension UniqueSet {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension UniqueSet: Equatable {}
|
||||
extension UniqueSet: Equatable where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueSet {
|
||||
extension UniqueSet where Element: ~Copyable {
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
|
||||
|
||||
@@ -19,10 +19,10 @@ import ContainersPreview
|
||||
#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension UniqueSet: Hashable {}
|
||||
extension UniqueSet: Hashable where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueSet {
|
||||
extension UniqueSet where Element: ~Copyable {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
_storage.hash(into: &hasher)
|
||||
|
||||
@@ -19,14 +19,18 @@ import ContainersPreview
|
||||
#endif
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDeque /*: Equatable */ where Element: Equatable /* & ~Copyable */ {
|
||||
extension RigidDeque: Equatable where Element: Equatable & ~Copyable {
|
||||
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
||||
self._handle.isIdentical(to: other._handle)
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension RigidDeque: Equatable where Element: Equatable & ~Copyable {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDeque /*: Equatable */ where Element: Equatable /* & ~Copyable */ {
|
||||
extension RigidDeque where Element: Equatable & ~Copyable {
|
||||
@inlinable
|
||||
public static func ==(
|
||||
left: borrowing Self,
|
||||
|
||||
@@ -17,8 +17,12 @@
|
||||
import InternalCollectionsUtilities
|
||||
#endif
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension RigidDeque: Hashable where Element: Hashable & ~Copyable {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDeque /*: Hashable */ where Element: Hashable /* & ~Copyable */ {
|
||||
extension RigidDeque where Element: Hashable & ~Copyable {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(self.count)
|
||||
|
||||
@@ -17,8 +17,12 @@
|
||||
import InternalCollectionsUtilities
|
||||
#endif
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension UniqueDeque: Equatable where Element: Equatable & ~Copyable {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueDeque /*: Equatable */ where Element: Equatable /* & ~Copyable */ {
|
||||
extension UniqueDeque where Element: Equatable & ~Copyable {
|
||||
@inlinable
|
||||
public static func ==(
|
||||
left: borrowing Self,
|
||||
|
||||
@@ -13,8 +13,12 @@
|
||||
|
||||
#if compiler(>=6.2)
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension UniqueDeque: Hashable where Element: Hashable & ~Copyable {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueDeque /*: Hashable */ where Element: Hashable /* & ~Copyable */ {
|
||||
extension UniqueDeque where Element: Hashable & ~Copyable {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
self._storage.hash(into: &hasher)
|
||||
|
||||
Reference in new issue
Block a user