@@ -376,6 +376,7 @@ getModuleInfoFromOpaqueModule(clang::index::writer::OpaqueModule mod,
376376static bool
377377emitDataForSwiftSerializedModule (ModuleDecl *module ,
378378 StringRef indexStorePath,
379+ bool indexClangModules,
379380 bool indexSystemModules,
380381 bool skipStdlib,
381382 StringRef targetTriple,
@@ -387,6 +388,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
387388
388389static void addModuleDependencies (ArrayRef<ImportedModule> imports,
389390 StringRef indexStorePath,
391+ bool indexClangModules,
390392 bool indexSystemModules,
391393 bool skipStdlib,
392394 StringRef targetTriple,
@@ -424,15 +426,16 @@ static void addModuleDependencies(ArrayRef<ImportedModule> imports,
424426 bool withoutUnitName = true ;
425427 if (FU->getKind () == FileUnitKind::ClangModule) {
426428 auto clangModUnit = cast<ClangModuleUnit>(LFU);
427- if (!clangModUnit->isSystemModule () || indexSystemModules) {
428- withoutUnitName = false ;
429- if (auto clangMod = clangModUnit->getUnderlyingClangModule ()) {
430- moduleName = clangMod->getTopLevelModuleName ();
431- // FIXME: clang's -Rremarks do not seem to go through Swift's
432- // diagnostic emitter.
429+ bool shouldIndexModule = indexClangModules &&
430+ (!clangModUnit->isSystemModule () || indexSystemModules);
431+ withoutUnitName = !shouldIndexModule;
432+ if (auto clangMod = clangModUnit->getUnderlyingClangModule ()) {
433+ moduleName = clangMod->getTopLevelModuleName ();
434+ // FIXME: clang's -Rremarks do not seem to go through Swift's
435+ // diagnostic emitter.
436+ if (shouldIndexModule)
433437 clang::index::emitIndexDataForModuleFile (clangMod,
434438 clangCI, unitWriter);
435- }
436439 }
437440 } else {
438441 // Serialized AST file.
@@ -443,6 +446,7 @@ static void addModuleDependencies(ArrayRef<ImportedModule> imports,
443446 if (mod->isSystemModule () && indexSystemModules &&
444447 (!skipStdlib || !mod->isStdlibModule ())) {
445448 emitDataForSwiftSerializedModule (mod, indexStorePath,
449+ indexClangModules,
446450 indexSystemModules, skipStdlib,
447451 targetTriple, clangCI, diags,
448452 unitWriter,
@@ -472,6 +476,7 @@ static void addModuleDependencies(ArrayRef<ImportedModule> imports,
472476static bool
473477emitDataForSwiftSerializedModule (ModuleDecl *module ,
474478 StringRef indexStorePath,
479+ bool indexClangModules,
475480 bool indexSystemModules,
476481 bool skipStdlib,
477482 StringRef targetTriple,
@@ -596,9 +601,10 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
596601 module ->getImportedModules (imports, {ModuleDecl::ImportFilterKind::Exported,
597602 ModuleDecl::ImportFilterKind::Default});
598603 StringScratchSpace moduleNameScratch;
599- addModuleDependencies (imports, indexStorePath, indexSystemModules, skipStdlib,
600- targetTriple, clangCI, diags, unitWriter,
601- moduleNameScratch, pathRemapper, initialFile);
604+ addModuleDependencies (imports, indexStorePath, indexClangModules,
605+ indexSystemModules, skipStdlib, targetTriple, clangCI,
606+ diags, unitWriter, moduleNameScratch, pathRemapper,
607+ initialFile);
602608
603609 if (unitWriter.write (error)) {
604610 diags.diagnose (SourceLoc (), diag::error_write_index_unit, error);
@@ -610,9 +616,9 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
610616
611617static bool
612618recordSourceFileUnit (SourceFile *primarySourceFile, StringRef indexUnitToken,
613- StringRef indexStorePath, bool indexSystemModules ,
614- bool skipStdlib , bool isDebugCompilation ,
615- StringRef targetTriple,
619+ StringRef indexStorePath, bool indexClangModules ,
620+ bool indexSystemModules , bool skipStdlib ,
621+ bool isDebugCompilation, StringRef targetTriple,
616622 ArrayRef<const clang::FileEntry *> fileDependencies,
617623 const clang::CompilerInstance &clangCI,
618624 const PathRemapper &pathRemapper,
@@ -638,9 +644,10 @@ recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
638644 ModuleDecl::ImportFilterKind::Default,
639645 ModuleDecl::ImportFilterKind::ImplementationOnly});
640646 StringScratchSpace moduleNameScratch;
641- addModuleDependencies (imports, indexStorePath, indexSystemModules, skipStdlib,
642- targetTriple, clangCI, diags, unitWriter,
643- moduleNameScratch, pathRemapper, primarySourceFile);
647+ addModuleDependencies (imports, indexStorePath, indexClangModules,
648+ indexSystemModules, skipStdlib, targetTriple, clangCI,
649+ diags, unitWriter, moduleNameScratch, pathRemapper,
650+ primarySourceFile);
644651
645652 // File dependencies.
646653 for (auto *F : fileDependencies)
@@ -690,6 +697,7 @@ collectFileDependencies(llvm::SetVector<const clang::FileEntry *> &result,
690697bool index::indexAndRecord (SourceFile *primarySourceFile,
691698 StringRef indexUnitToken,
692699 StringRef indexStorePath,
700+ bool indexClangModules,
693701 bool indexSystemModules,
694702 bool skipStdlib,
695703 bool isDebugCompilation,
@@ -720,7 +728,8 @@ bool index::indexAndRecord(SourceFile *primarySourceFile,
720728#endif
721729
722730 return recordSourceFileUnit (primarySourceFile, indexUnitToken,
723- indexStorePath, indexSystemModules, skipStdlib,
731+ indexStorePath, indexClangModules,
732+ indexSystemModules, skipStdlib,
724733 isDebugCompilation, targetTriple,
725734 fileDependencies.getArrayRef (),
726735 clangCI, pathRemapper, diags);
@@ -730,6 +739,7 @@ bool index::indexAndRecord(ModuleDecl *module,
730739 ArrayRef<std::string> indexUnitTokens,
731740 StringRef moduleUnitToken,
732741 StringRef indexStorePath,
742+ bool indexClangModules,
733743 bool indexSystemModules,
734744 bool skipStdlib,
735745 bool isDebugCompilation,
@@ -768,7 +778,8 @@ bool index::indexAndRecord(ModuleDecl *module,
768778 return true ;
769779 }
770780 if (recordSourceFileUnit (SF, indexUnitTokens[unitIndex],
771- indexStorePath, indexSystemModules, skipStdlib,
781+ indexStorePath, indexClangModules,
782+ indexSystemModules, skipStdlib,
772783 isDebugCompilation, targetTriple,
773784 fileDependencies.getArrayRef (),
774785 clangCI, pathRemapper, diags))
0 commit comments