@@ -326,8 +326,7 @@ static void findAllImportedClangModules(StringRef moduleName,
326326}
327327
328328llvm::ErrorOr<ModuleDependencyInfo>
329- ModuleDependencyScanner::getMainModuleDependencyInfo (
330- ModuleDecl *mainModule, std::optional<SwiftDependencyTracker> tracker) {
329+ ModuleDependencyScanner::getMainModuleDependencyInfo (ModuleDecl *mainModule) {
331330 // Main module file name.
332331 auto newExt = file_types::getExtension (file_types::TY_SwiftModuleFile);
333332 llvm::SmallString<32 > mainModulePath = mainModule->getName ().str ();
@@ -345,35 +344,9 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(
345344 ExtraPCMArgs.begin (),
346345 {" -Xcc" , " -target" , " -Xcc" , ScanASTContext.LangOpts .Target .str ()});
347346
348- std::string rootID;
349- std::vector<std::string> buildArgs;
350347 auto clangImporter =
351348 static_cast <ClangImporter *>(ScanASTContext.getClangModuleLoader ());
352- if (tracker) {
353- tracker->startTracking ();
354- for (auto fileUnit : mainModule->getFiles ()) {
355- auto sf = dyn_cast<SourceFile>(fileUnit);
356- if (!sf)
357- continue ;
358- tracker->trackFile (sf->getFilename ());
359- }
360- tracker->addCommonSearchPathDeps (
361- ScanCompilerInvocation.getSearchPathOptions ());
362- // Fetch some dependency files from clang importer.
363- std::vector<std::string> clangDependencyFiles;
364- clangImporter->addClangInvovcationDependencies (clangDependencyFiles);
365- llvm::for_each (clangDependencyFiles,
366- [&](std::string &file) { tracker->trackFile (file); });
367-
368- auto root = tracker->createTreeFromDependencies ();
369- if (!root) {
370- Diagnostics.diagnose (SourceLoc (), diag::error_cas,
371- toString (root.takeError ()));
372- return std::make_error_code (std::errc::io_error);
373- }
374- rootID = root->getID ().toString ();
375- }
376-
349+ std::vector<std::string> buildArgs;
377350 if (ScanASTContext.ClangImporterOpts .ClangImporterDirectCC1Scan ) {
378351 buildArgs.push_back (" -direct-clang-cc1-module-build" );
379352 for (auto &arg : clangImporter->getSwiftExplicitModuleDirectCC1Args ()) {
@@ -389,7 +362,15 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(
389362 });
390363
391364 auto mainDependencies = ModuleDependencyInfo::forSwiftSourceModule (
392- rootID, buildCommands, {}, ExtraPCMArgs);
365+ {}, buildCommands, {}, ExtraPCMArgs);
366+
367+ if (ScanASTContext.CASOpts .EnableCaching ) {
368+ std::vector<std::string> clangDependencyFiles;
369+ clangImporter->addClangInvovcationDependencies (clangDependencyFiles);
370+ llvm::for_each (clangDependencyFiles, [&](std::string &file) {
371+ mainDependencies.addAuxiliaryFile (file);
372+ });
373+ }
393374
394375 llvm::StringSet<> alreadyAddedModules;
395376 // Compute Implicit dependencies of the main module
@@ -808,6 +789,7 @@ void ModuleDependencyScanner::discoverCrossImportOverlayDependencies(
808789 llvm::function_ref<void (ModuleDependencyID)> action) {
809790 // Modules explicitly imported. Only these can be secondary module.
810791 llvm::SetVector<Identifier> newOverlays;
792+ std::vector<std::string> overlayFiles;
811793 for (auto dep : allDependencies) {
812794 auto moduleName = dep.ModuleName ;
813795 // Do not look for overlays of main module under scan
@@ -817,7 +799,7 @@ void ModuleDependencyScanner::discoverCrossImportOverlayDependencies(
817799 auto dependencies = cache.findDependency (moduleName, dep.Kind ).value ();
818800 // Collect a map from secondary module name to cross-import overlay names.
819801 auto overlayMap = dependencies->collectCrossImportOverlayNames (
820- ScanASTContext, moduleName);
802+ ScanASTContext, moduleName, overlayFiles );
821803 if (overlayMap.empty ())
822804 continue ;
823805 for (const auto &dependencyId : allDependencies) {
@@ -879,11 +861,9 @@ void ModuleDependencyScanner::discoverCrossImportOverlayDependencies(
879861
880862 // Update main module's dependencies to include these new overlays.
881863 auto resolvedDummyDep =
882- *(cache.findDependency (dummyMainName, ModuleDependencyKind::SwiftSource)
883- .value ());
864+ **cache.findDependency (dummyMainName, ModuleDependencyKind::SwiftSource);
884865 auto mainDep =
885- *(cache.findDependency (mainModuleName, ModuleDependencyKind::SwiftSource)
886- .value ());
866+ **cache.findDependency (mainModuleName, ModuleDependencyKind::SwiftSource);
887867 auto newOverlayDeps = resolvedDummyDep.getDirectModuleDependencies ();
888868 auto existingMainDeps = mainDep.getDirectModuleDependencies ();
889869 ModuleDependencyIDSet existingMainDepsSet (existingMainDeps.begin (),
@@ -895,6 +875,11 @@ void ModuleDependencyScanner::discoverCrossImportOverlayDependencies(
895875 if (!existingMainDepsSet.count (crossImportOverlayModID))
896876 mainDep.addModuleDependency (crossImportOverlayModID);
897877 });
878+
879+ llvm::for_each (overlayFiles, [&mainDep](const std::string &file) {
880+ mainDep.addAuxiliaryFile (file);
881+ });
882+
898883 cache.updateDependency (
899884 {mainModuleName.str (), ModuleDependencyKind::SwiftSource}, mainDep);
900885
0 commit comments