@@ -79,7 +79,8 @@ public class IncrementalCompilationState {
79
79
outOfDateBuildRecord,
80
80
outputFileMap,
81
81
& driver,
82
- self . reporter)
82
+ self . reporter,
83
+ isCrossModuleIncrementalBuildEnabled: isCrossModuleIncrementalBuildEnabled)
83
84
else {
84
85
return nil
85
86
}
@@ -106,15 +107,16 @@ public class IncrementalCompilationState {
106
107
_ outOfDateBuildRecord: BuildRecord ,
107
108
_ outputFileMap: OutputFileMap ,
108
109
_ driver: inout Driver ,
109
- _ reporter: Reporter ?
110
+ _ reporter: Reporter ? ,
111
+ isCrossModuleIncrementalBuildEnabled: Bool
110
112
)
111
113
-> ( ModuleDependencyGraph ,
112
114
inputsHavingMalformedDependencySources: [ TypedVirtualPath ] ) ?
113
115
{
114
116
let diagnosticEngine = driver. diagnosticEngine
115
117
guard let (
116
118
moduleDependencyGraph,
117
- inputsAndMalformedDependencySources : inputsAndMalformedDependencySources
119
+ inputsAndMalformedSwiftDeps : inputsAndMalformedSwiftDeps
118
120
) =
119
121
ModuleDependencyGraph . buildInitialGraph (
120
122
diagnosticEngine: diagnosticEngine,
@@ -124,20 +126,22 @@ public class IncrementalCompilationState {
124
126
parsedOptions: & driver. parsedOptions,
125
127
remarkDisabled: Diagnostic . Message. remark_incremental_compilation_has_been_disabled,
126
128
reporter: reporter,
127
- fileSystem: driver. fileSystem)
129
+ fileSystem: driver. fileSystem,
130
+ isCrossModuleIncrementalBuildEnabled: isCrossModuleIncrementalBuildEnabled
131
+ )
128
132
else {
129
133
return nil
130
134
}
131
135
// Preserve legacy behavior,
132
136
// but someday, just ensure inputsAndMalformedDependencySources are compiled
133
- if let badDependencySource = inputsAndMalformedDependencySources . first? . 1 {
137
+ if let badSwiftDeps = inputsAndMalformedSwiftDeps . first? . 1 {
134
138
diagnosticEngine. emit (
135
139
. remark_incremental_compilation_has_been_disabled(
136
- because: " malformed dependencies file ' \( badDependencySource ) ' " )
140
+ because: " malformed dependencies file ' \( badSwiftDeps ) ' " )
137
141
)
138
142
return nil
139
143
}
140
- let inputsHavingMalformedDependencySources = inputsAndMalformedDependencySources . map { $0. 0 }
144
+ let inputsHavingMalformedDependencySources = inputsAndMalformedSwiftDeps . map { $0. 0 }
141
145
return ( moduleDependencyGraph,
142
146
inputsHavingMalformedDependencySources: inputsHavingMalformedDependencySources)
143
147
}
@@ -289,6 +293,7 @@ extension IncrementalCompilationState {
289
293
alwaysRebuildDependents: Bool ,
290
294
reporter: IncrementalCompilationState . Reporter ?
291
295
) -> Set < TypedVirtualPath > {
296
+ // Input == source file
292
297
let changedInputs = Self . computeChangedInputs (
293
298
groups: allGroups,
294
299
buildRecordInfo: buildRecordInfo,
@@ -297,7 +302,15 @@ extension IncrementalCompilationState {
297
302
fileSystem: fileSystem,
298
303
reporter: reporter)
299
304
300
- let externalDependents = computeExternallyDependentInputs (
305
+ let externallyChangedInputs = computeExternallyChangedInputs (
306
+ forIncrementalExternalDependencies: false ,
307
+ buildTime: outOfDateBuildRecord. buildTime,
308
+ fileSystem: fileSystem,
309
+ moduleDependencyGraph: moduleDependencyGraph,
310
+ reporter: moduleDependencyGraph. reporter)
311
+
312
+ let incrementallyExternallyChangedInputs = computeExternallyChangedInputs (
313
+ forIncrementalExternalDependencies: true ,
301
314
buildTime: outOfDateBuildRecord. buildTime,
302
315
fileSystem: fileSystem,
303
316
moduleDependencyGraph: moduleDependencyGraph,
@@ -311,7 +324,8 @@ extension IncrementalCompilationState {
311
324
312
325
// Combine to obtain the inputs that definitely must be recompiled.
313
326
let definitelyRequiredInputs =
314
- Set ( changedInputs. map ( { $0. filePath } ) + externalDependents +
327
+ Set ( changedInputs. map ( { $0. filePath } ) +
328
+ externallyChangedInputs + incrementallyExternallyChangedInputs +
315
329
inputsHavingMalformedDependencySources
316
330
+ inputsMissingOutputs)
317
331
if let reporter = reporter {
@@ -326,7 +340,7 @@ extension IncrementalCompilationState {
326
340
// as each first wave job finished.
327
341
let speculativeInputs = computeSpeculativeInputs (
328
342
changedInputs: changedInputs,
329
- externalDependents: externalDependents ,
343
+ externalDependents: externallyChangedInputs ,
330
344
inputsMissingOutputs: Set ( inputsMissingOutputs) ,
331
345
moduleDependencyGraph: moduleDependencyGraph,
332
346
alwaysRebuildDependents: alwaysRebuildDependents,
@@ -409,18 +423,22 @@ extension IncrementalCompilationState {
409
423
}
410
424
411
425
/// Any files dependent on modified files from other modules must be compiled, too.
412
- private static func computeExternallyDependentInputs(
426
+ private static func computeExternallyChangedInputs(
427
+ forIncrementalExternalDependencies: Bool ,
413
428
buildTime: Date ,
414
429
fileSystem: FileSystem ,
415
430
moduleDependencyGraph: ModuleDependencyGraph ,
416
431
reporter: IncrementalCompilationState . Reporter ?
417
432
) -> [ TypedVirtualPath ] {
418
433
var externalDependencySources = Set < ModuleDependencyGraph . DependencySource > ( )
419
- for extDep in moduleDependencyGraph. externalDependencies {
434
+ let extDeps = forIncrementalExternalDependencies
435
+ ? moduleDependencyGraph. incrementalExternalDependencies
436
+ : moduleDependencyGraph. externalDependencies
437
+ for extDep in extDeps {
420
438
let extModTime = extDep. file. flatMap { try ? fileSystem. getFileInfo ( $0) . modTime}
421
439
?? Date . distantFuture
422
440
if extModTime >= buildTime {
423
- for dependent in moduleDependencyGraph. untracedDependents ( of: extDep) {
441
+ for dependent in moduleDependencyGraph. untracedDependents ( of: extDep, isIncremental : forIncrementalExternalDependencies ) {
424
442
guard let dependencySource = dependent. dependencySource else {
425
443
fatalError ( " Dependent \( dependent) does not have dependencies file! " )
426
444
}
0 commit comments