Skip to content

Commit 762564e

Browse files
committed
[Gardening] Deprecate global SwiftScan diagnostic gathering
1 parent f65a248 commit 762564e

File tree

6 files changed

+47
-156
lines changed

6 files changed

+47
-156
lines changed

Sources/CSwiftScan/include/swiftscan_header.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,6 @@ typedef struct {
257257
(*swiftscan_import_set_create)(swiftscan_scanner_t, swiftscan_scan_invocation_t);
258258

259259
//=== Scanner Diagnostics -------------------------------------------------===//
260-
swiftscan_diagnostic_set_t*
261-
(*swiftscan_scanner_diagnostics_query)(swiftscan_scanner_t);
262-
void
263-
(*swiftscan_scanner_diagnostics_reset)(swiftscan_scanner_t);
264260
swiftscan_string_ref_t
265261
(*swiftscan_diagnostic_get_message)(swiftscan_diagnostic_info_t);
266262
swiftscan_diagnostic_severity_t

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ import var TSCBasic.localFileSystem
1717

1818
import Dispatch
1919

20-
// An inter-module dependency oracle, responsible for responding to queries about
21-
// dependencies of a given module, caching already-discovered dependencies along the way.
20+
// An inter-module dependency oracle, responsible for responding to queries of
21+
// dependencies of a given Swift source module.
2222
//
23-
// The oracle is currently implemented as a simple store of ModuleInfo nodes.
24-
// It is the responsibility of the Driver to populate and update
25-
// the store. It does so by invoking individual -scan-dependencies jobs and
26-
// accumulating resulting dependency graphs into the oracle's store.
23+
// The oracle is implemented as a simple wrapper over a 'SwiftScan' instance.
24+
// An oracle instance may be created by 'SwiftDriver' to be used for a given
25+
// build's queries (such as on a standalone 'swiftc' invocation), or provided
26+
// to the driver by a build system (e.g. swift-build) client when the oracle
27+
// is shared across multiple driver invocations.
2728
//
28-
// The design of the oracle's public API is meant to abstract that away,
29-
// allowing us to replace the underlying implementation in the future, with
30-
// a persistent-across-targets dependency scanning library.
29+
// The design of the oracle's public API is meant to abstract away the
30+
// underlying implementation of the interface with the libSwiftScan shared
31+
// library, allowing us to replace the underlying implementation in the future.
3132
//
32-
/// An abstraction of a cache and query-engine of inter-module dependencies
3333
public class InterModuleDependencyOracle {
3434
/// Allow external clients to instantiate the oracle
3535
public init() {}
@@ -58,12 +58,6 @@ public class InterModuleDependencyOracle {
5858
diagnostics: &diagnostics)
5959
}
6060

61-
@available(*, deprecated, message: "use verifyOrCreateScannerInstance(swiftScanLibPath:)")
62-
public func verifyOrCreateScannerInstance(fileSystem: FileSystem,
63-
swiftScanLibPath: AbsolutePath) throws {
64-
return try verifyOrCreateScannerInstance(swiftScanLibPath: swiftScanLibPath)
65-
}
66-
6761
/// Given a specified toolchain path, locate and instantiate an instance of the SwiftScan library
6862
public func verifyOrCreateScannerInstance(swiftScanLibPath: AbsolutePath?) throws {
6963
return try queue.sync {
@@ -94,13 +88,6 @@ public class InterModuleDependencyOracle {
9488
return swiftScan.hasBinarySwiftModuleHeaderModuleDependencies
9589
}
9690

97-
@_spi(Testing) public func supportsScannerDiagnostics() throws -> Bool {
98-
guard let swiftScan = swiftScanLibInstance else {
99-
fatalError("Attempting to query supported scanner API with no scanner instance.")
100-
}
101-
return swiftScan.supportsScannerDiagnostics
102-
}
103-
10491
@_spi(Testing) public func supportsBinaryModuleHeaderDependencies() throws -> Bool {
10592
guard let swiftScan = swiftScanLibInstance else {
10693
fatalError("Attempting to query supported scanner API with no scanner instance.")
@@ -151,18 +138,6 @@ public class InterModuleDependencyOracle {
151138
return swiftScan.supportsSeparateImportOnlyDependencise
152139
}
153140

154-
@_spi(Testing) public func getScannerDiagnostics() throws -> [ScannerDiagnosticPayload]? {
155-
guard let swiftScan = swiftScanLibInstance else {
156-
fatalError("Attempting to reset scanner cache with no scanner instance.")
157-
}
158-
guard swiftScan.supportsScannerDiagnostics else {
159-
return nil
160-
}
161-
let diags = try swiftScan.queryScannerDiagnostics()
162-
try swiftScan.resetScannerDiagnostics()
163-
return diags.isEmpty ? nil : diags
164-
}
165-
166141
public func getOrCreateCAS(pluginPath: AbsolutePath?, onDiskPath: AbsolutePath?, pluginOptions: [(String, String)]) throws -> SwiftScanCAS {
167142
guard let swiftScan = swiftScanLibInstance else {
168143
fatalError("Attempting to reset scanner cache with no scanner instance.")

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,7 @@ public extension Driver {
223223
moduleAliases: moduleOutputInfo.aliases,
224224
commandLine: command,
225225
diagnostics: &scanDiagnostics)
226-
} catch let DependencyScanningError.dependencyScanFailed(reason) {
227-
try emitGlobalScannerDiagnostics()
228-
throw DependencyScanningError.dependencyScanFailed(reason)
229226
}
230-
try emitGlobalScannerDiagnostics()
231227
} else {
232228
// Fallback to legacy invocation of the dependency scanner with
233229
// `swift-frontend -scan-dependencies -import-prescan`
@@ -262,17 +258,6 @@ public extension Driver {
262258
}
263259
}
264260

265-
mutating internal func emitGlobalScannerDiagnostics() throws {
266-
// We only emit global scanner-collected diagnostics as a legacy flow
267-
// when the scanner does not support per-scan diagnostic output
268-
guard try !interModuleDependencyOracle.supportsPerScanDiagnostics() else {
269-
return
270-
}
271-
if let diags = try interModuleDependencyOracle.getScannerDiagnostics() {
272-
try emitScannerDiagnostics(diags)
273-
}
274-
}
275-
276261
mutating func performDependencyScan(forVariantModule: Bool = false) throws -> InterModuleDependencyGraph {
277262
let scannerJob = try dependencyScanningJob(forVariantModule: forVariantModule)
278263
let forceResponseFiles = parsedOptions.hasArgument(.driverForceResponseFiles)
@@ -300,11 +285,7 @@ public extension Driver {
300285
commandLine: command,
301286
diagnostics: &scanDiagnostics)
302287
try emitScannerDiagnostics(scanDiagnostics)
303-
} catch let DependencyScanningError.dependencyScanFailed(reason) {
304-
try emitGlobalScannerDiagnostics()
305-
throw DependencyScanningError.dependencyScanFailed(reason)
306288
}
307-
try emitGlobalScannerDiagnostics()
308289
} else {
309290
// Fallback to legacy invocation of the dependency scanner with
310291
// `swift-frontend -scan-dependencies`

Sources/SwiftDriver/SwiftScan/SwiftScan.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,6 @@ private extension String {
258258
return api.swiftscan_swift_textual_detail_get_swift_source_import_module_dependencies != nil
259259
}
260260

261-
@_spi(Testing) public var supportsScannerDiagnostics : Bool {
262-
return api.swiftscan_scanner_diagnostics_query != nil &&
263-
api.swiftscan_scanner_diagnostics_reset != nil &&
264-
api.swiftscan_diagnostic_get_message != nil &&
265-
api.swiftscan_diagnostic_get_severity != nil &&
266-
api.swiftscan_diagnostics_set_dispose != nil
267-
}
268-
269261
@_spi(Testing) public var supportsCaching : Bool {
270262
#if os(Windows)
271263
// Caching is currently not supported on Windows hosts.
@@ -363,21 +355,6 @@ private extension String {
363355
return result
364356
}
365357

366-
@_spi(Testing) public func queryScannerDiagnostics() throws -> [ScannerDiagnosticPayload] {
367-
let diagnosticSetRefOrNull = api.swiftscan_scanner_diagnostics_query(scanner)
368-
guard let diagnosticSetRef = diagnosticSetRefOrNull else {
369-
// Seems heavy-handed to fail here
370-
// throw DependencyScanningError.dependencyScanFailed
371-
return []
372-
}
373-
defer { api.swiftscan_diagnostics_set_dispose(diagnosticSetRef) }
374-
return try mapToDriverDiagnosticPayload(diagnosticSetRef)
375-
}
376-
377-
@_spi(Testing) public func resetScannerDiagnostics() throws {
378-
api.swiftscan_scanner_diagnostics_reset(scanner)
379-
}
380-
381358
@_spi(Testing) public func canQuerySupportedArguments() -> Bool {
382359
return api.swiftscan_compiler_supported_arguments_query != nil &&
383360
api.swiftscan_string_set_dispose != nil
@@ -498,10 +475,6 @@ private extension swiftscan_functions_t {
498475
loadOptional("swiftscan_compiler_target_info_query_v2")
499476

500477
// Scanner diagnostic emission query
501-
self.swiftscan_scanner_diagnostics_query =
502-
loadOptional("swiftscan_scanner_diagnostics_query")
503-
self.swiftscan_scanner_diagnostics_reset =
504-
loadOptional("swiftscan_scanner_diagnostics_reset")
505478
self.swiftscan_diagnostic_get_message =
506479
loadOptional("swiftscan_diagnostic_get_message")
507480
self.swiftscan_diagnostic_get_severity =

Tests/SwiftDriverTests/CachingBuildTests.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -856,18 +856,8 @@ final class CachingBuildTests: XCTestCase {
856856
XCTAssertTrue(error is DependencyScanningError)
857857
}
858858

859-
let testDiagnostics: [ScannerDiagnosticPayload]
860-
if try dependencyOracle.supportsPerScanDiagnostics(),
861-
!scanDiagnostics.isEmpty {
862-
testDiagnostics = scanDiagnostics
863-
print("Using Per-Scan diagnostics")
864-
} else {
865-
testDiagnostics = try XCTUnwrap(dependencyOracle.getScannerDiagnostics())
866-
print("Using Scanner-Global diagnostics")
867-
}
868-
869-
XCTAssertEqual(testDiagnostics.count, 1)
870-
XCTAssertEqual(testDiagnostics[0].severity, .error)
859+
XCTAssertEqual(scanDiagnostics.count, 1)
860+
XCTAssertEqual(scanDiagnostics[0].severity, .error)
871861
}
872862
}
873863

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 35 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,8 +1836,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
18361836
let dependencyOracle = InterModuleDependencyOracle()
18371837
let scanLibPath = try XCTUnwrap(toolchain.lookupSwiftScanLib())
18381838
try dependencyOracle.verifyOrCreateScannerInstance(swiftScanLibPath: scanLibPath)
1839-
guard try dependencyOracle.supportsScannerDiagnostics() else {
1840-
throw XCTSkip("libSwiftScan does not support diagnostics query.")
1839+
guard try dependencyOracle.supportsPerScanDiagnostics() else {
1840+
throw XCTSkip("libSwiftScan does not support diagnostics queries.")
18411841
}
18421842

18431843
// Missing Swift Interface dependency
@@ -1871,16 +1871,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
18711871
try dependencyOracle.getDependencies(workingDirectory: path,
18721872
commandLine: scannerCommand,
18731873
diagnostics: &scanDiagnostics)
1874-
let potentialDiags: [ScannerDiagnosticPayload]?
1875-
if try dependencyOracle.supportsPerScanDiagnostics() {
1876-
potentialDiags = scanDiagnostics
1877-
print("Using Per-Scan diagnostics")
1878-
} else {
1879-
potentialDiags = try dependencyOracle.getScannerDiagnostics()
1880-
print("Using Scanner-Global diagnostics")
1881-
}
1882-
XCTAssertEqual(potentialDiags?.count, 5)
1883-
let diags = try XCTUnwrap(potentialDiags)
1874+
XCTAssertEqual(scanDiagnostics.count, 5)
1875+
let diags = try XCTUnwrap(scanDiagnostics)
18841876
let error = diags[0]
18851877
XCTAssertEqual(error.severity, .error)
18861878
if try dependencyOracle.supportsDiagnosticSourceLocations() {
@@ -1950,16 +1942,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
19501942
try dependencyOracle.getDependencies(workingDirectory: path,
19511943
commandLine: scannerCommand,
19521944
diagnostics: &scanDiagnostics)
1953-
let potentialDiags: [ScannerDiagnosticPayload]?
1954-
if try dependencyOracle.supportsPerScanDiagnostics() {
1955-
potentialDiags = scanDiagnostics
1956-
print("Using Per-Scan diagnostics")
1957-
} else {
1958-
potentialDiags = try dependencyOracle.getScannerDiagnostics()
1959-
print("Using Scanner-Global diagnostics")
1960-
}
1961-
XCTAssertEqual(potentialDiags?.count, 2)
1962-
let diags = try XCTUnwrap(potentialDiags)
1945+
XCTAssertEqual(scanDiagnostics.count, 2)
1946+
let diags = try XCTUnwrap(scanDiagnostics)
19631947
let error = diags[0]
19641948
XCTAssertEqual(error.severity, .error)
19651949
if try dependencyOracle.supportsDiagnosticSourceLocations() {
@@ -2287,48 +2271,40 @@ final class ExplicitModuleBuildTests: XCTestCase {
22872271
}
22882272
}
22892273
// Examine the results
2290-
if try dependencyOracle.supportsPerScanDiagnostics() {
2291-
for scanIndex in 0..<numFiles {
2292-
let diagnostics = scanDiagnostics[scanIndex]
2293-
XCTAssertEqual(diagnostics.count, 2)
2294-
// Diagnostic source locations came after per-scan diagnostics, only meaningful
2295-
// on this test code-path
2296-
if try dependencyOracle.supportsDiagnosticSourceLocations() {
2297-
let sourceLoc = try XCTUnwrap(diagnostics[0].sourceLocation)
2298-
XCTAssertEqual(sourceLoc.lineNumber, 1)
2299-
XCTAssertEqual(sourceLoc.columnNumber, 8)
2300-
let errorVariant1 =
2301-
"""
2302-
Unable to find module dependency: 'UnknownModule\(scanIndex)'
2303-
import UnknownModule\(scanIndex);
2304-
^
2305-
"""
2306-
let errorVariant2 =
2307-
"""
2308-
unable to resolve module dependency: 'UnknownModule\(scanIndex)'
2309-
import UnknownModule\(scanIndex);
2310-
^
2311-
"""
2312-
XCTAssertTrue(diagnostics[0].message == errorVariant1 || diagnostics[0].message == errorVariant2)
2313-
let noteSourceLoc = try XCTUnwrap(diagnostics[1].sourceLocation)
2314-
XCTAssertEqual(noteSourceLoc.lineNumber, 1)
2315-
XCTAssertEqual(noteSourceLoc.columnNumber, 8)
2316-
XCTAssertEqual(diagnostics[1].message,
2274+
for scanIndex in 0..<numFiles {
2275+
let diagnostics = scanDiagnostics[scanIndex]
2276+
XCTAssertEqual(diagnostics.count, 2)
2277+
// Diagnostic source locations came after per-scan diagnostics, only meaningful
2278+
// on this test code-path
2279+
if try dependencyOracle.supportsDiagnosticSourceLocations() {
2280+
let sourceLoc = try XCTUnwrap(diagnostics[0].sourceLocation)
2281+
XCTAssertEqual(sourceLoc.lineNumber, 1)
2282+
XCTAssertEqual(sourceLoc.columnNumber, 8)
2283+
let errorVariant1 =
2284+
"""
2285+
Unable to find module dependency: 'UnknownModule\(scanIndex)'
2286+
import UnknownModule\(scanIndex);
2287+
^
2288+
"""
2289+
let errorVariant2 =
2290+
"""
2291+
unable to resolve module dependency: 'UnknownModule\(scanIndex)'
2292+
import UnknownModule\(scanIndex);
2293+
^
2294+
"""
2295+
XCTAssertTrue(diagnostics[0].message == errorVariant1 || diagnostics[0].message == errorVariant2)
2296+
let noteSourceLoc = try XCTUnwrap(diagnostics[1].sourceLocation)
2297+
XCTAssertEqual(noteSourceLoc.lineNumber, 1)
2298+
XCTAssertEqual(noteSourceLoc.columnNumber, 8)
2299+
XCTAssertEqual(diagnostics[1].message,
23172300
"""
23182301
a dependency of main module 'testParallelDependencyScanningDiagnostics\(scanIndex)'
23192302
import UnknownModule\(scanIndex);
23202303
^
23212304
""")
2322-
} else {
2323-
XCTAssertEqual(diagnostics[0].message, "Unable to find module dependency: 'UnknownModule\(scanIndex)'")
2324-
XCTAssertEqual(diagnostics[1].message, "a dependency of main module 'testParallelDependencyScanningDiagnostics\(scanIndex)'")
2325-
}
2326-
}
2327-
} else {
2328-
let globalDiagnostics = try dependencyOracle.getScannerDiagnostics()
2329-
for scanIndex in 0..<numFiles {
2330-
XCTAssertTrue(globalDiagnostics?.contains(where: {$0.message == "Unable to find module dependency: 'UnknownModule\(scanIndex)'"}))
2331-
XCTAssertTrue(globalDiagnostics?.contains(where: {$0.message == "a dependency of main module 'testParallelDependencyScanningDiagnostics\(scanIndex)'"}))
2305+
} else {
2306+
XCTAssertEqual(diagnostics[0].message, "Unable to find module dependency: 'UnknownModule\(scanIndex)'")
2307+
XCTAssertEqual(diagnostics[1].message, "a dependency of main module 'testParallelDependencyScanningDiagnostics\(scanIndex)'")
23322308
}
23332309
}
23342310
}

0 commit comments

Comments
 (0)