Skip to content

Commit 4022e1a

Browse files
author
David Ungar
committed
Address review comments.
1 parent b567bec commit 4022e1a

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,21 +54,21 @@ 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? {
68+
@_spi(Testing) public func input(neededFor source: DependencySource) -> TypedVirtualPath? {
6969
guard let input =
7070
info.simulateGetInputFailure ? nil
71-
: inputDependencySourceMap.getInputIfKnown(for: source)
71+
: inputDependencySourceMap.input(ifKnownFor: source)
7272
else {
7373
info.diagnosticEngine.emit(warning: "Failed to find source file for '\(source.file.basename)', recovering with a full rebuild. Next build will be incremental.")
7474
info.reporter?.report(
@@ -145,7 +145,7 @@ extension ModuleDependencyGraph {
145145
return TransitivelyInvalidatedInputSet()
146146
}
147147
return collectInputsRequiringCompilationAfterProcessing(
148-
dependencySource: getRequiredSource(for: input))
148+
dependencySource: source(requiredFor: input))
149149
}
150150
}
151151

@@ -167,14 +167,14 @@ extension ModuleDependencyGraph {
167167
/// speculatively scheduled in the first wave.
168168
func collectInputsInvalidatedBy(input: TypedVirtualPath
169169
) -> TransitivelyInvalidatedInputArray {
170-
let changedSource = getRequiredSource(for: input)
170+
let changedSource = source(requiredFor: input)
171171
let allDependencySourcesToRecompile =
172172
collectSwiftDepsUsing(dependencySource: changedSource)
173173

174174
return allDependencySourcesToRecompile.compactMap {
175175
depedencySource in
176176
guard depedencySource != changedSource else {return nil}
177-
let dependentInput = inputDependencySourceMap.getInputIfKnown(for: depedencySource)
177+
let dependentInput = inputDependencySourceMap.input(ifKnownFor: depedencySource)
178178
info.reporter?.report(
179179
"Found dependent of \(input.file.basename):", dependentInput)
180180
return dependentInput
@@ -194,7 +194,7 @@ extension ModuleDependencyGraph {
194194
/// Does the graph contain any dependency nodes for a given source-code file?
195195
func containsNodes(forSourceFile file: TypedVirtualPath) -> Bool {
196196
precondition(file.type == .swift)
197-
guard let source = inputDependencySourceMap.getSourceIfKnown(for: file) else {
197+
guard let source = inputDependencySourceMap.sourceIfKnown(for: file) else {
198198
return false
199199
}
200200
return containsNodes(forDependencySource: source)
@@ -207,7 +207,7 @@ extension ModuleDependencyGraph {
207207

208208
/// Returns: false on error
209209
func populateInputDependencySourceMap(
210-
`for` purpose: InputDependencySourceMap.AdditionPurpose
210+
for purpose: InputDependencySourceMap.AdditionPurpose
211211
) -> Bool {
212212
let ofm = info.outputFileMap
213213
let diags = info.diagnosticEngine
@@ -254,7 +254,7 @@ extension ModuleDependencyGraph {
254254
func collectInputsRequiringCompilation(byCompiling input: TypedVirtualPath
255255
) -> TransitivelyInvalidatedInputSet? {
256256
precondition(input.type == .swift)
257-
let dependencySource = getRequiredSource(for: input)
257+
let dependencySource = source(requiredFor: input)
258258
return collectInputsRequiringCompilationAfterProcessing(
259259
dependencySource: dependencySource)
260260
}
@@ -341,7 +341,7 @@ extension ModuleDependencyGraph {
341341
) -> TransitivelyInvalidatedInputSet? {
342342
var invalidatedInputs = TransitivelyInvalidatedInputSet()
343343
for invalidatedSwiftDeps in collectSwiftDepsUsingInvalidated(nodes: directlyInvalidatedNodes) {
344-
guard let invalidatedInput = getNeededInput(for: invalidatedSwiftDeps)
344+
guard let invalidatedInput = input(neededFor: invalidatedSwiftDeps)
345345
else {
346346
return nil
347347
}

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)