Skip to content

Commit d853e50

Browse files
authored
Merge pull request #1778 from owenv/ovoorhees/remove-legacy-incremental
Obselete -disable-incremental-imports setting
2 parents 3da0373 + eac023b commit d853e50

19 files changed

+55
-568
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,68 +1778,33 @@ extension Driver {
17781778
// In case the write fails, don't crash the build.
17791779
// A mitigation to rdar://76359678.
17801780
// If the write fails, import incrementality is lost, but it is not a fatal error.
1781-
guard
1782-
let buildRecordInfo = self.buildRecordInfo,
1783-
let absPath = buildRecordInfo.buildRecordPath.absolutePath
1784-
else {
1781+
guard let buildRecordInfo = self.buildRecordInfo, let incrementalCompilationState = self.incrementalCompilationState else {
17851782
return
17861783
}
1787-
1784+
17881785
let buildRecord = buildRecordInfo.buildRecord(
17891786
jobs, self.incrementalCompilationState?.blockingConcurrentMutationToProtectedState{
17901787
$0.skippedCompilationInputs
17911788
})
1792-
1793-
if
1794-
let incrementalCompilationState = self.incrementalCompilationState,
1795-
incrementalCompilationState.info.isCrossModuleIncrementalBuildEnabled
1796-
{
1797-
do {
1798-
try incrementalCompilationState.writeDependencyGraph(to: buildRecordInfo.dependencyGraphPath, buildRecord)
1799-
} catch {
1800-
diagnosticEngine.emit(
1801-
.warning("next compile won't be incremental; could not write dependency graph: \(error.localizedDescription)"))
1802-
/// Ensure that a bogus dependency graph is not used next time.
1803-
buildRecordInfo.removeBuildRecord()
1804-
buildRecordInfo.removeInterModuleDependencyGraph()
1805-
return
1806-
}
1807-
do {
1808-
try incrementalCompilationState.writeInterModuleDependencyGraph(buildRecordInfo)
1809-
} catch {
1810-
diagnosticEngine.emit(
1811-
.warning("next compile must run a full dependency scan; could not write inter-module dependency graph: \(error.localizedDescription)"))
1812-
buildRecordInfo.removeBuildRecord()
1813-
buildRecordInfo.removeInterModuleDependencyGraph()
1814-
return
1815-
}
1816-
} else {
1817-
// FIXME: This is all legacy code. Once the cross module incremental build
1818-
// becomes the default:
1819-
//
1820-
// 1) Delete this branch
1821-
// 2) Delete the parts of the incremental build that talk about anything
1822-
// derived from `buildRecordPath`
1823-
// 3) Delete the Yams dependency.
1824-
1825-
// Before writing to the dependencies file path, preserve any previous file
1826-
// that may have been there. No error handling -- this is just a nicety, it
1827-
// doesn't matter if it fails.
1828-
// Added for the sake of compatibility with the legacy driver.
1829-
try? fileSystem.move(
1830-
from: absPath, to: absPath.appending(component: absPath.basename + "~"))
1831-
1832-
guard let contents = buildRecord.encode(diagnosticEngine: diagnosticEngine) else {
1833-
diagnosticEngine.emit(.warning_could_not_write_build_record(absPath))
1834-
return
1835-
}
1836-
1837-
do {
1838-
try fileSystem.writeFileContents(absPath,
1839-
bytes: ByteString(encodingAsUTF8: contents))
1840-
} catch {
1841-
diagnosticEngine.emit(.warning_could_not_write_build_record(absPath))
1842-
}
1789+
1790+
do {
1791+
try incrementalCompilationState.writeDependencyGraph(to: buildRecordInfo.dependencyGraphPath, buildRecord)
1792+
} catch {
1793+
diagnosticEngine.emit(
1794+
.warning("next compile won't be incremental; could not write dependency graph: \(error.localizedDescription)"))
1795+
/// Ensure that a bogus dependency graph is not used next time.
1796+
buildRecordInfo.removeBuildRecord()
1797+
buildRecordInfo.removeInterModuleDependencyGraph()
1798+
return
1799+
}
1800+
do {
1801+
try incrementalCompilationState.writeInterModuleDependencyGraph(buildRecordInfo)
1802+
} catch {
1803+
diagnosticEngine.emit(
1804+
.warning("next compile must run a full dependency scan; could not write inter-module dependency graph: \(error.localizedDescription)"))
1805+
buildRecordInfo.removeBuildRecord()
1806+
buildRecordInfo.removeInterModuleDependencyGraph()
1807+
return
18431808
}
18441809
}
18451810

Sources/SwiftDriver/IncrementalCompilation/BuildRecord.swift

Lines changed: 0 additions & 229 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import class TSCBasic.DiagnosticsEngine
1414
import struct TSCBasic.AbsolutePath
1515
import struct TSCBasic.Diagnostic
1616

17-
@_implementationOnly import Yams
18-
1917
/// Holds the info about inputs needed to plan incremenal compilation
2018
/// A.k.a. BuildRecord was the legacy name
2119
public struct BuildRecord {
@@ -40,155 +38,6 @@ public struct BuildRecord {
4038
self.buildEndTime = buildEndTime
4139
self.inputInfos = inputInfos
4240
}
43-
44-
public enum SectionName: String, CaseIterable {
45-
case swiftVersion = "version"
46-
case argsHash = "options"
47-
// Implement this for a smoother transition
48-
case legacyBuildStartTime = "build_time"
49-
case buildStartTime = "build_start_time"
50-
case buildEndTime = "build_end_time"
51-
case inputInfos = "inputs"
52-
53-
var serializedName: String { rawValue }
54-
}
55-
56-
var allInputs: Set<VirtualPath> {
57-
Set(inputInfos.map { $0.key })
58-
}
59-
}
60-
61-
// MARK: - Reading the old map and deciding whether to use it
62-
public extension BuildRecord {
63-
enum Error: Swift.Error {
64-
case malformedYAML
65-
case invalidKey
66-
case missingTimeStamp
67-
case missingInputSequenceNode
68-
case missingInputEntryNode
69-
case missingPriorBuildState
70-
case unexpectedKey(String)
71-
case malformed(SectionName)
72-
73-
var reason: String {
74-
switch self {
75-
case .malformedYAML:
76-
return ""
77-
case .invalidKey:
78-
return ""
79-
case .missingTimeStamp:
80-
return "could not read time value in build record"
81-
case .missingInputSequenceNode:
82-
return "no sequence node for input entry in build record"
83-
case .missingInputEntryNode:
84-
return "no input entry in build record"
85-
case .missingPriorBuildState:
86-
return "no previous build state in build record"
87-
case .unexpectedKey(let key):
88-
return "Unexpected key '\(key)'"
89-
case .malformed(let section):
90-
return "Malformed value for key '\(section.serializedName)'"
91-
}
92-
}
93-
}
94-
init(contents: String) throws {
95-
guard let sections = try? Parser(yaml: contents, resolver: .basic, encoding: .utf8)
96-
.singleRoot()?.mapping
97-
else {
98-
throw Error.malformedYAML
99-
}
100-
var argsHash: String?
101-
var swiftVersion: String?
102-
// Legacy driver does not disable incremental if no buildTime field.
103-
var buildStartTime: TimePoint = .distantPast
104-
var buildEndTime: TimePoint = .distantFuture
105-
var inputInfos: [VirtualPath: InputInfo]?
106-
for (key, value) in sections {
107-
guard let k = key.string else {
108-
throw Error.invalidKey
109-
}
110-
switch k {
111-
case SectionName.swiftVersion.serializedName:
112-
// There's a test that uses "" for an illegal value
113-
guard let s = value.string, s != "" else {
114-
break
115-
}
116-
swiftVersion = s
117-
case SectionName.argsHash.serializedName:
118-
guard let s = value.string, s != "" else {
119-
break
120-
}
121-
argsHash = s
122-
case SectionName.buildStartTime.serializedName,
123-
SectionName.legacyBuildStartTime.serializedName:
124-
buildStartTime = try Self.decodeDate(value, forInputInfo: false)
125-
case SectionName.buildEndTime.serializedName:
126-
buildEndTime = try Self.decodeDate(value, forInputInfo: false)
127-
case SectionName.inputInfos.serializedName:
128-
inputInfos = try Self.decodeInputInfos(value)
129-
default:
130-
throw Error.unexpectedKey(k)
131-
}
132-
}
133-
// The legacy driver allows argHash to be absent to ease testing.
134-
// Mimic the legacy driver for testing ease: If no `argsHash` section,
135-
// record still matches.
136-
guard let sv = swiftVersion else {
137-
throw Error.malformed(.swiftVersion)
138-
}
139-
guard let iis = inputInfos else {
140-
throw Error.malformed(.inputInfos)
141-
}
142-
guard let argsHash = argsHash else {
143-
throw Error.malformed(.argsHash)
144-
}
145-
self.init(argsHash: argsHash,
146-
swiftVersion: sv,
147-
buildStartTime: buildStartTime,
148-
buildEndTime: buildEndTime,
149-
inputInfos: iis)
150-
}
151-
152-
private static func decodeDate(
153-
_ node: Yams.Node,
154-
forInputInfo: Bool
155-
) throws -> TimePoint {
156-
guard let vals = node.sequence else {
157-
if forInputInfo {
158-
throw Error.missingInputSequenceNode
159-
} else {
160-
throw Error.missingTimeStamp
161-
}
162-
}
163-
guard vals.count == 2,
164-
let secs = vals[0].int,
165-
let ns = vals[1].int
166-
else {
167-
throw Error.missingTimeStamp
168-
}
169-
return TimePoint(seconds: UInt64(secs), nanoseconds: UInt32(ns))
170-
}
171-
172-
private static func decodeInputInfos(
173-
_ node: Yams.Node
174-
) throws -> [VirtualPath: InputInfo] {
175-
guard let map = node.mapping else {
176-
throw BuildRecord.Error.malformed(.inputInfos)
177-
}
178-
var infos = [VirtualPath: InputInfo]()
179-
for (keyNode, valueNode) in map {
180-
guard let pathString = keyNode.string,
181-
let path = try? VirtualPath(path: pathString)
182-
else {
183-
throw BuildRecord.Error.missingInputEntryNode
184-
}
185-
let previousModTime = try decodeDate(valueNode, forInputInfo: true)
186-
let inputInfo = try InputInfo(
187-
tag: valueNode.tag.description, previousModTime: previousModTime)
188-
infos[path] = inputInfo
189-
}
190-
return infos
191-
}
19241
}
19342

19443
// MARK: - Creating and writing a new map
@@ -222,82 +71,4 @@ extension BuildRecord {
22271
inputInfos: Dictionary(uniqueKeysWithValues: inputInfosArray)
22372
)
22473
}
225-
226-
/// Pass in `currentArgsHash` to ensure it is non-nil
227-
public func encode(diagnosticEngine: DiagnosticsEngine) -> String? {
228-
let pathsAndInfos = inputInfos.map {
229-
input, inputInfo -> (String, InputInfo) in
230-
return (input.name, inputInfo)
231-
}
232-
let inputInfosNode = Yams.Node(
233-
pathsAndInfos
234-
.sorted {$0.0 < $1.0}
235-
.map {(Yams.Node($0.0, .implicit, .doubleQuoted), Self.encode($0.1))}
236-
)
237-
let fieldNodes = [
238-
(SectionName.swiftVersion, Yams.Node(swiftVersion, .implicit, .doubleQuoted)),
239-
(SectionName.argsHash, Yams.Node(argsHash, .implicit, .doubleQuoted)),
240-
(SectionName.buildStartTime, Self.encode(buildStartTime)),
241-
(SectionName.buildEndTime, Self.encode(buildEndTime)),
242-
(SectionName.inputInfos, inputInfosNode )
243-
] .map { (Yams.Node($0.0.serializedName), $0.1) }
244-
245-
let buildRecordNode = Yams.Node(fieldNodes, .implicit, .block)
246-
// let options = Yams.Emitter.Options(canonical: true)
247-
do {
248-
return try Yams.serialize(node: buildRecordNode,
249-
width: -1,
250-
sortKeys: false)
251-
} catch {
252-
diagnosticEngine.emit(.warning_could_not_serialize_build_record(error))
253-
return nil
254-
}
255-
}
256-
257-
private static func encode(_ date: TimePoint, tag tagString: String? = nil) -> Yams.Node {
258-
return Yams.Node(
259-
[ Yams.Node(String(date.seconds)), Yams.Node(String(date.nanoseconds)) ],
260-
tagString.map {Yams.Tag(Yams.Tag.Name(rawValue: $0))} ?? .implicit,
261-
.flow)
262-
}
263-
264-
private static func encode(_ inputInfo: InputInfo) -> Yams.Node {
265-
encode(inputInfo.previousModTime, tag: inputInfo.tag)
266-
}
267-
268-
}
269-
270-
extension Diagnostic.Message {
271-
static func warning_could_not_serialize_build_record(_ err: Error
272-
) -> Diagnostic.Message {
273-
.warning("next compile won't be incremental; Could not serialize build record: \(err.localizedDescription)")
274-
}
275-
static func warning_could_not_write_build_record_not_absolutePath(
276-
_ path: VirtualPath
277-
) -> Diagnostic.Message {
278-
.warning("next compile won't be incremental; build record path was not absolute: \(path)")
279-
}
280-
static func warning_could_not_write_build_record(_ path: AbsolutePath
281-
) -> Diagnostic.Message {
282-
.warning("next compile won't be incremental; could not write build record to \(path)")
283-
}
284-
}
285-
286-
287-
// MARK: - reading
288-
extension InputInfo {
289-
fileprivate init(
290-
tag: String,
291-
previousModTime: TimePoint
292-
) throws {
293-
guard let status = Status(identifier: tag) else {
294-
throw BuildRecord.Error.missingPriorBuildState
295-
}
296-
self.init(status: status, previousModTime: previousModTime)
297-
}
298-
}
299-
300-
// MARK: - writing
301-
extension InputInfo {
302-
fileprivate var tag: String { status.identifier }
30374
}

Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState+Extensions.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,16 +374,6 @@ extension IncrementalCompilationState {
374374
/// integrity of the driver's dependency graph and aborts if any errors
375375
/// are detected.
376376
public static let verifyDependencyGraphAfterEveryImport = Options(rawValue: 1 << 3)
377-
/// Enables the cross-module incremental build infrastructure.
378-
///
379-
/// FIXME: This option is transitory. We intend to make this the
380-
/// default behavior. This option should flip to a "disable" bit after that.
381-
public static let enableCrossModuleIncrementalBuild = Options(rawValue: 1 << 4)
382-
/// Enables an optimized form of start-up for the incremental build state
383-
/// that reads the dependency graph from a serialized format on disk instead
384-
/// of reading O(N) swiftdeps files.
385-
public static let readPriorsFromModuleDependencyGraph = Options(rawValue: 1 << 5)
386-
387377
/// Enables additional handling of explicit module build artifacts:
388378
/// Additional reading and writing of the inter-module dependency graph.
389379
public static let explicitModuleBuild = Options(rawValue: 1 << 6)
@@ -410,7 +400,6 @@ extension IncrementalCompilationState {
410400
to path: VirtualPath,
411401
_ buildRecord: BuildRecord
412402
) throws {
413-
precondition(info.isCrossModuleIncrementalBuildEnabled)
414403
try blockingConcurrentAccessOrMutationToProtectedState {
415404
try $0.writeGraph(
416405
to: path,

Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ public final class IncrementalCompilationState {
6060
outputFileMap: driver.outputFileMap)
6161
: nil
6262

63-
reporter?.reportOnIncrementalImports(
64-
initialState.incrementalOptions.contains(.enableCrossModuleIncrementalBuild))
65-
6663
let firstWave = try FirstWaveComputer(
6764
initialState: initialState,
6865
jobsInPhases: jobsInPhases,
@@ -104,10 +101,3 @@ extension IncrementalCompilationState: IncrementalCompilationSynchronizer {
104101
info.incrementalCompilationQueue
105102
}
106103
}
107-
108-
fileprivate extension IncrementalCompilationState.Reporter {
109-
func reportOnIncrementalImports(_ enabled: Bool) {
110-
report(
111-
"\(enabled ? "Enabling" : "Disabling") incremental cross-module building")
112-
}
113-
}

0 commit comments

Comments
 (0)