Skip to content

Commit 2516cdb

Browse files
authored
Work around miscompilation of entry point function on Windows with Swift 5.10 (Take 2). (#382)
I saw our [Windows CI](https://ci-external.swift.org/job/swift-testing-main-swift-5.10-windows/66/) fail even after the changes in #381. Trying a different approach here by using `consuming` to transfer ownership of the troublesome value rather than using a pointer to trick the ownership checker. ### 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 8a13baf commit 2516cdb

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

Sources/Testing/EntryPoints/ABIEntryPoint.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ public typealias ABIEntryPoint_v0 = @Sendable (
6060
@usableFromInline
6161
func abiEntryPoint_v0(_ outEntryPoint: UnsafeMutableRawPointer) {
6262
outEntryPoint.initializeMemory(as: ABIEntryPoint_v0.self) { argumentsJSON, eventHandler in
63-
var args = try! argumentsJSON.map { argumentsJSON in
63+
let args = try! argumentsJSON.map { argumentsJSON in
6464
try JSON.decode(__CommandLineArguments_v0.self, from: argumentsJSON)
6565
}
6666

6767
let eventHandler = eventHandlerForStreamingEvents_v0(to: eventHandler)
68-
return await entryPoint(passing: &args, eventHandler: eventHandler)
68+
return await entryPoint(passing: args, eventHandler: eventHandler)
6969
}
7070
}
7171
#endif

Sources/Testing/EntryPoints/EntryPoint.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ private import TestingInternals
2626
/// - Warning: This function is used by Swift Package Manager. Do not call it
2727
/// directly.
2828
@_disfavoredOverload public func __swiftPMEntryPoint(passing args: __CommandLineArguments_v0? = nil) async -> CInt {
29-
var args = args
30-
return await entryPoint(passing: &args, eventHandler: nil)
29+
await entryPoint(passing: args, eventHandler: nil)
3130
}
3231

3332
/// The entry point to the testing library used by Swift Package Manager.
@@ -56,17 +55,12 @@ public func __swiftPMEntryPoint(passing args: __CommandLineArguments_v0? = nil)
5655
/// - args: A previously-parsed command-line arguments structure to interpret.
5756
/// If `nil`, a new instance is created from the command-line arguments to
5857
/// the current process.
59-
/// - eventHandler: An event handler.
60-
///
61-
/// - Bug: This function takes `args` as a pointer in order to work around a
62-
/// code generation bug when using the Swift 5.10 toolchain on Windows. This
63-
/// function should be updated to take `args` directly when Swift 5.10
64-
/// support is removed.
65-
func entryPoint(passing args: UnsafePointer<__CommandLineArguments_v0?>, eventHandler: Event.Handler?) async -> CInt {
58+
/// - eventHandler: An event handler
59+
func entryPoint(passing args: consuming __CommandLineArguments_v0?, eventHandler: Event.Handler?) async -> CInt {
6660
let exitCode = Locked(rawValue: EXIT_SUCCESS)
6761

6862
do {
69-
let args = try args.pointee ?? parseCommandLineArguments(from: CommandLine.arguments())
63+
let args = try args ?? parseCommandLineArguments(from: CommandLine.arguments())
7064
if args.listTests {
7165
for testID in await listTestsForSwiftPM(Test.all) {
7266
#if SWT_TARGET_OS_APPLE && !SWT_NO_FILE_IO

Sources/Testing/EntryPoints/XCTestScaffold.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ public enum XCTestScaffold: Sendable {
144144
functionName[...]
145145
}
146146
args.xcTestCaseHostIdentifier = "\(typeName)/\(functionName)"
147-
var argsCopy: __CommandLineArguments_v0? = args
148147

149-
_ = await entryPoint(passing: &argsCopy) { event, _ in
148+
_ = await entryPoint(passing: args) { event, _ in
150149
guard case let .issueRecorded(issue) = event.kind else {
151150
return
152151
}

0 commit comments

Comments
 (0)