Skip to content

Commit f6ff09b

Browse files
committed
Revert "Merge pull request #2094 from ahoppen/contextual-sourcekitd-request"
This reverts commit 188e174, reversing changes made to be5ae8c. Should be a fairly harmless change, but it's also quite large. Skipping for 6.2.
1 parent 020ca39 commit f6ff09b

32 files changed

+208
-462
lines changed

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ var targets: [Target] = [
429429
dependencies: [
430430
"BuildSystemIntegration",
431431
"CSKTestSupport",
432-
"Csourcekitd",
433432
"InProcessClient",
434433
"LanguageServerProtocol",
435434
"LanguageServerProtocolExtensions",

Sources/Diagnose/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ add_library(Diagnose STATIC
1919
StderrStreamConcurrencySafe.swift
2020
SwiftFrontendCrashScraper.swift
2121
Toolchain+SwiftFrontend.swift
22-
Toolchain+PluginPaths.swift
2322
TraceFromSignpostsCommand.swift)
2423

2524
set_target_properties(Diagnose PROPERTIES

Sources/Diagnose/DiagnoseCommand.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
package import ArgumentParser
1414
import Foundation
1515
import LanguageServerProtocolExtensions
16-
import SKLogging
1716
import SwiftExtensions
1817
import TSCExtensions
1918
import ToolchainRegistry
@@ -137,7 +136,6 @@ package struct DiagnoseCommand: AsyncParsableCommand {
137136
break
138137
} catch {
139138
// Reducing this request failed. Continue reducing the next one, maybe that one succeeds.
140-
logger.info("Reducing sourcekitd crash failed: \(error.forLogging)")
141139
}
142140
}
143141
}
@@ -175,7 +173,6 @@ package struct DiagnoseCommand: AsyncParsableCommand {
175173

176174
let executor = OutOfProcessSourceKitRequestExecutor(
177175
sourcekitd: sourcekitd,
178-
pluginPaths: toolchain.pluginPaths,
179176
swiftFrontend: crashInfo.swiftFrontend,
180177
reproducerPredicate: nil
181178
)
@@ -460,7 +457,6 @@ package struct DiagnoseCommand: AsyncParsableCommand {
460457
let requestInfo = requestInfo
461458
let executor = OutOfProcessSourceKitRequestExecutor(
462459
sourcekitd: sourcekitd,
463-
pluginPaths: toolchain.pluginPaths,
464460
swiftFrontend: swiftFrontend,
465461
reproducerPredicate: nil
466462
)

Sources/Diagnose/MergeSwiftFiles.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ extension RequestInfo {
3131
let compilerArgs = compilerArgs.filter { $0 != "-primary-file" && !$0.hasSuffix(".swift") } + ["$FILE"]
3232
let mergedRequestInfo = RequestInfo(
3333
requestTemplate: requestTemplate,
34-
contextualRequestTemplates: contextualRequestTemplates,
3534
offset: offset,
3635
compilerArgs: compilerArgs,
3736
fileContents: mergedFile

Sources/Diagnose/OSLogScraper.swift

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
#if canImport(OSLog)
1414
import OSLog
15-
import SKLogging
16-
import RegexBuilder
1715

1816
/// Reads oslog messages to find recent sourcekitd crashes.
1917
struct OSLogScraper {
@@ -47,90 +45,34 @@ struct OSLogScraper {
4745
#"subsystem CONTAINS "sourcekit-lsp" AND composedMessage CONTAINS "sourcekitd crashed" AND category = %@"#,
4846
logCategory
4947
)
50-
enum LogSection {
51-
case request
52-
case fileContents
53-
case contextualRequest
54-
}
55-
var section = LogSection.request
48+
var isInFileContentSection = false
5649
var request = ""
5750
var fileContents = ""
58-
var contextualRequests: [String] = []
59-
let sourcekitdCrashedRegex = Regex {
60-
"sourcekitd crashed ("
61-
OneOrMore(.digit)
62-
"/"
63-
OneOrMore(.digit)
64-
")"
65-
}
66-
let contextualRequestRegex = Regex {
67-
"Contextual request "
68-
OneOrMore(.digit)
69-
" / "
70-
OneOrMore(.digit)
71-
":"
72-
}
73-
7451
for entry in try getLogEntries(matching: predicate) {
7552
for line in entry.composedMessage.components(separatedBy: "\n") {
76-
if try sourcekitdCrashedRegex.wholeMatch(in: line) != nil {
53+
if line.starts(with: "sourcekitd crashed (") {
7754
continue
7855
}
7956
if line == "Request:" {
8057
continue
8158
}
8259
if line == "File contents:" {
83-
section = .fileContents
84-
continue
85-
}
86-
if line == "File contents:" {
87-
section = .fileContents
88-
continue
89-
}
90-
if try contextualRequestRegex.wholeMatch(in: line) != nil {
91-
section = .contextualRequest
92-
contextualRequests.append("")
60+
isInFileContentSection = true
9361
continue
9462
}
9563
if line == "--- End Chunk" {
9664
continue
9765
}
98-
switch section {
99-
case .request:
100-
request += line + "\n"
101-
case .fileContents:
66+
if isInFileContentSection {
10267
fileContents += line + "\n"
103-
case .contextualRequest:
104-
if !contextualRequests.isEmpty {
105-
contextualRequests[contextualRequests.count - 1] += line + "\n"
106-
} else {
107-
// Should never happen because we have appended at least one element to `contextualRequests` when switching
108-
// to the `contextualRequest` section.
109-
logger.fault("Dropping contextual request line: \(line)")
110-
}
68+
} else {
69+
request += line + "\n"
11170
}
11271
}
11372
}
11473

11574
var requestInfo = try RequestInfo(request: request)
116-
117-
let contextualRequestInfos = contextualRequests.compactMap { contextualRequest in
118-
orLog("Processsing contextual request") {
119-
try RequestInfo(request: contextualRequest)
120-
}
121-
}.filter { contextualRequest in
122-
if contextualRequest.fileContents != requestInfo.fileContents {
123-
logger.error("Contextual request concerns a different file than the crashed request. Ignoring it")
124-
return false
125-
}
126-
return true
127-
}
128-
requestInfo.contextualRequestTemplates = contextualRequestInfos.map(\.requestTemplate)
129-
if requestInfo.compilerArgs.isEmpty {
130-
requestInfo.compilerArgs = contextualRequestInfos.last(where: { !$0.compilerArgs.isEmpty })?.compilerArgs ?? []
131-
}
13275
requestInfo.fileContents = fileContents
133-
13476
return requestInfo
13577
}
13678

Sources/Diagnose/ReduceCommand.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
package import ArgumentParser
1414
import Foundation
15-
import SourceKitD
1615
import ToolchainRegistry
1716

1817
import struct TSCBasic.AbsolutePath
@@ -69,16 +68,12 @@ package struct ReduceCommand: AsyncParsableCommand {
6968

7069
@MainActor
7170
package func run() async throws {
72-
guard let toolchain = try await toolchain else {
73-
throw GenericError("Unable to find toolchain")
74-
}
75-
guard let sourcekitd = toolchain.sourcekitd else {
71+
guard let sourcekitd = try await toolchain?.sourcekitd else {
7672
throw GenericError("Unable to find sourcekitd.framework")
7773
}
78-
guard let swiftFrontend = toolchain.swiftFrontend else {
74+
guard let swiftFrontend = try await toolchain?.swiftFrontend else {
7975
throw GenericError("Unable to find sourcekitd.framework")
8076
}
81-
let pluginPaths = toolchain.pluginPaths
8277

8378
let progressBar = PercentProgressAnimation(stream: stderrStreamConcurrencySafe, header: "Reducing sourcekitd issue")
8479

@@ -87,7 +82,6 @@ package struct ReduceCommand: AsyncParsableCommand {
8782

8883
let executor = OutOfProcessSourceKitRequestExecutor(
8984
sourcekitd: sourcekitd,
90-
pluginPaths: pluginPaths,
9185
swiftFrontend: swiftFrontend,
9286
reproducerPredicate: nsPredicate
9387
)
@@ -102,6 +96,6 @@ package struct ReduceCommand: AsyncParsableCommand {
10296
try reduceRequestInfo.fileContents.write(to: reducedSourceFile, atomically: true, encoding: .utf8)
10397

10498
print("Reduced Request:")
105-
print(try reduceRequestInfo.requests(for: reducedSourceFile).joined(separator: "\n\n\n\n"))
99+
print(try reduceRequestInfo.request(for: reducedSourceFile))
106100
}
107101
}

Sources/Diagnose/ReduceFrontendCommand.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ package struct ReduceFrontendCommand: AsyncParsableCommand {
9090

9191
let executor = OutOfProcessSourceKitRequestExecutor(
9292
sourcekitd: sourcekitd,
93-
pluginPaths: nil,
9493
swiftFrontend: swiftFrontend,
9594
reproducerPredicate: nsPredicate
9695
)

Sources/Diagnose/ReproducerBundle.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ func makeReproducerBundle(for requestInfo: RequestInfo, toolchain: Toolchain, bu
4040
+ requestInfo.compilerArgs.replacing(["$FILE"], with: ["./input.swift"]).joined(separator: " \\\n")
4141
try command.write(to: bundlePath.appendingPathComponent("command.sh"), atomically: true, encoding: .utf8)
4242
} else {
43-
let requests = try requestInfo.requests(for: bundlePath.appendingPathComponent("input.swift"))
44-
for (index, request) in requests.enumerated() {
45-
try request.write(
46-
to: bundlePath.appendingPathComponent("request-\(index).yml"),
47-
atomically: true,
48-
encoding: .utf8
49-
)
50-
}
43+
let request = try requestInfo.request(for: URL(fileURLWithPath: "/input.swift"))
44+
try request.write(
45+
to: bundlePath.appendingPathComponent("request.yml"),
46+
atomically: true,
47+
encoding: .utf8
48+
)
5149
}
5250
for compilerArg in requestInfo.compilerArgs {
5351
// Find the first slash so we are also able to copy files from eg.

0 commit comments

Comments
 (0)