Skip to content

Commit f0deac5

Browse files
author
David Ungar
committed
Redo Reporter interface
1 parent 83135ba commit f0deac5

File tree

5 files changed

+49
-31
lines changed

5 files changed

+49
-31
lines changed

Sources/SwiftDriver/IncrementalCompilation/BuildRecordInfo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ final class BuildRecordInfo {
176176
do {
177177
contents = try fileSystem.readFileContents(buildRecordPath).cString
178178
} catch {
179-
reporter?.report("Incremental compilation could not read build record at \(buildRecordPath)")
179+
reporter?.report("Incremental compilation could not read build record at ", buildRecordPath)
180180
reporter?.reportDisablingIncrementalBuild("could not read build record")
181181
return nil
182182
}
183183
func failedToReadOutOfDateMap(_ reason: String? = nil) {
184184
let why = "malformed build record file\(reason.map {" " + $0} ?? "")"
185185
reporter?.report(
186-
"Incremental compilation has been disabled due to \(why) '\(buildRecordPath)'")
186+
"Incremental compilation has been disabled due to \(why)", buildRecordPath)
187187
reporter?.reportDisablingIncrementalBuild(why)
188188
}
189189
guard let outOfDateBuildRecord = BuildRecord(contents: contents,

Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ extension IncrementalCompilationState {
330330
+ inputsMissingOutputs)
331331
if let reporter = reporter {
332332
for scheduledInput in definitelyRequiredInputs.sorted(by: {$0.file.name < $1.file.name}) {
333-
reporter.report("Queuing (initial):", path: scheduledInput)
333+
reporter.report("Queuing (initial):", scheduledInput)
334334
}
335335
}
336336

@@ -349,7 +349,7 @@ extension IncrementalCompilationState {
349349

350350
if let reporter = reporter {
351351
for dependent in speculativeInputs.sorted(by: {$0.file.name < $1.file.name}) {
352-
reporter.report("Queuing because of the initial set:", path: dependent)
352+
reporter.report("Queuing because of the initial set:", dependent)
353353
}
354354
}
355355
let immediatelyCompiledInputs = definitelyRequiredInputs.union(speculativeInputs)
@@ -358,7 +358,7 @@ extension IncrementalCompilationState {
358358
.subtracting(immediatelyCompiledInputs)
359359
if let reporter = reporter {
360360
for skippedInput in skippedInputs.sorted(by: {$0.file.name < $1.file.name}) {
361-
reporter.report("Skipping input:", path: skippedInput)
361+
reporter.report("Skipping input:", skippedInput)
362362
}
363363
}
364364
return skippedInputs
@@ -404,17 +404,17 @@ extension IncrementalCompilationState {
404404

405405
switch previousCompilationStatus {
406406
case .upToDate where datesMatch:
407-
reporter?.report("May skip current input:", path: input)
407+
reporter?.report("May skip current input:", input)
408408
return nil
409409

410410
case .upToDate:
411-
reporter?.report("Scheduing changed input", path: input)
411+
reporter?.report("Scheduing changed input", input)
412412
case .newlyAdded:
413-
reporter?.report("Scheduling new", path: input)
413+
reporter?.report("Scheduling new", input)
414414
case .needsCascadingBuild:
415-
reporter?.report("Scheduling cascading build", path: input)
415+
reporter?.report("Scheduling cascading build", input)
416416
case .needsNonCascadingBuild:
417-
reporter?.report("Scheduling noncascading build", path: input)
417+
reporter?.report("Scheduling noncascading build", input)
418418
}
419419
return ChangedInput(filePath: input,
420420
status: previousCompilationStatus,
@@ -444,7 +444,7 @@ extension IncrementalCompilationState {
444444
}
445445
reporter?.report(
446446
"Queuing because of \(forIncrementalExternalDependencies ? "incremental " : "")external dependency on newer \(extDep.file?.basename ?? "extDep?")",
447-
path: dependencySource.typedFile)
447+
dependencySource.typedFile)
448448
externalDependencySources.insert(dependencySource)
449449
}
450450
}
@@ -481,7 +481,7 @@ extension IncrementalCompilationState {
481481
for dep in dependentsOfOneFile where !cascadingFileSet.contains(dep) {
482482
if dependentFiles.insert(dep).0 {
483483
reporter?.report(
484-
"Immediately scheduling dependent on \(cascadingFile.file.basename)", path: dep)
484+
"Immediately scheduling dependent on \(cascadingFile.file.basename)", dep)
485485
}
486486
}
487487
}
@@ -560,7 +560,8 @@ extension IncrementalCompilationState {
560560

561561
if let reporter = self.reporter {
562562
for input in discoveredInputs {
563-
reporter.report("Queuing because of dependencies discovered later:", path: input)
563+
reporter.report(
564+
"Queuing because of dependencies discovered later:", input)
564565
}
565566
}
566567
let newJobs = try getJobsFor(discoveredCompilationInputs: discoveredInputs)
@@ -585,7 +586,8 @@ extension IncrementalCompilationState {
585586
if let found = moduleDependencyGraph.findSourcesToCompileAfterCompiling(input, on: self.driver.fileSystem) {
586587
return found
587588
}
588-
self.reporter?.report("Failed to read some dependencies source; compiling everything", path: input)
589+
self.reporter?.report(
590+
"Failed to read some dependencies source; compiling everything", input)
589591
return Array(skippedCompileGroups.keys)
590592
}
591593
)
@@ -603,11 +605,11 @@ extension IncrementalCompilationState {
603605
let primaryInputs = group.compileJob.primaryInputs
604606
assert(primaryInputs.count == 1)
605607
assert(primaryInputs[0] == input)
606-
self.reporter?.report("Scheduling discovered", path: input)
608+
self.reporter?.report("Scheduling discovered", input)
607609
return group.allJobs()
608610
}
609611
else {
610-
self.reporter?.report("Tried to schedule discovered input again", path: input)
612+
self.reporter?.report("Tried to schedule discovered input again", input)
611613
return []
612614
}
613615
}
@@ -651,20 +653,38 @@ extension IncrementalCompilationState {
651653
///
652654
/// - Parameters:
653655
/// - message: The message to emit in the remark.
654-
/// - path: If non-nil, the path of an output for an incremental job.
655-
func report(_ message: String, path: TypedVirtualPath? = nil) {
656-
guard let outputFileMap = outputFileMap,
657-
let path = path,
656+
/// - path: If non-nil, the path of some file. If the output for an incremental job, will print out the
657+
/// source and object files.
658+
func report(_ message: String, _ path: TypedVirtualPath?) {
659+
guard let path = path,
660+
let outputFileMap = outputFileMap,
658661
let input = path.type == .swift ? path.file : outputFileMap.getInput(outputFile: path.file)
659662
else {
660-
diagnosticEngine.emit(.remark_incremental_compilation(because: message))
663+
report(message, path?.file)
661664
return
662665
}
663666
let output = outputFileMap.getOutput(inputFile: path.file, outputType: .object)
664667
let compiling = " {compile: \(output.basename) <= \(input.basename)}"
665668
diagnosticEngine.emit(.remark_incremental_compilation(because: "\(message) \(compiling)"))
666669
}
667670

671+
/// Entry point for a simple path, won't print the compile job, path could be anything.
672+
func report(_ message: String, _ path: VirtualPath?) {
673+
guard let path = path
674+
else {
675+
report(message)
676+
diagnosticEngine.emit(.remark_incremental_compilation(because: message))
677+
return
678+
}
679+
diagnosticEngine.emit(.remark_incremental_compilation(because: "\(message) '\(path.name)'"))
680+
}
681+
682+
/// Entry point if no path.
683+
func report(_ message: String) {
684+
diagnosticEngine.emit(.remark_incremental_compilation(because: message))
685+
}
686+
687+
668688
// Emits a remark indicating incremental compilation has been disabled.
669689
func reportDisablingIncrementalBuild(_ why: String) {
670690
report("Disabling incremental build: \(why)")

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ extension ModuleDependencyGraph {
180180
return nil
181181
}
182182
let dependencySource = DependencySource(TypedVirtualPath(file: file, type: .swiftModule))
183-
reporter?.report("integrating incrementalExperimentalDependency", path: dependencySource.typedFile)
183+
reporter?.report("integrating incrementalExperimentalDependency", dependencySource.typedFile)
184184
let results = Integrator.integrate(
185185
dependencySource: dependencySource,
186186
into: graph,
@@ -213,7 +213,7 @@ extension ModuleDependencyGraph {
213213
return allDependencySourcesToRecompile.map {
214214
let dependentSource = inputDependencySourceMap[$0]
215215
self.reporter?.report(
216-
"Found dependent of \(sourceFile.file.basename):", path: dependentSource)
216+
"Found dependent of \(sourceFile.file.basename):", dependentSource)
217217
return dependentSource
218218
}
219219
}

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraphParts/Integrator.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extension ModuleDependencyGraph.Integrator {
7474
guard let sfdg = try? SourceFileDependencyGraph.read(
7575
from: dependencySource, on: fileSystem)
7676
else {
77-
reporter?.report("Could not read \(dependencySource)", path: input)
77+
reporter?.report("Could not read \(dependencySource)", input)
7878
return nil
7979
}
8080
return integrate(from: sfdg,
@@ -224,8 +224,8 @@ extension ModuleDependencyGraph.Integrator {
224224
}
225225
else if !isCrossModuleIncrementalBuildEnabled {
226226
destination.reporter?.report(
227-
"found incremntalExternalDependency but treating as non-incremental",
228-
path: externalDependency.file.map{ TypedVirtualPath(file: $0, type: .swiftModule)})
227+
"found incrementalExternalDependency but treating as non-incremental",
228+
externalDependency.file)
229229
// treat like nonincremental
230230
let key = DependencyKey(
231231
aspect: .interface,
@@ -237,9 +237,8 @@ extension ModuleDependencyGraph.Integrator {
237237
}
238238
}
239239
else {
240-
destination.reporter?.report(
241-
"found incremntalExternalDependency",
242-
path: externalDependency.file.map{ TypedVirtualPath(file: $0, type: .swiftModule)})
240+
destination.reporter?.report( "found incrementalExternalDependency",
241+
externalDependency.file)
243242
results.discoveredIncrementalExternalDependencies.insert(externalDependency)
244243
}
245244
results.changedNodes.insert(moduleUseNode)

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraphParts/Tracer.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ extension ModuleDependencyGraph.Tracer {
130130
.map { "\(node.dependencyKey) in \($0.file.basename)"}
131131
}
132132
.joined(separator: " -> ")
133-
].joined(separator: " "),
134-
path: nil
133+
].joined(separator: " ")
135134
)
136135
}
137136
}

0 commit comments

Comments
 (0)