Skip to content

Commit 321373c

Browse files
Compute cache key when needed
1 parent 4b99005 commit 321373c

File tree

6 files changed

+19
-34
lines changed

6 files changed

+19
-34
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ public struct Driver {
207207
/// CacheKey for bridging header
208208
var bridgingHeaderCacheKey: String? = nil
209209

210-
/// CacheKey for swift interface
211-
var swiftInterfaceCacheKey: String? = nil
212-
/// CacheKey for private swift interface
213-
var privateSwiftInterfaceCacheKey: String? = nil
214-
215210
/// The set of input files
216211
@_spi(Testing) public let inputFiles: [TypedVirtualPath]
217212

Sources/SwiftDriver/Jobs/CompileJob.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,6 @@ extension Driver {
394394
displayInputs = primaryInputs
395395
}
396396

397-
// Assume swiftinterface file is always the supplementary output for first input file.
398-
try computeCacheKeyForInterface(mainInput: displayInputs[0], outputs: outputs, commandLine: commandLine)
399-
400397
return Job(
401398
moduleName: moduleOutputInfo.name,
402399
kind: .compile,

Sources/SwiftDriver/Jobs/EmitModuleJob.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ extension Driver {
118118
commandLine.appendPath(abiPath.file)
119119
outputs.append(abiPath)
120120
}
121-
// Assume swiftinterface file is always the supplementary output for first input file.
122-
try computeCacheKeyForInterface(mainInput: inputs[0], outputs: outputs, commandLine: commandLine)
123121
return Job(
124122
moduleName: moduleOutputInfo.name,
125123
kind: .emitModule,

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -671,23 +671,6 @@ extension Driver {
671671
try dependencyPlanner.resolveBridgingHeaderDependencies(inputs: &inputs, commandLine: &commandLine)
672672
}
673673

674-
/// Compute the cache key for swift interface outputs.
675-
mutating func computeCacheKeyForInterface(mainInput: TypedVirtualPath,
676-
outputs: [TypedVirtualPath],
677-
commandLine: [Job.ArgTemplate]) throws {
678-
if enableCaching {
679-
func computeKeyForInterface(forPrivate: Bool) throws -> String? {
680-
let outputType: FileType =
681-
forPrivate ? .privateSwiftInterface : .swiftInterface
682-
let isNeeded = outputs.contains { $0.type == outputType }
683-
guard isNeeded else { return nil }
684-
return try interModuleDependencyOracle.computeCacheKeyForOutput(kind: outputType, commandLine: commandLine, input: mainInput.fileHandle)
685-
}
686-
swiftInterfaceCacheKey = try computeKeyForInterface(forPrivate: false)
687-
privateSwiftInterfaceCacheKey = try computeKeyForInterface(forPrivate: true)
688-
}
689-
}
690-
691674
/// In Explicit Module Build mode, distinguish between main module jobs and intermediate dependency build jobs,
692675
/// such as Swift modules built from .swiftmodule files and Clang PCMs.
693676
public func isExplicitMainModuleJob(job: Job) -> Bool {

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,9 @@ extension Driver {
564564
let mergeInterfaceOutputs = emitModuleJob.outputs.filter { $0.type == outputType }
565565
assert(mergeInterfaceOutputs.count == 1,
566566
"Merge module job should only have one swiftinterface output")
567-
let job = try verifyModuleInterfaceJob(interfaceInput: mergeInterfaceOutputs[0], optIn: optIn)
567+
let job = try verifyModuleInterfaceJob(interfaceInput: mergeInterfaceOutputs[0],
568+
emitModuleJob: emitModuleJob,
569+
optIn: optIn)
568570
addJob(job)
569571
}
570572
try addVerifyJob(forPrivate: false)

Sources/SwiftDriver/Jobs/VerifyModuleInterfaceJob.swift

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

1313
extension Driver {
14-
mutating func verifyModuleInterfaceJob(interfaceInput: TypedVirtualPath, optIn: Bool) throws -> Job {
14+
func computeCacheKeyForInterface(emitModuleJob: Job,
15+
interfaceKind: FileType) throws -> String? {
16+
assert(interfaceKind == .swiftInterface || interfaceKind == .privateSwiftInterface,
17+
"only expect interface output kind")
18+
let isNeeded = emitModuleJob.outputs.contains { $0.type == interfaceKind }
19+
guard enableCaching && isNeeded else { return nil }
20+
21+
// Assume swiftinterface file is always the supplementary output for first input file.
22+
let mainInput = emitModuleJob.inputs[0]
23+
return try interModuleDependencyOracle.computeCacheKeyForOutput(kind: interfaceKind,
24+
commandLine: emitModuleJob.commandLine,
25+
input: mainInput.fileHandle)
26+
}
27+
28+
mutating func verifyModuleInterfaceJob(interfaceInput: TypedVirtualPath, emitModuleJob: Job, optIn: Bool) throws -> Job {
1529
var commandLine: [Job.ArgTemplate] = swiftCompilerPrefixArgs.map { Job.ArgTemplate.flag($0) }
1630
var inputs: [TypedVirtualPath] = [interfaceInput]
1731
commandLine.appendFlags("-frontend", "-typecheck-module-from-interface")
@@ -28,11 +42,7 @@ extension Driver {
2842

2943
if parsedOptions.contains(.driverExplicitModuleBuild) {
3044
commandLine.appendFlag("-explicit-interface-module-build")
31-
if let key = swiftInterfaceCacheKey, interfaceInput.type == .swiftInterface {
32-
commandLine.appendFlag("-input-file-key")
33-
commandLine.appendFlag(key)
34-
}
35-
if let key = privateSwiftInterfaceCacheKey, interfaceInput.type == .privateSwiftInterface {
45+
if let key = try computeCacheKeyForInterface(emitModuleJob: emitModuleJob, interfaceKind: interfaceInput.type) {
3646
commandLine.appendFlag("-input-file-key")
3747
commandLine.appendFlag(key)
3848
}

0 commit comments

Comments
 (0)