@@ -216,37 +216,45 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
216
216
llvm::PrefixMapper *Mapper, DiagnosticEngine &Diagnostics)
217
217
: workerCompilerInvocation(
218
218
std::make_unique<CompilerInvocation>(ScanCompilerInvocation)),
219
- workerASTContext(std::unique_ptr<ASTContext>(
220
- ASTContext::get (workerCompilerInvocation->getLangOptions (),
221
- workerCompilerInvocation->getTypeCheckerOptions(),
222
- workerCompilerInvocation->getSILOptions(),
223
- workerCompilerInvocation->getSearchPathOptions(),
224
- workerCompilerInvocation->getClangImporterOptions(),
225
- workerCompilerInvocation->getSymbolGraphOptions(),
226
- workerCompilerInvocation->getCASOptions(),
227
- workerCompilerInvocation->getSerializationOptions(),
228
- ScanASTContext.SourceMgr, Diagnostics))),
229
- scanningASTDelegate(std::make_unique<InterfaceSubContextDelegateImpl>(
230
- workerASTContext->SourceMgr, &workerASTContext->Diags,
231
- workerASTContext->SearchPathOpts, workerASTContext->LangOpts,
232
- workerASTContext->ClangImporterOpts, workerASTContext->CASOpts,
233
- workerCompilerInvocation->getFrontendOptions (),
234
- /* buildModuleCacheDirIfAbsent */ false,
235
- getModuleCachePathFromClang(
236
- ScanASTContext.getClangModuleLoader()->getClangInstance()),
237
- workerCompilerInvocation->getFrontendOptions()
238
- .PrebuiltModuleCachePath,
239
- workerCompilerInvocation->getFrontendOptions()
240
- .BackupModuleInterfaceDir,
241
- workerCompilerInvocation->getFrontendOptions().CacheReplayPrefixMap,
242
- workerCompilerInvocation->getFrontendOptions()
243
- .SerializeModuleInterfaceDependencyHashes,
244
- workerCompilerInvocation->getFrontendOptions()
245
- .shouldTrackSystemDependencies(),
246
- RequireOSSAModules_t(SILOptions))),
247
219
clangScanningTool(*globalScanningService.ClangScanningService,
248
220
getClangScanningFS (CAS, ScanASTContext)),
249
221
CAS(CAS), ActionCache(ActionCache) {
222
+ // Instantiate a worker-specific diagnostic engine and copy over
223
+ // the scanner's diagnostic consumers (expected to be thread-safe).
224
+ workerDiagnosticEngine = std::make_unique<DiagnosticEngine>(ScanASTContext.SourceMgr );
225
+ for (auto &scannerDiagConsumer : Diagnostics.getConsumers ())
226
+ workerDiagnosticEngine->addConsumer (*scannerDiagConsumer);
227
+
228
+ workerASTContext = std::unique_ptr<ASTContext>(
229
+ ASTContext::get (workerCompilerInvocation->getLangOptions (),
230
+ workerCompilerInvocation->getTypeCheckerOptions (),
231
+ workerCompilerInvocation->getSILOptions (),
232
+ workerCompilerInvocation->getSearchPathOptions (),
233
+ workerCompilerInvocation->getClangImporterOptions (),
234
+ workerCompilerInvocation->getSymbolGraphOptions (),
235
+ workerCompilerInvocation->getCASOptions (),
236
+ workerCompilerInvocation->getSerializationOptions (),
237
+ ScanASTContext.SourceMgr , *workerDiagnosticEngine));
238
+
239
+ scanningASTDelegate = std::make_unique<InterfaceSubContextDelegateImpl>(
240
+ workerASTContext->SourceMgr , &workerASTContext->Diags ,
241
+ workerASTContext->SearchPathOpts , workerASTContext->LangOpts ,
242
+ workerASTContext->ClangImporterOpts , workerASTContext->CASOpts ,
243
+ workerCompilerInvocation->getFrontendOptions (),
244
+ /* buildModuleCacheDirIfAbsent */ false ,
245
+ getModuleCachePathFromClang (
246
+ ScanASTContext.getClangModuleLoader ()->getClangInstance ()),
247
+ workerCompilerInvocation->getFrontendOptions ()
248
+ .PrebuiltModuleCachePath ,
249
+ workerCompilerInvocation->getFrontendOptions ()
250
+ .BackupModuleInterfaceDir ,
251
+ workerCompilerInvocation->getFrontendOptions ().CacheReplayPrefixMap ,
252
+ workerCompilerInvocation->getFrontendOptions ()
253
+ .SerializeModuleInterfaceDependencyHashes ,
254
+ workerCompilerInvocation->getFrontendOptions ()
255
+ .shouldTrackSystemDependencies (),
256
+ RequireOSSAModules_t (SILOptions));
257
+
250
258
auto loader = std::make_unique<PluginLoader>(
251
259
*workerASTContext, /* DepTracker=*/ nullptr ,
252
260
workerCompilerInvocation->getFrontendOptions ().CacheReplayPrefixMap ,
0 commit comments