Skip to content

Commit 066c993

Browse files
author
David Ungar
committed
Generalize read interface to SourceFileDepGraph
1 parent ba6efef commit 066c993

File tree

7 files changed

+246
-81
lines changed

7 files changed

+246
-81
lines changed

Sources/SwiftDriver/IncrementalCompilation/DependencyKey.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@ public struct DependencyKey: Hashable, CustomStringConvertible {
152152
/// available from this node.
153153
case incrementalExternalDependency(ExternalDependency)
154154

155-
var externalDependency: ExternalDependency? {
155+
var externalDependency: (ExternalDependency, isIncremental: Bool)? {
156156
switch self {
157157
case let .externalDepend(externalDependency):
158-
return externalDependency
158+
return (externalDependency, isIncremental: false)
159+
case let .incrementalExternalDependency(externalDependency):
160+
return (externalDependency, isIncremental: true)
159161
default:
160162
return nil}
161163
}

Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public class IncrementalCompilationState {
7979
outOfDateBuildRecord,
8080
outputFileMap,
8181
&driver,
82-
self.reporter)
82+
self.reporter,
83+
isCrossModuleIncrementalBuildEnabled: isCrossModuleIncrementalBuildEnabled)
8384
else {
8485
return nil
8586
}
@@ -106,15 +107,16 @@ public class IncrementalCompilationState {
106107
_ outOfDateBuildRecord: BuildRecord,
107108
_ outputFileMap: OutputFileMap,
108109
_ driver: inout Driver,
109-
_ reporter: Reporter?
110+
_ reporter: Reporter?,
111+
isCrossModuleIncrementalBuildEnabled: Bool
110112
)
111113
-> (ModuleDependencyGraph,
112114
inputsHavingMalformedDependencySources: [TypedVirtualPath])?
113115
{
114116
let diagnosticEngine = driver.diagnosticEngine
115117
guard let (
116118
moduleDependencyGraph,
117-
inputsAndMalformedDependencySources: inputsAndMalformedDependencySources
119+
inputsAndMalformedSwiftDeps: inputsAndMalformedSwiftDeps
118120
) =
119121
ModuleDependencyGraph.buildInitialGraph(
120122
diagnosticEngine: diagnosticEngine,
@@ -124,20 +126,22 @@ public class IncrementalCompilationState {
124126
parsedOptions: &driver.parsedOptions,
125127
remarkDisabled: Diagnostic.Message.remark_incremental_compilation_has_been_disabled,
126128
reporter: reporter,
127-
fileSystem: driver.fileSystem)
129+
fileSystem: driver.fileSystem,
130+
isCrossModuleIncrementalBuildEnabled: isCrossModuleIncrementalBuildEnabled
131+
)
128132
else {
129133
return nil
130134
}
131135
// Preserve legacy behavior,
132136
// but someday, just ensure inputsAndMalformedDependencySources are compiled
133-
if let badDependencySource = inputsAndMalformedDependencySources.first?.1 {
137+
if let badSwiftDeps = inputsAndMalformedSwiftDeps.first?.1 {
134138
diagnosticEngine.emit(
135139
.remark_incremental_compilation_has_been_disabled(
136-
because: "malformed dependencies file '\(badDependencySource)'")
140+
because: "malformed dependencies file '\(badSwiftDeps)'")
137141
)
138142
return nil
139143
}
140-
let inputsHavingMalformedDependencySources = inputsAndMalformedDependencySources.map {$0.0}
144+
let inputsHavingMalformedDependencySources = inputsAndMalformedSwiftDeps.map {$0.0}
141145
return (moduleDependencyGraph,
142146
inputsHavingMalformedDependencySources: inputsHavingMalformedDependencySources)
143147
}
@@ -289,6 +293,7 @@ extension IncrementalCompilationState {
289293
alwaysRebuildDependents: Bool,
290294
reporter: IncrementalCompilationState.Reporter?
291295
) -> Set<TypedVirtualPath> {
296+
// Input == source file
292297
let changedInputs = Self.computeChangedInputs(
293298
groups: allGroups,
294299
buildRecordInfo: buildRecordInfo,
@@ -297,7 +302,15 @@ extension IncrementalCompilationState {
297302
fileSystem: fileSystem,
298303
reporter: reporter)
299304

300-
let externalDependents = computeExternallyDependentInputs(
305+
let externallyChangedInputs = computeExternallyChangedInputs(
306+
forIncrementalExternalDependencies: false,
307+
buildTime: outOfDateBuildRecord.buildTime,
308+
fileSystem: fileSystem,
309+
moduleDependencyGraph: moduleDependencyGraph,
310+
reporter: moduleDependencyGraph.reporter)
311+
312+
let incrementallyExternallyChangedInputs = computeExternallyChangedInputs(
313+
forIncrementalExternalDependencies: true,
301314
buildTime: outOfDateBuildRecord.buildTime,
302315
fileSystem: fileSystem,
303316
moduleDependencyGraph: moduleDependencyGraph,
@@ -311,7 +324,8 @@ extension IncrementalCompilationState {
311324

312325
// Combine to obtain the inputs that definitely must be recompiled.
313326
let definitelyRequiredInputs =
314-
Set(changedInputs.map({ $0.filePath }) + externalDependents +
327+
Set(changedInputs.map({ $0.filePath }) +
328+
externallyChangedInputs + incrementallyExternallyChangedInputs +
315329
inputsHavingMalformedDependencySources
316330
+ inputsMissingOutputs)
317331
if let reporter = reporter {
@@ -326,7 +340,7 @@ extension IncrementalCompilationState {
326340
// as each first wave job finished.
327341
let speculativeInputs = computeSpeculativeInputs(
328342
changedInputs: changedInputs,
329-
externalDependents: externalDependents,
343+
externalDependents: externallyChangedInputs,
330344
inputsMissingOutputs: Set(inputsMissingOutputs),
331345
moduleDependencyGraph: moduleDependencyGraph,
332346
alwaysRebuildDependents: alwaysRebuildDependents,
@@ -409,18 +423,22 @@ extension IncrementalCompilationState {
409423
}
410424

411425
/// Any files dependent on modified files from other modules must be compiled, too.
412-
private static func computeExternallyDependentInputs(
426+
private static func computeExternallyChangedInputs(
427+
forIncrementalExternalDependencies: Bool,
413428
buildTime: Date,
414429
fileSystem: FileSystem,
415430
moduleDependencyGraph: ModuleDependencyGraph,
416431
reporter: IncrementalCompilationState.Reporter?
417432
) -> [TypedVirtualPath] {
418433
var externalDependencySources = Set<ModuleDependencyGraph.DependencySource>()
419-
for extDep in moduleDependencyGraph.externalDependencies {
434+
let extDeps = forIncrementalExternalDependencies
435+
? moduleDependencyGraph.incrementalExternalDependencies
436+
: moduleDependencyGraph.externalDependencies
437+
for extDep in extDeps {
420438
let extModTime = extDep.file.flatMap {try? fileSystem.getFileInfo($0).modTime}
421439
?? Date.distantFuture
422440
if extModTime >= buildTime {
423-
for dependent in moduleDependencyGraph.untracedDependents(of: extDep) {
441+
for dependent in moduleDependencyGraph.untracedDependents(of: extDep, isIncremental: forIncrementalExternalDependencies) {
424442
guard let dependencySource = dependent.dependencySource else {
425443
fatalError("Dependent \(dependent) does not have dependencies file!")
426444
}

0 commit comments

Comments
 (0)