@@ -149,12 +149,12 @@ extension IncrementalCompilationState.FirstWaveComputer {
149
149
throws -> Set < ModuleDependencyId > {
150
150
let mainModuleInfo = moduleDependencyGraph. mainModule
151
151
var modulesRequiringRebuild : Set < ModuleDependencyId > = [ ]
152
- var visitedModules : Set < ModuleDependencyId > = [ ]
152
+ var visited : Set < ModuleDependencyId > = [ ]
153
153
// Scan from the main module's dependencies to avoid reporting
154
154
// the main module itself in the results.
155
155
for dependencyId in mainModuleInfo. directDependencies ?? [ ] {
156
- try outOfDateModuleScan ( on: moduleDependencyGraph, from: dependencyId, visited : & visitedModules ,
157
- modulesRequiringRebuild: & modulesRequiringRebuild)
156
+ try outOfDateModuleScan ( on: moduleDependencyGraph, from: dependencyId,
157
+ visited : & visited , modulesRequiringRebuild: & modulesRequiringRebuild)
158
158
}
159
159
160
160
reporter? . reportExplicitDependencyReBuildSet ( Array ( modulesRequiringRebuild) )
@@ -171,24 +171,36 @@ extension IncrementalCompilationState.FirstWaveComputer {
171
171
let moduleInfo = try moduleDependencyGraph. moduleInfo ( of: moduleId)
172
172
// Visit the module's dependencies
173
173
var hasOutOfDateModuleDependency = false
174
+ var mostRecentlyUpdatedDependencyOutput : TimePoint = . zero
174
175
for dependencyId in moduleInfo. directDependencies ?? [ ] {
175
176
// If we have not already visited this module, recurse.
176
177
if !visited. contains ( dependencyId) {
177
178
try outOfDateModuleScan ( on: moduleDependencyGraph, from: dependencyId,
178
- visited: & visited,
179
- modulesRequiringRebuild: & modulesRequiringRebuild)
179
+ visited: & visited, modulesRequiringRebuild: & modulesRequiringRebuild)
180
180
}
181
181
// Even if we're not revisiting a dependency, we must check if it's already known to be out of date.
182
182
hasOutOfDateModuleDependency = hasOutOfDateModuleDependency || modulesRequiringRebuild. contains ( dependencyId)
183
+
184
+ // Keep track of dependencies' output file time stamp to determine if it is newer than the current module.
185
+ if let depOutputTimeStamp = try ? fileSystem. lastModificationTime ( for: VirtualPath . lookup ( moduleDependencyGraph. moduleInfo ( of: dependencyId) . modulePath. path) ) ,
186
+ depOutputTimeStamp > mostRecentlyUpdatedDependencyOutput {
187
+ mostRecentlyUpdatedDependencyOutput = depOutputTimeStamp
188
+ }
183
189
}
184
190
185
191
if hasOutOfDateModuleDependency {
186
- reporter? . reportExplicitDependencyWillBeReBuilt ( moduleId. moduleNameForDiagnostic, reason: " Invalidated by downstream dependency " )
187
- modulesRequiringRebuild. insert ( moduleId)
192
+ reporter? . reportExplicitDependencyWillBeReBuilt ( moduleId. moduleNameForDiagnostic, reason: " Invalidated by downstream dependency " )
193
+ modulesRequiringRebuild. insert ( moduleId)
188
194
} else if try ! IncrementalCompilationState. IncrementalDependencyAndInputSetup. verifyModuleDependencyUpToDate ( moduleID: moduleId, moduleInfo: moduleInfo,
189
195
fileSystem: fileSystem, reporter: reporter) {
190
- reporter? . reportExplicitDependencyWillBeReBuilt ( moduleId. moduleNameForDiagnostic, reason: " Out-of-date " )
191
- modulesRequiringRebuild. insert ( moduleId)
196
+ reporter? . reportExplicitDependencyWillBeReBuilt ( moduleId. moduleNameForDiagnostic, reason: " Out-of-date " )
197
+ modulesRequiringRebuild. insert ( moduleId)
198
+ } else if let outputModTime = try ? fileSystem. lastModificationTime ( for: VirtualPath . lookup ( moduleInfo. modulePath. path) ) ,
199
+ outputModTime < mostRecentlyUpdatedDependencyOutput {
200
+ // If a prior variant of this module dependnecy exists, and is older than any of its direct or transitive
201
+ // module dependency outputs, it must also be re-built.
202
+ reporter? . reportExplicitDependencyWillBeReBuilt ( moduleId. moduleNameForDiagnostic, reason: " Has newer module dependency inputs " )
203
+ modulesRequiringRebuild. insert ( moduleId)
192
204
}
193
205
194
206
// Now that we've determined if this module must be rebuilt, mark it as visited.
0 commit comments