Skip to content

Commit 6ae20a9

Browse files
author
Harlan Haskins
committed
[ParseableInterface] Refine cache key for cached swiftmodules
Previously, we included the PCH hash components in the cache key. While they didn’t do any harm, they didn’t contribute any unique information about the module in question. Additionally, passing the effective language version in means that each dependency that uses a different -swift-version would re-compile all of its dependencies. This is unfortunate, as that means the standard library is recompiled potentially several times.
1 parent 70df66f commit 6ae20a9

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

include/swift/Serialization/SerializationOptions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ namespace swift {
3535
StringRef ModuleLinkName;
3636
ArrayRef<std::string> ExtraClangOptions;
3737

38-
/// Describes a dependency that
3938
struct FileDependency {
4039
uint64_t Size;
4140
uint64_t ModificationTime;

lib/Frontend/ParseableInterfaceSupport.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ getStatusOfDependency(clang::vfs::FileSystem &FS,
110110
}
111111
return Status.get();
112112
}
113+
113114
/// Construct a cache key for the .swiftmodule being generated. There is a
114115
/// balance to be struck here between things that go in the cache key and
115116
/// things that go in the "up to date" check of the cache entry. We want to
@@ -124,20 +125,23 @@ static std::string getCacheHash(ASTContext &Ctx,
124125
const CompilerInvocation &SubInvocation,
125126
StringRef InPath) {
126127
// Start with the compiler version (which will be either tag names or revs).
127-
std::string vers = swift::version::getSwiftFullVersion(
128-
Ctx.LangOpts.EffectiveLanguageVersion);
129-
llvm::hash_code H = llvm::hash_value(vers);
128+
// Explicitly don't pass in the "effective" language version -- this would
129+
// mean modules built in different -swift-version modes would rebuild their
130+
// dependencies.
131+
llvm::hash_code H = hash_value(swift::version::getSwiftFullVersion());
130132

131133
// Simplest representation of input "identity" (not content) is just a
132134
// pathname, and probably all we can get from the VFS in this regard anyways.
133-
H = llvm::hash_combine(H, InPath);
134-
135-
// ClangImporterOpts does include the target CPU, which is redundant: we
136-
// already have separate .swiftinterface files per target due to expanding
137-
// preprocessing directives, but further specializing the cache key to that
138-
// target is harmless and will not make any extra cache entries, so allow it.
139-
H = llvm::hash_combine(
140-
H, SubInvocation.getClangImporterOptions().getPCHHashComponents());
135+
H = hash_combine(H, InPath);
136+
137+
// Include the target CPU. In practice, .swiftinterface files will be in
138+
// architecture-specific subdirectories and would have target-specific pieces
139+
// #if'd out. However, it doesn't hurt to include it, and it guards against
140+
// mistakenly reusing cached modules across targets.
141+
H = hash_combine(H, SubInvocation.getTargetTriple());
142+
143+
// The SDK path is going to affect how this module is imported, so include it.
144+
H = hash_combine(H, SubInvocation.getSDKPath());
141145

142146
return llvm::APInt(64, H).toString(36, /*Signed=*/false);
143147
}

0 commit comments

Comments
 (0)