Skip to content

Commit c985351

Browse files
committed
Require SendableMetatype in ShrinkSequence when using Swift 6.2
1 parent 0dda842 commit c985351

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Sources/PropertyBased/Gen+Collection.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// Adapted from https://github.com/pointfreeco/swift-gen
22
// Copyright (c) 2019 Point-Free, Inc. MIT License
33

4+
#if compiler(>=6.2)
5+
@_documentation(visibility: internal)
6+
public typealias SendableHashableType = Hashable & SendableMetatype
7+
#else
8+
@_documentation(visibility: internal)
9+
public typealias SendableHashableType = Hashable
10+
#endif
11+
412
extension Gen {
513
/// Produces a generator of random elements of the given collection.
614
///
@@ -116,7 +124,9 @@ extension Generator {
116124
/// - Parameter count: The size of the random dictionary. If duplicate keys are generated, the dictionary will have a smaller size.
117125
/// - Returns: A generator of dictionaries.
118126
@inlinable
119-
public func dictionary<K: Hashable, V>(ofAtMost count: ClosedRange<Int>) -> Generator<[K: V], ArrayShrink>
127+
public func dictionary<K: SendableHashableType, V>(ofAtMost count: ClosedRange<Int>) -> Generator<
128+
[K: V], ArrayShrink
129+
>
120130
where ResultValue == (K, V) {
121131
return array(of: count).map {
122132
Dictionary($0, uniquingKeysWith: { a, _ in a })
@@ -136,13 +146,13 @@ extension Generator {
136146
/// - Parameter count: The size of the random dictionary. If duplicate keys are generated, the dictionary will have a smaller size.
137147
/// - Returns: A generator of dictionaries.
138148
@inlinable
139-
public func dictionary<K: Hashable, V>(ofAtMost count: Int) -> Generator<[K: V], ArrayShrink>
149+
public func dictionary<K: SendableHashableType, V>(ofAtMost count: Int) -> Generator<[K: V], ArrayShrink>
140150
where ResultValue == (K, V) {
141151
return dictionary(ofAtMost: count...count)
142152
}
143153
}
144154

145-
extension Generator where ResultValue: Hashable {
155+
extension Generator where ResultValue: SendableHashableType {
146156
/// Produces a new generator of sets of this generator's values.
147157
///
148158
/// ### Example
@@ -172,7 +182,7 @@ extension Generator where ResultValue: Hashable {
172182
}
173183
}
174184

175-
extension Gen where Value: OptionSet, Value.RawValue: FixedWidthInteger & Sendable {
185+
extension Gen where Value: OptionSet & Sendable, Value.RawValue: FixedWidthInteger & Sendable {
176186
/// Produces a generator of sets for an OptionSet.
177187
///
178188
/// This generator will generate sets that may exceed the static properties declared in this option set.

Sources/PropertyBased/Gen+SIMD.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension Generator {
1919
}
2020
}
2121

22-
extension Generator where ResultValue: SIMDScalar {
22+
extension Generator where ResultValue: SIMDScalar & Sendable {
2323
/// Produces a generator that creates a SIMD vector of values.
2424
///
2525
/// ### Example

Sources/PropertyBased/Generator.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// Adapted from https://github.com/pointfreeco/swift-gen
22
// Copyright (c) 2019 Point-Free, Inc. MIT License
33

4+
#if compiler(>=6.2)
5+
@_documentation(visibility: internal)
6+
public typealias SendableSequenceType = Sequence & SendableMetatype
7+
#else
8+
@_documentation(visibility: internal)
9+
public typealias SendableSequenceType = Sequence
10+
#endif
11+
412
/// A composable, transformable context for generating random values.
513
///
614
/// A Generator contains a specific function that creates new values, as well as a function
@@ -10,7 +18,7 @@
1018
/// ```swift
1119
/// let gen = Generator<Output, some Sequence> = ...
1220
/// ```
13-
public struct Generator<ResultValue, ShrinkSequence: Sequence>: Sendable {
21+
public struct Generator<ResultValue, ShrinkSequence: SendableSequenceType>: Sendable {
1422
public typealias InputValue = ShrinkSequence.Element
1523

1624
/// Generate a single result, before mapping or filtering.

0 commit comments

Comments
 (0)