Skip to content

Commit 70455c3

Browse files
committed
[Dependency Scanning] Use a synchronous dispatch queue for accesses to the scanner
1 parent ab7e09f commit 70455c3

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
/// An API to allow clients to accumulate InterModuleDependencyGraphs across mutiple main externalModules/targets
4949
/// into a single collection of discovered externalModules.
5050
func mergeModules(from dependencyGraph: InterModuleDependencyGraph) throws {
51-
try self.lock.withLock {
51+
try queue.sync {
5252
for (moduleId, moduleInfo) in dependencyGraph.modules {
5353
try InterModuleDependencyGraph.mergeModule(moduleId, moduleInfo, into: &externalModules)
5454
}
@@ -58,7 +58,7 @@
5858
// This is a backwards-compatibility shim to handle existing ModuleInfoMap-based API
5959
// used by SwiftPM
6060
func mergeModules(from moduleInfoMap: ModuleInfoMap) throws {
61-
try self.lock.withLock {
61+
try queue.sync {
6262
for (moduleId, moduleInfo) in moduleInfoMap {
6363
try InterModuleDependencyGraph.mergeModule(moduleId, moduleInfo, into: &externalModules)
6464
}

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import TSCBasic
14+
import Foundation
1415

1516
// An inter-module dependency oracle, responsible for responding to queries about
1617
// dependencies of a given module, caching already-discovered dependencies along the way.
@@ -42,26 +43,28 @@ public class InterModuleDependencyOracle {
4243
swiftScanLibInstance = try SwiftScan(dylib: swiftScanLibPath)
4344
}
4445

45-
public func getDependencies(workingDirectory: AbsolutePath,
46-
commandLine: [String]) throws -> InterModuleDependencyGraph {
47-
try self.lock.withLock {
46+
@_spi(Testing) public func getDependencies(workingDirectory: AbsolutePath,
47+
commandLine: [String])
48+
throws -> InterModuleDependencyGraph {
49+
try queue.sync {
4850
return try swiftScanLibInstance.scanDependencies(workingDirectory: workingDirectory,
4951
invocationCommand: commandLine)
5052
}
5153
}
5254

53-
public func getBatchDependencies(workingDirectory: AbsolutePath,
54-
commandLine: [String],
55-
batchInfos: [BatchScanModuleInfo])
55+
func getBatchDependencies(workingDirectory: AbsolutePath,
56+
commandLine: [String],
57+
batchInfos: [BatchScanModuleInfo])
5658
throws -> [ModuleDependencyId: [InterModuleDependencyGraph]] {
57-
try self.lock.withLock {
59+
try queue.sync {
5860
return try swiftScanLibInstance.batchScanDependencies(workingDirectory: workingDirectory,
5961
invocationCommand: commandLine,
6062
batchInfos: batchInfos)
6163
}
6264
}
6365

64-
internal let lock = Lock()
66+
/// Queue to sunchronize accesses to the scanner
67+
internal let queue = DispatchQueue(label: "org.swift.swift-driver.swift-scan")
6568

6669
/// A reference to an instance of the compiler's libSwiftScan shared library
6770
private let swiftScanLibInstance: SwiftScan
@@ -74,8 +77,8 @@ public class InterModuleDependencyOracle {
7477
/// from the concept of a placeholder module so we should be able to get rid of this in the future.
7578
internal var externalModules: ModuleInfoMap = [:]
7679
/// Query the ModuleInfo of a module with a given ID
77-
public func getExternalModuleInfo(of moduleId: ModuleDependencyId) -> ModuleInfo? {
78-
self.lock.withLock {
80+
@_spi(Testing) public func getExternalModuleInfo(of moduleId: ModuleDependencyId) -> ModuleInfo? {
81+
queue.sync {
7982
return externalModules[moduleId]
8083
}
8184
}

0 commit comments

Comments
 (0)