From 2a4682263d45c7615a53e84694da9189de5d19ba Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 12 Mar 2024 20:50:48 +0000 Subject: [PATCH] Remove DispatchShims.swift and replace it with a conditional typealias The use of DispatchQueue in XCTest is now very limited, and it's only used in a single place in XCTestCase.swift. --- CMakeLists.txt | 1 - Sources/XCTest/Private/DispatchShims.swift | 47 ---------------------- Sources/XCTest/Public/XCTestCase.swift | 18 ++++++++- 3 files changed, 17 insertions(+), 49 deletions(-) delete mode 100644 Sources/XCTest/Private/DispatchShims.swift diff --git a/CMakeLists.txt b/CMakeLists.txt index 75fd3da4..14ecd0fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,6 @@ add_library(XCTest Sources/XCTest/Private/WaiterManager.swift Sources/XCTest/Private/IgnoredErrors.swift Sources/XCTest/Private/XCTestCase.TearDownBlocksState.swift - Sources/XCTest/Private/DispatchShims.swift Sources/XCTest/Public/XCTestRun.swift Sources/XCTest/Public/XCTestMain.swift Sources/XCTest/Public/XCTestCase.swift diff --git a/Sources/XCTest/Private/DispatchShims.swift b/Sources/XCTest/Private/DispatchShims.swift deleted file mode 100644 index 55ce8b68..00000000 --- a/Sources/XCTest/Private/DispatchShims.swift +++ /dev/null @@ -1,47 +0,0 @@ -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See http://swift.org/LICENSE.txt for license information -// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -// -// NoThreadDispatchShims.swift -// - -// This file is a shim for platforms that don't have libdispatch and do assume a single-threaded environment. - -// NOTE: We can't use use `#if canImport(Dispatch)` because Dispatch Clang module is placed directly in the resource -// directory, and not split into target-specific directories. This means that the module is always available, even on -// platforms that don't have libdispatch. Thus, we need to check for the actual platform. -#if os(WASI) - -/// No-op shim function -func dispatchPrecondition(condition: DispatchPredicate) {} - -struct DispatchPredicate { - static func onQueue(_: X) -> Self { - return DispatchPredicate() - } - - static func notOnQueue(_: X) -> Self { - return DispatchPredicate() - } -} - -extension XCTWaiter { - /// Single-threaded queue without any actual queueing - struct DispatchQueue { - init(label: String) {} - - func sync(_ body: () -> T) -> T { - body() - } - func async(_ body: @escaping () -> Void) { - body() - } - } -} - -#endif diff --git a/Sources/XCTest/Public/XCTestCase.swift b/Sources/XCTest/Public/XCTestCase.swift index 1f2ab76a..2d899b91 100644 --- a/Sources/XCTest/Public/XCTestCase.swift +++ b/Sources/XCTest/Public/XCTestCase.swift @@ -54,7 +54,23 @@ open class XCTestCase: XCTest { return 1 } - internal static let subsystemQueue = DispatchQueue(label: "org.swift.XCTestCase") + #if DISABLE_XCTWAITER && os(WASI) + /// Single-threaded queue without any actual queueing + struct SubsystemQueue { + init(label: String) {} + + func sync(_ body: () -> T) -> T { + body() + } + func async(_ body: @escaping () -> Void) { + body() + } + } + #else + typealias SubsystemQueue = DispatchQueue + #endif + + internal static let subsystemQueue = SubsystemQueue(label: "org.swift.XCTestCase") #if !DISABLE_XCTWAITER @MainActor