@@ -65,6 +65,9 @@ internal extension Driver {
65
65
}
66
66
}
67
67
68
+ /// Resolution of versioned clang dependencies.
69
+ /// FIXME: This code currently operates on instances of InterModuleDependencyGraph,
70
+ /// It should be transitioned to operate on an instance of an InterModuleDependencyOracle.
68
71
private extension InterModuleDependencyGraph {
69
72
/// For each module scanned at multiple target versions, combine their dependencies across version-specific graphs.
70
73
mutating func resolveVersionedClangModules( using versionedGraphMap: ModuleVersionedGraphMap )
@@ -108,24 +111,35 @@ private extension InterModuleDependencyGraph {
108
111
pathPCMArtSet: Set < [ String ] > ,
109
112
pcmArgSetMap: inout [ ModuleDependencyId : Set < [ String ] > ] )
110
113
throws {
114
+ guard let moduleInfo = modules [ moduleId] else {
115
+ throw Driver . Error. missingModuleDependency ( moduleId. moduleName)
116
+ }
111
117
switch moduleId {
112
118
case . swift:
119
+ guard case . swift( let swiftModuleDetails) = moduleInfo. details else {
120
+ throw Driver . Error. malformedModuleDependency ( moduleId. moduleName,
121
+ " no Swift `details` object " )
122
+ }
113
123
// Add extraPCMArgs of the visited node to the current path set
114
124
// and proceed to visit all direct dependencies
115
- let modulePCMArgs = try swiftModulePCMArgs ( of : moduleId )
125
+ let modulePCMArgs = swiftModuleDetails . extraPcmArgs
116
126
var newPathPCMArgSet = pathPCMArtSet
117
127
newPathPCMArgSet. insert ( modulePCMArgs)
118
- for dependencyId in try moduleInfo ( of : moduleId ) . directDependencies! {
128
+ for dependencyId in moduleInfo. directDependencies! {
119
129
try visit ( dependencyId,
120
130
pathPCMArtSet: newPathPCMArgSet,
121
131
pcmArgSetMap: & pcmArgSetMap)
122
132
}
123
133
case . clang:
134
+ guard case . clang( let clangModuleDetails) = moduleInfo. details else {
135
+ throw Driver . Error. malformedModuleDependency ( moduleId. moduleName,
136
+ " no Clang `details` object " )
137
+ }
124
138
// The details of this module contain information on which sets of PCMArgs are already
125
139
// captured in the described dependencies of this module. Only re-scan at PCMArgs not
126
140
// already captured.
127
- let moduleDetails = try clangModuleDetails ( of : moduleId )
128
- let alreadyCapturedPCMArgs = moduleDetails . dependenciesCapturedPCMArgs ?? Set < [ String ] > ( )
141
+ let alreadyCapturedPCMArgs =
142
+ clangModuleDetails . dependenciesCapturedPCMArgs ?? Set < [ String ] > ( )
129
143
let newPCMArgSet = pathPCMArtSet. filter { !alreadyCapturedPCMArgs. contains ( $0) }
130
144
// Add current path's PCMArgs to the SetMap and stop traversal
131
145
if pcmArgSetMap [ moduleId] != nil {
@@ -138,7 +152,7 @@ private extension InterModuleDependencyGraph {
138
152
// We can rely on the fact that this pre-built module already has its
139
153
// versioned-PCM dependencies satisfied, so we do not need to add additional
140
154
// arguments. Proceed traversal to its dependencies.
141
- for dependencyId in try moduleInfo ( of : moduleId ) . directDependencies! {
155
+ for dependencyId in moduleInfo. directDependencies! {
142
156
try visit ( dependencyId,
143
157
pathPCMArtSet: pathPCMArtSet,
144
158
pcmArgSetMap: & pcmArgSetMap)
@@ -159,57 +173,19 @@ private extension InterModuleDependencyGraph {
159
173
[ ModuleDependencyId : Set < [ String ] > ]
160
174
) throws {
161
175
for (moduleId, newPCMArgs) in pcmArgSetMap {
162
- var moduleDetails = try clangModuleDetails ( of: moduleId)
163
- if moduleDetails. dependenciesCapturedPCMArgs == nil {
164
- moduleDetails. dependenciesCapturedPCMArgs = Set < [ String ] > ( )
176
+ guard let moduleInfo = modules [ moduleId] else {
177
+ throw Driver . Error. missingModuleDependency ( moduleId. moduleName)
178
+ }
179
+ guard case . clang( var clangModuleDetails) = moduleInfo. details else {
180
+ throw Driver . Error. malformedModuleDependency ( moduleId. moduleName,
181
+ " no Clang `details` object " )
165
182
}
166
- newPCMArgs. forEach { moduleDetails. dependenciesCapturedPCMArgs!. insert ( $0) }
167
- modules [ moduleId] !. details = . clang( moduleDetails)
183
+ if clangModuleDetails. dependenciesCapturedPCMArgs == nil {
184
+ clangModuleDetails. dependenciesCapturedPCMArgs = Set < [ String ] > ( )
185
+ }
186
+ newPCMArgs. forEach { clangModuleDetails. dependenciesCapturedPCMArgs!. insert ( $0) }
187
+ modules [ moduleId] !. details = . clang( clangModuleDetails)
168
188
}
169
189
}
170
190
}
171
191
172
- public extension InterModuleDependencyGraph {
173
- /// Given two moduleInfos of clang modules, merge them by combining their directDependencies and
174
- /// dependenciesCapturedPCMArgs and sourceFiles fields. These fields may differ across the same module
175
- /// scanned at different PCMArgs (e.g. -target option).
176
- static func mergeClangModuleInfoDependencies( _ firstInfo: ModuleInfo , _ secondInfo: ModuleInfo
177
- ) -> ModuleInfo {
178
- guard case . clang( let firstDetails) = firstInfo. details,
179
- case . clang( let secondDetails) = secondInfo. details
180
- else {
181
- fatalError ( " mergeClangModules expected two valid ClangModuleDetails objects. " )
182
- }
183
-
184
- // As far as their dependencies go, these module infos are identical
185
- if firstInfo. directDependencies == secondInfo. directDependencies,
186
- firstDetails. dependenciesCapturedPCMArgs == secondDetails. dependenciesCapturedPCMArgs,
187
- firstInfo. sourceFiles == secondInfo. sourceFiles {
188
- return firstInfo
189
- }
190
-
191
- // Create a new moduleInfo that represents this module with combined dependency information
192
- let firstModuleSources = firstInfo. sourceFiles ?? [ ]
193
- let secondModuleSources = secondInfo. sourceFiles ?? [ ]
194
- let combinedSourceFiles = Array ( Set ( firstModuleSources + secondModuleSources) )
195
-
196
- let firstModuleDependencies = firstInfo. directDependencies ?? [ ]
197
- let secondModuleDependencies = secondInfo. directDependencies ?? [ ]
198
- let combinedDependencies = Array ( Set ( firstModuleDependencies + secondModuleDependencies) )
199
-
200
- let firstModuleCapturedPCMArgs = firstDetails. dependenciesCapturedPCMArgs ?? Set < [ String ] > ( )
201
- let secondModuleCapturedPCMArgs = secondDetails. dependenciesCapturedPCMArgs ?? Set < [ String ] > ( )
202
- let combinedCapturedPCMArgs = firstModuleCapturedPCMArgs. union ( secondModuleCapturedPCMArgs)
203
-
204
- let combinedModuleDetails =
205
- ClangModuleDetails ( moduleMapPath: firstDetails. moduleMapPath,
206
- dependenciesCapturedPCMArgs: combinedCapturedPCMArgs,
207
- contextHash: firstDetails. contextHash,
208
- commandLine: firstDetails. commandLine)
209
-
210
- return ModuleInfo ( modulePath: firstInfo. modulePath,
211
- sourceFiles: combinedSourceFiles,
212
- directDependencies: combinedDependencies,
213
- details: . clang( combinedModuleDetails) )
214
- }
215
- }
0 commit comments