Skip to content
Draft

Test3 #86030

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 17 additions & 54 deletions lib/DependencyScan/ModuleDependencyScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,23 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
break;
}

if (ScanASTContext.LangOpts.EnableCXXInterop) {
StringRef mainModuleName = mainModule->getName().str();
if (mainModuleName != CXX_MODULE_NAME)
mainDependencies.addModuleImport(CXX_MODULE_NAME, /* isExported */ false,
AccessLevel::Public,
&alreadyAddedModules);
if (llvm::none_of(llvm::ArrayRef<StringRef>{CXX_MODULE_NAME,
ScanASTContext.Id_CxxStdlib.str(), "std"},
[mainModuleName](StringRef Name) {
return mainModuleName == Name;
}))
mainDependencies.addModuleImport(ScanASTContext.Id_CxxStdlib.str(),
/* isExported */ false,
AccessLevel::Public,
&alreadyAddedModules);
}

// Add any implicit module names.
for (const auto &import : importInfo.AdditionalUnloadedImports) {
mainDependencies.addModuleImport(
Expand Down Expand Up @@ -1583,60 +1600,6 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
for (const auto &clangDep : visibleClangDependencies)
recordResult(clangDep.getKey().str());

// C++ Interop requires additional handling
bool lookupCxxStdLibOverlay =
ScanCompilerInvocation.getLangOptions().EnableCXXInterop;
if (lookupCxxStdLibOverlay &&
moduleID.Kind == ModuleDependencyKind::SwiftInterface) {
const auto &moduleInfo = DependencyCache.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())
lookupCxxStdLibOverlay = false;
} else if (lookupCxxStdLibOverlay &&
moduleID.Kind == ModuleDependencyKind::SwiftBinary) {
const auto &moduleDetails =
DependencyCache.findKnownDependency(moduleID).getAsSwiftBinaryModule();
// If the binary module was built without C++ interop, do not query
// the C++ Standard Library Swift overlay.
if (!moduleDetails->isBuiltWithCxxInterop)
lookupCxxStdLibOverlay = false;
}

// FIXME: We always declare the 'Darwin' module as formally having been built
// without C++Interop, for compatibility with prior versions. Once we are certain
// that we are only building against modules built with support of
// '-formal-cxx-interoperability-mode', this hard-coded check should be removed.
if (lookupCxxStdLibOverlay && moduleID.ModuleName == "Darwin")
lookupCxxStdLibOverlay = false;

if (lookupCxxStdLibOverlay) {
for (const auto &clangDepNameEntry : visibleClangDependencies) {
auto clangDepName = clangDepNameEntry.getKey().str();

// 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 =
DependencyCache.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;
}
}
}

// Resolve the dependency info with Swift overlay dependency module
// information.
DependencyCache.setSwiftOverlayDependencies(
Expand Down
43 changes: 43 additions & 0 deletions test/ScanDependencies/win-explicit-cxx-interop-cxxstdlib.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// REQUIRES: OS=windows-msvc

// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-frontend -scan-dependencies -module-name NoCpp \
// RUN: -module-cache-path %t/clang-module-cache -disable-objc-interop \
// RUN: -cxx-interoperability-mode=default \
// RUN: %t/NoCpp.swift -o %t/NoCpp-deps.json -I %t 2>&1
// RUN: %target-swift-frontend -scan-dependencies -module-name Cpp \
// RUN: -module-cache-path %t/clang-module-cache -disable-objc-interop \
// RUN: -cxx-interoperability-mode=default \
// RUN: %t/Cpp.swift -o %t/Cpp-deps.json -I %t 2>&1
// RUN: %target-swift-frontend -scan-dependencies -module-name Crt \
// RUN: -module-cache-path %t/clang-module-cache -disable-objc-interop \
// RUN: -cxx-interoperability-mode=default \
// RUN: %t/Crt.swift -o %t/Crt-deps.json -I %t 2>&1
// RUN: %FileCheck %s --check-prefix=NOCPP < %t/NoCpp-deps.json
// RUN: %FileCheck %s --check-prefix=CPP < %t/Cpp-deps.json
// RUN: %FileCheck %s --check-prefix=CRT < %t/Crt-deps.json

// NOCPP: "mainModuleName": "NoCpp"
// NOCPP: "linkName": "swiftCxxStdlib",
// NOCPP-NEXT: "isStatic": true,

// CPP: "mainModuleName": "Cpp"
// CPP: "linkName": "swiftCxxStdlib",
// CPP-NEXT: "isStatic": true,

// CRT: "mainModuleName": "Crt"
// CRT: "linkName": "swiftCxxStdlib",
// CRT-NEXT: "isStatic": true,

//--- NoCpp.swift
// Empty

//--- Cpp.swift
import CxxStdlib

//--- Crt.swift
import CRT