Skip to content

Commit 9080611

Browse files
author
David Ungar
authored
Merge pull request #390 from davidungar/refactor-trace-printing
[Incremental] Refactor & enhance dependency trace printing.
2 parents b75b984 + 3c3a03e commit 9080611

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

Sources/SwiftDriver/Incremental Compilation/DependencyKey.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct ExternalDependency: Hashable, CustomStringConvertible {
1818

1919

2020

21-
public struct DependencyKey: Hashable {
21+
public struct DependencyKey: Hashable, CustomStringConvertible {
2222
/// Instead of the status quo scheme of two kinds of "Depends", cascading and
2323
/// non-cascading this code represents each entity ("Provides" in the status
2424
/// quo), by a pair of nodes. One node represents the "implementation." If the
@@ -39,7 +39,7 @@ public struct DependencyKey: Hashable {
3939
/// graph, splitting the current *member* into \ref member and \ref
4040
/// potentialMember and adding \ref sourceFileProvide.
4141
///
42-
enum Designator: Hashable {
42+
enum Designator: Hashable, CustomStringConvertible {
4343
case
4444
topLevel(name: String),
4545
dynamicLookup(name: String),
@@ -60,6 +60,25 @@ public struct DependencyKey: Hashable {
6060
default:
6161
return nil}
6262
}
63+
64+
public var description: String {
65+
switch self {
66+
case let .topLevel(name: name):
67+
return "top-level name \(name)"
68+
case let .nominal(context: context):
69+
return "type \(context)"
70+
case let .potentialMember(context: context):
71+
return "potential members of \(context)"
72+
case let .member(context: context, name: name):
73+
return "member \(name) of \(context)"
74+
case let .dynamicLookup(name: name):
75+
return "AnyObject member \(name)"
76+
case let .externalDepend(externalDependency):
77+
return "module \(externalDependency)"
78+
case let .sourceFileProvide(name: name):
79+
return (try? VirtualPath(path: name).basename) ?? name
80+
}
81+
}
6382
}
6483

6584
let aspect: DeclAspect
@@ -80,6 +99,10 @@ public struct DependencyKey: Hashable {
8099
return Self(aspect: .implementation, designator: designator)
81100
}
82101

102+
public var description: String {
103+
"\(aspect) of \(designator)"
104+
}
105+
83106
@discardableResult
84107
func verify() -> Bool {
85108
// This space reserved for future use.

Sources/SwiftDriver/Incremental Compilation/ModuleDependencyGraph Parts/Tracer.swift

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -123,38 +123,11 @@ extension ModuleDependencyGraph.Tracer {
123123
.compactMap { node in
124124
node.swiftDeps
125125
.flatMap {graph.sourceSwiftDepsMap[$0] }
126-
.map (node.dependencyKey.descriptionForPath(from:))
126+
.map { "\(node.dependencyKey) from: \($0.file.basename)"}
127127
}
128128
.joined(separator: " -> ")
129129
].joined(separator: " "),
130130
nil
131131
)
132132
}
133133
}
134-
135-
fileprivate extension DependencyKey {
136-
func descriptionForPath(from sourceFile: TypedVirtualPath) -> String {
137-
"\(aspect) of \(designator.descriptionForPath(from: sourceFile))"
138-
}
139-
}
140-
141-
fileprivate extension DependencyKey.Designator {
142-
func descriptionForPath(from sourceFile: TypedVirtualPath) -> String {
143-
switch self {
144-
case let .topLevel(name: name):
145-
return "top-level name \(name)"
146-
case let .nominal(context: context):
147-
return "type \(context)"
148-
case let .potentialMember(context: context):
149-
return "potential members of \(context)"
150-
case let .member(context: context, name: name):
151-
return "member \(name) of \(context)"
152-
case let .dynamicLookup(name: name):
153-
return "AnyObject member \(name)"
154-
case let .externalDepend(externalDependency):
155-
return "module \(externalDependency)"
156-
case let .sourceFileProvide(name: name):
157-
return (try? VirtualPath(path: name).basename) ?? name
158-
}
159-
}
160-
}

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ final class IncrementalCompilationTests: XCTestCase {
478478
"Forming batch job from 1 constituents: main.swift",
479479
"Incremental compilation: Queuing Compiling main.swift",
480480
"Starting Compiling main.swift",
481-
"Incremental compilation: Traced: interface of main.swiftdeps -> interface of top-level name foo -> implementation of other.swiftdeps",
481+
"Incremental compilation: Traced: interface of main.swiftdeps from: main.swift -> interface of top-level name foo from: main.swift -> implementation of other.swiftdeps from: other.swift",
482482
"Incremental compilation: Queuing because of dependencies discovered later: {compile: other.o <= other.swift}",
483483
"Incremental compilation: Scheduling discovered {compile: other.o <= other.swift}",
484484
"Finished Compiling main.swift",

0 commit comments

Comments
 (0)