Skip to content

Commit f5e1c37

Browse files
authored
Merge pull request #1235 from artemcm/RevertIncrementalChangesRecent
Revert [Explicit Module Builds] Serialize the inter-module dependenc… … …y graph as incremental build state"
2 parents 40a54f8 + 7337af9 commit f5e1c37

15 files changed

+190
-720
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ public struct Driver {
235235
/// Only present when the driver will be writing the record.
236236
/// Only used for reading when compiling incrementally.
237237
@_spi(Testing) public let buildRecordInfo: BuildRecordInfo?
238+
239+
/// A build-record-relative path to the location of a serialized copy of the
240+
/// driver's dependency graph.
241+
///
242+
/// FIXME: This is a little ridiculous. We could probably just replace the
243+
/// build record outright with a serialized format.
244+
var driverDependencyGraphPath: VirtualPath? {
245+
guard let recordInfo = self.buildRecordInfo else {
246+
return nil
247+
}
248+
let filename = recordInfo.buildRecordPath.basenameWithoutExt
249+
return recordInfo
250+
.buildRecordPath
251+
.parentDirectory
252+
.appending(component: filename + ".priors")
253+
}
238254

239255
/// Whether to consider incremental compilation.
240256
let shouldAttemptIncrementalCompilation: Bool
@@ -1267,6 +1283,10 @@ extension Driver {
12671283
public mutating func run(
12681284
jobs: [Job]
12691285
) throws {
1286+
if parsedOptions.hasArgument(.v) {
1287+
try printVersion(outputStream: &stderrStream)
1288+
}
1289+
12701290
let forceResponseFiles = parsedOptions.contains(.driverForceResponseFiles)
12711291

12721292
// If we're only supposed to print the jobs, do so now.
@@ -1431,15 +1451,6 @@ extension Driver {
14311451
buildRecordInfo?.removeBuildRecord()
14321452
return
14331453
}
1434-
do {
1435-
try incrementalCompilationState.writeInterModuleDependencyGraph(buildRecordInfo)
1436-
}
1437-
catch {
1438-
diagnosticEngine.emit(
1439-
.warning("next compile must run a full dependency scan; could not write inter-module dependency graph: \(error.localizedDescription)"))
1440-
buildRecordInfo?.removeInterModuleDependencyGraph()
1441-
return
1442-
}
14431454
}
14441455
buildRecordInfo?.writeBuildRecord(
14451456
jobs,

Sources/SwiftDriver/ExplicitModuleBuilds/ClangVersionedDependencyResolution.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private extension InterModuleDependencyGraph {
178178

179179
/// Update the set of all PCMArgs against which a given clang module was re-scanned
180180
mutating func updateCapturedPCMArgClangDependencies(using pcmArgSetMap:
181-
[ModuleDependencyId : Set<[String]>]
181+
[ModuleDependencyId : Set<[String]>]
182182
) throws {
183183
for (moduleId, newPCMArgs) in pcmArgSetMap {
184184
guard let moduleInfo = modules[moduleId] else {

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyGraph.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import class Foundation.JSONEncoder
14-
import struct Foundation.Data
1514

1615
/// A map from a module identifier to its info
1716
public typealias ModuleInfoMap = [ModuleDependencyId: ModuleInfo]
@@ -276,7 +275,7 @@ public struct InterModuleDependencyGraph: Codable {
276275
}
277276

278277
internal extension InterModuleDependencyGraph {
279-
func toJSONData() throws -> Data {
278+
func toJSONString() throws -> String {
280279
let encoder = JSONEncoder()
281280
#if os(Linux) || os(Android)
282281
encoder.outputFormatting = [.prettyPrinted]
@@ -285,11 +284,8 @@ internal extension InterModuleDependencyGraph {
285284
encoder.outputFormatting = [.prettyPrinted, .withoutEscapingSlashes]
286285
}
287286
#endif
288-
return try encoder.encode(self)
289-
}
290-
291-
func toJSONString() throws -> String {
292-
return try String(data: toJSONData(), encoding: .utf8)!
287+
let data = try encoder.encode(self)
288+
return String(data: data, encoding: .utf8)!
293289
}
294290
}
295291

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -41,116 +41,6 @@ extension Diagnostic.Message {
4141
}
4242
}
4343

44-
@_spi(Testing) public extension Driver {
45-
/// Scan the current module's input source-files to compute its direct and transitive
46-
/// module dependencies.
47-
mutating func gatherModuleDependencies()
48-
throws -> InterModuleDependencyGraph {
49-
var dependencyGraph = try performDependencyScan()
50-
51-
if parsedOptions.hasArgument(.printPreprocessedExplicitDependencyGraph) {
52-
try stdoutStream <<< dependencyGraph.toJSONString()
53-
stdoutStream.flush()
54-
}
55-
56-
if let externalTargetDetails = externalTargetModuleDetailsMap {
57-
// Resolve external dependencies in the dependency graph, if any.
58-
try dependencyGraph.resolveExternalDependencies(for: externalTargetDetails)
59-
}
60-
61-
// Re-scan Clang modules at all the targets they will be built against.
62-
// This is currently disabled because we are investigating it being unnecessary
63-
// try resolveVersionedClangDependencies(dependencyGraph: &dependencyGraph)
64-
65-
// Set dependency modules' paths to be saved in the module cache.
66-
try resolveDependencyModulePaths(dependencyGraph: &dependencyGraph)
67-
68-
if parsedOptions.hasArgument(.printExplicitDependencyGraph) {
69-
let outputFormat = parsedOptions.getLastArgument(.explicitDependencyGraphFormat)?.asSingle
70-
if outputFormat == nil || outputFormat == "json" {
71-
try stdoutStream <<< dependencyGraph.toJSONString()
72-
} else if outputFormat == "dot" {
73-
DOTModuleDependencyGraphSerializer(dependencyGraph).writeDOT(to: &stdoutStream)
74-
}
75-
stdoutStream.flush()
76-
}
77-
78-
return dependencyGraph
79-
}
80-
81-
/// Update the given inter-module dependency graph to set module paths to be within the module cache,
82-
/// if one is present, and for Swift modules to use the context hash in the file name.
83-
private mutating func resolveDependencyModulePaths(dependencyGraph: inout InterModuleDependencyGraph)
84-
throws {
85-
// If a module cache path is specified, update all module dependencies
86-
// to be output into it.
87-
if let moduleCachePath = parsedOptions.getLastArgument(.moduleCachePath)?.asSingle {
88-
try resolveDependencyModulePathsRelativeToModuleCache(dependencyGraph: &dependencyGraph,
89-
moduleCachePath: moduleCachePath)
90-
}
91-
92-
// Set the output path to include the module's context hash
93-
try resolveDependencyModuleFileNamesWithContextHash(dependencyGraph: &dependencyGraph)
94-
}
95-
96-
/// For Swift module dependencies, set the output path to include the module's context hash
97-
private mutating func resolveDependencyModuleFileNamesWithContextHash(dependencyGraph: inout InterModuleDependencyGraph)
98-
throws {
99-
for (moduleId, moduleInfo) in dependencyGraph.modules {
100-
// Output path on the main module is determined by the invocation arguments.
101-
guard moduleId.moduleName != dependencyGraph.mainModuleName else {
102-
continue
103-
}
104-
105-
let plainPath = VirtualPath.lookup(dependencyGraph.modules[moduleId]!.modulePath.path)
106-
if case .swift(let swiftDetails) = moduleInfo.details {
107-
guard let contextHash = swiftDetails.contextHash else {
108-
throw Driver.Error.missingContextHashOnSwiftDependency(moduleId.moduleName)
109-
}
110-
let updatedPath = plainPath.parentDirectory.appending(component: "\(plainPath.basenameWithoutExt)-\(contextHash).\(plainPath.extension!)")
111-
dependencyGraph.modules[moduleId]!.modulePath = TextualVirtualPath(path: updatedPath.intern())
112-
}
113-
// TODO: Remove this once toolchain is updated
114-
else if case .clang(let clangDetails) = moduleInfo.details {
115-
if !moduleInfo.modulePath.path.description.contains(clangDetails.contextHash) {
116-
let contextHash = clangDetails.contextHash
117-
let updatedPath = plainPath.parentDirectory.appending(component: "\(plainPath.basenameWithoutExt)-\(contextHash).\(plainPath.extension!)")
118-
dependencyGraph.modules[moduleId]!.modulePath = TextualVirtualPath(path: updatedPath.intern())
119-
}
120-
}
121-
}
122-
}
123-
124-
/// Resolve all paths to dependency binary module files to be relative to the module cache path.
125-
private mutating func resolveDependencyModulePathsRelativeToModuleCache(dependencyGraph: inout InterModuleDependencyGraph,
126-
moduleCachePath: String)
127-
throws {
128-
for (moduleId, moduleInfo) in dependencyGraph.modules {
129-
// Output path on the main module is determined by the invocation arguments.
130-
if case .swift(let name) = moduleId {
131-
if name == dependencyGraph.mainModuleName {
132-
continue
133-
}
134-
let modulePath = VirtualPath.lookup(moduleInfo.modulePath.path)
135-
// Use VirtualPath to get the OS-specific path separators right.
136-
let modulePathInCache =
137-
try VirtualPath(path: moduleCachePath).appending(component: modulePath.basename)
138-
dependencyGraph.modules[moduleId]!.modulePath =
139-
TextualVirtualPath(path: modulePathInCache.intern())
140-
}
141-
// TODO: Remove this once toolchain is updated
142-
else if case .clang(_) = moduleId {
143-
let modulePath = VirtualPath.lookup(moduleInfo.modulePath.path)
144-
// Use VirtualPath to get the OS-specific path separators right.
145-
let modulePathInCache =
146-
try VirtualPath(path: moduleCachePath).appending(component: modulePath.basename)
147-
dependencyGraph.modules[moduleId]!.modulePath =
148-
TextualVirtualPath(path: modulePathInCache.intern())
149-
}
150-
}
151-
}
152-
}
153-
15444
public extension Driver {
15545
/// Precompute the dependencies for a given Swift compilation, producing a
15646
/// dependency graph including all Swift and C module files and

Sources/SwiftDriver/IncrementalCompilation/BuildRecordInfo.swift

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import struct Foundation.Data
14-
import class Foundation.JSONDecoder
15-
1613
import class TSCBasic.DiagnosticsEngine
1714
import protocol TSCBasic.FileSystem
1815
import struct TSCBasic.AbsolutePath
@@ -49,7 +46,6 @@ import class Dispatch.DispatchQueue
4946
@_spi(Testing) public let timeBeforeFirstJob: TimePoint
5047
let diagnosticEngine: DiagnosticsEngine
5148
let compilationInputModificationDates: [TypedVirtualPath: TimePoint]
52-
private var explicitModuleDependencyGraph: InterModuleDependencyGraph? = nil
5349

5450
private var finishedJobResults = [JobResult]()
5551
// A confinement queue that protects concurrent access to the
@@ -75,6 +71,7 @@ import class Dispatch.DispatchQueue
7571
self.compilationInputModificationDates = compilationInputModificationDates
7672
}
7773

74+
7875
convenience init?(
7976
actualSwiftVersion: String,
8077
compilerOutputType: FileType?,
@@ -196,13 +193,6 @@ import class Dispatch.DispatchQueue
196193
try? fileSystem.removeFileTree(absPath)
197194
}
198195

199-
func removeInterModuleDependencyGraph() {
200-
guard let absPath = interModuleDependencyGraphPath.absolutePath else {
201-
return
202-
}
203-
try? fileSystem.removeFileTree(absPath)
204-
}
205-
206196
/// Before writing to the dependencies file path, preserve any previous file
207197
/// that may have been there. No error handling -- this is just a nicety, it
208198
/// doesn't matter if it fails.
@@ -213,8 +203,9 @@ import class Dispatch.DispatchQueue
213203
}
214204

215205

216-
// TODO: Incremental too many names, buildRecord BuildRecord outofdatemap
206+
// TODO: Incremental too many names, buildRecord BuildRecord outofdatemap
217207
func populateOutOfDateBuildRecord(
208+
inputFiles: [TypedVirtualPath],
218209
reporter: IncrementalCompilationState.Reporter?
219210
) -> BuildRecord? {
220211
let contents: String
@@ -254,29 +245,6 @@ import class Dispatch.DispatchQueue
254245
return outOfDateBuildRecord
255246
}
256247

257-
func readOutOfDateInterModuleDependencyGraph(
258-
buildRecord: BuildRecord?,
259-
reporter: IncrementalCompilationState.Reporter?
260-
) -> InterModuleDependencyGraph? {
261-
// If a valid build record could not be produced, do not bother here
262-
guard buildRecord != nil else {
263-
reporter?.report("Incremental compilation did not attempt to read inter-module dependency graph.")
264-
return nil
265-
}
266-
267-
let decodedGraph: InterModuleDependencyGraph
268-
do {
269-
let contents = try fileSystem.readFileContents(interModuleDependencyGraphPath).cString
270-
decodedGraph = try JSONDecoder().decode(InterModuleDependencyGraph.self,
271-
from: Data(contents.utf8))
272-
} catch {
273-
return nil
274-
}
275-
reporter?.report("Read inter-module dependency graph", interModuleDependencyGraphPath)
276-
277-
return decodedGraph
278-
}
279-
280248
func jobFinished(job: Job, result: ProcessResult) {
281249
self.confinementQueue.sync {
282250
finishedJobResults.append(JobResult(job, result))
@@ -295,15 +263,6 @@ import class Dispatch.DispatchQueue
295263
.appending(component: filename + ".priors")
296264
}
297265

298-
/// A build-record-relative path to the location of a serialized copy of the
299-
/// driver's inter-module dependency graph.
300-
var interModuleDependencyGraphPath: VirtualPath {
301-
let filename = buildRecordPath.basenameWithoutExt
302-
return buildRecordPath
303-
.parentDirectory
304-
.appending(component: filename + ".moduledeps")
305-
}
306-
307266
/// Directory to emit dot files into
308267
var dotFileDirectory: VirtualPath {
309268
buildRecordPath.parentDirectory

Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationProtectedState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension IncrementalCompilationState {
3636
fileprivate let moduleDependencyGraph: ModuleDependencyGraph
3737

3838
fileprivate let reporter: Reporter?
39-
39+
4040
init(skippedCompileGroups: [TypedVirtualPath: CompileJobGroup],
4141
_ moduleDependencyGraph: ModuleDependencyGraph,
4242
_ driver: inout Driver) {

0 commit comments

Comments
 (0)