mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Dependency Scanning][C++Interop] Do not query 'CxxStdlib' Swift overlay for textual modules which were not built with c++interop
When we discover a textual module dependency which is a module which was not originally built from source using C++ interop (specifying '-formal-cxx-interoperability-mode=off'), avoid looking up the C++ standard library Swift overlay for it. This is required for the case of the 'Darwin' module, for example, which includes headers which map to C++ stdlib headers when the compiler is operating in C++ interop mode, but the C++ standard library Swift overlay module itself depends on 'Darwin', which results in a cycle. To resolve such situations, we can rely on the fact that Swift textual interfaces of modules which were not built with C++ interop must be able to build without importing the C++ standard library Swift overlay, so we avoid specifying it as a dependency for such modules. The primary source module, as well as Swift textual module dependencies which *were* built with C++ interop will continue getting a direct depedency of the 'CxxStdlib' Swift module. Resolves rdar://150222155
This commit is contained in:
@@ -468,7 +468,7 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
|
||||
// build command to main module to ensure frontend gets the same result.
|
||||
// This needs to happen after visiting all the top-level decls from all
|
||||
// SourceFiles.
|
||||
auto buildArgs = mainDependencies.getCommandline();
|
||||
std::vector<std::string> buildArgs = mainDependencies.getCommandline();
|
||||
mainModule->getASTContext().forEachCanImportVersionCheck(
|
||||
[&](StringRef moduleName, const llvm::VersionTuple &Version,
|
||||
const llvm::VersionTuple &UnderlyingVersion) {
|
||||
@@ -1328,25 +1328,33 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
|
||||
recordResult(clangDep);
|
||||
|
||||
// C++ Interop requires additional handling
|
||||
if (ScanCompilerInvocation.getLangOptions().EnableCXXInterop) {
|
||||
for (const auto &clangDepName : allClangDependencies) {
|
||||
// If this Clang module is a part of the C++ stdlib, and we haven't loaded
|
||||
// the overlay for it so far, it is a split libc++ module (e.g.
|
||||
// std_vector). Load the CxxStdlib overlay explicitly.
|
||||
const auto &clangDepInfo =
|
||||
cache.findDependency(clangDepName, ModuleDependencyKind::Clang)
|
||||
.value()
|
||||
->getAsClangModule();
|
||||
if (importer::isCxxStdModule(clangDepName, clangDepInfo->IsSystem) &&
|
||||
!swiftOverlayDependencies.contains(
|
||||
{clangDepName, ModuleDependencyKind::SwiftInterface}) &&
|
||||
!swiftOverlayDependencies.contains(
|
||||
{clangDepName, ModuleDependencyKind::SwiftBinary})) {
|
||||
ScanningThreadPool.async(
|
||||
scanForSwiftDependency,
|
||||
getModuleImportIdentifier(ScanASTContext.Id_CxxStdlib.str()));
|
||||
ScanningThreadPool.wait();
|
||||
recordResult(ScanASTContext.Id_CxxStdlib.str().str());
|
||||
if (ScanCompilerInvocation.getLangOptions().EnableCXXInterop &&
|
||||
moduleID.Kind == ModuleDependencyKind::SwiftInterface) {
|
||||
const auto &moduleInfo = cache.findKnownDependency(moduleID);
|
||||
const auto commandLine = moduleInfo.getCommandline();
|
||||
|
||||
// If the textual interface was built without C++ interop, do not query
|
||||
// the C++ Standard Library Swift overlay for its compilation.
|
||||
if (llvm::find(commandLine, "-formal-cxx-interoperability-mode=off") ==
|
||||
commandLine.end()) {
|
||||
for (const auto &clangDepName : allClangDependencies) {
|
||||
// If this Clang module is a part of the C++ stdlib, and we haven't
|
||||
// loaded the overlay for it so far, it is a split libc++ module (e.g.
|
||||
// std_vector). Load the CxxStdlib overlay explicitly.
|
||||
const auto &clangDepInfo =
|
||||
cache.findDependency(clangDepName, ModuleDependencyKind::Clang)
|
||||
.value()
|
||||
->getAsClangModule();
|
||||
if (importer::isCxxStdModule(clangDepName, clangDepInfo->IsSystem) &&
|
||||
!swiftOverlayDependencies.contains(
|
||||
{clangDepName, ModuleDependencyKind::SwiftInterface}) &&
|
||||
!swiftOverlayDependencies.contains(
|
||||
{clangDepName, ModuleDependencyKind::SwiftBinary})) {
|
||||
scanForSwiftDependency(
|
||||
getModuleImportIdentifier(ScanASTContext.Id_CxxStdlib.str()));
|
||||
recordResult(ScanASTContext.Id_CxxStdlib.str().str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1401,7 +1409,7 @@ void ModuleDependencyScanner::resolveCrossImportOverlayDependencies(
|
||||
// Update the command-line on the main module to
|
||||
// disable implicit cross-import overlay search.
|
||||
auto mainDep = cache.findKnownDependency(actualMainID);
|
||||
auto cmdCopy = mainDep.getCommandline();
|
||||
std::vector<std::string> cmdCopy = mainDep.getCommandline();
|
||||
cmdCopy.push_back("-disable-cross-import-overlay-search");
|
||||
for (auto &entry : overlayFiles) {
|
||||
mainDep.addAuxiliaryFile(entry.second);
|
||||
|
||||
Reference in New Issue
Block a user