[ModuleInterfaces] Combine the normalized target triple into the cache hash

Previously, we'd combine just the target architecture, and rely on the
fact that the .swiftinterface is in a reasonably-target-specific
subdirectory to include enough entropy to avoid hash collisions. But in
the presence of a VFS or if two targets are sharing the same
.swiftinterface file (which can sometimes happen in tests), they will
collide since the hash only includes architecture.

Instead, use the same normalization that the serialized module loader
uses, and serialize the normalized target triple instead.

Fixes rdar://55881335
This commit is contained in:
Harlan Haskins
2019-10-01 13:48:09 -07:00
parent 1a1f731aad
commit c0908160a6
2 changed files with 36 additions and 5 deletions

View File

@@ -391,12 +391,15 @@ class ModuleInterfaceLoaderImpl {
// anyways.
H = hash_combine(H, interfacePath);
// Include the target CPU architecture. In practice, .swiftinterface files
// will be in architecture-specific subdirectories and would have
// architecture-specific pieces #if'd out. However, it doesn't hurt to
// Include the normalized target triple. In practice, .swiftinterface files
// will be in target-specific subdirectories and would have
// target-specific pieces #if'd out. However, it doesn't hurt to
// include it, and it guards against mistakenly reusing cached modules
// across architectures.
H = hash_combine(H, SubInvocation.getLangOptions().Target.getArchName());
// across targets. Note that this normalization explicitly doesn't
// include the minimum deployment target (e.g. the '12.0' in 'ios12.0').
auto normalizedTargetTriple =
getTargetSpecificModuleTriple(SubInvocation.getLangOptions().Target);
H = hash_combine(H, normalizedTargetTriple.str());
// The SDK path is going to affect how this module is imported, so include
// it.