Skip to content

Commit 2ded8ba

Browse files
Merge pull request #71586 from cachemeifyoucan/eng/PR-122814823
[Caching] Do not mix swift modules built from CAS vs. from FileSystem
2 parents 81dbc53 + 8fd0f73 commit 2ded8ba

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

include/swift/Basic/CASOptions.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define SWIFT_BASIC_CASOPTIONS_H
2020

2121
#include "clang/CAS/CASOptions.h"
22+
#include "llvm/ADT/Hashing.h"
2223

2324
namespace swift {
2425

@@ -58,6 +59,21 @@ class CASOptions final {
5859
(!CASFSRootIDs.empty() || !ClangIncludeTrees.empty() ||
5960
!InputFileKey.empty() || !BridgingHeaderPCHCacheKey.empty());
6061
}
62+
63+
/// Return a hash code of any components from these options that should
64+
/// contribute to a Swift Bridging PCH hash.
65+
llvm::hash_code getPCHHashComponents() const {
66+
// The CASIDs are generated from scanner, thus not part of the hash since
67+
// they will always be empty when requested.
68+
// TODO: Add frozen clang::CASOptions to the hash.
69+
return llvm::hash_combine(EnableCaching);
70+
}
71+
72+
/// Return a hash code of any components from these options that should
73+
/// contribute to a Swift Dependency Scanning hash.
74+
llvm::hash_code getModuleScanningHashComponents() const {
75+
return getPCHHashComponents();
76+
}
6177
};
6278

6379
} // namespace swift

lib/Frontend/Frontend.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ std::string CompilerInvocation::getPCHHash() const {
7171
SearchPathOpts.getPCHHashComponents(),
7272
DiagnosticOpts.getPCHHashComponents(),
7373
SILOpts.getPCHHashComponents(),
74-
IRGenOpts.getPCHHashComponents());
74+
IRGenOpts.getPCHHashComponents(),
75+
CASOpts.getPCHHashComponents());
7576

7677
return llvm::toString(llvm::APInt(64, Code), 36, /*Signed=*/false);
7778
}
@@ -85,7 +86,8 @@ std::string CompilerInvocation::getModuleScanningHash() const {
8586
SearchPathOpts.getModuleScanningHashComponents(),
8687
DiagnosticOpts.getModuleScanningHashComponents(),
8788
SILOpts.getModuleScanningHashComponents(),
88-
IRGenOpts.getModuleScanningHashComponents());
89+
IRGenOpts.getModuleScanningHashComponents(),
90+
CASOpts.getModuleScanningHashComponents());
8991

9092
return llvm::toString(llvm::APInt(64, Code), 36, /*Signed=*/false);
9193
}

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,10 @@ InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath,
19321932
// invalidation behavior of this cache item.
19331933
genericSubInvocation.getFrontendOptions().shouldTrackSystemDependencies(),
19341934

1935+
// Whether or not caching is enabled affects if the instance is able to
1936+
// correctly load the dependencies.
1937+
genericSubInvocation.getCASOptions().getModuleScanningHashComponents(),
1938+
19351939
// Whether or not OSSA modules are enabled.
19361940
//
19371941
// If OSSA modules are enabled, we use a separate namespace of modules to

test/CAS/module_hash.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: mkdir -p %t/clang-module-cache
3+
4+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -module-name Test
5+
6+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps_cache.json -module-name Test \
7+
// RUN: -cache-compile-job -cas-path %t/cas
8+
9+
// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json Swift modulePath > %t/path1
10+
// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps_cache.json Swift modulePath > %t/path2
11+
// RUN: not diff %t/path1 %t/path2
12+
13+
func test() {}

0 commit comments

Comments
 (0)