@@ -23,7 +23,7 @@ extension ModuleDependencyGraph {
2323 // Shorthands
2424 /*@_spi(Testing)*/ public typealias Graph = ModuleDependencyGraph
2525
26- public private( set) var results = Results ( )
26+ public private( set) var invalidatedNodes = DirectlyInvalidatedNodes ( )
2727
2828 /// the graph to be integrated
2929 let sourceGraph : SourceFileDependencyGraph
@@ -48,6 +48,14 @@ extension ModuleDependencyGraph {
4848 var reporter : IncrementalCompilationState . Reporter ? {
4949 destination. info. reporter
5050 }
51+
52+ var sourceType : FileType {
53+ sourceGraph. dependencySource. typedFile. type
54+ }
55+
56+ var isUpdating : Bool {
57+ destination. phase. isUpdating
58+ }
5159 }
5260}
5361// MARK: - integrate a graph
@@ -60,7 +68,7 @@ extension ModuleDependencyGraph.Integrator {
6068 /*@_spi(Testing)*/ public static func integrate(
6169 from g: SourceFileDependencyGraph ,
6270 into destination: Graph
63- ) -> Results {
71+ ) -> DirectlyInvalidatedNodes {
6472 var integrator = Self ( sourceGraph: g, destination: destination)
6573 integrator. integrate ( )
6674
@@ -69,21 +77,21 @@ extension ModuleDependencyGraph.Integrator {
6977 }
7078 destination. dotFileWriter? . write ( g)
7179 destination. dotFileWriter? . write ( destination)
72- return integrator. results
80+ return integrator. invalidatedNodes
7381 }
7482
7583 private mutating func integrate( ) {
7684 integrateEachSourceNode ( )
7785 handleDisappearedNodes ( )
7886 // Ensure transitive closure will get started.
79- destination. ensureGraphWillRetrace ( results . all )
87+ destination. ensureGraphWillRetrace ( invalidatedNodes )
8088 }
8189 private mutating func integrateEachSourceNode( ) {
8290 sourceGraph. forEachNode { integrate ( oneNode: $0) }
8391 }
8492 private mutating func handleDisappearedNodes( ) {
8593 for (_, node) in disappearedNodes {
86- results . addDisappeared ( node)
94+ addDisappeared ( node)
8795 destination. nodeFinder. remove ( node)
8896 }
8997 }
@@ -122,7 +130,7 @@ extension ModuleDependencyGraph.Integrator {
122130 disappearedNodes. removeValue ( forKey: matchHere. key)
123131 if matchHere. fingerprint != integrand. fingerprint {
124132 matchHere. setFingerprint ( integrand. fingerprint)
125- results . addChanged ( matchHere)
133+ addChanged ( matchHere)
126134 reporter? . report ( " Fingerprint changed for \( matchHere) " )
127135 }
128136 return matchHere
@@ -143,10 +151,7 @@ extension ModuleDependencyGraph.Integrator {
143151 . replace ( expat,
144152 newDependencySource: sourceGraph. dependencySource,
145153 newFingerprint: integrand. fingerprint)
146- if destination. phase. isUpdating {
147- reporter? . report ( " Discovered a definition for \( integratedNode) " )
148- }
149- results. addPatriated ( integratedNode)
154+ addPatriated ( integratedNode)
150155 return integratedNode
151156 }
152157
@@ -161,10 +166,7 @@ extension ModuleDependencyGraph.Integrator {
161166 dependencySource: sourceGraph. dependencySource)
162167 let oldNode = destination. nodeFinder. insert ( newNode)
163168 assert ( oldNode == nil , " Should be new! " )
164- if destination. phase. isUpdating {
165- reporter? . report ( " New definition: \( newNode) " )
166- }
167- results. addNew ( newNode)
169+ addNew ( newNode)
168170 return newNode
169171 }
170172
@@ -180,7 +182,7 @@ extension ModuleDependencyGraph.Integrator {
180182 use: moduleUseNode)
181183 if let externalDependency = def. key. designator. externalDependency,
182184 isNewUse {
183- recordNodesInvalidatedByUsing (
185+ collectNodesInvalidatedByUsing (
184186 externalDependency: FingerprintedExternalDependency ( externalDependency, def. fingerprint) ,
185187 moduleFileGraphUseNode: moduleUseNode)
186188 }
@@ -193,41 +195,41 @@ extension ModuleDependencyGraph.Integrator {
193195 // Remember the dependency for later processing in externalDependencies, and
194196 // also return it in results.
195197 // Also the use node has changed.
196- private mutating func recordNodesInvalidatedByUsing (
198+ private mutating func collectNodesInvalidatedByUsing (
197199 externalDependency fingerprintedExternalDependency: FingerprintedExternalDependency ,
198- moduleFileGraphUseNode moduleUseNode: Graph . Node ) {
199-
200+ moduleFileGraphUseNode moduleUseNode: Graph . Node
201+ ) {
200202 let invalidated = destination. collectNodesInvalidatedByProcessing (
201203 fingerprintedExternalDependency: fingerprintedExternalDependency)
202- results . addUsesOfSomeExternal ( invalidated)
204+ collectUsesOfSomeExternal ( invalidated)
203205 }
204206}
205207
206208// MARK: - Results {
207209extension ModuleDependencyGraph . Integrator {
208210 /*@_spi(Testing)*/
209- public struct Results {
210- typealias Node = ModuleDependencyGraph . Node
211-
212- private( set) var all = DirectlyInvalidatedNodes ( )
213- private( set) var usesOfSomeExternal = DirectlyInvalidatedNodes ( )
214-
215- mutating func addUsesOfSomeExternal( _ invalidated: DirectlyInvalidatedNodes )
216- {
217- all. formUnion ( invalidated)
218- usesOfSomeExternal. formUnion ( invalidated)
219- }
220- mutating func addDisappeared( _ node: Node ) {
221- all. insert ( node)
222- }
223- mutating func addChanged( _ node: Node ) {
224- all. insert ( node)
225- }
226- mutating func addPatriated( _ node: Node ) {
227- all. insert ( node)
211+ mutating func collectUsesOfSomeExternal( _ invalidated: DirectlyInvalidatedNodes )
212+ {
213+ invalidatedNodes. formUnion ( invalidated)
214+ }
215+ mutating func addDisappeared( _ node: Graph . Node ) {
216+ assert ( isUpdating)
217+ invalidatedNodes. insert ( node)
218+ }
219+ mutating func addChanged( _ node: Graph . Node ) {
220+ assert ( isUpdating)
221+ invalidatedNodes. insert ( node)
222+ }
223+ mutating func addPatriated( _ node: Graph . Node ) {
224+ if isUpdating {
225+ reporter? . report ( " Discovered a definition for \( node) " )
226+ invalidatedNodes. insert ( node)
228227 }
229- mutating func addNew( _ node: Node ) {
230- all. insert ( node)
228+ }
229+ mutating func addNew( _ node: Graph . Node ) {
230+ if isUpdating {
231+ reporter? . report ( " New definition: \( node) " )
232+ invalidatedNodes. insert ( node)
231233 }
232234 }
233235}
0 commit comments