[Modules] Avoid false swift module sharing

When the swiftmodule is built with different clang importer arguments,
they can have the same module hash, causing them to be wrongly re-used even
they contains different interfaces. Add ReducedExtraArgs to the module hash to
disambiguate them.

However, some Xcc arguments, most commonly `-D` options do not affect the
swiftmodule being generated. Do not pass `-Xcc -DARGS` to swift
interface compilation to reduce the amount of module variants in the
build.

rdar://131408266
This commit is contained in:
Steven Wu
2024-07-10 11:12:04 -07:00
parent 4993f4bf22
commit a32dd9539b
8 changed files with 114 additions and 22 deletions

View File

@@ -2072,6 +2072,8 @@ InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath,
auto normalizedTargetTriple =
getTargetSpecificModuleTriple(genericSubInvocation.getLangOptions().Target);
std::string sdkBuildVersion = getSDKBuildVersion(sdkPath);
const auto ExtraArgs = genericSubInvocation.getClangImporterOptions()
.getReducedExtraArgsForSwiftModuleDependency();
llvm::hash_code H = hash_combine(
// Start with the compiler version (which will be either tag names or
@@ -2113,6 +2115,10 @@ InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath,
// correctly load the dependencies.
genericSubInvocation.getCASOptions().getModuleScanningHashComponents(),
// Clang ExtraArgs that affects how clang types are imported into swift
// module.
llvm::hash_combine_range(ExtraArgs.begin(), ExtraArgs.end()),
// Whether or not OSSA modules are enabled.
//
// If OSSA modules are enabled, we use a separate namespace of modules to