Skip to content

Commit 484dfff

Browse files
author
David Ungar
committed
Start work on populating the out of date input map
1 parent db7515c commit 484dfff

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ public struct Driver {
197197
}
198198

199199
// Classify and collect all of the input files.
200-
self.inputFiles = try Self.collectInputFiles(&self.parsedOptions)
200+
let inputFiles = try Self.collectInputFiles(&self.parsedOptions)
201+
self.inputFiles = inputFiles
201202

202203
// Initialize an empty output file map, which will be populated when we start creating jobs.
203204
if let outputFileMapArg = parsedOptions.getLastArgument(.output_file_map)?.asSingle {
@@ -234,6 +235,7 @@ public struct Driver {
234235
outputFileMap: self.outputFileMap,
235236
compilerOutputType: self.compilerOutputType,
236237
moduleOutput: moduleOutput,
238+
inputFiles: inputFiles,
237239
diagnosticEngine: diagnosticEngine)
238240

239241
self.sdkPath = Self.computeSDKPath(&parsedOptions, compilerMode: compilerMode, toolchain: toolchain, diagnosticsEngine: diagnosticEngine)

Sources/SwiftDriver/Driver/IncrementalCompilation.swift renamed to Sources/SwiftDriver/Incremental Compilation/IncrementalCompilation.swift

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import TSCBasic
22
import TSCUtility
3+
import Foundation
34

5+
// FIXME: rename to something like IncrementalCompilationInitialState
46
public struct IncrementalCompilation {
57
public let showIncrementalBuildDecisions: Bool
68
public let shouldCompileIncrementally: Bool
79
public let buildRecordPath: VirtualPath?
810
public let outputBuildRecordForModuleOnlyBuild: Bool
11+
public let argsHash: String
12+
public let lastBuildTime: Date
13+
public let outOfDateMap: InputInfoMap?
14+
public let rebuildEverything: Bool
915

1016
public init(_ parsedOptions: inout ParsedOptions,
1117
compilerMode: CompilerMode,
1218
outputFileMap: OutputFileMap?,
1319
compilerOutputType: FileType?,
1420
moduleOutput: ModuleOutput?,
21+
inputFiles: [TypedVirtualPath],
1522
diagnosticEngine: DiagnosticsEngine
1623
) {
1724
let showIncrementalBuildDecisions = Self.getShowIncrementalBuildDecisions(&parsedOptions)
@@ -33,9 +40,29 @@ public struct IncrementalCompilation {
3340
// file for '-emit-module' only mode as well.
3441
self.outputBuildRecordForModuleOnlyBuild = self.buildRecordPath != nil &&
3542
moduleOutput?.isTopLevel ?? false
43+
44+
let argsHash = Self.computeArgsHash(parsedOptions)
45+
self.argsHash = argsHash
46+
let lastBuildTime = Date.init()
47+
self.lastBuildTime = lastBuildTime
48+
49+
if let buRP = buildRecordPath, shouldCompileIncrementally {
50+
self.outOfDateMap = InputInfoMap.populateOutOfDateMap(
51+
argsHash: argsHash,
52+
lastBuildTime: lastBuildTime,
53+
inputFiles: inputFiles,
54+
buildRecordPath: buRP,
55+
showIncrementalBuildDecisions: showIncrementalBuildDecisions)
56+
}
57+
else {
58+
self.outOfDateMap = nil
59+
}
60+
// FIXME: Distinguish errors from "file removed", which is benign.
61+
self.rebuildEverything = outOfDateMap == nil
3662
}
3763

38-
private static func getShowIncrementalBuildDecisions(_ parsedOptions: inout ParsedOptions) -> Bool {
64+
private static func getShowIncrementalBuildDecisions(_ parsedOptions: inout ParsedOptions)
65+
-> Bool {
3966
parsedOptions.hasArgument(.driver_show_incremental)
4067
}
4168

@@ -87,6 +114,16 @@ public struct IncrementalCompilation {
87114
? VirtualPath(path: partialBuildRecordPath.name + "~moduleonly")
88115
: partialBuildRecordPath
89116
}
117+
118+
static private func computeArgsHash(_ parsedOptionsArg: ParsedOptions) -> String {
119+
var parsedOptions = parsedOptionsArg
120+
let hashInput = parsedOptions
121+
.filter { $0.option.affectsIncrementalBuild && $0.option.kind != .input}
122+
.map {$0.option.spelling}
123+
.sorted()
124+
.joined()
125+
return SHA256(hashInput).digestString()
126+
}
90127
}
91128

92129

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import TSCBasic
2+
import TSCUtility
3+
import Foundation
4+
5+
/// Holds the info about inputs needed to plan incremenal compilation
6+
public struct InputInfoMap {
7+
public static func populateOutOfDateMap(
8+
argsHash: String,
9+
lastBuildTime: Date,
10+
inputFiles: [TypedVirtualPath],
11+
buildRecordPath: VirtualPath,
12+
showIncrementalBuildDecisions: Bool
13+
) -> Self? {
14+
stderrStream <<< "WARNING: incremental compilation not implemented yet\n"
15+
stderrStream.flush()
16+
return nil
17+
}
18+
}

0 commit comments

Comments
 (0)