Skip to content

Commit 6fa330b

Browse files
author
David Ungar
committed
Throw instead of return hadError
1 parent 911febb commit 6fa330b

File tree

4 files changed

+32
-36
lines changed

4 files changed

+32
-36
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,11 +1057,15 @@ extension Driver {
10571057
// A mitigation to rdar://76359678.
10581058
// If the write fails, import incrementality is lost, but it is not a fatal error.
10591059
if let incrementalCompilationState = self.incrementalCompilationState {
1060-
let hadError = incrementalCompilationState.writeDependencyGraph()
1061-
/// Ensure that a bogus dependency graph is not used next time.
1062-
guard !hadError else {
1063-
buildRecordInfo?.removeBuildRecord()
1064-
return
1060+
do {
1061+
try incrementalCompilationState.writeDependencyGraph()
1062+
}
1063+
catch {
1064+
diagnosticEngine.emit(
1065+
.warning("next compile won't be incremental; could not write dependency graph: \(error.localizedDescription)"))
1066+
/// Ensure that a bogus dependency graph is not used next time.
1067+
buildRecordInfo?.removeBuildRecord()
1068+
return
10651069
}
10661070
}
10671071
buildRecordInfo?.writeBuildRecord(

Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,6 @@ extension Diagnostic.Message {
223223
fileprivate static func remark_incremental_compilation(because why: String) -> Diagnostic.Message {
224224
.remark("Incremental compilation: \(why)")
225225
}
226-
227-
fileprivate static var warning_could_not_write_dependency_graph: Diagnostic.Message {
228-
.warning("next compile won't be incremental; could not write dependency graph")
229-
}
230226
}
231227

232228
// MARK: - Scheduling the 2nd wave
@@ -496,26 +492,32 @@ extension IncrementalCompilationState {
496492
// MARK: - Serialization
497493

498494
extension IncrementalCompilationState {
499-
@_spi(Testing) public func writeDependencyGraph() -> Bool {
495+
enum WriteDependencyGraphError: LocalizedError {
496+
case noBuildRecordInfo,
497+
couldNotWrite(path: VirtualPath, error: Error)
498+
var errorDescription: String? {
499+
switch self {
500+
case .noBuildRecordInfo:
501+
return "No build record information"
502+
case let .couldNotWrite(path, error):
503+
return "Could not write to \(path), error: \(error.localizedDescription)"
504+
}
505+
}
506+
}
507+
@_spi(Testing) public func writeDependencyGraph() throws {
500508
// If the cross-module build is not enabled, the status quo dictates we
501509
// not emit this file.
502510
guard moduleDependencyGraph.info.isCrossModuleIncrementalBuildEnabled else {
503-
return false
511+
return
504512
}
505-
506513
guard
507514
let recordInfo = self.driver.buildRecordInfo
508515
else {
509-
// It's OK to silently fail because no build record will be written
510-
// so there will be no attempt to use the saved module dependency graph
511-
// next time.
512-
self.driver.diagnosticEngine.emit(
513-
.warning_could_not_write_dependency_graph)
514-
return true
515-
}
516-
return self.moduleDependencyGraph.write(to: recordInfo.dependencyGraphPath,
517-
on: self.driver.fileSystem,
518-
compilerVersion: recordInfo.actualSwiftVersion)
516+
throw WriteDependencyGraphError.noBuildRecordInfo
517+
}
518+
try self.moduleDependencyGraph.write(to: recordInfo.dependencyGraphPath,
519+
on: self.driver.fileSystem,
520+
compilerVersion: recordInfo.actualSwiftVersion)
519521
}
520522
}
521523

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -668,17 +668,16 @@ extension ModuleDependencyGraph {
668668
to path: VirtualPath,
669669
on fileSystem: FileSystem,
670670
compilerVersion: String
671-
) -> Bool {
671+
) throws {
672672
let data = ModuleDependencyGraph.Serializer.serialize(self, compilerVersion)
673673

674674
do {
675675
try fileSystem.writeFileContents(path,
676676
bytes: data,
677677
atomically: true)
678-
return false
679678
} catch {
680-
info.diagnosticEngine.emit(.warning_could_not_write_dep_graph(to: path, error: error))
681-
return true
679+
throw IncrementalCompilationState.WriteDependencyGraphError.couldNotWrite(
680+
path: path, error: error)
682681
}
683682
}
684683

@@ -1037,15 +1036,6 @@ fileprivate extension DependencyKey.Designator {
10371036
}
10381037
}
10391038

1040-
extension Diagnostic.Message {
1041-
fileprivate static func warning_could_not_write_dep_graph(
1042-
to path: VirtualPath,
1043-
error: Error
1044-
) -> Diagnostic.Message {
1045-
.warning("could not write driver dependency graph to \(path), Returned error was: \(error.localizedDescription)")
1046-
}
1047-
}
1048-
10491039
// MARK: - Checking Serialization
10501040

10511041
extension ModuleDependencyGraph {

Tests/SwiftDriverTests/DependencyGraphSerializationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DependencyGraphSerializationTests: XCTestCase {
1818
func roundTrip(_ graph: ModuleDependencyGraph) throws {
1919
let mockPath = VirtualPath.absolute(AbsolutePath("/module-dependency-graph"))
2020
let fs = InMemoryFileSystem()
21-
graph.write(to: mockPath, on: fs, compilerVersion: "Swift 99")
21+
try graph.write(to: mockPath, on: fs, compilerVersion: "Swift 99")
2222

2323
let deserializedGraph = try ModuleDependencyGraph.read(from: mockPath,
2424
info: .mock(fileSystem: fs))!

0 commit comments

Comments
 (0)