Swift 6 language mode support needed
let 'benchmarks' is not concurrency-safe because non-'Sendable' type '() -> ()' may have shared mutable state
~What is the workaround here?~
Use explicit type:
let benchmarks : @Sendable () -> Benchmark? = {
If you have many Benchmark:
let benchmarks : @Sendable () -> Void = {
Would also be nice to conform BenchmarkMetric to Sendable since we currently can't define custom metrics like so:
enum CustomMeasurement {
static let forward = BenchmarkMetric.custom("run forward (ns)", polarity: .prefersSmaller, useScalingFactor: true)
static let reverse = BenchmarkMetric.custom("run reverse (ns)", polarity: .prefersSmaller, useScalingFactor: true)
static let ratio = BenchmarkMetric.custom("ratio", polarity: .prefersSmaller, useScalingFactor: true)
}
returns the following error:
Static property 'forward' is not concurrency-safe because non-'Sendable' type 'BenchmarkMetric' may have shared mutable state
There's also an issue when setting the defaultConfiguration for benchmarks like so:
let benchmarks: @Sendable () -> Void = {
Benchmark.defaultConfiguration = .init( // Reference to class property 'defaultConfiguration' is not concurrency-safe because it involves shared mutable state
warmupIterations: 1,
scalingFactor: .kilo
)
Benchmark("b1") {
// ...
}
}
Are there workarounds for these?
I think we can make BenchmarkMetric conform to Sendable right? But for the Benchmark.defaultConfiguration I'm not sure what a good solution would be.
Making BenchmarkMetric conform to Sendable in https://github.com/ordo-one/package-benchmark/pull/309
The defaultConfiguration I need to have a look at.
I fixed defaultConfiguration too with a lock, I think Swift 6 benchmarks targets should be completely possible now with https://github.com/ordo-one/package-benchmark/releases/tag/1.28.0
Please give it a spin and open new issues if you find anything remaining.
Nice will give it a try thanks!