diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h index e980d009d73f5..733b1ead82fb5 100644 --- a/include/swift/AST/ASTContext.h +++ b/include/swift/AST/ASTContext.h @@ -1094,9 +1094,6 @@ class ASTContext final { /// $SDKROOT/System/Library/Frameworks/ and $SDKROOT/Library/Frameworks/. std::vector getDarwinImplicitFrameworkSearchPaths() const; - /// Return a set of all possible filesystem locations where modules can be found. - llvm::StringSet<> getAllModuleSearchPathsSet() const; - /// Load extensions to the given nominal type from the external /// module loaders. /// diff --git a/include/swift/AST/ModuleDependencies.h b/include/swift/AST/ModuleDependencies.h index 391b2acc0b4a0..f51ead05087d7 100644 --- a/include/swift/AST/ModuleDependencies.h +++ b/include/swift/AST/ModuleDependencies.h @@ -787,11 +787,6 @@ class ModuleDependencyInfo { return storage->auxiliaryFiles; } - void - setAuxiliaryFiles(const ArrayRef auxiliaryFiles) { - storage->auxiliaryFiles.assign(auxiliaryFiles.begin(), auxiliaryFiles.end()); - } - bool isStaticLibrary() const { if (auto *detail = getAsSwiftInterfaceModule()) return detail->isStatic; diff --git a/include/swift/AST/SearchPathOptions.h b/include/swift/AST/SearchPathOptions.h index 1d32b1625bd91..1156288955327 100644 --- a/include/swift/AST/SearchPathOptions.h +++ b/include/swift/AST/SearchPathOptions.h @@ -323,6 +323,10 @@ class SearchPathOptions { friend bool operator!=(const SearchPath &LHS, const SearchPath &RHS) { return !(LHS == RHS); } + friend llvm::hash_code + hash_value(const SearchPath &searchPath) { + return llvm::hash_combine(searchPath.Path, searchPath.IsSystem); + } }; private: @@ -599,30 +603,17 @@ class SearchPathOptions { makeOverlayFileSystem( llvm::IntrusiveRefCntPtr BaseFS) const; -private: - static StringRef pathStringFromSearchPath(const SearchPath &next) { - return next.Path; - }; - public: /// Return a hash code of any components from these options that should /// contribute to a Swift Bridging PCH hash. llvm::hash_code getPCHHashComponents() const { using llvm::hash_combine; using llvm::hash_combine_range; - - using SearchPathView = - ArrayRefView; - SearchPathView importPathsOnly{ImportSearchPaths}; - SearchPathView frameworkPathsOnly{FrameworkSearchPaths}; - return hash_combine(SDKPath, - // FIXME: Should we include the system-ness of - // search paths too? - hash_combine_range(importPathsOnly.begin(), importPathsOnly.end()), + hash_combine_range(ImportSearchPaths.begin(), ImportSearchPaths.end()), hash_combine_range(VFSOverlayFiles.begin(), VFSOverlayFiles.end()), - hash_combine_range(frameworkPathsOnly.begin(), - frameworkPathsOnly.end()), + hash_combine_range(FrameworkSearchPaths.begin(), + FrameworkSearchPaths.end()), hash_combine_range(LibrarySearchPaths.begin(), LibrarySearchPaths.end()), RuntimeResourcePath, diff --git a/include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h b/include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h index fddb8bdd721dc..b12f8a28ebaa8 100644 --- a/include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h +++ b/include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h @@ -41,7 +41,7 @@ using llvm::BCVBR; const unsigned char MODULE_DEPENDENCY_CACHE_FORMAT_SIGNATURE[] = {'I', 'M', 'D','C'}; const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR = 9; /// Increment this on every change. -const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 1; +const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 2; /// Various identifiers in this format will rely on having their strings mapped /// using this ID. @@ -80,7 +80,6 @@ using LinkLibrariesArrayIDField = IdentifierIDField; using MacroDependenciesArrayIDField = IdentifierIDField; using FlagIDArrayIDField = IdentifierIDField; using DependencyIDArrayIDField = IdentifierIDField; -using AuxiliaryFilesArrayIDField = IdentifierIDField; using SourceLocationIDArrayIDField = IdentifierIDField; /// The ID of the top-level block containing the dependency graph @@ -204,8 +203,7 @@ using ModuleInfoLayout = DependencyIDArrayIDField, // importedClangModules DependencyIDArrayIDField, // crossImportOverlayModules DependencyIDArrayIDField, // swiftOverlayDependencies - ModuleCacheKeyIDField, // moduleCacheKey - AuxiliaryFilesArrayIDField // auxiliaryFiles + ModuleCacheKeyIDField // moduleCacheKey >; using SwiftInterfaceModuleDetailsLayout = diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 892209281dfe6..7c07a5e07af1c 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -2212,46 +2212,6 @@ const { return SearchPathOpts.getDarwinImplicitFrameworkSearchPaths(); } -llvm::StringSet<> ASTContext::getAllModuleSearchPathsSet() -const { - llvm::StringSet<> result; - - // Import and framework paths are "special", they contain more than path - // strings, but path strings are all we care about here. - using SearchPathView = ArrayRefView; - - SearchPathView importPathsOnly{SearchPathOpts.getImportSearchPaths()}; - result.insert(importPathsOnly.begin(), importPathsOnly.end()); - - SearchPathView frameworkPathsOnly{SearchPathOpts.getFrameworkSearchPaths()}; - result.insert(frameworkPathsOnly.begin(), frameworkPathsOnly.end()); - - if (LangOpts.Target.isOSDarwin()) { - auto implicitFrameworkSearchPaths = getDarwinImplicitFrameworkSearchPaths(); - result.insert(implicitFrameworkSearchPaths.begin(), - implicitFrameworkSearchPaths.end()); - } - result.insert(SearchPathOpts.RuntimeLibraryImportPaths.begin(), - SearchPathOpts.RuntimeLibraryImportPaths.end()); - - // ClangImporter special-cases the path for SwiftShims, so do the same here - // If there are no shims in the resource dir, add a search path in the SDK. - SmallString<128> shimsPath(SearchPathOpts.RuntimeResourcePath); - llvm::sys::path::append(shimsPath, "shims"); - if (!llvm::sys::fs::exists(shimsPath)) { - shimsPath = SearchPathOpts.getSDKPath(); - llvm::sys::path::append(shimsPath, "usr", "lib", "swift", "shims"); - } - result.insert(shimsPath.str()); - - // Clang system modules are found in the SDK root - SmallString<128> clangSysRootPath(SearchPathOpts.getSDKPath()); - llvm::sys::path::append(clangSysRootPath, "usr", "include"); - result.insert(clangSysRootPath.str()); - return result; -} - void ASTContext::loadExtensions(NominalTypeDecl *nominal, unsigned previousGeneration) { PrettyStackTraceDecl stackTrace("loading extensions for", nominal); diff --git a/lib/DependencyScan/ModuleDependencyCacheSerialization.cpp b/lib/DependencyScan/ModuleDependencyCacheSerialization.cpp index 7dd4d09569e07..8aec122f6307e 100644 --- a/lib/DependencyScan/ModuleDependencyCacheSerialization.cpp +++ b/lib/DependencyScan/ModuleDependencyCacheSerialization.cpp @@ -218,9 +218,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph( bool hasCurrentModule = false; std::string currentModuleName; - std::vector currentModuleImports; - std::vector currentOptionalModuleImports; - std::vector importedSwiftDependenciesIDs; std::vector importedClangDependenciesIDs; std::vector crossImportOverlayDependenciesIDs; @@ -232,27 +229,12 @@ bool ModuleDependenciesCacheDeserializer::readGraph( std::vector importStatements; std::vector optionalImportStatements; - std::vector auxiliaryFiles; - auto addCommonDependencyInfo = - [¤tModuleImports, ¤tOptionalModuleImports, - &importedClangDependenciesIDs, &auxiliaryFiles, - ¯oDependencies](ModuleDependencyInfo &moduleDep) { - // Add imports of this module - for (const auto &moduleName : currentModuleImports) - moduleDep.addModuleImport(moduleName.importIdentifier, - moduleName.isExported); - // Add optional imports of this module - for (const auto &moduleName : currentOptionalModuleImports) - moduleDep.addOptionalModuleImport(moduleName.importIdentifier, - moduleName.isExported); - + [&importedClangDependenciesIDs, ¯oDependencies] + (ModuleDependencyInfo &moduleDep) { // Add qualified dependencies of this module moduleDep.setImportedClangDependencies(importedClangDependenciesIDs); - // Add any auxiliary files - moduleDep.setAuxiliaryFiles(auxiliaryFiles); - // Add macro dependencies for (const auto &md : macroDependencies) moduleDep.addMacroDependency(md.first, md.second.LibraryPath, @@ -297,7 +279,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph( llvm::report_fatal_error("Bad bridging module dependencies"); llvm::StringSet<> alreadyAdded; std::vector bridgingModuleDepIDs; - for (const auto &mod : bridgingModuleDeps.value()) + for (const auto &mod : *bridgingModuleDeps) bridgingModuleDepIDs.push_back( ModuleDependencyID{mod, ModuleDependencyKind::Clang}); moduleDep.setHeaderClangDependencies(bridgingModuleDepIDs); @@ -364,7 +346,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph( llvm::report_fatal_error("Bad link library identifier"); LinkLibraries.emplace_back( - libraryIdentifier.value(), + *libraryIdentifier, isFramework ? LibraryKind::Framework : LibraryKind::Library, isStatic, shouldForceLoad); @@ -395,8 +377,8 @@ bool ModuleDependenciesCacheDeserializer::readGraph( llvm::report_fatal_error("Bad macro dependency: no executable path"); MacroDependencies.push_back( - {macroModuleName.value(), - MacroPluginDependency{libraryPath.value(), executablePath.value()}}); + {*macroModuleName, + MacroPluginDependency{*libraryPath, *executablePath}}); break; } @@ -422,10 +404,14 @@ bool ModuleDependenciesCacheDeserializer::readGraph( if (!bufferIdentifier) llvm::report_fatal_error( "Bad import statement info: no buffer identifier"); - ImportStatements.push_back(ScannerImportStatementInfo( - importIdentifier.value(), isExported, - ScannerImportStatementInfo::ImportDiagnosticLocationInfo( - bufferIdentifier.value(), lineNumber, columnNumber))); + if (bufferIdentifier->empty()) + ImportStatements.push_back(ScannerImportStatementInfo( + *importIdentifier, isExported)); + else + ImportStatements.push_back(ScannerImportStatementInfo( + *importIdentifier, isExported, + ScannerImportStatementInfo::ImportDiagnosticLocationInfo( + *bufferIdentifier, lineNumber, columnNumber))); break; } @@ -450,8 +436,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph( importedSwiftDependenciesIDsArrayID, importedClangDependenciesIDsArrayID, crossImportOverlayDependenciesIDsArrayID, - swiftOverlayDependenciesIDsArrayID, moduleCacheKeyID, - AuxiliaryFilesArrayID; + swiftOverlayDependenciesIDsArrayID, moduleCacheKeyID; ModuleInfoLayout::readRecord(Scratch, moduleNameID, moduleImportsArrayID, optionalImportsArrayID, linkLibraryArrayID, @@ -460,7 +445,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph( importedClangDependenciesIDsArrayID, crossImportOverlayDependenciesIDsArrayID, swiftOverlayDependenciesIDsArrayID, - moduleCacheKeyID, AuxiliaryFilesArrayID); + moduleCacheKeyID); auto moduleName = getIdentifier(moduleNameID); if (!moduleName) llvm::report_fatal_error("Bad module name"); @@ -470,19 +455,12 @@ bool ModuleDependenciesCacheDeserializer::readGraph( getImportStatementInfoArray(moduleImportsArrayID); if (!optionalImportStatementInfos) llvm::report_fatal_error("Bad direct Swift dependencies: no imports"); - importStatements = optionalImportStatementInfos.value(); + importStatements = *optionalImportStatementInfos; auto optionalOptionalImportStatementInfos = getOptionalImportStatementInfoArray(optionalImportsArrayID); - if (!optionalOptionalImportStatementInfos) - llvm::report_fatal_error( - "Bad direct Swift dependencies: no optional imports"); - optionalImportStatements = optionalOptionalImportStatementInfos.value(); - - auto optionalAuxiliaryFiles = getStringArray(AuxiliaryFilesArrayID); - if (optionalAuxiliaryFiles.has_value()) - for (const auto &af : optionalAuxiliaryFiles.value()) - auxiliaryFiles.push_back(af); + if (optionalOptionalImportStatementInfos) + optionalImportStatements = *optionalOptionalImportStatementInfos; auto optionalImportedSwiftDependenciesIDs = getModuleDependencyIDArray(importedSwiftDependenciesIDsArrayID); @@ -490,7 +468,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph( llvm::report_fatal_error( "Bad direct Swift dependencies: no qualified dependencies"); importedSwiftDependenciesIDs = - optionalImportedSwiftDependenciesIDs.value(); + *optionalImportedSwiftDependenciesIDs; auto optionalImportedClangDependenciesIDs = getModuleDependencyIDArray(importedClangDependenciesIDsArrayID); @@ -498,7 +476,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph( llvm::report_fatal_error( "Bad direct Clang dependencies: no qualified dependencies"); importedClangDependenciesIDs = - optionalImportedClangDependenciesIDs.value(); + *optionalImportedClangDependenciesIDs; auto optionalCrossImportOverlayDependenciesIDs = getModuleDependencyIDArray(crossImportOverlayDependenciesIDsArrayID); @@ -506,14 +484,14 @@ bool ModuleDependenciesCacheDeserializer::readGraph( llvm::report_fatal_error( "Bad Cross-Import Overlay dependencies: no qualified dependencies"); crossImportOverlayDependenciesIDs = - optionalCrossImportOverlayDependenciesIDs.value(); + *optionalCrossImportOverlayDependenciesIDs; auto optionalSwiftOverlayDependenciesIDs = getModuleDependencyIDArray(swiftOverlayDependenciesIDsArrayID); if (!optionalSwiftOverlayDependenciesIDs) llvm::report_fatal_error( "Bad Swift Overlay dependencies: no qualified dependencies"); - swiftOverlayDependenciesIDs = optionalSwiftOverlayDependenciesIDs.value(); + swiftOverlayDependenciesIDs = *optionalSwiftOverlayDependenciesIDs; auto optionalLinkLibraries = getLinkLibraryArray(linkLibraryArrayID); if (!optionalLinkLibraries) @@ -587,7 +565,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph( // Form the dependencies storage object auto moduleDep = ModuleDependencyInfo::forSwiftInterfaceModule( - optionalSwiftInterfaceFile.value(), compiledCandidatesRefs, + *optionalSwiftInterfaceFile, compiledCandidatesRefs, buildCommandRefs, importStatements, optionalImportStatements, linkLibraries, isFramework, isStatic, *rootFileSystemID, *moduleCacheKey, *userModuleVersion); @@ -711,7 +689,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph( // Form the dependencies storage object auto moduleDep = ModuleDependencyInfo::forSwiftBinaryModule( *compiledModulePath, *moduleDocPath, *moduleSourceInfoPath, - currentModuleImports, currentOptionalModuleImports, linkLibraries, + importStatements, optionalImportStatements, linkLibraries, *headerImport, *definingInterfacePath, isFramework, isStatic, *moduleCacheKey, *userModuleVersion); @@ -984,7 +962,7 @@ ModuleDependenciesCacheDeserializer::getOptionalImportStatementInfoArray( std::optional> ModuleDependenciesCacheDeserializer::getModuleDependencyIDArray(unsigned n) { auto encodedIdentifierStringArray = getStringArray(n); - if (encodedIdentifierStringArray.has_value()) { + if (encodedIdentifierStringArray) { static const std::string textualPrefix("swiftTextual"); static const std::string binaryPrefix("swiftBinary"); static const std::string placeholderPrefix("swiftPlaceholder"); @@ -1053,7 +1031,6 @@ enum ModuleIdentifierArrayKind : uint8_t { ImportedClangDependenciesIDs, CrossImportOverlayDependenciesIDs, SwiftOverlayDependenciesIDs, - AuxiliaryFileIDs, CompiledModuleCandidates, BuildCommandLine, SourceFiles, @@ -1288,8 +1265,8 @@ void ModuleDependenciesCacheSerializer::writeLinkLibraries( for (const auto &entry : modMap) { ModuleDependencyID moduleID = {entry.getKey().str(), kind}; auto optionalDependencyInfo = cache.findDependency(moduleID); - assert(optionalDependencyInfo.has_value() && "Expected dependency info."); - auto dependencyInfo = optionalDependencyInfo.value(); + assert(optionalDependencyInfo && "Expected dependency info."); + auto dependencyInfo = *optionalDependencyInfo; unsigned numLLs = writeLinkLibraryInfos(*dependencyInfo); moduleLLArrayMap.insert({moduleID, std::make_pair(lastLLIndex, numLLs)}); lastLLIndex += numLLs; @@ -1343,8 +1320,8 @@ void ModuleDependenciesCacheSerializer::writeMacroDependencies( for (const auto &entry : modMap) { ModuleDependencyID moduleID = {entry.getKey().str(), kind}; auto optionalDependencyInfo = cache.findDependency(moduleID); - assert(optionalDependencyInfo.has_value() && "Expected dependency info."); - auto dependencyInfo = optionalDependencyInfo.value(); + assert(optionalDependencyInfo && "Expected dependency info."); + auto dependencyInfo = *optionalDependencyInfo; unsigned numMDs = writeMacroDependencies(*dependencyInfo); moduleMacroDepArrayMap.insert( {moduleID, std::make_pair(lastMDIndex, numMDs)}); @@ -1399,11 +1376,11 @@ void ModuleDependenciesCacheSerializer::writeImportStatementInfos( for (auto kind = ModuleDependencyKind::FirstKind; kind != ModuleDependencyKind::LastKind; ++kind) { auto modMap = cache.getDependenciesMap(kind); - for (const auto &entry : modMap) { - ModuleDependencyID moduleID = {entry.getKey().str(), kind}; + for (const auto &entry : modMap.keys()) { + ModuleDependencyID moduleID = {entry.str(), kind}; auto optionalDependencyInfo = cache.findDependency(moduleID); - assert(optionalDependencyInfo.has_value() && "Expected dependency info."); - auto dependencyInfo = optionalDependencyInfo.value(); + assert(optionalDependencyInfo && "Expected dependency info."); + auto dependencyInfo = *optionalDependencyInfo; auto numImportInfos = writeImportStatementInfos(*dependencyInfo, /* optional */ false); @@ -1414,22 +1391,28 @@ void ModuleDependenciesCacheSerializer::writeImportStatementInfos( auto numOptionalImportInfos = writeImportStatementInfos(*dependencyInfo, /* optional */ true); optionalImportInfoArrayMap.insert( - {moduleID, std::make_pair(lastImportInfoIndex, numImportInfos)}); + {moduleID, std::make_pair(lastImportInfoIndex, numOptionalImportInfos)}); lastImportInfoIndex += numOptionalImportInfos; } } unsigned lastImportInfoArrayIndex = 1; + unsigned lastOptionalImportInfoArrayIndex = 1; for (auto kind = ModuleDependencyKind::FirstKind; kind != ModuleDependencyKind::LastKind; ++kind) { auto modMap = cache.getDependenciesMap(kind); - for (const auto &entry : modMap) { - ModuleDependencyID moduleID = {entry.getKey().str(), kind}; + for (const auto &entry : modMap.keys()) { + ModuleDependencyID moduleID = {entry.str(), kind}; auto entries = importInfoArrayMap.at(moduleID); - if (entries.second == 0) - continue; - writeImportStatementInfosArray(entries.first, entries.second); - ImportInfosArrayIDsMap.insert({moduleID, lastImportInfoArrayIndex++}); + if (entries.second != 0) { + writeImportStatementInfosArray(entries.first, entries.second); + ImportInfosArrayIDsMap.insert({moduleID, lastImportInfoArrayIndex++}); + } + auto optionalEntries = optionalImportInfoArrayMap.at(moduleID); + if (optionalEntries.second != 0) { + writeImportStatementInfosArray(optionalEntries.first, optionalEntries.second); + OptionalImportInfosArrayIDsMap.insert({moduleID, lastOptionalImportInfoArrayIndex++}); + } } } } @@ -1440,22 +1423,31 @@ unsigned ModuleDependenciesCacheSerializer::writeImportStatementInfos( size_t count = 0; auto emitImportStatementInfo = [this, &count](const auto &importInfo, bool isOptional) { - for (auto &importLoc : importInfo.importLocations) { + if (importInfo.importLocations.empty()) { ImportStatementLayout::emitRecord( Out, ScratchRecord, AbbrCodes[ImportStatementLayout::Code], getIdentifier(importInfo.importIdentifier), - getIdentifier(importLoc.bufferIdentifier), importLoc.lineNumber, - importLoc.columnNumber, isOptional, importInfo.isExported); + 0, 0, 0, isOptional, importInfo.isExported); count++; + } else { + for (auto &importLoc : importInfo.importLocations) { + ImportStatementLayout::emitRecord( + Out, ScratchRecord, AbbrCodes[ImportStatementLayout::Code], + getIdentifier(importInfo.importIdentifier), + getIdentifier(importLoc.bufferIdentifier), importLoc.lineNumber, + importLoc.columnNumber, isOptional, importInfo.isExported); + count++; + } } }; - for (auto &importInfo : dependencyInfo.getModuleImports()) - emitImportStatementInfo(importInfo, false); - - for (auto &importInfo : dependencyInfo.getOptionalModuleImports()) - emitImportStatementInfo(importInfo, true); - + if (!optional) { + for (auto &importInfo : dependencyInfo.getModuleImports()) + emitImportStatementInfo(importInfo, false); + } else { + for (auto &importInfo : dependencyInfo.getOptionalModuleImports()) + emitImportStatementInfo(importInfo, true); + } return count; } @@ -1486,9 +1478,7 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo( ModuleIdentifierArrayKind::CrossImportOverlayDependenciesIDs), getIdentifierArrayID( moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependenciesIDs), - getIdentifier(dependencyInfo.getModuleCacheKey()), - getIdentifierArrayID(moduleID, - ModuleIdentifierArrayKind::AuxiliaryFileIDs)); + getIdentifier(dependencyInfo.getModuleCacheKey())); switch (dependencyInfo.getKind()) { case swift::ModuleDependencyKind::SwiftInterface: { @@ -1500,8 +1490,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo( getIdentifier(swiftTextDeps->swiftInterfaceFile); unsigned bridgingHeaderFileId = swiftTextDeps->textualModuleDetails.bridgingHeaderFile - ? getIdentifier(swiftTextDeps->textualModuleDetails - .bridgingHeaderFile.value()) + ? getIdentifier(*(swiftTextDeps->textualModuleDetails + .bridgingHeaderFile)) : 0; SwiftInterfaceModuleDetailsLayout::emitRecord( Out, ScratchRecord, AbbrCodes[SwiftInterfaceModuleDetailsLayout::Code], @@ -1529,8 +1519,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo( assert(swiftSourceDeps); unsigned bridgingHeaderFileId = swiftSourceDeps->textualModuleDetails.bridgingHeaderFile - ? getIdentifier(swiftSourceDeps->textualModuleDetails - .bridgingHeaderFile.value()) + ? getIdentifier(*(swiftSourceDeps->textualModuleDetails + .bridgingHeaderFile)) : 0; SwiftSourceModuleDetailsLayout::emitRecord( Out, ScratchRecord, AbbrCodes[SwiftSourceModuleDetailsLayout::Code], @@ -1732,20 +1722,14 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays( for (auto kind = ModuleDependencyKind::FirstKind; kind != ModuleDependencyKind::LastKind; ++kind) { auto modMap = cache.getDependenciesMap(kind); - for (const auto &entry : modMap) { - ModuleDependencyID moduleID = {entry.getKey().str(), kind}; + for (const auto &entry : modMap.keys()) { + ModuleDependencyID moduleID = {entry.str(), kind}; auto optionalDependencyInfo = cache.findDependency(moduleID); - assert(optionalDependencyInfo.has_value() && "Expected dependency info."); - auto dependencyInfo = optionalDependencyInfo.value(); + assert(optionalDependencyInfo && "Expected dependency info."); + auto dependencyInfo = *optionalDependencyInfo; // Add the module's name addIdentifier(moduleID.ModuleName); - // Map import infos to their respective module identifiers - auto importInfoArrayToIdentifier = - [](const auto &importInfo) -> std::string { - return importInfo.importIdentifier; - }; - for (const auto &ll : dependencyInfo->getLinkLibraries()) addIdentifier(ll.getName().str()); @@ -1754,22 +1738,18 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays( addIdentifier(md.second.LibraryPath); addIdentifier(md.second.ExecutablePath); } + + for (const auto &ii : dependencyInfo->getModuleImports()) { + addIdentifier(ii.importIdentifier); + for (const auto &il : ii.importLocations) + addIdentifier(il.bufferIdentifier); + } - // Add the module's imports - std::vector importIdentifiers; - llvm::transform(dependencyInfo->getModuleImports(), - std::back_inserter(importIdentifiers), - importInfoArrayToIdentifier); - std::vector optionalImportIdentifiers; - llvm::transform(dependencyInfo->getOptionalModuleImports(), - std::back_inserter(optionalImportIdentifiers), - importInfoArrayToIdentifier); - - addStringArray(moduleID, ModuleIdentifierArrayKind::DependencyImports, - importIdentifiers); - addStringArray(moduleID, - ModuleIdentifierArrayKind::OptionalDependencyImports, - optionalImportIdentifiers); + for (const auto &oii : dependencyInfo->getOptionalModuleImports()) { + addIdentifier(oii.importIdentifier); + for (const auto &oil : oii.importLocations) + addIdentifier(oil.bufferIdentifier); + } addDependencyIDArray( moduleID, ModuleIdentifierArrayKind::ImportedSwiftDependenciesIDs, @@ -1785,9 +1765,6 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays( moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependenciesIDs, dependencyInfo->getSwiftOverlayDependencies()); - addStringArray(moduleID, ModuleIdentifierArrayKind::AuxiliaryFileIDs, - dependencyInfo->getAuxiliaryFiles()); - std::vector clangHeaderDependencyNames; for (const auto &headerDepID : dependencyInfo->getHeaderClangDependencies()) @@ -1806,9 +1783,9 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays( addStringArray(moduleID, ModuleIdentifierArrayKind::BuildCommandLine, swiftTextDeps->textualModuleDetails.buildCommandLine); addIdentifier(swiftTextDeps->contextHash); - if (swiftTextDeps->textualModuleDetails.bridgingHeaderFile.has_value()) + if (swiftTextDeps->textualModuleDetails.bridgingHeaderFile) addIdentifier( - swiftTextDeps->textualModuleDetails.bridgingHeaderFile.value()); + *(swiftTextDeps->textualModuleDetails.bridgingHeaderFile)); addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles, std::vector()); addStringArray(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles, @@ -1855,10 +1832,9 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays( case swift::ModuleDependencyKind::SwiftSource: { auto swiftSourceDeps = dependencyInfo->getAsSwiftSourceModule(); assert(swiftSourceDeps); - if (swiftSourceDeps->textualModuleDetails.bridgingHeaderFile - .has_value()) + if (swiftSourceDeps->textualModuleDetails.bridgingHeaderFile) addIdentifier( - swiftSourceDeps->textualModuleDetails.bridgingHeaderFile.value()); + *(swiftSourceDeps->textualModuleDetails.bridgingHeaderFile)); addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles, swiftSourceDeps->sourceFiles); addStringArray( diff --git a/test/ScanDependencies/Incremental/system_search_path_invalidate.swift b/test/ScanDependencies/Incremental/system_search_path_invalidate.swift new file mode 100644 index 0000000000000..7e003ac018087 --- /dev/null +++ b/test/ScanDependencies/Incremental/system_search_path_invalidate.swift @@ -0,0 +1,17 @@ +// RUN: %empty-directory(%t) +// RUN: %empty-directory(%t/module-cache) +// RUN: %empty-directory(%t/Frameworks) + +// RUN: %target-swift-frontend -scan-dependencies -scanner-module-validation -module-load-mode prefer-interface -Rdependency-scan-cache -load-dependency-scan-cache -serialize-dependency-scan-cache -dependency-scan-cache-path %t/cache.moddepcache -module-cache-path %t/module-cache %s -o %t/deps.json -I %t/ExtraCModules -I %S/../Inputs/CHeaders -F %t/Frameworks &> %t/first_scan_output.txt +// RUN: cat %t/first_scan_output.txt | %FileCheck %s + +// RUN: %target-swift-frontend -scan-dependencies -scanner-module-validation -module-load-mode prefer-interface -Rdependency-scan-cache -load-dependency-scan-cache -serialize-dependency-scan-cache -dependency-scan-cache-path %t/cache.moddepcache -module-cache-path %t/module-cache %s -o %t/deps.json -I %t/ExtraCModules -I %S/../Inputs/CHeaders -F %t/Frameworks &> %t/second_scan_output.txt +// RUN: cat %t/second_scan_output.txt | %FileCheck %s -check-prefix=INCREMENTAL-CHECK + +// Change an '-F' to a '-Fsystem' and ensure that the serialized cache does not get reused +// RUN: %target-swift-frontend -scan-dependencies -scanner-module-validation -module-load-mode prefer-interface -Rdependency-scan-cache -load-dependency-scan-cache -serialize-dependency-scan-cache -dependency-scan-cache-path %t/cache.moddepcache -module-cache-path %t/module-cache %s -o %t/deps.json -I %t/ExtraCModules -I %S/../Inputs/CHeaders -Fsystem %t/Frameworks &> %t/second_system_scan_output.txt +// RUN: cat %t/second_system_scan_output.txt | %FileCheck %s + +// CHECK: remark: Incremental module scan: Failed to load module scanning dependency cache from: +// INCREMENTAL-CHECK-NOT: remark: Incremental module scan: Failed to load module scanning dependency cache from: + diff --git a/test/ScanDependencies/serialized_imports.swift b/test/ScanDependencies/serialized_imports.swift new file mode 100644 index 0000000000000..1b62894eb6067 --- /dev/null +++ b/test/ScanDependencies/serialized_imports.swift @@ -0,0 +1,29 @@ +// REQUIRES: objc_interop +// RUN: %empty-directory(%t) +// RUN: %empty-directory(%t/module-cache) + +// Run the scanner once, emitting the serialized scanner cache +// RUN: %target-swift-frontend -scan-dependencies -module-load-mode prefer-interface -Rdependency-scan-cache -serialize-dependency-scan-cache -load-dependency-scan-cache -dependency-scan-cache-path %t/cache.moddepcache -module-cache-path %t/module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -enable-cross-import-overlays 2>&1 | %FileCheck %s -check-prefix CHECK-REMARK-SAVE +// RUN: llvm-bcanalyzer --dump %t/cache.moddepcache > %t/cache.moddepcache.initial.dump.txt + +// Run the scanner again, but now re-using previously-serialized cache +// RUN: %target-swift-frontend -scan-dependencies -module-load-mode prefer-interface -Rdependency-scan-cache -serialize-dependency-scan-cache -load-dependency-scan-cache -dependency-scan-cache-path %t/cache.moddepcache -module-cache-path %t/module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -enable-cross-import-overlays 2>&1 | %FileCheck %s -check-prefix CHECK-REMARK-LOAD +// RUN: llvm-bcanalyzer --dump %t/cache.moddepcache > %t/cache.moddepcache.dump.txt + +// Ensure that the initial scan, and the secondary scan which just re-used the initial scan's results report +// the same number of import statement nodes, ensuring that serialization-deserialization did not affect +// the import sets +// +// RUN: grep "IMPORT_STATEMENT_NODE" %t/cache.moddepcache.initial.dump.txt | wc -l > %t/initial_scan_import_count.txt +// RUN: grep "IMPORT_STATEMENT_NODE" %t/cache.moddepcache.dump.txt | wc -l > %t/secondary_scan_import_count.txt +// RUN: diff %t/initial_scan_import_count.txt %t/secondary_scan_import_count.txt + +// CHECK-REMARK-SAVE: remark: Incremental module scan: Failed to load module scanning dependency cache from: +// CHECK-REMARK-SAVE: remark: Incremental module scan: Serializing module scanning dependency cache to: +// CHECK-REMARK-LOAD: remark: Incremental module scan: Re-using serialized module scanning dependency cache from: + +import E + + + +