@@ -166,38 +166,48 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
166166 const CompilerInvocation &ScanCompilerInvocation,
167167 const SILOptions &SILOptions, ASTContext &ScanASTContext,
168168 swift::DependencyTracker &DependencyTracker, DiagnosticEngine &Diagnostics)
169- : // Diagnostics(Diagnostics),
170- clangScanningTool(*globalScanningService.ClangScanningService,
169+ : clangScanningTool(*globalScanningService.ClangScanningService,
171170 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.
173185 auto ClangModuleCachePath = getModuleCachePathFromClang (
174186 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,
181192 /* buildModuleCacheDirIfAbsent*/ false , ClangModuleCachePath,
182193 FEOpts.PrebuiltModuleCachePath , FEOpts.BackupModuleInterfaceDir ,
183194 FEOpts.SerializeModuleInterfaceDependencyHashes ,
184195 FEOpts.shouldTrackSystemDependencies (), RequireOSSAModules_t (SILOptions));
185196
186- // Set up the Clang importer .
197+ // Set up the ClangImporter .
187198 clangScannerModuleLoader = ClangImporter::create (
188- ScanASTContext, ScanCompilerInvocation.getPCHHash (), &DependencyTracker);
199+ *workerASTContext, workerCompilerInvocation->getPCHHash (),
200+ &DependencyTracker);
189201 if (!clangScannerModuleLoader)
190202 Diagnostics.diagnose (SourceLoc (), diag::error_clang_importer_create_fail);
191203
192204 // Set up the Swift interface loader for Swift scanning.
193205 swiftScannerModuleLoader = ModuleInterfaceLoader::create (
194- ScanASTContext ,
206+ *workerASTContext ,
195207 *static_cast <ModuleInterfaceCheckerImpl *>(
196208 ScanASTContext.getModuleInterfaceChecker ()),
197209 &DependencyTracker,
198- ScanCompilerInvocation.getSearchPathOptions ().ModuleLoadMode );
199-
200- llvm::cl::ResetAllOptionOccurrences ();
210+ workerCompilerInvocation->getSearchPathOptions ().ModuleLoadMode );
201211}
202212
203213ModuleDependencyVector
@@ -210,15 +220,15 @@ ModuleDependencyScanningWorker::scanFilesystemForModuleDependency(
210220 moduleName, cache.getModuleOutputPath (),
211221 cache.getScanService ().getCachingFS (),
212222 cache.getAlreadySeenClangModules (), clangScanningTool,
213- *ScanningASTDelegate , cache.getScanService ().getPrefixMapper (),
223+ *scanningASTDelegate , cache.getScanService ().getPrefixMapper (),
214224 isTestableImport);
215225
216226 if (moduleDependencies.empty ())
217227 moduleDependencies = clangScannerModuleLoader->getModuleDependencies (
218228 moduleName, cache.getModuleOutputPath (),
219229 cache.getScanService ().getCachingFS (),
220230 cache.getAlreadySeenClangModules (), clangScanningTool,
221- *ScanningASTDelegate , cache.getScanService ().getPrefixMapper (),
231+ *scanningASTDelegate , cache.getScanService ().getPrefixMapper (),
222232 isTestableImport);
223233
224234 return moduleDependencies;
@@ -230,7 +240,7 @@ ModuleDependencyScanningWorker::scanFilesystemForSwiftModuleDependency(
230240 return swiftScannerModuleLoader->getModuleDependencies (
231241 moduleName, cache.getModuleOutputPath (),
232242 cache.getScanService ().getCachingFS (), cache.getAlreadySeenClangModules (),
233- clangScanningTool, *ScanningASTDelegate ,
243+ clangScanningTool, *scanningASTDelegate ,
234244 cache.getScanService ().getPrefixMapper (), false );
235245}
236246
@@ -240,7 +250,7 @@ ModuleDependencyScanningWorker::scanFilesystemForClangModuleDependency(
240250 return clangScannerModuleLoader->getModuleDependencies (
241251 moduleName, cache.getModuleOutputPath (),
242252 cache.getScanService ().getCachingFS (), cache.getAlreadySeenClangModules (),
243- clangScanningTool, *ScanningASTDelegate ,
253+ clangScanningTool, *scanningASTDelegate ,
244254 cache.getScanService ().getPrefixMapper (), false );
245255}
246256
0 commit comments