Skip to content

Commit a448cef

Browse files
committed
Include system-ness of framework and import search paths in the PCH hash
This hash is also used for the dependency scanning hash. In both cases, PCH contents may differ based on whether a certain module they depend on is found in a system or non-system search path. In dependency scanning, systemness should cause a full change of scanning context requiring a from-scratch scan. Resolves rdar://150334077
1 parent 7037893 commit a448cef

File tree

5 files changed

+25
-60
lines changed

5 files changed

+25
-60
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/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

+1-1
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.

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);
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)