mirror of
https://github.com/apple/swift-collections
synced 2026-11-22 04:20:40 +00:00
[BasicContainers] Make the hashed containers Sendable
RigidSet, UniqueSet, RigidDictionary and UniqueDictionary had no Sendable conformance, while the arrays and deques conform when their elements are Sendable. Add the same conditional conformances: unchecked for the rigid containers, which keep their elements behind unsafe pointers, and checked for the unique ones.
This commit is contained in:
8 files changed
+42
No files matched your search
@@ -80,6 +80,10 @@ public struct RigidDictionary<
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDictionary: @unchecked Sendable
|
||||
where Key: Sendable & ~Copyable, Value: Sendable & ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
|
||||
@inlinable
|
||||
|
||||
@@ -78,6 +78,9 @@ public struct RigidSet<Element: Hashable & ~Copyable>: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidSet: @unchecked Sendable where Element: Sendable & ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidSet where Element: ~Copyable {
|
||||
@inlinable
|
||||
|
||||
@@ -41,6 +41,10 @@ public struct UniqueDictionary<
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueDictionary: Sendable
|
||||
where Key: Sendable & ~Copyable, Value: Sendable & ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueDictionary where Key: ~Copyable, Value: ~Copyable {
|
||||
@inlinable
|
||||
|
||||
@@ -40,6 +40,9 @@ public struct UniqueSet<Element: Hashable & ~Copyable>: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueSet: Sendable where Element: Sendable & ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueSet where Element: ~Copyable {
|
||||
@inlinable
|
||||
|
||||
@@ -28,6 +28,13 @@ class RigidDictionaryTests: CollectionTestCase {
|
||||
expectEqual(MemoryLayout<RigidDictionary<String, Int>>.stride, 7 * word)
|
||||
expectEqual(MemoryLayout<RigidDictionary<String, Int>?>.stride, 7 * word)
|
||||
}
|
||||
|
||||
func test_sendable_conformance_static() {
|
||||
// Compile-time assertion: RigidDictionary conforms to Sendable when its contents do.
|
||||
func requireSendable<T: Sendable & ~Copyable>(_ type: T.Type) {}
|
||||
requireSendable(RigidDictionary<Int, String>.self)
|
||||
requireSendable(RigidDictionary<String, Int>.self)
|
||||
}
|
||||
|
||||
func test_empty() {
|
||||
let s = RigidDictionary<Int, String>()
|
||||
|
||||
@@ -65,6 +65,13 @@ class RigidSetTests: CollectionTestCase {
|
||||
expectEqual(MemoryLayout<RigidSet<Int>?>.stride, 6 * word)
|
||||
}
|
||||
|
||||
func test_sendable_conformance_static() {
|
||||
// Compile-time assertion: RigidSet conforms to Sendable when its contents do.
|
||||
func requireSendable<T: Sendable & ~Copyable>(_ type: T.Type) {}
|
||||
requireSendable(RigidSet<Int>.self)
|
||||
requireSendable(RigidSet<String>.self)
|
||||
}
|
||||
|
||||
func test_empty() {
|
||||
let s = RigidSet<Int>()
|
||||
expectEqual(s.count, 0)
|
||||
|
||||
@@ -28,6 +28,13 @@ class UniqueDictionaryTests: CollectionTestCase {
|
||||
expectEqual(MemoryLayout<UniqueDictionary<String, Int>>.stride, 7 * word)
|
||||
expectEqual(MemoryLayout<UniqueDictionary<String, Int>?>.stride, 7 * word)
|
||||
}
|
||||
|
||||
func test_sendable_conformance_static() {
|
||||
// Compile-time assertion: UniqueDictionary conforms to Sendable when its contents do.
|
||||
func requireSendable<T: Sendable & ~Copyable>(_ type: T.Type) {}
|
||||
requireSendable(UniqueDictionary<Int, String>.self)
|
||||
requireSendable(UniqueDictionary<String, Int>.self)
|
||||
}
|
||||
|
||||
func test_empty() {
|
||||
let s = UniqueDictionary<Int, String>()
|
||||
|
||||
@@ -28,6 +28,13 @@ class UniqueSetTests: CollectionTestCase {
|
||||
expectEqual(MemoryLayout<UniqueSet<Int>>.stride, 6 * word)
|
||||
expectEqual(MemoryLayout<UniqueSet<Int>?>.stride, 6 * word)
|
||||
}
|
||||
|
||||
func test_sendable_conformance_static() {
|
||||
// Compile-time assertion: UniqueSet conforms to Sendable when its contents do.
|
||||
func requireSendable<T: Sendable & ~Copyable>(_ type: T.Type) {}
|
||||
requireSendable(UniqueSet<Int>.self)
|
||||
requireSendable(UniqueSet<String>.self)
|
||||
}
|
||||
|
||||
func test_empty() {
|
||||
let s = UniqueSet<Int>()
|
||||
|
||||
Reference in new issue
Block a user