@@ -108,24 +108,35 @@ private extension InterModuleDependencyGraph {
108
108
pathPCMArtSet: Set < [ String ] > ,
109
109
pcmArgSetMap: inout [ ModuleDependencyId : Set < [ String ] > ] )
110
110
throws {
111
+ guard let moduleInfo = modules [ moduleId] else {
112
+ throw Driver . Error. missingModuleDependency ( moduleId. moduleName)
113
+ }
111
114
switch moduleId {
112
115
case . swift:
116
+ guard case . swift( let swiftModuleDetails) = moduleInfo. details else {
117
+ throw Driver . Error. malformedModuleDependency ( moduleId. moduleName,
118
+ " no Swift `details` object " )
119
+ }
113
120
// Add extraPCMArgs of the visited node to the current path set
114
121
// and proceed to visit all direct dependencies
115
- let modulePCMArgs = try swiftModulePCMArgs ( of : moduleId )
122
+ let modulePCMArgs = swiftModuleDetails . extraPcmArgs
116
123
var newPathPCMArgSet = pathPCMArtSet
117
124
newPathPCMArgSet. insert ( modulePCMArgs)
118
- for dependencyId in try moduleInfo ( of : moduleId ) . directDependencies! {
125
+ for dependencyId in moduleInfo. directDependencies! {
119
126
try visit ( dependencyId,
120
127
pathPCMArtSet: newPathPCMArgSet,
121
128
pcmArgSetMap: & pcmArgSetMap)
122
129
}
123
130
case . clang:
131
+ guard case . clang( let clangModuleDetails) = moduleInfo. details else {
132
+ throw Driver . Error. malformedModuleDependency ( moduleId. moduleName,
133
+ " no Clang `details` object " )
134
+ }
124
135
// The details of this module contain information on which sets of PCMArgs are already
125
136
// captured in the described dependencies of this module. Only re-scan at PCMArgs not
126
137
// already captured.
127
- let moduleDetails = try clangModuleDetails ( of : moduleId )
128
- let alreadyCapturedPCMArgs = moduleDetails . dependenciesCapturedPCMArgs ?? Set < [ String ] > ( )
138
+ let alreadyCapturedPCMArgs =
139
+ clangModuleDetails . dependenciesCapturedPCMArgs ?? Set < [ String ] > ( )
129
140
let newPCMArgSet = pathPCMArtSet. filter { !alreadyCapturedPCMArgs. contains ( $0) }
130
141
// Add current path's PCMArgs to the SetMap and stop traversal
131
142
if pcmArgSetMap [ moduleId] != nil {
@@ -138,7 +149,7 @@ private extension InterModuleDependencyGraph {
138
149
// We can rely on the fact that this pre-built module already has its
139
150
// versioned-PCM dependencies satisfied, so we do not need to add additional
140
151
// arguments. Proceed traversal to its dependencies.
141
- for dependencyId in try moduleInfo ( of : moduleId ) . directDependencies! {
152
+ for dependencyId in moduleInfo. directDependencies! {
142
153
try visit ( dependencyId,
143
154
pathPCMArtSet: pathPCMArtSet,
144
155
pcmArgSetMap: & pcmArgSetMap)
@@ -159,57 +170,19 @@ private extension InterModuleDependencyGraph {
159
170
[ ModuleDependencyId : Set < [ String ] > ]
160
171
) throws {
161
172
for (moduleId, newPCMArgs) in pcmArgSetMap {
162
- var moduleDetails = try clangModuleDetails ( of: moduleId)
163
- if moduleDetails. dependenciesCapturedPCMArgs == nil {
164
- moduleDetails. dependenciesCapturedPCMArgs = Set < [ String ] > ( )
173
+ guard let moduleInfo = modules [ moduleId] else {
174
+ throw Driver . Error. missingModuleDependency ( moduleId. moduleName)
175
+ }
176
+ guard case . clang( var clangModuleDetails) = moduleInfo. details else {
177
+ throw Driver . Error. malformedModuleDependency ( moduleId. moduleName,
178
+ " no Clang `details` object " )
165
179
}
166
- newPCMArgs. forEach { moduleDetails. dependenciesCapturedPCMArgs!. insert ( $0) }
167
- modules [ moduleId] !. details = . clang( moduleDetails)
180
+ if clangModuleDetails. dependenciesCapturedPCMArgs == nil {
181
+ clangModuleDetails. dependenciesCapturedPCMArgs = Set < [ String ] > ( )
182
+ }
183
+ newPCMArgs. forEach { clangModuleDetails. dependenciesCapturedPCMArgs!. insert ( $0) }
184
+ modules [ moduleId] !. details = . clang( clangModuleDetails)
168
185
}
169
186
}
170
187
}
171
188
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