Skip to content

Commit 660ab9f

Browse files
author
David Ungar
committed
phases
1 parent 495e7e1 commit 660ab9f

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

Sources/SwiftDriver/IncrementalCompilation/InitialStateComputer.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ extension IncrementalCompilationState.InitialStateComputer {
167167
private func buildInitialGraphFromSwiftDepsAndCollectInputsInvalidatedByChangedExternals(
168168
) -> (ModuleDependencyGraph, Set<TypedVirtualPath>)?
169169
{
170-
let graph = ModuleDependencyGraph(self)
170+
let graph = ModuleDependencyGraph(self, .buildingWithoutAPrior)
171171
assert(outputFileMap.onlySourceFilesHaveSwiftDeps())
172172
guard graph.populateInputDependencySourceMap() else {
173173
return nil
@@ -215,9 +215,13 @@ extension IncrementalCompilationState.InitialStateComputer {
215215
batchJobFormer.formBatchedJobs(
216216
mandatoryCompileGroupsInOrder.flatMap {$0.allJobs()},
217217
showJobLifecycle: showJobLifecycle)
218+
219+
moduleDependencyGraph.phase = .buildingAfterEachCompilation
218220
return (skippedCompileGroups: [:],
219221
mandatoryJobsInOrder: mandatoryJobsInOrder)
220222
}
223+
moduleDependencyGraph.phase = .updatingAfterCompilation
224+
221225

222226
let skippedInputs = computeSkippedCompilationInputs(
223227
inputsInvalidatedByExternals: inputsInvalidatedByExternals,

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ import SwiftOptions
3535
/// For debugging, something to write out files for visualizing graphs
3636
let dotFileWriter: DependencyGraphDotFileWriter?
3737

38-
public init(_ info: IncrementalCompilationState.InitialStateComputer
38+
var phase: Phase
39+
40+
public init(_ info: IncrementalCompilationState.InitialStateComputer,
41+
_ phase: Phase
3942
) {
4043
self.info = info
4144
self.dotFileWriter = info.emitDependencyDotFileAfterEveryImport
4245
? DependencyGraphDotFileWriter(info)
4346
: nil
47+
self.phase = phase
4448
}
4549

4650
private func addMapEntry(_ input: TypedVirtualPath, _ dependencySource: DependencySource) {
@@ -65,6 +69,25 @@ import SwiftOptions
6569
}
6670
}
6771

72+
extension ModuleDependencyGraph {
73+
public enum Phase {
74+
case
75+
buildingWithoutAPrior,
76+
updatingFromAPrior,
77+
updatingAfterCompilation,
78+
buildingAfterEachCompilation
79+
80+
var isUpdating: Bool {
81+
switch self {
82+
case .buildingWithoutAPrior, .buildingAfterEachCompilation:
83+
return false
84+
case .updatingAfterCompilation, .updatingFromAPrior:
85+
return true
86+
}
87+
}
88+
}
89+
}
90+
6891
// MARK: - Building from swiftdeps
6992
extension ModuleDependencyGraph {
7093
/// Integrates `input` as needed and returns any inputs that were invalidated by external dependencies
@@ -462,7 +485,7 @@ extension ModuleDependencyGraph {
462485

463486
init(_ info: IncrementalCompilationState.InitialStateComputer) {
464487
self.fileSystem = info.fileSystem
465-
self.graph = ModuleDependencyGraph(info)
488+
self.graph = ModuleDependencyGraph(info, .updatingFromAPrior)
466489
}
467490

468491
func finalizeGraph() -> ModuleDependencyGraph {

Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ extension ModuleDependencyGraph {
942942
mock diagnosticEngine: DiagnosticsEngine,
943943
options: IncrementalCompilationState.Options = [ .verifyDependencyGraphAfterEveryImport ]
944944
) {
945-
self.init(IncrementalCompilationState.InitialStateComputer.mock())
945+
self.init(IncrementalCompilationState.InitialStateComputer.mock(), .buildingWithoutAPrior)
946946
}
947947

948948

0 commit comments

Comments
 (0)