10
10
11
11
private import _TestingInternals
12
12
13
- /// A type that encapsulates test content records that produce instances of
14
- /// ``Test``.
15
- ///
16
- /// This type is necessary because such test content records produce an indirect
17
- /// `async` accessor function rather than directly producing instances of
18
- /// ``Test``, but functions are non-nominal types and cannot directly conform to
19
- /// protocols.
20
- ///
21
- /// - Note: This helper type must have the exact in-memory layout of the `async`
22
- /// accessor function. Do not add any additional stored properties. The layout
23
- /// of this type is _de facto_ [guaranteed](https://github.com/swiftlang/swift/blob/main/docs/ABI/TypeLayout.rst)
24
- /// by the Swift ABI.
25
- /* @frozen */ private struct _TestRecord : TestContent {
26
- static var testContentKind : UInt32 {
27
- 0x74657374
28
- }
13
+ extension Test {
14
+ /// A type that encapsulates test content records that produce instances of
15
+ /// ``Test``.
16
+ ///
17
+ /// This type is necessary because such test content records produce an
18
+ /// indirect `async` accessor function rather than directly producing
19
+ /// instances of ``Test``, but functions are non-nominal types and cannot
20
+ /// directly conform to protocols.
21
+ ///
22
+ /// - Note: This helper type must have the exact in-memory layout of the
23
+ /// `async` accessor function. Do not add any additional cases or associated
24
+ /// values. The layout of this type is [guaranteed](https://github.com/swiftlang/swift/blob/main/docs/ABI/TypeLayout.rst#fragile-enum-layout)
25
+ /// by the Swift ABI.
26
+ /* @frozen */ private enum _Record : TestContent {
27
+ static var testContentKind : UInt32 {
28
+ 0x74657374
29
+ }
29
30
30
- /// This instance's actual (asynchronous) accessor function.
31
- var asyncAccessor : @Sendable ( ) async -> Test
32
- }
31
+ /// The actual (asynchronous) accessor function.
32
+ case generator ( @Sendable ( ) async -> Test )
33
+ }
33
34
34
- extension Test {
35
35
/// All available ``Test`` instances in the process, according to the runtime.
36
36
///
37
37
/// The order of values in this sequence is unspecified.
@@ -58,7 +58,12 @@ extension Test {
58
58
// Walk all test content and gather generator functions, then call them in
59
59
// a task group and collate their results.
60
60
if useNewMode {
61
- let generators = _TestRecord. allTestContentRecords ( ) . lazy. compactMap { $0. load ( ) ? . asyncAccessor }
61
+ let generators = _Record. allTestContentRecords ( ) . lazy. compactMap { record in
62
+ if case let . generator( generator) = record. load ( ) {
63
+ return generator
64
+ }
65
+ return nil // currently unreachable, but not provably so
66
+ }
62
67
await withTaskGroup ( of: Self . self) { taskGroup in
63
68
for generator in generators {
64
69
taskGroup. addTask ( operation: generator)
0 commit comments