Skip to content

Commit 30d0f5e

Browse files
author
David Ungar
committed
Obviate the need for a reverse mapping from swiftdeps to swift by keeping the swift file in the dependency source of the graph nodes
1 parent d47a1f2 commit 30d0f5e

21 files changed

+338
-521
lines changed

Sources/SwiftDriver/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ add_library(SwiftDriver
3333
Execution/ParsableOutput.swift
3434
Execution/ProcessProtocol.swift
3535

36-
"IncrementalCompilation/ModuleDependencyGraphParts/InputDependencySourceMap.swift"
3736
"IncrementalCompilation/ModuleDependencyGraphParts/Integrator.swift"
3837
"IncrementalCompilation/ModuleDependencyGraphParts/Node.swift"
3938
"IncrementalCompilation/ModuleDependencyGraphParts/NodeFinder.swift"
4039
"IncrementalCompilation/ModuleDependencyGraphParts/DependencySource.swift"
4140
"IncrementalCompilation/ModuleDependencyGraphParts/Tracer.swift"
42-
"IncrementalCompilation/BidirectionalMap.swift"
4341
"IncrementalCompilation/BuildRecord.swift"
4442
"IncrementalCompilation/BuildRecordInfo.swift"
4543
"IncrementalCompilation/DependencyGraphDotFileWriter.swift"

Sources/SwiftDriver/IncrementalCompilation/BidirectionalMap.swift

Lines changed: 0 additions & 116 deletions
This file was deleted.

Sources/SwiftDriver/IncrementalCompilation/DependencyGraphDotFileWriter.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class DependencyGraphDotFileWriter {
2222
self.info = info
2323
}
2424

25-
func write(_ sfdg: SourceFileDependencyGraph) {
26-
let basename = sfdg.dependencySource.shortDescription
25+
func write(_ sfdg: SourceFileDependencyGraph, for file: TypedVirtualPath) {
26+
let basename = file.file.basename
2727
write(sfdg, basename: basename)
2828
}
2929

@@ -41,6 +41,7 @@ fileprivate extension DependencyGraphDotFileWriter {
4141
try! info.fileSystem.writeFileContents(path) { stream in
4242
var s = DOTDependencyGraphSerializer<Graph>(
4343
graph,
44+
graphID: basename,
4445
stream,
4546
includeExternals: info.dependencyDotFilesIncludeExternals,
4647
includeAPINotes: info.dependencyDotFilesIncludeAPINotes)
@@ -58,16 +59,12 @@ fileprivate extension DependencyGraphDotFileWriter {
5859

5960
// MARK: - Making dependency graphs exportable
6061
fileprivate protocol ExportableGraph {
61-
var graphID: String {get}
6262
associatedtype Node: ExportableNode
6363
func forEachExportableNode(_ visit: (Node) -> Void)
6464
func forEachExportableArc(_ visit: (Node, Node) -> Void)
6565
}
6666

6767
extension SourceFileDependencyGraph: ExportableGraph {
68-
fileprivate var graphID: String {
69-
return try! VirtualPath(path: sourceFileName).basename
70-
}
7168
fileprivate func forEachExportableNode<Node: ExportableNode>(_ visit: (Node) -> Void) {
7269
forEachNode { visit($0 as! Node) }
7370
}
@@ -180,17 +177,20 @@ fileprivate extension DependencyKey.Designator {
180177
fileprivate struct DOTDependencyGraphSerializer<Graph: ExportableGraph> {
181178
private let includeExternals: Bool
182179
private let includeAPINotes: Bool
180+
private let graphID: String
183181
private let graph: Graph
184182
private var nodeIDs = [Graph.Node: Int]()
185183
private var out: WritableByteStream
186184

187185
fileprivate init(
188186
_ graph: Graph,
187+
graphID: String,
189188
_ stream: WritableByteStream,
190189
includeExternals: Bool,
191190
includeAPINotes: Bool
192191
) {
193192
self.graph = graph
193+
self.graphID = graphID
194194
self.out = stream
195195
self.includeExternals = includeExternals
196196
self.includeAPINotes = includeAPINotes
@@ -205,7 +205,7 @@ fileprivate struct DOTDependencyGraphSerializer<Graph: ExportableGraph> {
205205
}
206206

207207
private func emitPrelude() {
208-
out <<< "digraph " <<< graph.graphID.quoted <<< " {\n"
208+
out <<< "digraph " <<< graphID.quoted <<< " {\n"
209209
}
210210
private mutating func emitLegend() {
211211
for dummy in DependencyKey.Designator.oneOfEachKind {

Sources/SwiftDriver/IncrementalCompilation/DependencyKey.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public struct DependencyKey: CustomStringConvertible {
300300
case let .externalDepend(externalDependency):
301301
return "import '\(externalDependency.shortDescription)'"
302302
case let .sourceFileProvide(name: name):
303-
return "source file \((try? VirtualPath(path: name).basename) ?? name)"
303+
return "source file from \((try? VirtualPath(path: name).basename) ?? name)"
304304
}
305305
}
306306
}

Sources/SwiftDriver/IncrementalCompilation/DirectAndTransitiveCollections.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public struct InvalidatedSet<ClosureLevel, Element: Hashable>: Sequence {
4343
public func compactMap<R>(_ transform: (Element) -> R? ) -> InvalidatedArray<ClosureLevel, R> {
4444
InvalidatedArray(contents.compactMap(transform))
4545
}
46+
public func filter(_ isIncluded: (Element) -> Bool) -> InvalidatedArray<ClosureLevel, Element> {
47+
InvalidatedArray(contents.filter(isIncluded))
48+
}
4649
}
4750

4851
extension InvalidatedSet where Element: Comparable {

Sources/SwiftDriver/IncrementalCompilation/FirstWaveComputer.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ extension IncrementalCompilationState.FirstWaveComputer {
236236
return nil
237237

238238
case .upToDate:
239-
reporter?.report("Scheduing changed input", input)
239+
reporter?.report("Scheduling changed input", input)
240240
case .newlyAdded:
241241
reporter?.report("Scheduling new", input)
242242
case .needsCascadingBuild:
@@ -269,12 +269,13 @@ extension IncrementalCompilationState.FirstWaveComputer {
269269

270270
return inputsToBeCertainlyRecompiled.reduce(into: Set()) {
271271
speculativelyRecompiledInputs, certainlyRecompiledInput in
272-
let speculativeDependents = moduleDependencyGraph.collectInputsInvalidatedBy(input: certainlyRecompiledInput)
272+
let speculativeDependents = moduleDependencyGraph.collectInputsInvalidatedBy(changedInput: certainlyRecompiledInput)
273273
for speculativeDependent in speculativeDependents
274274
where !inputsToBeCertainlyRecompiled.contains(speculativeDependent) {
275275
if speculativelyRecompiledInputs.insert(speculativeDependent).inserted {
276276
reporter?.report(
277-
"Immediately scheduling dependent on \(certainlyRecompiledInput.file.basename)", speculativeDependent)
277+
"Immediately scheduling dependent on \(certainlyRecompiledInput.file.basename)",
278+
speculativeDependent)
278279
}
279280
}
280281
}

Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -542,22 +542,46 @@ extension OutputFileMap {
542542
}
543543

544544
// MARK: SourceFiles
545+
546+
/// Handy information about the source files in the current invocation
545547
@_spi(Testing) public struct SourceFiles {
548+
/// The current files in same order as the invocation
546549
let currentInOrder: [TypedVirtualPath]
547-
private let previous: Set<VirtualPath>
550+
551+
/// The set of current files (actually the handles)
552+
let currentSet: Set<VirtualPath.Handle>
553+
554+
/// Handles of the input files in the previous invocation
555+
private let previous: Set<VirtualPath.Handle>
556+
557+
/// The files that were in the previous but not in the current invocation
548558
let disappeared: [VirtualPath]
549559

550560
init(inputFiles: [TypedVirtualPath], buildRecord: BuildRecord?) {
551561
self.currentInOrder = inputFiles.filter {$0.type == .swift}
552-
let currentSet = Set(currentInOrder.map {$0.file} )
553-
self.previous = buildRecord.map {
554-
Set($0.inputInfos.keys)
555-
} ?? Set()
556-
557-
self.disappeared = previous.filter {!currentSet.contains($0)}
562+
self.currentSet = currentInOrder.reduce(into: Set()) {
563+
currentSet, currentFile in
564+
currentSet.insert(currentFile.fileHandle)
565+
}
566+
guard let buildRecord = buildRecord else {
567+
self.previous = Set()
568+
self.disappeared = []
569+
return
570+
}
571+
var previous = Set<VirtualPath.Handle>()
572+
var disappeared = [VirtualPath]()
573+
for prevPath in buildRecord.inputInfos.keys {
574+
let handle = prevPath.intern()
575+
previous.insert(handle)
576+
if !currentSet.contains(handle) {
577+
disappeared.append(prevPath)
578+
}
579+
}
580+
self.previous = previous
581+
self.disappeared = disappeared.sorted {$0.name < $1.name}
558582
}
559583

560584
func isANewInput(_ file: VirtualPath) -> Bool {
561-
!previous.contains(file)
585+
!previous.contains(file.intern())
562586
}
563587
}

Sources/SwiftDriver/IncrementalCompilation/IncrementalDependencyAndInputSetup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ extension IncrementalCompilationState.IncrementalDependencyAndInputSetup {
234234
let nodesDirectlyInvalidatedByExternals =
235235
graph.collectNodesInvalidatedByChangedOrAddedExternals()
236236
// Wait till the last minute to do the transitive closure as an optimization.
237-
guard let inputsInvalidatedByExternals = graph.collectInputsUsingInvalidated(
237+
guard let inputsInvalidatedByExternals = graph.collectInputsInBuildUsingInvalidated(
238238
nodes: nodesDirectlyInvalidatedByExternals)
239239
else {
240240
return nil

0 commit comments

Comments
 (0)