Skip to content

Commit 8e5736d

Browse files
authored
Merge pull request #1301 from ahoppen/6.0/merge-main-2024-05-14
Merge `main` into `release/6.0`
2 parents aa0ed90 + d555ccd commit 8e5736d

File tree

96 files changed

+3731
-544
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+3731
-544
lines changed

.github/ISSUE_TEMPLATE/BUG_REPORT.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ body:
1818
id: editor
1919
attributes:
2020
label: Editor
21-
description: Which text editor are you using?
22-
placeholder: Eg. Visual Studio Code with Swift plugin 1.9.0, neovim
21+
description: Which text editor are you using (and LSP extension/plugin if applicable)?
22+
placeholder: Eg. Visual Studio Code with Swift extension 1.9.0, Neovim
2323
- type: dropdown
2424
id: reproduces-with-swift-6
2525
attributes:
@@ -50,4 +50,4 @@ body:
5050
label: Logging
5151
description: |
5252
If you are using SourceKit-LSP from Swift 6, running `sourcekit-lsp diagnose` in terminal and attaching the generated bundle helps us diagnose the issue.
53-
The generated bundle might contain portions of your source code, so please only attach it if you feel comfortable sharing it.
53+
The generated bundle may contain paths to files on disk as well as portions of your source code. This greatly helps in reproducing issues, but you should only attach it if you feel comfortable doing so.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
default.profraw
33
Package.resolved
44
/.build
5+
/.index-build
56
/Packages
67
/*.xcodeproj
78
/*.sublime-project

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ let package = Package(
173173
.target(
174174
name: "SemanticIndex",
175175
dependencies: [
176+
"CAtomics",
177+
"LanguageServerProtocol",
176178
"LSPLogging",
177179
"SKCore",
178180
.product(name: "IndexStoreDB", package: "indexstore-db"),

Sources/Diagnose/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_library(Diagnose STATIC
2+
CommandConfiguration+Sendable.swift
23
CommandLineArgumentsReducer.swift
34
DiagnoseCommand.swift
45
MergeSwiftFiles.swift
@@ -11,9 +12,10 @@ add_library(Diagnose STATIC
1112
ReproducerBundle.swift
1213
RequestInfo.swift
1314
SourceKitD+RunWithYaml.swift
15+
SourcekitdRequestCommand.swift
1416
SourceKitDRequestExecutor.swift
1517
SourceReducer.swift
16-
SourcekitdRequestCommand.swift
18+
StderrStreamConcurrencySafe.swift
1719
SwiftFrontendCrashScraper.swift
1820
Toolchain+SwiftFrontend.swift)
1921

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import ArgumentParser
14+
15+
// If `CommandConfiguration` is not sendable, commands can't have static `configuration` properties.
16+
// Needed until we update Swift CI to swift-argument-parser 1.3.1, which has this conformance (rdar://128042447).
17+
#if compiler(<5.11)
18+
extension CommandConfiguration: @unchecked Sendable {}
19+
#else
20+
extension CommandConfiguration: @unchecked @retroactive Sendable {}
21+
#endif

Sources/Diagnose/CommandLineArgumentsReducer.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import LSPLogging
1616
// MARK: - Entry point
1717

1818
extension RequestInfo {
19+
@MainActor
1920
func reduceCommandLineArguments(
2021
using executor: SourceKitRequestExecutor,
2122
progressUpdate: (_ progress: Double, _ message: String) -> Void
@@ -49,6 +50,7 @@ fileprivate class CommandLineArgumentReducer {
4950
self.progressUpdate = progressUpdate
5051
}
5152

53+
@MainActor
5254
func run(initialRequestInfo: RequestInfo) async throws -> RequestInfo {
5355
var requestInfo = initialRequestInfo
5456
requestInfo = try await reduce(initialRequestInfo: requestInfo, simultaneousRemove: 10)
@@ -113,6 +115,7 @@ fileprivate class CommandLineArgumentReducer {
113115
return requestInfo
114116
}
115117

118+
@MainActor
116119
private func tryRemoving(
117120
_ argumentsToRemove: ClosedRange<Int>,
118121
from requestInfo: RequestInfo

Sources/Diagnose/DiagnoseCommand.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import SKCore
1616

1717
import struct TSCBasic.AbsolutePath
1818
import class TSCBasic.Process
19-
import var TSCBasic.stderrStream
2019
import class TSCUtility.PercentProgressAnimation
2120

2221
/// When diagnosis is started, a progress bar displayed on the terminal that shows how far the diagnose command has
2322
/// progressed.
2423
/// Can't be a member of `DiagnoseCommand` because then `DiagnoseCommand` is no longer codable, which it needs to be
2524
/// to be a `AsyncParsableCommand`.
25+
@MainActor
2626
private var progressBar: PercentProgressAnimation? = nil
2727

2828
/// A component of the diagnostic bundle that's collected in independent stages.
@@ -35,7 +35,7 @@ fileprivate enum BundleComponent: String, CaseIterable, ExpressibleByArgument {
3535
}
3636

3737
public struct DiagnoseCommand: AsyncParsableCommand {
38-
public static var configuration: CommandConfiguration = CommandConfiguration(
38+
public static let configuration: CommandConfiguration = CommandConfiguration(
3939
commandName: "diagnose",
4040
abstract: "Creates a bundle containing information that help diagnose issues with sourcekit-lsp"
4141
)
@@ -72,6 +72,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
7272
}
7373
}
7474

75+
@MainActor
7576
var toolchain: Toolchain? {
7677
get async throws {
7778
if let toolchainOverride {
@@ -96,6 +97,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
9697

9798
public init() {}
9899

100+
@MainActor
99101
private func addSourcekitdCrashReproducer(toBundle bundlePath: URL) async throws {
100102
reportProgress(.reproducingSourcekitdCrash(progress: 0), message: "Trying to reduce recent sourcekitd crashes")
101103
for (name, requestInfo) in try requestInfos() {
@@ -121,6 +123,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
121123
}
122124
}
123125

126+
@MainActor
124127
private func addSwiftFrontendCrashReproducer(toBundle bundlePath: URL) async throws {
125128
reportProgress(
126129
.reproducingSwiftFrontendCrash(progress: 0),
@@ -182,14 +185,16 @@ public struct DiagnoseCommand: AsyncParsableCommand {
182185
}
183186

184187
/// Execute body and if it throws, log the error.
185-
private func orPrintError(_ body: () async throws -> Void) async {
188+
@MainActor
189+
private func orPrintError(_ body: @MainActor () async throws -> Void) async {
186190
do {
187191
try await body()
188192
} catch {
189193
print(error)
190194
}
191195
}
192196

197+
@MainActor
193198
private func addOsLog(toBundle bundlePath: URL) async throws {
194199
#if os(macOS)
195200
reportProgress(.collectingLogMessages(progress: 0), message: "Collecting log messages")
@@ -227,6 +232,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
227232
#endif
228233
}
229234

235+
@MainActor
230236
private func addCrashLogs(toBundle bundlePath: URL) throws {
231237
#if os(macOS)
232238
reportProgress(.collectingCrashReports, message: "Collecting crash reports")
@@ -252,6 +258,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
252258
#endif
253259
}
254260

261+
@MainActor
255262
private func addSwiftVersion(toBundle bundlePath: URL) async throws {
256263
let outputFileUrl = bundlePath.appendingPathComponent("swift-versions.txt")
257264
FileManager.default.createFile(atPath: outputFileUrl.path, contents: nil)
@@ -283,10 +290,12 @@ public struct DiagnoseCommand: AsyncParsableCommand {
283290
}
284291
}
285292

293+
@MainActor
286294
private func reportProgress(_ state: DiagnoseProgressState, message: String) {
287295
progressBar?.update(step: Int(state.progress * 100), total: 100, text: message)
288296
}
289297

298+
@MainActor
290299
public func run() async throws {
291300
print(
292301
"""
@@ -303,7 +312,10 @@ public struct DiagnoseCommand: AsyncParsableCommand {
303312
"""
304313
)
305314

306-
progressBar = PercentProgressAnimation(stream: stderrStream, header: "Diagnosing sourcekit-lsp issues")
315+
progressBar = PercentProgressAnimation(
316+
stream: stderrStreamConcurrencySafe,
317+
header: "Diagnosing sourcekit-lsp issues"
318+
)
307319

308320
let dateFormatter = ISO8601DateFormatter()
309321
dateFormatter.timeZone = NSTimeZone.local
@@ -342,6 +354,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
342354

343355
}
344356

357+
@MainActor
345358
private func reduce(
346359
requestInfo: RequestInfo,
347360
toolchain: Toolchain?,

Sources/Diagnose/MergeSwiftFiles.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extension RequestInfo {
1717
/// Check if the issue reproduces when merging all `.swift` input files into a single file.
1818
///
1919
/// Returns `nil` if the issue didn't reproduce with all `.swift` files merged.
20+
@MainActor
2021
func mergeSwiftFiles(
2122
using executor: SourceKitRequestExecutor,
2223
progressUpdate: (_ progress: Double, _ message: String) -> Void

Sources/Diagnose/ReduceCommand.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import var TSCBasic.stderrStream
2020
import class TSCUtility.PercentProgressAnimation
2121

2222
public struct ReduceCommand: AsyncParsableCommand {
23-
public static var configuration: CommandConfiguration = CommandConfiguration(
23+
public static let configuration: CommandConfiguration = CommandConfiguration(
2424
commandName: "reduce",
2525
abstract: "Reduce a single sourcekitd crash",
2626
shouldDisplay: false
@@ -56,6 +56,7 @@ public struct ReduceCommand: AsyncParsableCommand {
5656
private var nsPredicate: NSPredicate? { nil }
5757
#endif
5858

59+
@MainActor
5960
var toolchain: Toolchain? {
6061
get async throws {
6162
if let toolchainOverride {
@@ -68,6 +69,7 @@ public struct ReduceCommand: AsyncParsableCommand {
6869

6970
public init() {}
7071

72+
@MainActor
7173
public func run() async throws {
7274
guard let sourcekitd = try await toolchain?.sourcekitd else {
7375
throw ReductionError("Unable to find sourcekitd.framework")

Sources/Diagnose/ReduceFrontendCommand.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import var TSCBasic.stderrStream
2020
import class TSCUtility.PercentProgressAnimation
2121

2222
public struct ReduceFrontendCommand: AsyncParsableCommand {
23-
public static var configuration: CommandConfiguration = CommandConfiguration(
23+
public static let configuration: CommandConfiguration = CommandConfiguration(
2424
commandName: "reduce-frontend",
2525
abstract: "Reduce a single swift-frontend crash",
2626
shouldDisplay: false
@@ -64,6 +64,7 @@ public struct ReduceFrontendCommand: AsyncParsableCommand {
6464
)
6565
var frontendArgs: [String]
6666

67+
@MainActor
6768
var toolchain: Toolchain? {
6869
get async throws {
6970
if let toolchainOverride {
@@ -76,6 +77,7 @@ public struct ReduceFrontendCommand: AsyncParsableCommand {
7677

7778
public init() {}
7879

80+
@MainActor
7981
public func run() async throws {
8082
guard let sourcekitd = try await toolchain?.sourcekitd else {
8183
throw ReductionError("Unable to find sourcekitd.framework")
@@ -84,7 +86,10 @@ public struct ReduceFrontendCommand: AsyncParsableCommand {
8486
throw ReductionError("Unable to find swift-frontend")
8587
}
8688

87-
let progressBar = PercentProgressAnimation(stream: stderrStream, header: "Reducing swift-frontend crash")
89+
let progressBar = PercentProgressAnimation(
90+
stream: stderrStream,
91+
header: "Reducing swift-frontend crash"
92+
)
8893

8994
let executor = OutOfProcessSourceKitRequestExecutor(
9095
sourcekitd: sourcekitd.asURL,

0 commit comments

Comments
 (0)