@@ -166,38 +166,48 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
166
166
const CompilerInvocation &ScanCompilerInvocation,
167
167
const SILOptions &SILOptions, ASTContext &ScanASTContext,
168
168
swift::DependencyTracker &DependencyTracker, DiagnosticEngine &Diagnostics)
169
- : // Diagnostics(Diagnostics),
170
- clangScanningTool(*globalScanningService.ClangScanningService,
169
+ : clangScanningTool(*globalScanningService.ClangScanningService,
171
170
globalScanningService.getClangScanningFS()) {
172
- // Configure the interface scanning AST delegate
171
+ // Create a scanner-specific Invocation and ASTContext.
172
+ workerCompilerInvocation =
173
+ std::make_unique<CompilerInvocation>(ScanCompilerInvocation);
174
+ workerASTContext = std::unique_ptr<ASTContext>(
175
+ ASTContext::get (workerCompilerInvocation->getLangOptions (),
176
+ workerCompilerInvocation->getTypeCheckerOptions (),
177
+ workerCompilerInvocation->getSILOptions (),
178
+ workerCompilerInvocation->getSearchPathOptions (),
179
+ workerCompilerInvocation->getClangImporterOptions (),
180
+ workerCompilerInvocation->getSymbolGraphOptions (),
181
+ workerCompilerInvocation->getCASOptions (),
182
+ ScanASTContext.SourceMgr , Diagnostics));
183
+
184
+ // Configure the interface scanning AST delegate.
173
185
auto ClangModuleCachePath = getModuleCachePathFromClang (
174
186
ScanASTContext.getClangModuleLoader ()->getClangInstance ());
175
- auto &FEOpts = ScanCompilerInvocation.getFrontendOptions ();
176
- ModuleInterfaceLoaderOptions LoaderOpts (FEOpts);
177
- ScanningASTDelegate = std::make_unique<InterfaceSubContextDelegateImpl>(
178
- ScanASTContext.SourceMgr , &ScanASTContext.Diags ,
179
- ScanASTContext.SearchPathOpts , ScanASTContext.LangOpts ,
180
- ScanASTContext.ClangImporterOpts , ScanASTContext.CASOpts , LoaderOpts,
187
+ auto &FEOpts = workerCompilerInvocation->getFrontendOptions ();
188
+ scanningASTDelegate = std::make_unique<InterfaceSubContextDelegateImpl>(
189
+ workerASTContext->SourceMgr , &workerASTContext->Diags ,
190
+ workerASTContext->SearchPathOpts , workerASTContext->LangOpts ,
191
+ workerASTContext->ClangImporterOpts , workerASTContext->CASOpts , FEOpts,
181
192
/* buildModuleCacheDirIfAbsent*/ false , ClangModuleCachePath,
182
193
FEOpts.PrebuiltModuleCachePath , FEOpts.BackupModuleInterfaceDir ,
183
194
FEOpts.SerializeModuleInterfaceDependencyHashes ,
184
195
FEOpts.shouldTrackSystemDependencies (), RequireOSSAModules_t (SILOptions));
185
196
186
- // Set up the Clang importer .
197
+ // Set up the ClangImporter .
187
198
clangScannerModuleLoader = ClangImporter::create (
188
- ScanASTContext, ScanCompilerInvocation.getPCHHash (), &DependencyTracker);
199
+ *workerASTContext, workerCompilerInvocation->getPCHHash (),
200
+ &DependencyTracker);
189
201
if (!clangScannerModuleLoader)
190
202
Diagnostics.diagnose (SourceLoc (), diag::error_clang_importer_create_fail);
191
203
192
204
// Set up the Swift interface loader for Swift scanning.
193
205
swiftScannerModuleLoader = ModuleInterfaceLoader::create (
194
- ScanASTContext ,
206
+ *workerASTContext ,
195
207
*static_cast <ModuleInterfaceCheckerImpl *>(
196
208
ScanASTContext.getModuleInterfaceChecker ()),
197
209
&DependencyTracker,
198
- ScanCompilerInvocation.getSearchPathOptions ().ModuleLoadMode );
199
-
200
- llvm::cl::ResetAllOptionOccurrences ();
210
+ workerCompilerInvocation->getSearchPathOptions ().ModuleLoadMode );
201
211
}
202
212
203
213
ModuleDependencyVector
@@ -210,15 +220,15 @@ ModuleDependencyScanningWorker::scanFilesystemForModuleDependency(
210
220
moduleName, cache.getModuleOutputPath (),
211
221
cache.getScanService ().getCachingFS (),
212
222
cache.getAlreadySeenClangModules (), clangScanningTool,
213
- *ScanningASTDelegate , cache.getScanService ().getPrefixMapper (),
223
+ *scanningASTDelegate , cache.getScanService ().getPrefixMapper (),
214
224
isTestableImport);
215
225
216
226
if (moduleDependencies.empty ())
217
227
moduleDependencies = clangScannerModuleLoader->getModuleDependencies (
218
228
moduleName, cache.getModuleOutputPath (),
219
229
cache.getScanService ().getCachingFS (),
220
230
cache.getAlreadySeenClangModules (), clangScanningTool,
221
- *ScanningASTDelegate , cache.getScanService ().getPrefixMapper (),
231
+ *scanningASTDelegate , cache.getScanService ().getPrefixMapper (),
222
232
isTestableImport);
223
233
224
234
return moduleDependencies;
@@ -230,7 +240,7 @@ ModuleDependencyScanningWorker::scanFilesystemForSwiftModuleDependency(
230
240
return swiftScannerModuleLoader->getModuleDependencies (
231
241
moduleName, cache.getModuleOutputPath (),
232
242
cache.getScanService ().getCachingFS (), cache.getAlreadySeenClangModules (),
233
- clangScanningTool, *ScanningASTDelegate ,
243
+ clangScanningTool, *scanningASTDelegate ,
234
244
cache.getScanService ().getPrefixMapper (), false );
235
245
}
236
246
@@ -240,7 +250,7 @@ ModuleDependencyScanningWorker::scanFilesystemForClangModuleDependency(
240
250
return clangScannerModuleLoader->getModuleDependencies (
241
251
moduleName, cache.getModuleOutputPath (),
242
252
cache.getScanService ().getCachingFS (), cache.getAlreadySeenClangModules (),
243
- clangScanningTool, *ScanningASTDelegate ,
253
+ clangScanningTool, *scanningASTDelegate ,
244
254
cache.getScanService ().getPrefixMapper (), false );
245
255
}
246
256
0 commit comments