@@ -17,7 +17,7 @@ extension IncrementalCompilationState {
17
17
struct FirstWaveComputer {
18
18
let moduleDependencyGraph : ModuleDependencyGraph
19
19
let jobsInPhases : JobsInPhases
20
- let inputsInvalidatedByExternals : TransitivelyInvalidatedInputSet
20
+ let inputsInvalidatedByExternals : TransitivelyInvalidatedSwiftSourceFileSet
21
21
let inputFiles : [ TypedVirtualPath ]
22
22
let sourceFiles : SourceFiles
23
23
let buildRecordInfo : BuildRecordInfo
@@ -74,20 +74,26 @@ extension IncrementalCompilationState.FirstWaveComputer {
74
74
Dictionary ( uniqueKeysWithValues:
75
75
jobsInPhases. compileGroups. map { ( $0. primaryInput, $0) } )
76
76
guard let buildRecord = maybeBuildRecord else {
77
- let mandatoryCompileGroupsInOrder = sourceFiles. currentInOrder. compactMap {
78
- input -> CompileJobGroup ? in
79
- compileGroups [ input]
80
- }
77
+ func everythingIsMandatory( )
78
+ throws -> ( skippedCompileGroups: [ TypedVirtualPath : CompileJobGroup ] ,
79
+ mandatoryJobsInOrder: [ Job ] )
80
+ {
81
+ let mandatoryCompileGroupsInOrder = sourceFiles. currentInOrder. compactMap {
82
+ input -> CompileJobGroup ? in
83
+ compileGroups [ input. typedFile]
84
+ }
81
85
82
- let mandatoryJobsInOrder = try
86
+ let mandatoryJobsInOrder = try
83
87
jobsInPhases. beforeCompiles +
84
88
batchJobFormer. formBatchedJobs (
85
89
mandatoryCompileGroupsInOrder. flatMap { $0. allJobs ( ) } ,
86
90
showJobLifecycle: showJobLifecycle)
87
91
88
- moduleDependencyGraph. phase = . buildingAfterEachCompilation
89
- return ( skippedCompileGroups: [ : ] ,
90
- mandatoryJobsInOrder: mandatoryJobsInOrder)
92
+ moduleDependencyGraph. phase = . buildingAfterEachCompilation
93
+ return ( skippedCompileGroups: [ : ] ,
94
+ mandatoryJobsInOrder: mandatoryJobsInOrder)
95
+ }
96
+ return try everythingIsMandatory ( )
91
97
}
92
98
moduleDependencyGraph. phase = . updatingAfterCompilation
93
99
@@ -117,7 +123,7 @@ extension IncrementalCompilationState.FirstWaveComputer {
117
123
118
124
// Figure out which compilation inputs are *not* mandatory
119
125
private func computeSkippedCompilationInputs(
120
- inputsInvalidatedByExternals: TransitivelyInvalidatedInputSet ,
126
+ inputsInvalidatedByExternals: TransitivelyInvalidatedSwiftSourceFileSet ,
121
127
_ moduleDependencyGraph: ModuleDependencyGraph ,
122
128
_ buildRecord: BuildRecord
123
129
) -> Set < TypedVirtualPath > {
@@ -153,11 +159,11 @@ extension IncrementalCompilationState.FirstWaveComputer {
153
159
}
154
160
155
161
// Combine to obtain the inputs that definitely must be recompiled.
156
- let definitelyRequiredInputs =
157
- Set ( changedInputs . map ( { $0. filePath } ) +
158
- inputsInvalidatedByExternals +
159
- inputsMissingFromGraph +
160
- inputsMissingOutputs )
162
+ var definitelyRequiredInputs = Set ( changedInputs . lazy . map { $0 . typedFile } )
163
+ definitelyRequiredInputs . formUnion ( inputsInvalidatedByExternals . lazy . map { $0. typedFile } )
164
+ definitelyRequiredInputs . formUnion ( inputsMissingFromGraph . lazy . map { $0 . typedFile } )
165
+ definitelyRequiredInputs . formUnion ( inputsMissingOutputs )
166
+
161
167
if let reporter = reporter {
162
168
for scheduledInput in sortByCommandLineOrder ( definitelyRequiredInputs) {
163
169
reporter. report ( " Queuing (initial): " , scheduledInput)
@@ -173,14 +179,15 @@ extension IncrementalCompilationState.FirstWaveComputer {
173
179
externalDependents: inputsInvalidatedByExternals,
174
180
inputsMissingOutputs: Set ( inputsMissingOutputs) ,
175
181
moduleDependencyGraph)
176
- . subtracting ( definitelyRequiredInputs)
182
+ . subtracting ( definitelyRequiredInputs. swiftSourceFiles)
183
+
177
184
178
185
if let reporter = reporter {
179
186
for dependent in sortByCommandLineOrder ( speculativeInputs) {
180
187
reporter. report ( " Queuing because of the initial set: " , dependent)
181
188
}
182
189
}
183
- let immediatelyCompiledInputs = definitelyRequiredInputs. union ( speculativeInputs)
190
+ let immediatelyCompiledInputs = definitelyRequiredInputs. union ( speculativeInputs. lazy . map { $0 . typedFile } )
184
191
185
192
let skippedInputs = Set ( buildRecordInfo. compilationInputModificationDates. keys)
186
193
. subtracting ( immediatelyCompiledInputs)
@@ -198,11 +205,17 @@ extension IncrementalCompilationState.FirstWaveComputer {
198
205
inputFiles. lazy. filter ( inputs. contains)
199
206
}
200
207
208
+ private func sortByCommandLineOrder(
209
+ _ inputs: Set < SwiftSourceFile >
210
+ ) -> LazyFilterSequence < [ TypedVirtualPath ] > {
211
+ inputFiles. lazy. filter { inputs. contains ( SwiftSourceFile ( $0) ) }
212
+ }
213
+
201
214
/// Encapsulates information about an input the driver has determined has
202
215
/// changed in a way that requires an incremental rebuild.
203
216
struct ChangedInput {
204
217
/// The path to the input file.
205
- let filePath : TypedVirtualPath
218
+ let typedFile : TypedVirtualPath
206
219
/// The status of the input file.
207
220
let status : InputInfo . Status
208
221
/// If `true`, the modification time of this input matches the modification
@@ -244,7 +257,7 @@ extension IncrementalCompilationState.FirstWaveComputer {
244
257
case . needsNonCascadingBuild:
245
258
reporter? . report ( " Scheduling noncascading build " , input)
246
259
}
247
- return ChangedInput ( filePath : input,
260
+ return ChangedInput ( typedFile : input,
248
261
status: previousCompilationStatus,
249
262
datesMatch: datesMatch)
250
263
}
@@ -256,22 +269,29 @@ extension IncrementalCompilationState.FirstWaveComputer {
256
269
// before the whole frontend job finished.
257
270
private func collectInputsToBeSpeculativelyRecompiled(
258
271
changedInputs: [ ChangedInput ] ,
259
- externalDependents: TransitivelyInvalidatedInputSet ,
272
+ externalDependents: TransitivelyInvalidatedSwiftSourceFileSet ,
260
273
inputsMissingOutputs: Set < TypedVirtualPath > ,
261
274
_ moduleDependencyGraph: ModuleDependencyGraph
262
- ) -> Set < TypedVirtualPath > {
275
+ ) -> Set < SwiftSourceFile > {
263
276
let cascadingChangedInputs = computeCascadingChangedInputs (
264
277
from: changedInputs,
265
278
inputsMissingOutputs: inputsMissingOutputs)
266
279
267
- var inputsToBeCertainlyRecompiled = alwaysRebuildDependents ? externalDependents : TransitivelyInvalidatedInputSet ( )
268
- inputsToBeCertainlyRecompiled. formUnion ( cascadingChangedInputs)
280
+ var inputsToBeCertainlyRecompiled = Set ( cascadingChangedInputs)
281
+ if alwaysRebuildDependents {
282
+ inputsToBeCertainlyRecompiled. formUnion ( externalDependents. lazy. map { $0. typedFile} )
283
+ }
269
284
270
285
return inputsToBeCertainlyRecompiled. reduce ( into: Set ( ) ) {
271
286
speculativelyRecompiledInputs, certainlyRecompiledInput in
272
- let speculativeDependents = moduleDependencyGraph. collectInputsInvalidatedBy ( changedInput: certainlyRecompiledInput)
287
+ guard let certainlyRecompiledSwiftSourceFile = SwiftSourceFile ( ifSource: certainlyRecompiledInput)
288
+ else {
289
+ return
290
+ }
291
+ let speculativeDependents = moduleDependencyGraph. collectInputsInvalidatedBy ( changedInput: certainlyRecompiledSwiftSourceFile)
292
+
273
293
for speculativeDependent in speculativeDependents
274
- where !inputsToBeCertainlyRecompiled. contains ( speculativeDependent) {
294
+ where !inputsToBeCertainlyRecompiled. contains ( speculativeDependent. typedFile ) {
275
295
if speculativelyRecompiledInputs. insert ( speculativeDependent) . inserted {
276
296
reporter? . report (
277
297
" Immediately scheduling dependent on \( certainlyRecompiledInput. file. basename) " ,
@@ -288,8 +308,8 @@ extension IncrementalCompilationState.FirstWaveComputer {
288
308
) -> [ TypedVirtualPath ] {
289
309
changedInputs. compactMap { changedInput in
290
310
let inputIsUpToDate =
291
- changedInput. datesMatch && !inputsMissingOutputs. contains ( changedInput. filePath )
292
- let basename = changedInput. filePath . file. basename
311
+ changedInput. datesMatch && !inputsMissingOutputs. contains ( changedInput. typedFile )
312
+ let basename = changedInput. typedFile . file. basename
293
313
294
314
// If we're asked to always rebuild dependents, all we need to do is
295
315
// return inputs whose modification times have changed.
@@ -301,15 +321,15 @@ extension IncrementalCompilationState.FirstWaveComputer {
301
321
} else {
302
322
reporter? . report (
303
323
" scheduling dependents of \( basename) ; -driver-always-rebuild-dependents " )
304
- return changedInput. filePath
324
+ return changedInput. typedFile
305
325
}
306
326
}
307
327
308
328
switch changedInput. status {
309
329
case . needsCascadingBuild:
310
330
reporter? . report (
311
331
" scheduling dependents of \( basename) ; needed cascading build " )
312
- return changedInput. filePath
332
+ return changedInput. typedFile
313
333
case . upToDate:
314
334
reporter? . report (
315
335
" not scheduling dependents of \( basename) ; unknown changes " )
0 commit comments