mirror of
https://github.com/apple/swift-collections
synced 2026-11-30 05:18:44 +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
|
#if compiler(>=6.4)
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 6.4, *)
|
||||||
extension RigidArray: Equatable where Element: Equatable & ~Copyable {
|
extension RigidArray: Equatable where Element: Equatable & ~Copyable {
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(SwiftStdlib 5.0, *)
|
||||||
|
extension RigidArray where Element: Equatable & ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public static func ==(
|
public static func ==(
|
||||||
left: borrowing Self,
|
left: borrowing Self,
|
||||||
|
|||||||
@@ -17,13 +17,28 @@
|
|||||||
import InternalCollectionsUtilities
|
import InternalCollectionsUtilities
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if compiler(>=6.4)
|
||||||
|
@available(SwiftStdlib 6.4, *)
|
||||||
|
extension RigidArray: Hashable where Element: Hashable & ~Copyable {
|
||||||
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension RigidArray /*: Hashable */ where Element: Hashable /* & ~Copyable */ {
|
extension RigidArray where Element: Hashable & ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
hasher.combine(self.count)
|
hasher.combine(self.count)
|
||||||
self.span._hashContents(into: &hasher)
|
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
|
#endif
|
||||||
@@ -20,7 +20,7 @@ import ContainersPreview
|
|||||||
#if compiler(>=6.4) && UnstableHashedContainers
|
#if compiler(>=6.4) && UnstableHashedContainers
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension RigidDictionary {
|
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
||||||
self._keys.isTriviallyIdentical(to: other._keys)
|
self._keys.isTriviallyIdentical(to: other._keys)
|
||||||
@@ -29,7 +29,7 @@ extension RigidDictionary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension RigidDictionary {
|
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public func isEqual(
|
public func isEqual(
|
||||||
to other: borrowing Self,
|
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, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension RigidDictionary: Equatable where Value: Equatable {
|
extension RigidDictionary where Key: ~Copyable, Value: Equatable & ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
|
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
|
||||||
left.isEqual(to: right, by: ==)
|
left.isEqual(to: right, by: ==)
|
||||||
|
|||||||
@@ -18,8 +18,12 @@ import ContainersPreview
|
|||||||
|
|
||||||
#if compiler(>=6.4) && UnstableHashedContainers
|
#if compiler(>=6.4) && UnstableHashedContainers
|
||||||
|
|
||||||
|
@available(SwiftStdlib 6.4, *)
|
||||||
|
extension RigidDictionary: Hashable where Value: Hashable & ~Copyable {
|
||||||
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension RigidDictionary: Hashable where Value: Hashable { // Should be Hashable
|
extension RigidDictionary where Value: Hashable & ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
var commutativeHash = 0
|
var commutativeHash = 0
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import ContainersPreview
|
|||||||
#if compiler(>=6.4) && UnstableHashedContainers
|
#if compiler(>=6.4) && UnstableHashedContainers
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension RigidSet {
|
extension RigidSet where Element: ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
||||||
self._members == other._members
|
self._members == other._members
|
||||||
@@ -28,12 +28,11 @@ extension RigidSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UnstableContainersPreview
|
|
||||||
@available(SwiftStdlib 6.4, *)
|
@available(SwiftStdlib 6.4, *)
|
||||||
extension RigidSet: Equatable {}
|
extension RigidSet: Equatable where Element: ~Copyable {}
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension RigidSet {
|
extension RigidSet where Element: ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
|
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
|
||||||
if left.isTriviallyIdentical(to: right) { return true }
|
if left.isTriviallyIdentical(to: right) { return true }
|
||||||
@@ -54,5 +53,3 @@ extension RigidSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -19,10 +19,10 @@ import ContainersPreview
|
|||||||
#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview
|
#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview
|
||||||
|
|
||||||
@available(SwiftStdlib 6.4, *)
|
@available(SwiftStdlib 6.4, *)
|
||||||
extension RigidSet: Hashable {}
|
extension RigidSet: Hashable where Element: ~Copyable {}
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension RigidSet {
|
extension RigidSet where Element: ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
// Generate a seed from a snapshot of the hasher. This makes members' hash
|
// Generate a seed from a snapshot of the hasher. This makes members' hash
|
||||||
@@ -42,7 +42,7 @@ extension RigidSet {
|
|||||||
let next = it.nextSpan_()
|
let next = it.nextSpan_()
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < next.count {
|
while i < next.count {
|
||||||
hash ^= next[i]._rawHashValue(seed: seed)
|
hash ^= next[unchecked: i]._rawHashValue(seed: seed)
|
||||||
i &+= 1
|
i &+= 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,13 @@ extension UniqueArray where Element: ~Copyable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if compiler(>=6.4) && UnstableContainersPreview
|
#if compiler(>=6.4)
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 6.4, *)
|
||||||
extension UniqueArray: Equatable where Element: Equatable & ~Copyable {
|
extension UniqueArray: Equatable where Element: Equatable & ~Copyable {
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(SwiftStdlib 5.0, *)
|
||||||
|
extension UniqueArray where Element: Equatable & ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public static func ==(
|
public static func ==(
|
||||||
left: borrowing Self,
|
left: borrowing Self,
|
||||||
|
|||||||
@@ -13,16 +13,30 @@
|
|||||||
|
|
||||||
#if compiler(>=6.2)
|
#if compiler(>=6.2)
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
#if !COLLECTIONS_SINGLE_MODULE
|
||||||
extension UniqueArray /*: Hashable */ where Element: Hashable /* & ~Copyable */ {
|
import InternalCollectionsUtilities
|
||||||
@inlinable
|
#endif
|
||||||
public func hash(into hasher: inout Hasher) {
|
|
||||||
hasher.combine(self.count)
|
#if compiler(>=6.4)
|
||||||
let span = self.span
|
@available(SwiftStdlib 6.4, *)
|
||||||
for i in 0 ..< count {
|
extension UniqueArray: Hashable where Element: Hashable & ~Copyable {
|
||||||
hasher.combine(span[unchecked: i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
#endif
|
||||||
@@ -20,7 +20,7 @@ import ContainersPreview
|
|||||||
#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview
|
#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension UniqueSet {
|
extension UniqueSet where Element: ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
||||||
@@ -29,10 +29,10 @@ extension UniqueSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 6.4, *)
|
@available(SwiftStdlib 6.4, *)
|
||||||
extension UniqueSet: Equatable {}
|
extension UniqueSet: Equatable where Element: ~Copyable {}
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension UniqueSet {
|
extension UniqueSet where Element: ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
|
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ import ContainersPreview
|
|||||||
#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview
|
#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview
|
||||||
|
|
||||||
@available(SwiftStdlib 6.4, *)
|
@available(SwiftStdlib 6.4, *)
|
||||||
extension UniqueSet: Hashable {}
|
extension UniqueSet: Hashable where Element: ~Copyable {}
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension UniqueSet {
|
extension UniqueSet where Element: ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
_storage.hash(into: &hasher)
|
_storage.hash(into: &hasher)
|
||||||
|
|||||||
@@ -19,14 +19,18 @@ import ContainersPreview
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@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 {
|
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
||||||
self._handle.isIdentical(to: other._handle)
|
self._handle.isIdentical(to: other._handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(SwiftStdlib 6.4, *)
|
||||||
|
extension RigidDeque: Equatable where Element: Equatable & ~Copyable {
|
||||||
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension RigidDeque /*: Equatable */ where Element: Equatable /* & ~Copyable */ {
|
extension RigidDeque where Element: Equatable & ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public static func ==(
|
public static func ==(
|
||||||
left: borrowing Self,
|
left: borrowing Self,
|
||||||
|
|||||||
@@ -17,8 +17,12 @@
|
|||||||
import InternalCollectionsUtilities
|
import InternalCollectionsUtilities
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@available(SwiftStdlib 6.4, *)
|
||||||
|
extension RigidDeque: Hashable where Element: Hashable & ~Copyable {
|
||||||
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension RigidDeque /*: Hashable */ where Element: Hashable /* & ~Copyable */ {
|
extension RigidDeque where Element: Hashable & ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
hasher.combine(self.count)
|
hasher.combine(self.count)
|
||||||
|
|||||||
@@ -17,8 +17,12 @@
|
|||||||
import InternalCollectionsUtilities
|
import InternalCollectionsUtilities
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@available(SwiftStdlib 6.4, *)
|
||||||
|
extension UniqueDeque: Equatable where Element: Equatable & ~Copyable {
|
||||||
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension UniqueDeque /*: Equatable */ where Element: Equatable /* & ~Copyable */ {
|
extension UniqueDeque where Element: Equatable & ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public static func ==(
|
public static func ==(
|
||||||
left: borrowing Self,
|
left: borrowing Self,
|
||||||
|
|||||||
@@ -13,8 +13,12 @@
|
|||||||
|
|
||||||
#if compiler(>=6.2)
|
#if compiler(>=6.2)
|
||||||
|
|
||||||
|
@available(SwiftStdlib 6.4, *)
|
||||||
|
extension UniqueDeque: Hashable where Element: Hashable & ~Copyable {
|
||||||
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 5.0, *)
|
@available(SwiftStdlib 5.0, *)
|
||||||
extension UniqueDeque /*: Hashable */ where Element: Hashable /* & ~Copyable */ {
|
extension UniqueDeque where Element: Hashable & ~Copyable {
|
||||||
@inlinable
|
@inlinable
|
||||||
public func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
self._storage.hash(into: &hasher)
|
self._storage.hash(into: &hasher)
|
||||||
|
|||||||
Reference in new issue
Block a user