Skip to content

Commit 9db691e

Browse files
committed
Remove some uses of @unchecked Sendable and AnySequence.
This PR removes some outstanding uses of `@unchecked Sendable` and of `AnySequence`. Ironically we still need `Test.testCases` to type-erase with `AnySequence` _in its implementation only_ for now because if we change it from `some Sequence<Test.Case>` to `any Sequence<Test.Case>` we get this diagnostic: > 🛑 Runtime support for parameterized protocol types is only available in macOS > 13.0.0 or newer
1 parent c6512ff commit 9db691e

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

Sources/Testing/Test.swift

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,19 @@ public struct Test: Sendable {
6969
public nonisolated(unsafe) var xcTestCompatibleSelector: __XCTestCompatibleSelector?
7070

7171
/// An enumeration describing the evaluation state of a test's cases.
72-
///
73-
/// This use of `@unchecked Sendable` and of `AnySequence` in this type's
74-
/// cases is necessary because it is not currently possible to express
75-
/// `Sequence<Test.Case> & Sendable` as an existential (`any`)
76-
/// ([96960993](rdar://96960993)). It is also not possible to have a value of
77-
/// an underlying generic sequence type without specifying its generic
78-
/// parameters.
79-
fileprivate enum TestCasesState: @unchecked Sendable {
72+
fileprivate enum TestCasesState: Sendable {
8073
/// The test's cases have not yet been evaluated.
8174
///
8275
/// - Parameters:
8376
/// - function: The function to call to evaluate the test's cases. The
8477
/// result is a sequence of test cases.
85-
case unevaluated(_ function: @Sendable () async throws -> AnySequence<Test.Case>)
78+
case unevaluated(_ function: @Sendable () async throws -> any Sequence<Test.Case> & Sendable)
8679

8780
/// The test's cases have been evaluated.
8881
///
8982
/// - Parameters:
9083
/// - testCases: The test's cases.
91-
case evaluated(_ testCases: AnySequence<Test.Case>)
84+
case evaluated(_ testCases: any Sequence<Test.Case> & Sendable)
9285

9386
/// An error was thrown when the testing library attempted to evaluate the
9487
/// test's cases.
@@ -124,7 +117,7 @@ public struct Test: Sendable {
124117
// attempt to run it, and thus never access this property.
125118
preconditionFailure("Attempting to access test cases with invalid state. Please file a bug report at https://github.com/swiftlang/swift-testing/issues/new and include this information: \(String(reflecting: testCasesState))")
126119
}
127-
return testCases
120+
return AnySequence(testCases)
128121
}
129122
}
130123

@@ -139,7 +132,7 @@ public struct Test: Sendable {
139132
var uncheckedTestCases: (some Sequence<Test.Case>)? {
140133
testCasesState.flatMap { testCasesState in
141134
if case let .evaluated(testCases) = testCasesState {
142-
return testCases
135+
return AnySequence(testCases)
143136
}
144137
return nil
145138
}
@@ -239,7 +232,7 @@ public struct Test: Sendable {
239232
self.sourceLocation = sourceLocation
240233
self.containingTypeInfo = containingTypeInfo
241234
self.xcTestCompatibleSelector = xcTestCompatibleSelector
242-
self.testCasesState = .unevaluated { .init(try await testCases()) }
235+
self.testCasesState = .unevaluated { try await testCases() }
243236
self.parameters = parameters
244237
}
245238

@@ -260,7 +253,7 @@ public struct Test: Sendable {
260253
self.sourceLocation = sourceLocation
261254
self.containingTypeInfo = containingTypeInfo
262255
self.xcTestCompatibleSelector = xcTestCompatibleSelector
263-
self.testCasesState = .evaluated(.init(testCases))
256+
self.testCasesState = .evaluated(testCases)
264257
self.parameters = parameters
265258
}
266259
}

Sources/_TestDiscovery/TestContentRecord.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public struct TestContentRecord<T> where T: DiscoverableAsTestContent {
8585
public private(set) nonisolated(unsafe) var imageAddress: UnsafeRawPointer?
8686

8787
/// A type defining storage for the underlying test content record.
88-
private enum _RecordStorage: @unchecked Sendable {
88+
private enum _RecordStorage {
8989
/// The test content record is stored by address.
9090
case atAddress(UnsafePointer<_TestContentRecord>)
9191

@@ -94,7 +94,7 @@ public struct TestContentRecord<T> where T: DiscoverableAsTestContent {
9494
}
9595

9696
/// Storage for `_record`.
97-
private var _recordStorage: _RecordStorage
97+
private nonisolated(unsafe) var _recordStorage: _RecordStorage
9898

9999
/// The underlying test content record.
100100
private var _record: _TestContentRecord {

0 commit comments

Comments
 (0)