Skip to content

Commit c679036

Browse files
author
David Ungar
committed
Move accessors
1 parent 45805a7 commit c679036

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,16 @@ import SwiftOptions
5858
function: String = #function,
5959
file: String = #file,
6060
line: Int = #line) -> DependencySource {
61-
guard let source = inputDependencySourceMap[input] else {
61+
guard let source = inputDependencySourceMap.getSource(for: input)
62+
else {
6263
fatalError("\(input.file.basename) not found in inputDependencySourceMap, \(file):\(line) in \(function)")
6364
}
6465
return source
6566
}
6667
@_spi(Testing) public func getInput(for source: DependencySource) -> TypedVirtualPath? {
6768
guard let input =
6869
info.simulateGetInputFailure ? nil
69-
: inputDependencySourceMap[source]
70+
: inputDependencySourceMap.getInput(for: source)
7071
else {
7172
info.diagnosticEngine.emit(warning: "Failed to find source file for '\(source.file.basename)', recovering with a full rebuild. Next build will be incremental.")
7273
info.reporter?.report(
@@ -172,10 +173,10 @@ extension ModuleDependencyGraph {
172173
return allDependencySourcesToRecompile.compactMap {
173174
depedencySource in
174175
guard depedencySource != changedSource else {return nil}
175-
let dependentSource = inputDependencySourceMap[depedencySource]
176+
let dependentInput = inputDependencySourceMap.getInput(for: depedencySource)
176177
info.reporter?.report(
177-
"Found dependent of \(input.file.basename):", dependentSource)
178-
return dependentSource
178+
"Found dependent of \(input.file.basename):", dependentInput)
179+
return dependentInput
179180
}
180181
}
181182

@@ -192,7 +193,7 @@ extension ModuleDependencyGraph {
192193
/// Does the graph contain any dependency nodes for a given source-code file?
193194
func containsNodes(forSourceFile file: TypedVirtualPath) -> Bool {
194195
precondition(file.type == .swift)
195-
guard let source = inputDependencySourceMap[file] else {
196+
guard let source = inputDependencySourceMap.getSource(for: file) else {
196197
return false
197198
}
198199
return containsNodes(forDependencySource: source)
@@ -803,7 +804,7 @@ extension ModuleDependencyGraph {
803804
}
804805
}
805806

806-
for (input, dependencySource) in graph.inputDependencySourceMap {
807+
graph.inputDependencySourceMap.enumerateToSerialize { input, dependencySource in
807808
self.addIdentifier(input.file.name)
808809
self.addIdentifier(dependencySource.file.name)
809810
}
@@ -948,7 +949,8 @@ extension ModuleDependencyGraph {
948949
}
949950
}
950951
}
951-
for (input, dependencySource) in graph.inputDependencySourceMap {
952+
graph.inputDependencySourceMap.enumerateToSerialize {
953+
input, dependencySource in
952954
serializer.stream.writeRecord(serializer.abbreviations[.mapNode]!) {
953955
$0.append(RecordID.mapNode)
954956
$0.append(serializer.lookupIdentifierCode(for: input.file.name))

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraphParts/InputDependencySourceMap.swift

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import Foundation
1212
import TSCBasic
1313

14-
@_spi(Testing) public struct InputDependencySourceMap: Equatable, Sequence {
14+
@_spi(Testing) public struct InputDependencySourceMap: Equatable {
1515

1616
/// Maps input files (e.g. .swift) to and from the DependencySource object.
1717
///
@@ -29,29 +29,30 @@ import TSCBasic
2929

3030
public typealias BiMap = BidirectionalMap<TypedVirtualPath, DependencySource>
3131
@_spi(Testing) public var biMap = BiMap()
32-
33-
@_spi(Testing) public subscript(input: TypedVirtualPath) -> DependencySource? {
34-
get { biMap[input] }
35-
set { biMap[input] = newValue }
36-
}
37-
38-
@_spi(Testing) public private(set) subscript(dependencySource: DependencySource) -> TypedVirtualPath? {
39-
get { biMap[dependencySource] }
40-
set { biMap[dependencySource] = newValue }
32+
33+
private mutating func addMapEntry(_ input: TypedVirtualPath, _ dependencySource: DependencySource) {
34+
assert(input.type == .swift && dependencySource.typedFile.type == .swiftDeps)
35+
biMap[input] = dependencySource
4136
}
37+
}
4238

43-
public func makeIterator() -> BiMap.Iterator {
44-
biMap.makeIterator()
39+
// MARK: - Accessing
40+
extension InputDependencySourceMap {
41+
@_spi(Testing) public func getSource(for input: TypedVirtualPath
42+
) -> DependencySource? {
43+
biMap[input]
4544
}
46-
47-
public func getInputForReportingPath(_ source: DependencySource
48-
) -> TypedVirtualPath? {
45+
46+
@_spi(Testing) public func getInput(for source: DependencySource) -> TypedVirtualPath? {
4947
biMap[source]
5048
}
51-
52-
private mutating func addMapEntry(_ input: TypedVirtualPath, _ dependencySource: DependencySource) {
53-
assert(input.type == .swift && dependencySource.typedFile.type == .swiftDeps)
54-
biMap[input] = dependencySource
49+
50+
@_spi(Testing) public func enumerateToSerialize(
51+
_ eachFn: (TypedVirtualPath, DependencySource) -> Void
52+
) {
53+
for (input, dependencySource) in biMap {
54+
eachFn(input, dependencySource)
55+
}
5556
}
5657
}
5758

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.getInputForReportingPath(source).map {
124+
graph.inputDependencySourceMap.getInput(for: source).map {
125125
input in
126126
"\(node.key) in \(input.file.basename)"
127127
}

0 commit comments

Comments
 (0)