From 1b1d91d6e362e93221f150a9b664709bafd7751a Mon Sep 17 00:00:00 2001 From: Artem Chikin Date: Thu, 31 Jul 2025 10:42:44 -0700 Subject: [PATCH 1/2] [Dependency Scanning] Reduce the amount of copying of collections of module IDs Previously, frequently-used methods like 'getAllDependencies' and 'getAllClangDependencies' had to aggregate (copy) multiple collections stored in a 'ModuleDependencyInfo' into a new result array to present to the client. These methods have been refactored to instead return an iterable joined view of the constituent collections. --- include/swift/AST/ModuleDependencies.h | 83 +++++++++++++++++-- lib/AST/ModuleDependencies.cpp | 68 ++++++--------- .../ModuleDependencyScanner.cpp | 31 +++---- lib/DependencyScan/ScanDependencies.cpp | 5 +- 4 files changed, 120 insertions(+), 67 deletions(-) diff --git a/include/swift/AST/ModuleDependencies.h b/include/swift/AST/ModuleDependencies.h index 3739d7465eaf1..f57095599a4df 100644 --- a/include/swift/AST/ModuleDependencies.h +++ b/include/swift/AST/ModuleDependencies.h @@ -94,6 +94,69 @@ struct ModuleDependencyIDHash { } }; +// An iterable view over multiple joined ArrayRefs +// FIXME: std::ranges::join_view +template +class JoinedArrayRefView { +public: + class Iterator { + public: + using iterator_category = std::forward_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = const T*; + using reference = const T&; + Iterator(const JoinedArrayRefView *parent, size_t memberIndex, + size_t elementIndex) + : parentView(parent), collectionIndex(memberIndex), + elementIndex(elementIndex) { + checkAdvance(); + } + const T &operator*() const { + return (parentView->memberCollections[collectionIndex])[elementIndex]; + } + const T *operator->() const { + return &(parentView->memberCollections[collectionIndex])[elementIndex]; + } + Iterator &operator++() { + ++elementIndex; + checkAdvance(); + return *this; + } + bool operator==(const Iterator &other) const { + return collectionIndex == other.collectionIndex && + elementIndex == other.elementIndex; + } + bool operator!=(const Iterator &other) const { return !(*this == other); } + + private: + const JoinedArrayRefView *parentView; + size_t collectionIndex; + size_t elementIndex; + + void checkAdvance() { + while (collectionIndex < parentView->memberCollections.size() && + elementIndex >= parentView->memberCollections[collectionIndex].size()) { + ++collectionIndex; + elementIndex = 0; + } + } + }; + + Iterator begin() const { return Iterator(this, 0, 0); } + Iterator end() const { return Iterator(this, memberCollections.size(), 0); } + + template + JoinedArrayRefView(Arrays ...arrs) { + memberCollections.reserve(sizeof...(arrs)); + (memberCollections.push_back(arrs), ...); + } + +private: + std::vector> memberCollections; +}; +using ModuleDependencyIDCollectionView = JoinedArrayRefView; + using ModuleDependencyIDSet = std::unordered_set; using ModuleDependencyIDSetVector = @@ -719,8 +782,8 @@ class ModuleDependencyInfo { return storage->swiftOverlayDependencies; } - void - setCrossImportOverlayDependencies(const ArrayRef dependencyIDs) { + void setCrossImportOverlayDependencies( + const ModuleDependencyIDCollectionView dependencyIDs) { assert(isSwiftModule()); storage->crossImportOverlayModules.assign(dependencyIDs.begin(), dependencyIDs.end()); @@ -1051,12 +1114,16 @@ class ModuleDependenciesCache { } /// Query all dependencies - ModuleDependencyIDSetVector + ModuleDependencyIDCollectionView getAllDependencies(const ModuleDependencyID &moduleID) const; + /// Query all directly-imported dependencies + ModuleDependencyIDCollectionView + getDirectImportedDependencies(const ModuleDependencyID &moduleID) const; + /// Query all Clang module dependencies. - ModuleDependencyIDSetVector - getClangDependencies(const ModuleDependencyID &moduleID) const; + ModuleDependencyIDCollectionView + getAllClangDependencies(const ModuleDependencyID &moduleID) const; /// Query all directly-imported Swift dependencies llvm::ArrayRef @@ -1138,9 +1205,9 @@ class ModuleDependenciesCache { setHeaderClangDependencies(ModuleDependencyID moduleID, const ArrayRef dependencyIDs); /// Resolve this module's cross-import overlay dependencies - void - setCrossImportOverlayDependencies(ModuleDependencyID moduleID, - const ArrayRef dependencyIDs); + void setCrossImportOverlayDependencies( + ModuleDependencyID moduleID, + const ModuleDependencyIDCollectionView dependencyIDs); /// Add to this module's set of visible Clang modules void addVisibleClangModules(ModuleDependencyID moduleID, diff --git a/lib/AST/ModuleDependencies.cpp b/lib/AST/ModuleDependencies.cpp index ae2ba45e722af..813629c551f70 100644 --- a/lib/AST/ModuleDependencies.cpp +++ b/lib/AST/ModuleDependencies.cpp @@ -904,12 +904,13 @@ void ModuleDependenciesCache::setSwiftOverlayDependencies(ModuleDependencyID mod updatedDependencyInfo.setSwiftOverlayDependencies(dependencyIDs); updateDependency(moduleID, updatedDependencyInfo); } -void -ModuleDependenciesCache::setCrossImportOverlayDependencies(ModuleDependencyID moduleID, - const ArrayRef dependencyIDs) { +void ModuleDependenciesCache::setCrossImportOverlayDependencies( + ModuleDependencyID moduleID, + const ModuleDependencyIDCollectionView dependencyIDs) { auto dependencyInfo = findKnownDependency(moduleID); assert(dependencyInfo.getCrossImportOverlayDependencies().empty()); - // Copy the existing info to a mutable one we can then replace it with, after setting its overlay dependencies. + // Copy the existing info to a mutable one we can then replace it with, + // after setting its overlay dependencies. auto updatedDependencyInfo = dependencyInfo; updatedDependencyInfo.setCrossImportOverlayDependencies(dependencyIDs); updateDependency(moduleID, updatedDependencyInfo); @@ -933,48 +934,33 @@ llvm::StringSet<> &ModuleDependenciesCache::getVisibleClangModules(ModuleDepende return findKnownDependency(moduleID).getVisibleClangModules(); } -ModuleDependencyIDSetVector -ModuleDependenciesCache::getAllDependencies(const ModuleDependencyID &moduleID) const { +ModuleDependencyIDCollectionView ModuleDependenciesCache::getAllDependencies( + const ModuleDependencyID &moduleID) const { const auto &moduleInfo = findKnownDependency(moduleID); - ModuleDependencyIDSetVector result; - if (moduleInfo.isSwiftModule()) { - auto swiftImportedDepsRef = moduleInfo.getImportedSwiftDependencies(); - auto headerClangDepsRef = moduleInfo.getHeaderClangDependencies(); - auto overlayDependenciesRef = moduleInfo.getSwiftOverlayDependencies(); - result.insert(swiftImportedDepsRef.begin(), - swiftImportedDepsRef.end()); - result.insert(headerClangDepsRef.begin(), - headerClangDepsRef.end()); - result.insert(overlayDependenciesRef.begin(), - overlayDependenciesRef.end()); - } - - if (moduleInfo.isSwiftSourceModule()) { - auto crossImportOverlayDepsRef = moduleInfo.getCrossImportOverlayDependencies(); - result.insert(crossImportOverlayDepsRef.begin(), - crossImportOverlayDepsRef.end()); - } - - auto clangImportedDepsRef = moduleInfo.getImportedClangDependencies(); - result.insert(clangImportedDepsRef.begin(), - clangImportedDepsRef.end()); + return ModuleDependencyIDCollectionView( + moduleInfo.getImportedSwiftDependencies(), + moduleInfo.getSwiftOverlayDependencies(), + moduleInfo.getCrossImportOverlayDependencies(), + moduleInfo.getHeaderClangDependencies(), + moduleInfo.getImportedClangDependencies()); +} - return result; +ModuleDependencyIDCollectionView +ModuleDependenciesCache::getDirectImportedDependencies( + const ModuleDependencyID &moduleID) const { + const auto &moduleInfo = findKnownDependency(moduleID); + return ModuleDependencyIDCollectionView( + moduleInfo.getImportedSwiftDependencies(), + moduleInfo.getImportedClangDependencies()); } -ModuleDependencyIDSetVector -ModuleDependenciesCache::getClangDependencies(const ModuleDependencyID &moduleID) const { +ModuleDependencyIDCollectionView +ModuleDependenciesCache::getAllClangDependencies( + const ModuleDependencyID &moduleID) const { const auto &moduleInfo = findKnownDependency(moduleID); - ModuleDependencyIDSetVector result; - auto clangImportedDepsRef = moduleInfo.getImportedClangDependencies(); - result.insert(clangImportedDepsRef.begin(), - clangImportedDepsRef.end()); - if (moduleInfo.isSwiftSourceModule() || moduleInfo.isSwiftBinaryModule()) { - auto headerClangDepsRef = moduleInfo.getHeaderClangDependencies(); - result.insert(headerClangDepsRef.begin(), - headerClangDepsRef.end()); - } - return result; + return ModuleDependencyIDCollectionView( + moduleInfo.getImportedClangDependencies(), + moduleInfo.getHeaderClangDependencies()); } llvm::ArrayRef diff --git a/lib/DependencyScan/ModuleDependencyScanner.cpp b/lib/DependencyScan/ModuleDependencyScanner.cpp index 3617a73294e18..72523a42fde6d 100644 --- a/lib/DependencyScan/ModuleDependencyScanner.cpp +++ b/lib/DependencyScan/ModuleDependencyScanner.cpp @@ -953,23 +953,25 @@ ModuleDependencyScanner::resolveImportedModuleDependencies( allModules.insert(discoveredSwiftModules.begin(), discoveredSwiftModules.end()); - ModuleDependencyIDSetVector discoveredClangModules; + // Resolve all remaining unresolved imports for which no Swift + // module could be found, assuming them to be Clang modules. + // This operation is done by gathering all unresolved import + // identifiers and querying them in-parallel to the Clang + // dependency scanner. resolveAllClangModuleDependencies(discoveredSwiftModules.getArrayRef(), cache, - discoveredClangModules); - allModules.insert(discoveredClangModules.begin(), - discoveredClangModules.end()); + allModules); - ModuleDependencyIDSetVector discoveredHeaderDependencyClangModules; + // For each discovered Swift module which was built with a + // bridging header, scan the header for module dependencies. + // This includes the source module bridging header. resolveHeaderDependencies(discoveredSwiftModules.getArrayRef(), cache, - discoveredHeaderDependencyClangModules); - allModules.insert(discoveredHeaderDependencyClangModules.begin(), - discoveredHeaderDependencyClangModules.end()); + allModules); - ModuleDependencyIDSetVector discoveredSwiftOverlayDependencyModules; + // For each Swift module which imports Clang modules, + // query whether all visible Clang dependencies from such imports + // have a Swift overaly module. resolveSwiftOverlayDependencies(discoveredSwiftModules.getArrayRef(), cache, - discoveredSwiftOverlayDependencyModules); - allModules.insert(discoveredSwiftOverlayDependencyModules.begin(), - discoveredSwiftOverlayDependencyModules.end()); + allModules); return allModules; } @@ -1612,9 +1614,8 @@ void ModuleDependencyScanner::resolveCrossImportOverlayDependencies( resolveImportedModuleDependencies(dummyMainID, cache); // Update main module's dependencies to include these new overlays. - auto newOverlayDeps = cache.getAllDependencies(dummyMainID); - cache.setCrossImportOverlayDependencies(actualMainID, - newOverlayDeps.getArrayRef()); + cache.setCrossImportOverlayDependencies( + actualMainID, cache.getAllDependencies(dummyMainID)); // Update the command-line on the main module to // disable implicit cross-import overlay search. diff --git a/lib/DependencyScan/ScanDependencies.cpp b/lib/DependencyScan/ScanDependencies.cpp index e78151de2eb71..b7dfc2557df9f 100644 --- a/lib/DependencyScan/ScanDependencies.cpp +++ b/lib/DependencyScan/ScanDependencies.cpp @@ -688,7 +688,7 @@ static bool writeJSONToOutput(DiagnosticEngine &diags, } static void -bridgeDependencyIDs(const ArrayRef dependencies, +bridgeDependencyIDs(const ModuleDependencyIDCollectionView dependencies, std::vector &bridgedDependencyNames) { for (const auto &dep : dependencies) { std::string dependencyKindAndName; @@ -925,8 +925,7 @@ static swiftscan_dependency_graph_t generateFullDependencyGraph( // Create a direct dependencies set according to the output format std::vector bridgedDependencyNames; - bridgeDependencyIDs(directDependencies.getArrayRef(), - bridgedDependencyNames); + bridgeDependencyIDs(directDependencies, bridgedDependencyNames); moduleInfo->direct_dependencies = create_set(bridgedDependencyNames); moduleInfo->details = getModuleDetails(); From 39a0735de687aeeed720419e4f7a5017141786d3 Mon Sep 17 00:00:00 2001 From: Artem Chikin Date: Thu, 31 Jul 2025 10:44:32 -0700 Subject: [PATCH 2/2] [NFC] Fix formatting issues in dependency scanning code Apply clang-format to code in 'ModuleDependencies.h', 'ModuleDependencies.cpp', 'ModuleDependencyScanner.cpp' --- include/swift/AST/ModuleDependencies.h | 124 ++++++----- lib/AST/ModuleDependencies.cpp | 194 +++++++++--------- .../ModuleDependencyScanner.cpp | 55 ++--- 3 files changed, 191 insertions(+), 182 deletions(-) diff --git a/include/swift/AST/ModuleDependencies.h b/include/swift/AST/ModuleDependencies.h index f57095599a4df..6c4d579f0309d 100644 --- a/include/swift/AST/ModuleDependencies.h +++ b/include/swift/AST/ModuleDependencies.h @@ -104,8 +104,8 @@ class JoinedArrayRefView { using iterator_category = std::forward_iterator_tag; using value_type = T; using difference_type = std::ptrdiff_t; - using pointer = const T*; - using reference = const T&; + using pointer = const T *; + using reference = const T &; Iterator(const JoinedArrayRefView *parent, size_t memberIndex, size_t elementIndex) : parentView(parent), collectionIndex(memberIndex), @@ -136,7 +136,8 @@ class JoinedArrayRefView { void checkAdvance() { while (collectionIndex < parentView->memberCollections.size() && - elementIndex >= parentView->memberCollections[collectionIndex].size()) { + elementIndex >= + parentView->memberCollections[collectionIndex].size()) { ++collectionIndex; elementIndex = 0; } @@ -147,7 +148,7 @@ class JoinedArrayRefView { Iterator end() const { return Iterator(this, memberCollections.size(), 0); } template - JoinedArrayRefView(Arrays ...arrs) { + JoinedArrayRefView(Arrays... arrs) { memberCollections.reserve(sizeof...(arrs)); (memberCollections.push_back(arrs), ...); } @@ -203,9 +204,9 @@ struct ScannerImportStatementInfo { : importIdentifier(importIdentifier), importLocations({location}), isExported(isExported), accessLevel(accessLevel) {} - ScannerImportStatementInfo(std::string importIdentifier, bool isExported, - AccessLevel accessLevel, - SmallVector locations) + ScannerImportStatementInfo( + std::string importIdentifier, bool isExported, AccessLevel accessLevel, + SmallVector locations) : importIdentifier(importIdentifier), importLocations(locations), isExported(isExported), accessLevel(accessLevel) {} @@ -288,10 +289,9 @@ class ModuleDependencyInfoStorageBase { struct CommonSwiftTextualModuleDependencyDetails { CommonSwiftTextualModuleDependencyDetails( - ArrayRef buildCommandLine, - StringRef CASFileSystemRootID) - : bridgingHeaderFile(std::nullopt), - bridgingSourceFiles(), bridgingModuleDependencies(), + ArrayRef buildCommandLine, StringRef CASFileSystemRootID) + : bridgingHeaderFile(std::nullopt), bridgingSourceFiles(), + bridgingModuleDependencies(), buildCommandLine(buildCommandLine.begin(), buildCommandLine.end()), CASFileSystemRootID(CASFileSystemRootID) {} @@ -407,7 +407,8 @@ class SwiftSourceModuleDependenciesStorage ArrayRef optionalModuleImports, ArrayRef bridgingHeaderBuildCommandLine) : ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftSource, - moduleImports, optionalModuleImports, {}), + moduleImports, optionalModuleImports, + {}), textualModuleDetails(buildCommandLine, RootID), testableImports(llvm::StringSet<>()), bridgingHeaderBuildCommandLine(bridgingHeaderBuildCommandLine.begin(), @@ -417,7 +418,6 @@ class SwiftSourceModuleDependenciesStorage return new SwiftSourceModuleDependenciesStorage(*this); } - static bool classof(const ModuleDependencyInfoStorageBase *base) { return base->dependencyKind == ModuleDependencyKind::SwiftSource; } @@ -464,9 +464,8 @@ class SwiftBinaryModuleDependencyStorage compiledModulePath(compiledModulePath), moduleDocPath(moduleDocPath), sourceInfoPath(sourceInfoPath), headerImport(headerImport), definingModuleInterfacePath(definingModuleInterface), - serializedSearchPaths(serializedSearchPaths), - isFramework(isFramework), isStatic(isStatic), - userModuleVersion(userModuleVersion) {} + serializedSearchPaths(serializedSearchPaths), isFramework(isFramework), + isStatic(isStatic), userModuleVersion(userModuleVersion) {} ModuleDependencyInfoStorageBase *clone() const override { return new SwiftBinaryModuleDependencyStorage(*this); @@ -561,8 +560,7 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase { StringRef CASFileSystemRootID, StringRef clangIncludeTreeRoot, StringRef moduleCacheKey, bool IsSystem) - : ModuleDependencyInfoStorageBase(ModuleDependencyKind::Clang, - {}, {}, + : ModuleDependencyInfoStorageBase(ModuleDependencyKind::Clang, {}, {}, linkLibraries, moduleCacheKey), pcmOutputPath(pcmOutputPath), mappedPCMPath(mappedPCMPath), moduleMapFile(moduleMapFile), contextHash(contextHash), @@ -642,31 +640,28 @@ class ModuleDependencyInfo { std::make_unique( compiledModulePath, moduleDocPath, sourceInfoPath, moduleImports, optionalModuleImports, linkLibraries, serializedSearchPaths, - headerImport, definingModuleInterface,isFramework, isStatic, + headerImport, definingModuleInterface, isFramework, isStatic, moduleCacheKey, userModuleVer)); } /// Describe the main Swift module. - static ModuleDependencyInfo - forSwiftSourceModule(const std::string &CASFileSystemRootID, - ArrayRef buildCommands, - ArrayRef moduleImports, - ArrayRef optionalModuleImports, - ArrayRef bridgingHeaderBuildCommands) { + static ModuleDependencyInfo forSwiftSourceModule( + const std::string &CASFileSystemRootID, ArrayRef buildCommands, + ArrayRef moduleImports, + ArrayRef optionalModuleImports, + ArrayRef bridgingHeaderBuildCommands) { return ModuleDependencyInfo( std::make_unique( CASFileSystemRootID, buildCommands, moduleImports, optionalModuleImports, bridgingHeaderBuildCommands)); } - static ModuleDependencyInfo - forSwiftSourceModule() { + static ModuleDependencyInfo forSwiftSourceModule() { return ModuleDependencyInfo( std::make_unique( - StringRef(), ArrayRef(), - ArrayRef(), - ArrayRef(), - ArrayRef())); + StringRef(), ArrayRef(), + ArrayRef(), + ArrayRef(), ArrayRef())); } /// Describe the module dependencies for a Clang module that can be @@ -693,16 +688,14 @@ class ModuleDependencyInfo { return storage->optionalModuleImports; } - std::string getModuleCacheKey() const { - return storage->moduleCacheKey; - } + std::string getModuleCacheKey() const { return storage->moduleCacheKey; } void updateModuleCacheKey(const std::string &key) { storage->moduleCacheKey = key; } - void - setImportedSwiftDependencies(const ArrayRef dependencyIDs) { + void setImportedSwiftDependencies( + const ArrayRef dependencyIDs) { assert(isSwiftModule()); storage->importedSwiftModules.assign(dependencyIDs.begin(), dependencyIDs.end()); @@ -711,8 +704,8 @@ class ModuleDependencyInfo { return storage->importedSwiftModules; } - void - setImportedClangDependencies(const ArrayRef dependencyIDs) { + void setImportedClangDependencies( + const ArrayRef dependencyIDs) { storage->importedClangModules.assign(dependencyIDs.begin(), dependencyIDs.end()); } @@ -727,15 +720,15 @@ class ModuleDependencyInfo { case swift::ModuleDependencyKind::SwiftInterface: { auto swiftInterfaceStorage = cast(storage.get()); - swiftInterfaceStorage->textualModuleDetails.bridgingModuleDependencies.assign(dependencyIDs.begin(), - dependencyIDs.end()); + swiftInterfaceStorage->textualModuleDetails.bridgingModuleDependencies + .assign(dependencyIDs.begin(), dependencyIDs.end()); break; } case swift::ModuleDependencyKind::SwiftSource: { auto swiftSourceStorage = cast(storage.get()); - swiftSourceStorage->textualModuleDetails.bridgingModuleDependencies.assign(dependencyIDs.begin(), - dependencyIDs.end()); + swiftSourceStorage->textualModuleDetails.bridgingModuleDependencies + .assign(dependencyIDs.begin(), dependencyIDs.end()); break; } case swift::ModuleDependencyKind::SwiftBinary: { @@ -755,12 +748,14 @@ class ModuleDependencyInfo { case swift::ModuleDependencyKind::SwiftInterface: { auto swiftInterfaceStorage = cast(storage.get()); - return swiftInterfaceStorage->textualModuleDetails.bridgingModuleDependencies; + return swiftInterfaceStorage->textualModuleDetails + .bridgingModuleDependencies; } case swift::ModuleDependencyKind::SwiftSource: { auto swiftSourceStorage = cast(storage.get()); - return swiftSourceStorage->textualModuleDetails.bridgingModuleDependencies; + return swiftSourceStorage->textualModuleDetails + .bridgingModuleDependencies; } case swift::ModuleDependencyKind::SwiftBinary: { auto swiftBinaryStorage = @@ -772,8 +767,8 @@ class ModuleDependencyInfo { } } - void - setSwiftOverlayDependencies(const ArrayRef dependencyIDs) { + void setSwiftOverlayDependencies( + const ArrayRef dependencyIDs) { assert(isSwiftModule()); storage->swiftOverlayDependencies.assign(dependencyIDs.begin(), dependencyIDs.end()); @@ -796,8 +791,7 @@ class ModuleDependencyInfo { return storage->linkLibraries; } - void - setLinkLibraries(const ArrayRef linkLibraries) { + void setLinkLibraries(const ArrayRef linkLibraries) { storage->linkLibraries.assign(linkLibraries.begin(), linkLibraries.end()); } @@ -894,8 +888,7 @@ class ModuleDependencyInfo { void addVisibleClangModules(const std::vector &moduleNames) const { - storage->visibleClangModules.insert(moduleNames.begin(), - moduleNames.end()); + storage->visibleClangModules.insert(moduleNames.begin(), moduleNames.end()); } /// Whether explicit input paths of all the module dependencies @@ -1067,7 +1060,8 @@ class ModuleDependenciesCache { /// Discovered dependencies ModuleDependenciesKindMap ModuleDependenciesMap; /// Set containing all of the Clang modules that have already been seen. - llvm::DenseSet alreadySeenClangModules; + llvm::DenseSet + alreadySeenClangModules; /// Name of the module under scan std::string mainScanModuleName; /// The context hash of the current scanning invocation @@ -1093,7 +1087,8 @@ class ModuleDependenciesCache { /// Retrieve the dependencies map that corresponds to the given dependency /// kind. ModuleNameToDependencyMap &getDependenciesMap(ModuleDependencyKind kind); - const ModuleNameToDependencyMap &getDependenciesMap(ModuleDependencyKind kind) const; + const ModuleNameToDependencyMap & + getDependenciesMap(ModuleDependencyKind kind) const; /// Whether we have cached dependency information for the given module. bool hasDependency(const ModuleDependencyID &moduleID) const; @@ -1131,7 +1126,8 @@ class ModuleDependenciesCache { /// Query all directly-imported Clang dependencies llvm::ArrayRef getImportedClangDependencies(const ModuleDependencyID &moduleID) const; - /// Query all Clang module dependencies of this module's imported (bridging) header + /// Query all Clang module dependencies of this module's imported (bridging) + /// header llvm::ArrayRef getHeaderClangDependencies(const ModuleDependencyID &moduleID) const; /// Query Swift overlay dependencies @@ -1141,8 +1137,7 @@ class ModuleDependenciesCache { llvm::ArrayRef getCrossImportOverlayDependencies(const ModuleDependencyID &moduleID) const; /// Query all visible Clang modules for a given Swift dependency - llvm::StringSet<>& - getVisibleClangModules(ModuleDependencyID moduleID) const; + llvm::StringSet<> &getVisibleClangModules(ModuleDependencyID moduleID) const; /// Look for module dependencies for a module with the given ID /// @@ -1180,20 +1175,20 @@ class ModuleDependenciesCache { /// Update stored dependencies for the given module. void updateDependency(ModuleDependencyID moduleID, ModuleDependencyInfo dependencyInfo); - + /// Remove a given dependency info from the cache. void removeDependency(ModuleDependencyID moduleID); /// Resolve this module's set of directly-imported Swift module /// dependencies - void - setImportedSwiftDependencies(ModuleDependencyID moduleID, - const ArrayRef dependencyIDs); + void setImportedSwiftDependencies( + ModuleDependencyID moduleID, + const ArrayRef dependencyIDs); /// Resolve this module's set of directly-imported Clang module /// dependencies - void - setImportedClangDependencies(ModuleDependencyID moduleID, - const ArrayRef dependencyIDs); + void setImportedClangDependencies( + ModuleDependencyID moduleID, + const ArrayRef dependencyIDs); /// Resolve this module's set of Swift module dependencies /// that are Swift overlays of Clang module dependencies. void @@ -1209,9 +1204,8 @@ class ModuleDependenciesCache { ModuleDependencyID moduleID, const ModuleDependencyIDCollectionView dependencyIDs); /// Add to this module's set of visible Clang modules - void - addVisibleClangModules(ModuleDependencyID moduleID, - const std::vector &moduleNames); + void addVisibleClangModules(ModuleDependencyID moduleID, + const std::vector &moduleNames); StringRef getMainModuleName() const { return mainScanModuleName; } diff --git a/lib/AST/ModuleDependencies.cpp b/lib/AST/ModuleDependencies.cpp index 813629c551f70..d0efb2335a9a8 100644 --- a/lib/AST/ModuleDependencies.cpp +++ b/lib/AST/ModuleDependencies.cpp @@ -39,16 +39,16 @@ bool ModuleDependencyInfo::isTextualSwiftModule() const { } namespace { - ModuleDependencyKind &operator++(ModuleDependencyKind &e) { - if (e == ModuleDependencyKind::LastKind) { - llvm_unreachable( - "Attempting to increment last enum value on ModuleDependencyKind"); - } - e = ModuleDependencyKind( - static_cast::type>(e) + 1); - return e; +ModuleDependencyKind &operator++(ModuleDependencyKind &e) { + if (e == ModuleDependencyKind::LastKind) { + llvm_unreachable( + "Attempting to increment last enum value on ModuleDependencyKind"); } + e = ModuleDependencyKind( + static_cast::type>(e) + 1); + return e; } +} // namespace bool ModuleDependencyInfo::isSwiftInterfaceModule() const { return isa(storage.get()); } @@ -113,8 +113,10 @@ std::string ModuleDependencyInfo::getModuleDefiningPath() const { } void ModuleDependencyInfo::addTestableImport(ImportPath::Module module) { - assert(getAsSwiftSourceModule() && "Expected source module for addTestableImport."); - dyn_cast(storage.get())->addTestableImport(module); + assert(getAsSwiftSourceModule() && + "Expected source module for addTestableImport."); + dyn_cast(storage.get()) + ->addTestableImport(module); } bool ModuleDependencyInfo::isTestableImport(StringRef moduleName) const { @@ -135,8 +137,8 @@ void ModuleDependencyInfo::addOptionalModuleImport( for (auto &existingImport : storage->optionalModuleImports) { if (existingImport.importIdentifier == module) { existingImport.isExported |= isExported; - existingImport.accessLevel = std::max(existingImport.accessLevel, - accessLevel); + existingImport.accessLevel = + std::max(existingImport.accessLevel, accessLevel); break; } } @@ -145,7 +147,7 @@ void ModuleDependencyInfo::addOptionalModuleImport( alreadyAddedModules->insert(module); storage->optionalModuleImports.push_back( - {module.str(), isExported, accessLevel}); + {module.str(), isExported, accessLevel}); } } @@ -175,8 +177,8 @@ void ModuleDependencyInfo::addModuleImport( scannerImportLocToDiagnosticLocInfo(sourceLocation)); } existingImport.isExported |= isExported; - existingImport.accessLevel = std::max(existingImport.accessLevel, - accessLevel); + existingImport.accessLevel = + std::max(existingImport.accessLevel, accessLevel); break; } } @@ -205,9 +207,8 @@ void ModuleDependencyInfo::addModuleImport( // Special case: a submodule named "Foo.Private" can be moved to a top-level // module named "Foo_Private". ClangImporter has special support for this. if (submoduleComponent.Item.str() == "Private") - addOptionalModuleImport(ImportedModuleName + "_Private", - isExported, accessLevel, - alreadyAddedModules); + addOptionalModuleImport(ImportedModuleName + "_Private", isExported, + accessLevel, alreadyAddedModules); } addModuleImport(ImportedModuleName, isExported, accessLevel, @@ -240,9 +241,8 @@ void ModuleDependencyInfo::addModuleImports( continue; addModuleImport(realPath, importDecl->isExported(), - importDecl->getAccessLevel(), - &alreadyAddedModules, sourceManager, - importDecl->getLoc()); + importDecl->getAccessLevel(), &alreadyAddedModules, + sourceManager, importDecl->getLoc()); // Additionally, keep track of which dependencies of a Source // module are `@Testable`. @@ -273,7 +273,8 @@ void ModuleDependencyInfo::addModuleImports( // If the storage is for an interface file, the only source file we // should see is that interface file. assert(fileName == - cast(storage.get())->swiftInterfaceFile); + cast(storage.get()) + ->swiftInterfaceFile); break; } case swift::ModuleDependencyKind::SwiftSource: { @@ -408,14 +409,16 @@ void ModuleDependencyInfo::addBridgingHeader(StringRef bridgingHeader) { auto swiftInterfaceStorage = cast(storage.get()); assert(!swiftInterfaceStorage->textualModuleDetails.bridgingHeaderFile); - swiftInterfaceStorage->textualModuleDetails.bridgingHeaderFile = bridgingHeader.str(); + swiftInterfaceStorage->textualModuleDetails.bridgingHeaderFile = + bridgingHeader.str(); break; } case swift::ModuleDependencyKind::SwiftSource: { auto swiftSourceStorage = cast(storage.get()); assert(!swiftSourceStorage->textualModuleDetails.bridgingHeaderFile); - swiftSourceStorage->textualModuleDetails.bridgingHeaderFile = bridgingHeader.str(); + swiftSourceStorage->textualModuleDetails.bridgingHeaderFile = + bridgingHeader.str(); break; } default: @@ -529,11 +532,9 @@ SwiftDependencyScanningService::SwiftDependencyScanningService() { clang::tooling::dependencies::ScanningOptimizations::All); } -bool -swift::dependencies::checkImportNotTautological(const ImportPath::Module modulePath, - const SourceLoc importLoc, - const SourceFile &SF, - bool isExported) { +bool swift::dependencies::checkImportNotTautological( + const ImportPath::Module modulePath, const SourceLoc importLoc, + const SourceFile &SF, bool isExported) { if (modulePath.front().Item != SF.getParentModule()->getName() || // Overlays use an @_exported self-import to load their clang module. isExported || @@ -586,10 +587,11 @@ void swift::dependencies::registerCxxInteropLibraries( // Do not try to link CxxStdlib with the C++ standard library, Cxx or // itself. - if (llvm::none_of(llvm::ArrayRef{CXX_MODULE_NAME, "CxxStdlib", "std"}, - [mainModuleName](StringRef Name) { - return mainModuleName == Name; - })) { + if (llvm::none_of( + llvm::ArrayRef{CXX_MODULE_NAME, "CxxStdlib", "std"}, + [mainModuleName](StringRef Name) { + return mainModuleName == Name; + })) { // Only link with CxxStdlib on platforms where the overlay is available. if (Target.isOSDarwin() || Target.isOSLinux() || Target.isOSWindows() || Target.isOSFreeBSD()) @@ -598,22 +600,22 @@ void swift::dependencies::registerCxxInteropLibraries( } } -void -swift::dependencies::registerBackDeployLibraries( +void swift::dependencies::registerBackDeployLibraries( const IRGenOptions &IRGenOpts, - std::function RegistrationCallback) { - auto addBackDeployLib = [&](llvm::VersionTuple version, - StringRef libraryName, bool forceLoad) { + std::function RegistrationCallback) { + auto addBackDeployLib = [&](llvm::VersionTuple version, StringRef libraryName, + bool forceLoad) { std::optional compatibilityVersion; if (libraryName == "swiftCompatibilityDynamicReplacements") { - compatibilityVersion = IRGenOpts. - AutolinkRuntimeCompatibilityDynamicReplacementLibraryVersion; + compatibilityVersion = + IRGenOpts + .AutolinkRuntimeCompatibilityDynamicReplacementLibraryVersion; } else if (libraryName == "swiftCompatibilityConcurrency") { compatibilityVersion = IRGenOpts.AutolinkRuntimeCompatibilityConcurrencyLibraryVersion; } else { - compatibilityVersion = IRGenOpts. - AutolinkRuntimeCompatibilityLibraryVersion; + compatibilityVersion = + IRGenOpts.AutolinkRuntimeCompatibilityLibraryVersion; } if (!compatibilityVersion) @@ -626,9 +628,9 @@ swift::dependencies::registerBackDeployLibraries( {libraryName, LibraryKind::Library, /*static=*/true, forceLoad}); }; -#define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName, ForceLoad) \ - addBackDeployLib(llvm::VersionTuple Version, LibraryName, ForceLoad); - #include "swift/Frontend/BackDeploymentLibs.def" +#define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName, ForceLoad) \ + addBackDeployLib(llvm::VersionTuple Version, LibraryName, ForceLoad); +#include "swift/Frontend/BackDeploymentLibs.def" } bool SwiftDependencyScanningService::setupCachingDependencyScanningService( @@ -664,7 +666,8 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService( } ModuleDependenciesCache::ModuleDependenciesCache( - const std::string &mainScanModuleName, const std::string &scannerContextHash) + const std::string &mainScanModuleName, + const std::string &scannerContextHash) : mainScanModuleName(mainScanModuleName), scannerContextHash(scannerContextHash), scanInitializationTime(std::chrono::system_clock::now()) { @@ -674,20 +677,16 @@ ModuleDependenciesCache::ModuleDependenciesCache( } const ModuleNameToDependencyMap & -ModuleDependenciesCache::getDependenciesMap( - ModuleDependencyKind kind) const { +ModuleDependenciesCache::getDependenciesMap(ModuleDependencyKind kind) const { auto it = ModuleDependenciesMap.find(kind); - assert(it != ModuleDependenciesMap.end() && - "invalid dependency kind"); + assert(it != ModuleDependenciesMap.end() && "invalid dependency kind"); return it->second; } ModuleNameToDependencyMap & -ModuleDependenciesCache::getDependenciesMap( - ModuleDependencyKind kind) { +ModuleDependenciesCache::getDependenciesMap(ModuleDependencyKind kind) { auto it = ModuleDependenciesMap.find(kind); - assert(it != ModuleDependenciesMap.end() && - "invalid dependency kind"); + assert(it != ModuleDependenciesMap.end() && "invalid dependency kind"); return it->second; } @@ -721,8 +720,7 @@ ModuleDependenciesCache::findDependency( // module under scan. if (optionalDep.has_value()) { auto dep = optionalDep.value(); - if (dep->getAsSwiftSourceModule() && - moduleName != mainScanModuleName && + if (dep->getAsSwiftSourceModule() && moduleName != mainScanModuleName && moduleName != "MainModuleCrossImportOverlays") { return std::nullopt; } @@ -733,24 +731,28 @@ ModuleDependenciesCache::findDependency( std::optional ModuleDependenciesCache::findSwiftDependency(StringRef moduleName) const { - if (auto found = findDependency(moduleName, ModuleDependencyKind::SwiftInterface)) + if (auto found = + findDependency(moduleName, ModuleDependencyKind::SwiftInterface)) return found; - if (auto found = findDependency(moduleName, ModuleDependencyKind::SwiftBinary)) + if (auto found = + findDependency(moduleName, ModuleDependencyKind::SwiftBinary)) return found; - if (auto found = findDependency(moduleName, ModuleDependencyKind::SwiftSource)) + if (auto found = + findDependency(moduleName, ModuleDependencyKind::SwiftSource)) return found; return std::nullopt; } const ModuleDependencyInfo &ModuleDependenciesCache::findKnownDependency( const ModuleDependencyID &moduleID) const { - + auto dep = findDependency(moduleID); assert(dep && "dependency unknown"); return **dep; } -bool ModuleDependenciesCache::hasDependency(const ModuleDependencyID &moduleID) const { +bool ModuleDependenciesCache::hasDependency( + const ModuleDependencyID &moduleID) const { return hasDependency(moduleID.ModuleName, moduleID.Kind); } @@ -805,11 +807,10 @@ void ModuleDependenciesCache::recordClangDependencies( SourceLoc(), diag::dependency_scan_unexpected_variant_context_hash_note, priorContextHash, newContextHash); - diags.diagnose( - SourceLoc(), - diag::dependency_scan_unexpected_variant_module_map_note, - priorClangModuleDetails->moduleMapFile, - newClangModuleDetails->moduleMapFile); + diags.diagnose(SourceLoc(), + diag::dependency_scan_unexpected_variant_module_map_note, + priorClangModuleDetails->moduleMapFile, + newClangModuleDetails->moduleMapFile); auto diagnoseExtraCommandLineFlags = [&diags](const ClangModuleDependencyStorage *checkModuleDetails, @@ -833,7 +834,7 @@ void ModuleDependenciesCache::recordClangDependencies( } else { recordDependency(dep.first.ModuleName, dep.second); addSeenClangModule(clang::tooling::dependencies::ModuleID{ - dep.first.ModuleName, newClangModuleDetails->contextHash}); + dep.first.ModuleName, newClangModuleDetails->contextHash}); } } } @@ -850,56 +851,61 @@ void ModuleDependenciesCache::removeDependency(ModuleDependencyID moduleID) { map.erase(moduleID.ModuleName); } -void -ModuleDependenciesCache::setImportedSwiftDependencies(ModuleDependencyID moduleID, - const ArrayRef dependencyIDs) { +void ModuleDependenciesCache::setImportedSwiftDependencies( + ModuleDependencyID moduleID, + const ArrayRef dependencyIDs) { auto dependencyInfo = findKnownDependency(moduleID); assert(dependencyInfo.getImportedSwiftDependencies().empty()); #ifndef NDEBUG for (const auto &depID : dependencyIDs) assert(depID.Kind != ModuleDependencyKind::Clang); #endif - // Copy the existing info to a mutable one we can then replace it with, after setting its overlay dependencies. + // Copy the existing info to a mutable one we can then replace it with, after + // setting its overlay dependencies. auto updatedDependencyInfo = dependencyInfo; updatedDependencyInfo.setImportedSwiftDependencies(dependencyIDs); updateDependency(moduleID, updatedDependencyInfo); } -void -ModuleDependenciesCache::setImportedClangDependencies(ModuleDependencyID moduleID, - const ArrayRef dependencyIDs) { +void ModuleDependenciesCache::setImportedClangDependencies( + ModuleDependencyID moduleID, + const ArrayRef dependencyIDs) { auto dependencyInfo = findKnownDependency(moduleID); assert(dependencyInfo.getImportedClangDependencies().empty()); #ifndef NDEBUG for (const auto &depID : dependencyIDs) assert(depID.Kind == ModuleDependencyKind::Clang); #endif - // Copy the existing info to a mutable one we can then replace it with, after setting its overlay dependencies. + // Copy the existing info to a mutable one we can then replace it with, after + // setting its overlay dependencies. auto updatedDependencyInfo = dependencyInfo; updatedDependencyInfo.setImportedClangDependencies(dependencyIDs); updateDependency(moduleID, updatedDependencyInfo); } -void -ModuleDependenciesCache::setHeaderClangDependencies(ModuleDependencyID moduleID, - const ArrayRef dependencyIDs) { +void ModuleDependenciesCache::setHeaderClangDependencies( + ModuleDependencyID moduleID, + const ArrayRef dependencyIDs) { auto dependencyInfo = findKnownDependency(moduleID); #ifndef NDEBUG for (const auto &depID : dependencyIDs) assert(depID.Kind == ModuleDependencyKind::Clang); #endif - // Copy the existing info to a mutable one we can then replace it with, after setting its overlay dependencies. + // Copy the existing info to a mutable one we can then replace it with, after + // setting its overlay dependencies. auto updatedDependencyInfo = dependencyInfo; updatedDependencyInfo.setHeaderClangDependencies(dependencyIDs); updateDependency(moduleID, updatedDependencyInfo); } -void ModuleDependenciesCache::setSwiftOverlayDependencies(ModuleDependencyID moduleID, - const ArrayRef dependencyIDs) { +void ModuleDependenciesCache::setSwiftOverlayDependencies( + ModuleDependencyID moduleID, + const ArrayRef dependencyIDs) { auto dependencyInfo = findKnownDependency(moduleID); assert(dependencyInfo.getSwiftOverlayDependencies().empty()); #ifndef NDEBUG for (const auto &depID : dependencyIDs) assert(depID.Kind != ModuleDependencyKind::Clang); #endif - // Copy the existing info to a mutable one we can then replace it with, after setting its overlay dependencies. + // Copy the existing info to a mutable one we can then replace it with, after + // setting its overlay dependencies. auto updatedDependencyInfo = dependencyInfo; updatedDependencyInfo.setSwiftOverlayDependencies(dependencyIDs); updateDependency(moduleID, updatedDependencyInfo); @@ -916,9 +922,8 @@ void ModuleDependenciesCache::setCrossImportOverlayDependencies( updateDependency(moduleID, updatedDependencyInfo); } -void -ModuleDependenciesCache::addVisibleClangModules(ModuleDependencyID moduleID, - const std::vector &moduleNames) { +void ModuleDependenciesCache::addVisibleClangModules( + ModuleDependencyID moduleID, const std::vector &moduleNames) { if (moduleNames.empty()) return; auto dependencyInfo = findKnownDependency(moduleID); @@ -927,7 +932,8 @@ ModuleDependenciesCache::addVisibleClangModules(ModuleDependencyID moduleID, updateDependency(moduleID, updatedDependencyInfo); } -llvm::StringSet<> &ModuleDependenciesCache::getVisibleClangModules(ModuleDependencyID moduleID) const { +llvm::StringSet<> &ModuleDependenciesCache::getVisibleClangModules( + ModuleDependencyID moduleID) const { ASSERT(moduleID.Kind == ModuleDependencyKind::SwiftSource || moduleID.Kind == ModuleDependencyKind::SwiftInterface || moduleID.Kind == ModuleDependencyKind::SwiftBinary); @@ -964,36 +970,40 @@ ModuleDependenciesCache::getAllClangDependencies( } llvm::ArrayRef -ModuleDependenciesCache::getImportedSwiftDependencies(const ModuleDependencyID &moduleID) const { +ModuleDependenciesCache::getImportedSwiftDependencies( + const ModuleDependencyID &moduleID) const { const auto &moduleInfo = findKnownDependency(moduleID); assert(moduleInfo.isSwiftModule()); return moduleInfo.getImportedSwiftDependencies(); } llvm::ArrayRef -ModuleDependenciesCache::getImportedClangDependencies(const ModuleDependencyID &moduleID) const { +ModuleDependenciesCache::getImportedClangDependencies( + const ModuleDependencyID &moduleID) const { const auto &moduleInfo = findKnownDependency(moduleID); return moduleInfo.getImportedClangDependencies(); } llvm::ArrayRef -ModuleDependenciesCache::getHeaderClangDependencies(const ModuleDependencyID &moduleID) const { +ModuleDependenciesCache::getHeaderClangDependencies( + const ModuleDependencyID &moduleID) const { const auto &moduleInfo = findKnownDependency(moduleID); assert(moduleInfo.isSwiftModule()); return moduleInfo.getHeaderClangDependencies(); } llvm::ArrayRef -ModuleDependenciesCache::getSwiftOverlayDependencies(const ModuleDependencyID &moduleID) const { +ModuleDependenciesCache::getSwiftOverlayDependencies( + const ModuleDependencyID &moduleID) const { const auto &moduleInfo = findKnownDependency(moduleID); assert(moduleInfo.isSwiftModule()); return moduleInfo.getSwiftOverlayDependencies(); } llvm::ArrayRef -ModuleDependenciesCache::getCrossImportOverlayDependencies(const ModuleDependencyID &moduleID) const { +ModuleDependenciesCache::getCrossImportOverlayDependencies( + const ModuleDependencyID &moduleID) const { const auto &moduleInfo = findKnownDependency(moduleID); assert(moduleInfo.isSwiftSourceModule()); return moduleInfo.getCrossImportOverlayDependencies(); } - diff --git a/lib/DependencyScan/ModuleDependencyScanner.cpp b/lib/DependencyScan/ModuleDependencyScanner.cpp index 72523a42fde6d..bb370a83dfecc 100644 --- a/lib/DependencyScan/ModuleDependencyScanner.cpp +++ b/lib/DependencyScan/ModuleDependencyScanner.cpp @@ -205,7 +205,7 @@ getClangScanningFS(std::shared_ptr cas, llvm::IntrusiveRefCntPtr baseFileSystem = llvm::vfs::createPhysicalFileSystem(); ClangInvocationFileMapping fileMapping = - applyClangInvocationMapping(ctx, nullptr, baseFileSystem, false); + applyClangInvocationMapping(ctx, nullptr, baseFileSystem, false); if (cas) return llvm::cas::createCASProvidingFileSystem(cas, baseFileSystem); @@ -295,7 +295,8 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker( workerCompilerInvocation->getSearchPathOptions().ModuleLoadMode, *scanningASTDelegate, moduleOutputPath, sdkModuleOutputPath, swiftModuleClangCC1CommandLineArgs, - workerCompilerInvocation->getSearchPathOptions().ExplicitSwiftModuleInputs); + workerCompilerInvocation->getSearchPathOptions() + .ExplicitSwiftModuleInputs); } SwiftModuleScannerQueryResult @@ -516,11 +517,11 @@ SwiftDependencyTracker::SwiftDependencyTracker( } // Add VFSOverlay file. - for (auto &Overlay: SearchPathOpts.VFSOverlayFiles) + for (auto &Overlay : SearchPathOpts.VFSOverlayFiles) addCommonFile(Overlay); // Add blocklist file. - for (auto &File: CI.getFrontendOptions().BlocklistConfigFilePaths) + for (auto &File : CI.getFrontendOptions().BlocklistConfigFilePaths) addCommonFile(File); } @@ -542,8 +543,7 @@ void SwiftDependencyTracker::trackFile(const Twine &path) { auto fileRef = (*file)->getObjectRefForContent(); if (!fileRef) return; - std::string realPath = - Mapper ? Mapper->mapToString(path.str()) : path.str(); + std::string realPath = Mapper ? Mapper->mapToString(path.str()) : path.str(); TrackedFiles.try_emplace(realPath, **fileRef, (size_t)status->getSize()); } @@ -930,8 +930,7 @@ ModuleDependencyScanner::performDependencyScan(ModuleDependencyID rootModuleID, if (ScanCompilerInvocation.getSearchPathOptions().BridgingHeaderChaining) { auto err = performBridgingHeaderChaining(rootModuleID, cache, allModules); if (err) - IssueReporter.Diagnostics.diagnose(SourceLoc(), - diag::error_scanner_extra, + IssueReporter.Diagnostics.diagnose(SourceLoc(), diag::error_scanner_extra, toString(std::move(err))); } @@ -1100,7 +1099,7 @@ void ModuleDependencyScanner::resolveAllClangModuleDependencies( // Module lookup result collection llvm::StringMap moduleLookupResult; const llvm::DenseSet - seenClangModules = cache.getAlreadySeenClangModules(); + seenClangModules = cache.getAlreadySeenClangModules(); std::mutex resultAccessLock; auto scanForClangModuleDependency = [this, &moduleLookupResult, &resultAccessLock, &seenClangModules]( @@ -1144,8 +1143,9 @@ void ModuleDependencyScanner::resolveAllClangModuleDependencies( if (!lookupResult.foundDependencyModuleGraph.empty() || !lookupResult.visibleModuleIdentifiers.empty()) { if (!lookupResult.foundDependencyModuleGraph.empty()) { - cache.recordClangDependencies(lookupResult.foundDependencyModuleGraph, - IssueReporter.Diagnostics); + cache.recordClangDependencies( + lookupResult.foundDependencyModuleGraph, + IssueReporter.Diagnostics); // Add the full transitive dependency set for (const auto &dep : lookupResult.foundDependencyModuleGraph) allDiscoveredClangModules.insert(dep.first); @@ -1351,8 +1351,8 @@ void ModuleDependencyScanner::resolveSwiftImportsForModule( moduleImport.importIdentifier, lookupResult.incompatibleCandidates); // Module was resolved from a cache - } else if (auto cachedInfo = cache.findSwiftDependency( - moduleImport.importIdentifier)) + } else if (auto cachedInfo = + cache.findSwiftDependency(moduleImport.importIdentifier)) importedSwiftDependencies.insert( {moduleImport.importIdentifier, cachedInfo.value()->getKind()}); else @@ -1476,7 +1476,8 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule( auto moduleName = moduleIdentifier.str(); { std::lock_guard guard(lookupResultLock); - if (cache.hasDependency(moduleName, ModuleDependencyKind::SwiftInterface) || + if (cache.hasDependency(moduleName, + ModuleDependencyKind::SwiftInterface) || cache.hasDependency(moduleName, ModuleDependencyKind::SwiftBinary)) return; } @@ -1486,7 +1487,7 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule( return ScanningWorker->scanFilesystemForSwiftModuleDependency( moduleIdentifier, /* isTestableImport */ false); }); - + { std::lock_guard guard(lookupResultLock); swiftOverlayLookupResult.insert_or_assign(moduleName, moduleDependencies); @@ -1527,20 +1528,24 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule( recordResult(clangDep.getKey().str()); // C++ Interop requires additional handling - bool lookupCxxStdLibOverlay = ScanCompilerInvocation.getLangOptions().EnableCXXInterop; - if (lookupCxxStdLibOverlay && moduleID.Kind == ModuleDependencyKind::SwiftInterface) { + bool lookupCxxStdLibOverlay = + ScanCompilerInvocation.getLangOptions().EnableCXXInterop; + if (lookupCxxStdLibOverlay && + moduleID.Kind == ModuleDependencyKind::SwiftInterface) { const auto &moduleInfo = cache.findKnownDependency(moduleID); const auto commandLine = moduleInfo.getCommandline(); // If the textual interface was built without C++ interop, do not query // the C++ Standard Library Swift overlay for its compilation. // - // FIXME: We always declare the 'Darwin' module as formally having been built - // without C++Interop, for compatibility with prior versions. Once we are certain - // that we are only building against modules built with support of - // '-formal-cxx-interoperability-mode', this hard-coded check should be removed. + // FIXME: We always declare the 'Darwin' module as formally having been + // built without C++Interop, for compatibility with prior versions. Once we + // are certain that we are only building against modules built with support + // of + // '-formal-cxx-interoperability-mode', this hard-coded check should be + // removed. if (moduleID.ModuleName == "Darwin" || llvm::find(commandLine, "-formal-cxx-interoperability-mode=off") != - commandLine.end()) + commandLine.end()) lookupCxxStdLibOverlay = false; } @@ -1892,9 +1897,9 @@ void ModuleDependencyIssueReporter::diagnoseFailureOnOnlyIncompatibleCandidates( if (candidates.empty()) return; - diagnoseModuleNotFoundFailure(moduleImport, cache, dependencyOf, - /* resolvingSerializedSearchPath */ std::nullopt, - candidates); + diagnoseModuleNotFoundFailure( + moduleImport, cache, dependencyOf, + /* resolvingSerializedSearchPath */ std::nullopt, candidates); } void ModuleDependencyIssueReporter::warnOnIncompatibleCandidates(