Skip to content

Commit 41237bf

Browse files
author
David Ungar
committed
Address review comments.
1 parent 72d9da7 commit 41237bf

File tree

3 files changed

+52
-23
lines changed

3 files changed

+52
-23
lines changed

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ import SwiftOptions
5454
self.creationPhase = phase
5555
}
5656

57-
@_spi(Testing) public func getRequiredSource(for input: TypedVirtualPath,
58-
function: String = #function,
59-
file: String = #file,
60-
line: Int = #line) -> DependencySource {
61-
guard let source = inputDependencySourceMap.getSourceIfKnown(for: input)
57+
@_spi(Testing) public func source(requiredFor input: TypedVirtualPath,
58+
function: String = #function,
59+
file: String = #file,
60+
line: Int = #line) -> DependencySource {
61+
guard let source = inputDependencySourceMap.sourceIfKnown(for: input)
6262
else {
6363
fatalError("\(input.file.basename) not found in inputDependencySourceMap, \(file):\(line) in \(function)")
6464
}
6565
return source
6666
}
6767

68-
@_spi(Testing) public func getNeededInput(for source: DependencySource) -> TypedVirtualPath? {
69-
guard let input = inputDependencySourceMap.getInputIfKnown(for: source)
68+
@_spi(Testing) public func input(neededFor source: DependencySource) -> TypedVirtualPath? {
69+
guard let input = inputDependencySourceMap.input(ifKnownFor: source)
7070
else {
7171
info.diagnosticEngine.emit(warning: "Failed to find source file for '\(source.file.basename)', recovering with a full rebuild. Next build will be incremental.")
7272
return nil
@@ -141,7 +141,7 @@ extension ModuleDependencyGraph {
141141
return TransitivelyInvalidatedInputSet()
142142
}
143143
return collectInputsRequiringCompilationAfterProcessing(
144-
dependencySource: getRequiredSource(for: input))
144+
dependencySource: source(requiredFor: input))
145145
}
146146
}
147147

@@ -163,14 +163,14 @@ extension ModuleDependencyGraph {
163163
/// speculatively scheduled in the first wave.
164164
func collectInputsInvalidatedBy(input: TypedVirtualPath
165165
) -> TransitivelyInvalidatedInputArray {
166-
let changedSource = getRequiredSource(for: input)
166+
let changedSource = source(requiredFor: input)
167167
let allDependencySourcesToRecompile =
168168
collectSwiftDepsUsing(dependencySource: changedSource)
169169

170170
return allDependencySourcesToRecompile.compactMap {
171171
depedencySource in
172172
guard depedencySource != changedSource else {return nil}
173-
let dependentInput = inputDependencySourceMap.getInputIfKnown(for: depedencySource)
173+
let dependentInput = inputDependencySourceMap.input(ifKnownFor: depedencySource)
174174
info.reporter?.report(
175175
"Found dependent of \(input.file.basename):", dependentInput)
176176
return dependentInput
@@ -190,7 +190,7 @@ extension ModuleDependencyGraph {
190190
/// Does the graph contain any dependency nodes for a given source-code file?
191191
func containsNodes(forSourceFile file: TypedVirtualPath) -> Bool {
192192
precondition(file.type == .swift)
193-
guard let source = inputDependencySourceMap.getSourceIfKnown(for: file) else {
193+
guard let source = inputDependencySourceMap.sourceIfKnown(for: file) else {
194194
return false
195195
}
196196
return containsNodes(forDependencySource: source)
@@ -203,7 +203,7 @@ extension ModuleDependencyGraph {
203203

204204
/// Returns: false on error
205205
func populateInputDependencySourceMap(
206-
`for` purpose: InputDependencySourceMap.AdditionPurpose
206+
for purpose: InputDependencySourceMap.AdditionPurpose
207207
) -> Bool {
208208
let ofm = info.outputFileMap
209209
let diags = info.diagnosticEngine
@@ -250,7 +250,7 @@ extension ModuleDependencyGraph {
250250
func collectInputsRequiringCompilation(byCompiling input: TypedVirtualPath
251251
) -> TransitivelyInvalidatedInputSet? {
252252
precondition(input.type == .swift)
253-
let dependencySource = getRequiredSource(for: input)
253+
let dependencySource = source(requiredFor: input)
254254
return collectInputsRequiringCompilationAfterProcessing(
255255
dependencySource: dependencySource)
256256
}
@@ -345,7 +345,7 @@ extension ModuleDependencyGraph {
345345
) -> TransitivelyInvalidatedInputSet? {
346346
var invalidatedInputs = TransitivelyInvalidatedInputSet()
347347
for invalidatedSwiftDeps in collectSwiftDepsUsingInvalidated(nodes: directlyInvalidatedNodes) {
348-
guard let invalidatedInput = getNeededInput(for: invalidatedSwiftDeps)
348+
guard let invalidatedInput = input(neededFor: invalidatedSwiftDeps)
349349
else {
350350
return nil
351351
}

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraphParts/InputDependencySourceMap.swift

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import Foundation
1212
import TSCBasic
1313

14+
/// Maps input source files to- and from- `DependencySource`s containing the swiftdeps paths.
15+
/// Deliberately at the level of specific intention, for clarity and to facilitate restructuring later.
1416
@_spi(Testing) public struct InputDependencySourceMap: Equatable {
1517

1618
/// Maps input files (e.g. .swift) to and from the DependencySource object.
@@ -26,21 +28,33 @@ import TSCBasic
2628
// replaced by a multi-map from swift files to dependency sources,
2729
// and a regular map from dependency sources to swift files -
2830
// since that direction really is one-to-one.
29-
31+
32+
/// Holds the mapping for now. To be replaced later.
3033
public typealias BiMap = BidirectionalMap<TypedVirtualPath, DependencySource>
3134
@_spi(Testing) public var biMap = BiMap()
3235
}
3336

3437
// MARK: - Accessing
3538
extension InputDependencySourceMap {
36-
@_spi(Testing) public func getSourceIfKnown(for input: TypedVirtualPath) -> DependencySource? {
39+
/// Find where the swiftdeps are stored for a given source file.
40+
///
41+
/// - Parameter input: A source file path
42+
/// - Returns: the corresponding `DependencySource`, or nil if none known.
43+
@_spi(Testing) public func sourceIfKnown(for input: TypedVirtualPath) -> DependencySource? {
3744
biMap[input]
3845
}
3946

40-
@_spi(Testing) public func getInputIfKnown(for source: DependencySource) -> TypedVirtualPath? {
47+
/// Find where the source file is for a given swiftdeps file.
48+
///
49+
/// - Parameter source: A `DependencySource` (containing a swiftdeps file)
50+
/// - Returns: the corresponding input source file, or nil if none known.
51+
@_spi(Testing) public func input(ifKnownFor source: DependencySource) -> TypedVirtualPath? {
4152
biMap[source]
4253
}
4354

55+
/// Enumerate the input <-> dependency source pairs to be serialized
56+
///
57+
/// - Parameter eachFn: a function to be called for each pair
4458
@_spi(Testing) public func enumerateToSerializePriors(
4559
_ eachFn: (TypedVirtualPath, DependencySource) -> Void
4660
) {
@@ -50,14 +64,29 @@ extension InputDependencySourceMap {
5064

5165
// MARK: - Populating
5266
extension InputDependencySourceMap {
67+
/// For structural modifications-to-come, reify the various reasons to add an entry.
5368
public enum AdditionPurpose {
54-
case mocking,
55-
buildingFromSwiftDeps,
56-
readingPriors,
57-
inputsAddedSincePriors }
69+
/// For unit testing
70+
case mocking
71+
72+
/// When building a graph from swiftDeps files without priors
73+
case buildingFromSwiftDeps
74+
75+
/// Deserializing the map stored with the priors
76+
case readingPriors
77+
78+
/// After reading the priors, used to add entries for any inputs that might not have been in the priors.
79+
case inputsAddedSincePriors
80+
}
81+
82+
/// Add a mapping to & from input source file to swiftDeps file path
83+
///
84+
/// - Parameter input: the source file path
85+
/// - Parameter dependencySource: the dependency source (holding the swiftdeps path)
86+
/// - Parameter why: the purpose for this addition. Will be used for future restructuring.
5887
@_spi(Testing) public mutating func addEntry(_ input: TypedVirtualPath,
5988
_ dependencySource: DependencySource,
60-
`for` _ : AdditionPurpose) {
89+
for why: AdditionPurpose) {
6190
assert(input.type == .swift && dependencySource.typedFile.type == .swiftDeps)
6291
biMap[input] = dependencySource
6392
}

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraphParts/Tracer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ extension ModuleDependencyGraph.Tracer {
121121
path.compactMap { node in
122122
node.dependencySource.map {
123123
source in
124-
graph.inputDependencySourceMap.getInputIfKnown(for: source).map {
124+
graph.inputDependencySourceMap.input(ifKnownFor: source).map {
125125
input in
126126
"\(node.key) in \(input.file.basename)"
127127
}

0 commit comments

Comments
 (0)