@@ -265,7 +265,7 @@ extension ModuleDependencyGraph {
265265 /// As an optimization, only return the nodes that have not been already traced, because the traced nodes
266266 /// will have already been used to schedule jobs to run.
267267 /*@_spi(Testing)*/ public func collectUntracedNodesUsing(
268- _ why: ExternalDependency . InvalidationReason ,
268+ _ why: ExternalDependency . Why ,
269269 _ fingerprintedExternalDependency: FingerprintedExternalDependency
270270 ) -> DirectlyInvalidatedNodeSet {
271271 // These nodes will depend on the *interface* of the external Decl.
@@ -336,30 +336,22 @@ extension ModuleDependencyGraph {
336336 isPresentInTheGraph: Bool ? )
337337 -> DirectlyInvalidatedNodeSet {
338338
339+ /// Compute this up front as an optimization.
339340 let isNewToTheGraph = isPresentInTheGraph != true && fingerprintedExternalDependencies. insert ( fed) . inserted
340341
341- // Even if invalidation won't be reported to the caller, a new or added
342- // incremental external dependency may require integration in order to
343- // transitively close them, (e.g. if an imported module imports a module).
344- let whyIntegrateForClosure = info. isCrossModuleIncrementalBuildEnabled
345- ? ExternalDependency . InvalidationReason ( self ,
346- isNewToTheGraph: isNewToTheGraph,
347- fed. externalDependency)
348- : nil
342+ let whyIntegrateForClosure = ExternalDependency . Why (
343+ should: fed,
344+ whichIsNewToTheGraph: isNewToTheGraph,
345+ closeOverSwiftModulesIn: self )
349346
350347 let invalidatedNodesFromIncrementalExternal = whyIntegrateForClosure. flatMap { why in
351348 collectNodesInvalidatedByAttemptingToProcess ( why, fed)
352349 }
353350
354- if phase. isCompilingAllInputsNoMatterWhat {
355- // going to compile every input anyway, less work for callers
356- return DirectlyInvalidatedNodeSet ( )
357- }
358-
359- guard let whyInvalidate = ExternalDependency . InvalidationReason (
360- self ,
361- isNewToTheGraph: phase. shouldNewExternalDependenciesTriggerInvalidation && isNewToTheGraph,
362- fed. externalDependency)
351+ guard let whyInvalidate = ExternalDependency . Why (
352+ shouldUsesOf: fed,
353+ whichIsNewToTheGraph: isNewToTheGraph,
354+ beInvalidatedIn: self )
363355 else {
364356 return DirectlyInvalidatedNodeSet ( )
365357 }
@@ -386,7 +378,7 @@ extension ModuleDependencyGraph {
386378 /// Try to read and integrate an external dependency.
387379 /// Return nil if it's not incremental, or if an error occurs.
388380 private func collectNodesInvalidatedByAttemptingToProcess(
389- _ why: ExternalDependency . InvalidationReason ,
381+ _ why: ExternalDependency . Why ,
390382 _ fed: FingerprintedExternalDependency
391383 ) -> DirectlyInvalidatedNodeSet ? {
392384 guard let source = fed. incrementalDependencySource,
0 commit comments