Skip to content

Commit af7a094

Browse files
authored
Avoid ObjC runtime warnings about duplicate class definitions for Serializer type (#1444)
This is a workaround meant to avoid Objective-C runtime warnings about duplicate classes stemming from our internal `Serializer` type which was added in #1390. ### Motivation: In some usage scenarios there can be two or more copies of the testing library loaded into a runner process. When this happens on platforms such as Darwin which use the Objective-C runtime, this can cause duplicate class definition warnings logged to the console because class types and (non-generic) actor types are implemented within the Objective-C runtime as classes. This can look something like the following: > objc[44611]: Class _TtC7Testing10Serializer is implemented in both ../path/to/libTesting.dylib (0x1011ac050) and path/to/swift-testing/.build/arm64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests (0x10cc3ab88). This may cause spurious casting failures and mysterious crashes. One of the duplicates must be removed or renamed. ### Modifications: I considered several potential fixes, but decided the simplest and most likely to work in all usage scenarios is to make the `Serializer` type generic by adding an unused generic type parameter `T`. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 56c2ad0 commit af7a094

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Sources/Testing/Running/Runner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ extension Runner {
7777
/// type at runtime, it may be better-suited for ``Configuration`` instead.
7878
private struct _Context: Sendable {
7979
/// A serializer used to reduce parallelism among test cases.
80-
var testCaseSerializer: Serializer?
80+
var testCaseSerializer: Serializer<Void>?
8181
}
8282

8383
/// Apply the custom scope for any test scope providers of the traits

Sources/Testing/Support/Serializer.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ var defaultParallelizationWidth: Int {
4242
/// items do not start running; they must wait until the suspended work item
4343
/// either returns or throws an error.
4444
///
45+
/// The generic type parameter `T` is unused. It avoids warnings when multiple
46+
/// copies of the testing library are loaded into a runner process on platforms
47+
/// which use the Objective-C runtime, due to non-generic actor types being
48+
/// implemented as classes there.
49+
///
4550
/// This type is not part of the public interface of the testing library.
46-
final actor Serializer {
51+
final actor Serializer<T> {
4752
/// The maximum number of work items that may run concurrently.
4853
nonisolated let maximumWidth: Int
4954

0 commit comments

Comments
 (0)