Skip to content

Commit 4f7ea25

Browse files
authored
Merge pull request #848 from artemcm/ScannerCapturesInitialPCMArgs
[Dependency Scanning] Adapt to changes in dependenncy scanner to capture initial PCM arguments
2 parents 06b4c91 + 8c55a56 commit 4f7ea25

File tree

7 files changed

+50
-25
lines changed

7 files changed

+50
-25
lines changed

Sources/CSwiftScan/include/swiftscan_header.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ typedef struct {
134134
(*swiftscan_clang_detail_get_context_hash)(swiftscan_module_details_t);
135135
swiftscan_string_set_t *
136136
(*swiftscan_clang_detail_get_command_line)(swiftscan_module_details_t);
137+
swiftscan_string_set_t *
138+
(*swiftscan_clang_detail_get_captured_pcm_args)(swiftscan_module_details_t);
137139

138140
//=== Batch Scan Input Functions ------------------------------------------===//
139141
swiftscan_batch_scan_input_t *

Sources/SwiftDriver/ExplicitModuleBuilds/ClangVersionedDependencyResolution.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ internal extension Driver {
5454
return moduleInfos
5555
}.reduce([], +)
5656

57+
guard !batchScanInputList.isEmpty else {
58+
// If no new re-scans are needed, we are done here.
59+
return
60+
}
61+
5762
// Batch scan all clang modules for each discovered new, unique set of PCMArgs, per module
5863
let moduleVersionedGraphMap: [ModuleDependencyId: [InterModuleDependencyGraph]] =
5964
try performBatchDependencyScan(moduleInfos: batchScanInputList)
@@ -142,7 +147,7 @@ private extension InterModuleDependencyGraph {
142147
// captured in the described dependencies of this module. Only re-scan at PCMArgs not
143148
// already captured.
144149
let alreadyCapturedPCMArgs =
145-
clangModuleDetails.dependenciesCapturedPCMArgs ?? Set<[String]>()
150+
clangModuleDetails.capturedPCMArgs ?? Set<[String]>()
146151
let newPCMArgSet = pathPCMArtSet.filter { !alreadyCapturedPCMArgs.contains($0) }
147152
// Add current path's PCMArgs to the SetMap and stop traversal
148153
if pcmArgSetMap[moduleId] != nil {
@@ -183,10 +188,10 @@ private extension InterModuleDependencyGraph {
183188
throw Driver.Error.malformedModuleDependency(moduleId.moduleName,
184189
"no Clang `details` object")
185190
}
186-
if clangModuleDetails.dependenciesCapturedPCMArgs == nil {
187-
clangModuleDetails.dependenciesCapturedPCMArgs = Set<[String]>()
191+
if clangModuleDetails.capturedPCMArgs == nil {
192+
clangModuleDetails.capturedPCMArgs = Set<[String]>()
188193
}
189-
newPCMArgs.forEach { clangModuleDetails.dependenciesCapturedPCMArgs!.insert($0) }
194+
newPCMArgs.forEach { clangModuleDetails.capturedPCMArgs!.insert($0) }
190195
modules[moduleId]!.details = .clang(clangModuleDetails)
191196
}
192197
}

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ extension InterModuleDependencyGraph {
184184

185185
// As far as their dependencies go, these module infos are identical
186186
if firstInfo.directDependencies == secondInfo.directDependencies,
187-
firstDetails.dependenciesCapturedPCMArgs == secondDetails.dependenciesCapturedPCMArgs,
187+
firstDetails.capturedPCMArgs == secondDetails.capturedPCMArgs,
188188
firstInfo.sourceFiles == secondInfo.sourceFiles {
189189
return firstInfo
190190
}
@@ -198,15 +198,15 @@ extension InterModuleDependencyGraph {
198198
let secondModuleDependencies = secondInfo.directDependencies ?? []
199199
let combinedDependencies = Array(Set(firstModuleDependencies + secondModuleDependencies))
200200

201-
let firstModuleCapturedPCMArgs = firstDetails.dependenciesCapturedPCMArgs ?? Set<[String]>()
202-
let secondModuleCapturedPCMArgs = secondDetails.dependenciesCapturedPCMArgs ?? Set<[String]>()
201+
let firstModuleCapturedPCMArgs = firstDetails.capturedPCMArgs ?? Set<[String]>()
202+
let secondModuleCapturedPCMArgs = secondDetails.capturedPCMArgs ?? Set<[String]>()
203203
let combinedCapturedPCMArgs = firstModuleCapturedPCMArgs.union(secondModuleCapturedPCMArgs)
204204

205205
let combinedModuleDetails =
206206
ClangModuleDetails(moduleMapPath: firstDetails.moduleMapPath,
207-
dependenciesCapturedPCMArgs: combinedCapturedPCMArgs,
208207
contextHash: firstDetails.contextHash,
209-
commandLine: firstDetails.commandLine)
208+
commandLine: firstDetails.commandLine,
209+
capturedPCMArgs: combinedCapturedPCMArgs)
210210

211211
return ModuleInfo(modulePath: firstInfo.modulePath,
212212
sourceFiles: combinedSourceFiles,

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyGraph.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,24 +151,24 @@ public struct ClangModuleDetails: Codable {
151151
/// The path to the module map used to build this module.
152152
public var moduleMapPath: TextualVirtualPath
153153

154-
/// Set of PCM Arguments of depending modules which
155-
/// are covered by the directDependencies info of this module
156-
public var dependenciesCapturedPCMArgs: Set<[String]>?
157-
158154
/// clang-generated context hash
159155
public var contextHash: String
160156

161157
/// Options to the compile command
162158
public var commandLine: [String] = []
163159

160+
/// Set of PCM Arguments of depending modules which
161+
/// are covered by the directDependencies info of this module
162+
public var capturedPCMArgs: Set<[String]>?
163+
164164
public init(moduleMapPath: TextualVirtualPath,
165-
dependenciesCapturedPCMArgs: Set<[String]>?,
166165
contextHash: String,
167-
commandLine: [String]) {
166+
commandLine: [String],
167+
capturedPCMArgs: Set<[String]>?) {
168168
self.moduleMapPath = moduleMapPath
169-
self.dependenciesCapturedPCMArgs = dependenciesCapturedPCMArgs
170169
self.contextHash = contextHash
171170
self.commandLine = commandLine
171+
self.capturedPCMArgs = capturedPCMArgs
172172
}
173173
}
174174

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class InterModuleDependencyOracle {
8787
guard let swiftScan = swiftScanLibInstance else {
8888
fatalError("Attempting to serialize scanner cache with no scanner instance.")
8989
}
90-
if swiftScan.canLoadStoreScannerCache() {
90+
if swiftScan.canLoadStoreScannerCache {
9191
swiftScan.serializeScannerCache(to: path)
9292
}
9393
}
@@ -96,7 +96,7 @@ public class InterModuleDependencyOracle {
9696
guard let swiftScan = swiftScanLibInstance else {
9797
fatalError("Attempting to load scanner cache with no scanner instance.")
9898
}
99-
if swiftScan.canLoadStoreScannerCache() {
99+
if swiftScan.canLoadStoreScannerCache {
100100
return swiftScan.loadScannerCache(from: path)
101101
}
102102
return false
@@ -106,7 +106,7 @@ public class InterModuleDependencyOracle {
106106
guard let swiftScan = swiftScanLibInstance else {
107107
fatalError("Attempting to reset scanner cache with no scanner instance.")
108108
}
109-
if swiftScan.canLoadStoreScannerCache() {
109+
if swiftScan.canLoadStoreScannerCache {
110110
swiftScan.resetScannerCache()
111111
}
112112
}

Sources/SwiftDriver/SwiftScan/DependencyGraphBuilder.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,20 @@ private extension SwiftScan {
230230
using: api.swiftscan_clang_detail_get_command_line,
231231
fieldName: "clang_detail.commandLine")
232232

233+
let capturedPCMArgs : Set<[String]>?
234+
if clangDetailsHaveCapturedPCMArgs {
235+
let capturedArgs = try getStringArrayDetail(from: moduleDetailsRef,
236+
using: api.swiftscan_clang_detail_get_captured_pcm_args,
237+
fieldName: "clang_detail.capturedPCMArgs")
238+
capturedPCMArgs = [capturedArgs]
239+
} else {
240+
capturedPCMArgs = nil
241+
}
242+
233243
return ClangModuleDetails(moduleMapPath: moduleMapPath,
234-
dependenciesCapturedPCMArgs: nil,
235244
contextHash: contextHash,
236-
commandLine: commandLine)
245+
commandLine: commandLine,
246+
capturedPCMArgs: capturedPCMArgs)
237247
}
238248
}
239249

Sources/SwiftDriver/SwiftScan/SwiftScan.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,14 @@ internal final class SwiftScan {
208208
return resultGraphMap
209209
}
210210

211-
@_spi(Testing) public func canLoadStoreScannerCache() -> Bool {
212-
return api.swiftscan_scanner_cache_load != nil &&
213-
api.swiftscan_scanner_cache_serialize != nil &&
214-
api.swiftscan_scanner_cache_reset != nil
211+
@_spi(Testing) public var canLoadStoreScannerCache : Bool {
212+
api.swiftscan_scanner_cache_load != nil &&
213+
api.swiftscan_scanner_cache_serialize != nil &&
214+
api.swiftscan_scanner_cache_reset != nil
215+
}
216+
217+
@_spi(Testing) public var clangDetailsHaveCapturedPCMArgs : Bool {
218+
api.swiftscan_clang_detail_get_captured_pcm_args != nil
215219
}
216220

217221
func serializeScannerCache(to path: AbsolutePath) {
@@ -289,6 +293,10 @@ private extension swiftscan_functions_t {
289293
self.swiftscan_scanner_cache_reset =
290294
try loadOptional("swiftscan_scanner_cache_reset")
291295

296+
// Clang dependency captured PCM args
297+
self.swiftscan_clang_detail_get_captured_pcm_args =
298+
try loadOptional("swiftscan_clang_detail_get_captured_pcm_args")
299+
292300
// MARK: Required Methods
293301
func loadRequired<T>(_ symbol: String) throws -> T {
294302
guard let sym: T = dlsym(swiftscan, symbol: symbol) else {

0 commit comments

Comments
 (0)