Skip to content

Commit 6baa3de

Browse files
authored
Merge pull request #81244 from artemcm/IncrementalScanUnlimitedGrowth
[Dependency Scanning] Fix search path context hashing hole and avoid serializing unnecessary field
2 parents 9de2419 + a448cef commit 6baa3de

File tree

7 files changed

+31
-90
lines changed

7 files changed

+31
-90
lines changed

include/swift/AST/ASTContext.h

-3
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,6 @@ class ASTContext final {
10971097
/// $SDKROOT/System/Library/Frameworks/ and $SDKROOT/Library/Frameworks/.
10981098
std::vector<std::string> getDarwinImplicitFrameworkSearchPaths() const;
10991099

1100-
/// Return a set of all possible filesystem locations where modules can be found.
1101-
llvm::StringSet<> getAllModuleSearchPathsSet() const;
1102-
11031100
/// Load extensions to the given nominal type from the external
11041101
/// module loaders.
11051102
///

include/swift/AST/ModuleDependencies.h

-5
Original file line numberDiff line numberDiff line change
@@ -787,11 +787,6 @@ class ModuleDependencyInfo {
787787
return storage->auxiliaryFiles;
788788
}
789789

790-
void
791-
setAuxiliaryFiles(const ArrayRef<std::string> auxiliaryFiles) {
792-
storage->auxiliaryFiles.assign(auxiliaryFiles.begin(), auxiliaryFiles.end());
793-
}
794-
795790
bool isStaticLibrary() const {
796791
if (auto *detail = getAsSwiftInterfaceModule())
797792
return detail->isStatic;

include/swift/AST/SearchPathOptions.h

+7-16
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ class SearchPathOptions {
323323
friend bool operator!=(const SearchPath &LHS, const SearchPath &RHS) {
324324
return !(LHS == RHS);
325325
}
326+
friend llvm::hash_code
327+
hash_value(const SearchPath &searchPath) {
328+
return llvm::hash_combine(searchPath.Path, searchPath.IsSystem);
329+
}
326330
};
327331

328332
private:
@@ -599,30 +603,17 @@ class SearchPathOptions {
599603
makeOverlayFileSystem(
600604
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS) const;
601605

602-
private:
603-
static StringRef pathStringFromSearchPath(const SearchPath &next) {
604-
return next.Path;
605-
};
606-
607606
public:
608607
/// Return a hash code of any components from these options that should
609608
/// contribute to a Swift Bridging PCH hash.
610609
llvm::hash_code getPCHHashComponents() const {
611610
using llvm::hash_combine;
612611
using llvm::hash_combine_range;
613-
614-
using SearchPathView =
615-
ArrayRefView<SearchPath, StringRef, pathStringFromSearchPath>;
616-
SearchPathView importPathsOnly{ImportSearchPaths};
617-
SearchPathView frameworkPathsOnly{FrameworkSearchPaths};
618-
619612
return hash_combine(SDKPath,
620-
// FIXME: Should we include the system-ness of
621-
// search paths too?
622-
hash_combine_range(importPathsOnly.begin(), importPathsOnly.end()),
613+
hash_combine_range(ImportSearchPaths.begin(), ImportSearchPaths.end()),
623614
hash_combine_range(VFSOverlayFiles.begin(), VFSOverlayFiles.end()),
624-
hash_combine_range(frameworkPathsOnly.begin(),
625-
frameworkPathsOnly.end()),
615+
hash_combine_range(FrameworkSearchPaths.begin(),
616+
FrameworkSearchPaths.end()),
626617
hash_combine_range(LibrarySearchPaths.begin(),
627618
LibrarySearchPaths.end()),
628619
RuntimeResourcePath,

include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ using llvm::BCVBR;
4141
const unsigned char MODULE_DEPENDENCY_CACHE_FORMAT_SIGNATURE[] = {'I', 'M', 'D','C'};
4242
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR = 9;
4343
/// Increment this on every change.
44-
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 1;
44+
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 2;
4545

4646
/// Various identifiers in this format will rely on having their strings mapped
4747
/// using this ID.
@@ -80,7 +80,6 @@ using LinkLibrariesArrayIDField = IdentifierIDField;
8080
using MacroDependenciesArrayIDField = IdentifierIDField;
8181
using FlagIDArrayIDField = IdentifierIDField;
8282
using DependencyIDArrayIDField = IdentifierIDField;
83-
using AuxiliaryFilesArrayIDField = IdentifierIDField;
8483
using SourceLocationIDArrayIDField = IdentifierIDField;
8584

8685
/// The ID of the top-level block containing the dependency graph
@@ -204,8 +203,7 @@ using ModuleInfoLayout =
204203
DependencyIDArrayIDField, // importedClangModules
205204
DependencyIDArrayIDField, // crossImportOverlayModules
206205
DependencyIDArrayIDField, // swiftOverlayDependencies
207-
ModuleCacheKeyIDField, // moduleCacheKey
208-
AuxiliaryFilesArrayIDField // auxiliaryFiles
206+
ModuleCacheKeyIDField // moduleCacheKey
209207
>;
210208

211209
using SwiftInterfaceModuleDetailsLayout =

lib/AST/ASTContext.cpp

-40
Original file line numberDiff line numberDiff line change
@@ -2214,46 +2214,6 @@ const {
22142214
return SearchPathOpts.getDarwinImplicitFrameworkSearchPaths();
22152215
}
22162216

2217-
llvm::StringSet<> ASTContext::getAllModuleSearchPathsSet()
2218-
const {
2219-
llvm::StringSet<> result;
2220-
2221-
// Import and framework paths are "special", they contain more than path
2222-
// strings, but path strings are all we care about here.
2223-
using SearchPathView = ArrayRefView<SearchPathOptions::SearchPath, StringRef,
2224-
pathStringFromSearchPath>;
2225-
2226-
SearchPathView importPathsOnly{SearchPathOpts.getImportSearchPaths()};
2227-
result.insert(importPathsOnly.begin(), importPathsOnly.end());
2228-
2229-
SearchPathView frameworkPathsOnly{SearchPathOpts.getFrameworkSearchPaths()};
2230-
result.insert(frameworkPathsOnly.begin(), frameworkPathsOnly.end());
2231-
2232-
if (LangOpts.Target.isOSDarwin()) {
2233-
auto implicitFrameworkSearchPaths = getDarwinImplicitFrameworkSearchPaths();
2234-
result.insert(implicitFrameworkSearchPaths.begin(),
2235-
implicitFrameworkSearchPaths.end());
2236-
}
2237-
result.insert(SearchPathOpts.RuntimeLibraryImportPaths.begin(),
2238-
SearchPathOpts.RuntimeLibraryImportPaths.end());
2239-
2240-
// ClangImporter special-cases the path for SwiftShims, so do the same here
2241-
// If there are no shims in the resource dir, add a search path in the SDK.
2242-
SmallString<128> shimsPath(SearchPathOpts.RuntimeResourcePath);
2243-
llvm::sys::path::append(shimsPath, "shims");
2244-
if (!llvm::sys::fs::exists(shimsPath)) {
2245-
shimsPath = SearchPathOpts.getSDKPath();
2246-
llvm::sys::path::append(shimsPath, "usr", "lib", "swift", "shims");
2247-
}
2248-
result.insert(shimsPath.str());
2249-
2250-
// Clang system modules are found in the SDK root
2251-
SmallString<128> clangSysRootPath(SearchPathOpts.getSDKPath());
2252-
llvm::sys::path::append(clangSysRootPath, "usr", "include");
2253-
result.insert(clangSysRootPath.str());
2254-
return result;
2255-
}
2256-
22572217
void ASTContext::loadExtensions(NominalTypeDecl *nominal,
22582218
unsigned previousGeneration) {
22592219
PrettyStackTraceDecl stackTrace("loading extensions for", nominal);

lib/DependencyScan/ModuleDependencyCacheSerialization.cpp

+5-22
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,12 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
229229
std::vector<ScannerImportStatementInfo> importStatements;
230230
std::vector<ScannerImportStatementInfo> optionalImportStatements;
231231

232-
std::vector<std::string> auxiliaryFiles;
233-
234232
auto addCommonDependencyInfo =
235-
[&importedClangDependenciesIDs, &auxiliaryFiles,
236-
&macroDependencies](ModuleDependencyInfo &moduleDep) {
233+
[&importedClangDependenciesIDs, &macroDependencies]
234+
(ModuleDependencyInfo &moduleDep) {
237235
// Add qualified dependencies of this module
238236
moduleDep.setImportedClangDependencies(importedClangDependenciesIDs);
239237

240-
// Add any auxiliary files
241-
moduleDep.setAuxiliaryFiles(auxiliaryFiles);
242-
243238
// Add macro dependencies
244239
for (const auto &md : macroDependencies)
245240
moduleDep.addMacroDependency(md.first, md.second.LibraryPath,
@@ -441,8 +436,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
441436
importedSwiftDependenciesIDsArrayID,
442437
importedClangDependenciesIDsArrayID,
443438
crossImportOverlayDependenciesIDsArrayID,
444-
swiftOverlayDependenciesIDsArrayID, moduleCacheKeyID,
445-
AuxiliaryFilesArrayID;
439+
swiftOverlayDependenciesIDsArrayID, moduleCacheKeyID;
446440

447441
ModuleInfoLayout::readRecord(Scratch, moduleNameID, moduleImportsArrayID,
448442
optionalImportsArrayID, linkLibraryArrayID,
@@ -451,7 +445,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
451445
importedClangDependenciesIDsArrayID,
452446
crossImportOverlayDependenciesIDsArrayID,
453447
swiftOverlayDependenciesIDsArrayID,
454-
moduleCacheKeyID, AuxiliaryFilesArrayID);
448+
moduleCacheKeyID);
455449
auto moduleName = getIdentifier(moduleNameID);
456450
if (!moduleName)
457451
llvm::report_fatal_error("Bad module name");
@@ -468,11 +462,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
468462
if (optionalOptionalImportStatementInfos)
469463
optionalImportStatements = *optionalOptionalImportStatementInfos;
470464

471-
auto optionalAuxiliaryFiles = getStringArray(AuxiliaryFilesArrayID);
472-
if (optionalAuxiliaryFiles)
473-
for (const auto &af : *optionalAuxiliaryFiles)
474-
auxiliaryFiles.push_back(af);
475-
476465
auto optionalImportedSwiftDependenciesIDs =
477466
getModuleDependencyIDArray(importedSwiftDependenciesIDsArrayID);
478467
if (!optionalImportedSwiftDependenciesIDs)
@@ -1042,7 +1031,6 @@ enum ModuleIdentifierArrayKind : uint8_t {
10421031
ImportedClangDependenciesIDs,
10431032
CrossImportOverlayDependenciesIDs,
10441033
SwiftOverlayDependenciesIDs,
1045-
AuxiliaryFileIDs,
10461034
CompiledModuleCandidates,
10471035
BuildCommandLine,
10481036
SourceFiles,
@@ -1490,9 +1478,7 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
14901478
ModuleIdentifierArrayKind::CrossImportOverlayDependenciesIDs),
14911479
getIdentifierArrayID(
14921480
moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependenciesIDs),
1493-
getIdentifier(dependencyInfo.getModuleCacheKey()),
1494-
getIdentifierArrayID(moduleID,
1495-
ModuleIdentifierArrayKind::AuxiliaryFileIDs));
1481+
getIdentifier(dependencyInfo.getModuleCacheKey()));
14961482

14971483
switch (dependencyInfo.getKind()) {
14981484
case swift::ModuleDependencyKind::SwiftInterface: {
@@ -1779,9 +1765,6 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
17791765
moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependenciesIDs,
17801766
dependencyInfo->getSwiftOverlayDependencies());
17811767

1782-
addStringArray(moduleID, ModuleIdentifierArrayKind::AuxiliaryFileIDs,
1783-
dependencyInfo->getAuxiliaryFiles());
1784-
17851768
std::vector<std::string> clangHeaderDependencyNames;
17861769
for (const auto &headerDepID :
17871770
dependencyInfo->getHeaderClangDependencies())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/module-cache)
3+
// RUN: %empty-directory(%t/Frameworks)
4+
5+
// 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
6+
// RUN: cat %t/first_scan_output.txt | %FileCheck %s
7+
8+
// 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
9+
// RUN: cat %t/second_scan_output.txt | %FileCheck %s -check-prefix=INCREMENTAL-CHECK
10+
11+
// Change an '-F' to a '-Fsystem' and ensure that the serialized cache does not get reused
12+
// 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
13+
// RUN: cat %t/second_system_scan_output.txt | %FileCheck %s
14+
15+
// CHECK: remark: Incremental module scan: Failed to load module scanning dependency cache from:
16+
// INCREMENTAL-CHECK-NOT: remark: Incremental module scan: Failed to load module scanning dependency cache from:
17+

0 commit comments

Comments
 (0)