Skip to content

Mark all closures in the .stream outputRedirection of TSC as @Sendable #1919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
arguments: arguments,
workingDirectory: nil,
outputRedirection: .stream(
stdout: { stdoutHandler.handleDataFromPipe(Data($0)) },
stderr: { stderrHandler.handleDataFromPipe(Data($0)) }
stdout: { @Sendable bytes in stdoutHandler.handleDataFromPipe(Data(bytes)) },
stderr: { @Sendable bytes in stderrHandler.handleDataFromPipe(Data(bytes)) }
)
)
let exitStatus = result.exitStatus.exhaustivelySwitchable
Expand Down
24 changes: 16 additions & 8 deletions Sources/Diagnose/DiagnoseCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ package struct DiagnoseCommand: AsyncParsableCommand {
throw GenericError("Failed to create log.txt")
}
let fileHandle = try FileHandle(forWritingTo: outputFileUrl)
var bytesCollected = 0
let bytesCollected = AtomicInt32(initialValue: 0)
let processExited = AtomicBool(initialValue: false)
// 50 MB is an average log size collected by sourcekit-lsp diagnose.
// It's a good proxy to show some progress indication for the majority of the time.
let expectedLogSize = 50_000_000
Expand All @@ -247,21 +248,28 @@ package struct DiagnoseCommand: AsyncParsableCommand {
"--signpost",
],
outputRedirection: .stream(
stdout: { bytes in
stdout: { @Sendable bytes in
try? fileHandle.write(contentsOf: bytes)
bytesCollected += bytes.count
var progress = Double(bytesCollected) / Double(expectedLogSize)
bytesCollected.value += Int32(bytes.count)
var progress = Double(bytesCollected.value) / Double(expectedLogSize)
if progress > 1 {
// The log is larger than we expected. Halt at 100%
progress = 1
}
reportProgress(.collectingLogMessages(progress: progress), message: "Collecting log messages")
Task(priority: .high) {
// We have launched an async task to call `reportProgress`, which means that the process might have exited
// before we execute this task. To avoid overriding a more recent progress, add a guard.
if !processExited.value {
await reportProgress(.collectingLogMessages(progress: progress), message: "Collecting log messages")
}
}
},
stderr: { _ in }
stderr: { @Sendable _ in }
)
)
try process.launch()
try await process.waitUntilExit()
processExited.value = true
#endif
}

Expand Down Expand Up @@ -343,8 +351,8 @@ package struct DiagnoseCommand: AsyncParsableCommand {
let process = Process(
arguments: [try swiftUrl.filePath, "--version"],
outputRedirection: .stream(
stdout: { try? fileHandle.write(contentsOf: $0) },
stderr: { _ in }
stdout: { @Sendable bytes in try? fileHandle.write(contentsOf: bytes) },
stderr: { @Sendable _ in }
)
)
try process.launch()
Expand Down
4 changes: 2 additions & 2 deletions Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ package struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
arguments: processArguments,
workingDirectory: workingDirectory,
outputRedirection: .stream(
stdout: { stdoutHandler.handleDataFromPipe(Data($0)) },
stderr: { stderrHandler.handleDataFromPipe(Data($0)) }
stdout: { @Sendable bytes in stdoutHandler.handleDataFromPipe(Data(bytes)) },
stderr: { @Sendable bytes in stderrHandler.handleDataFromPipe(Data(bytes)) }
)
)
}
Expand Down