@@ -3805,7 +3805,23 @@ ImportDecl *swift::createImportDecl(ASTContext &Ctx,
3805
3805
auto *ImportedMod = ClangN.getClangModule ();
3806
3806
assert (ImportedMod);
3807
3807
3808
- ImportPath::Builder importPath = getSwiftModulePath (Ctx, ImportedMod);
3808
+ ImportPath::Builder importPath;
3809
+ auto *TmpMod = ImportedMod;
3810
+ while (TmpMod) {
3811
+ // If this is a C++ stdlib module, print its name as `CxxStdlib` instead of
3812
+ // `std`. `CxxStdlib` is the only accepted spelling of the C++ stdlib module
3813
+ // name in Swift. In libc++ versions 17-19 there are multiple TLMs, named
3814
+ // std_vector, std_array etc. We don't support importing those modules, but
3815
+ // when printing the module interface it'd be weird to print "import
3816
+ // CxxStdlib" over and over, so those are still printed as "import
3817
+ // std_vector". This only affects the module interface for CxxStdlib.
3818
+ Identifier moduleName = !TmpMod->isSubModule () && TmpMod->Name == " std"
3819
+ ? Ctx.Id_CxxStdlib
3820
+ : Ctx.getIdentifier (TmpMod->Name );
3821
+ importPath.push_back (moduleName);
3822
+ TmpMod = TmpMod->Parent ;
3823
+ }
3824
+ std::reverse (importPath.begin (), importPath.end ());
3809
3825
3810
3826
bool IsExported = false ;
3811
3827
for (auto *ExportedMod : Exported) {
@@ -4653,8 +4669,8 @@ void ClangModuleUnit::getImportedModulesForLookup(
4653
4669
if (owner.SwiftContext .LangOpts .EnableCXXInterop && topLevel &&
4654
4670
isCxxStdModule (topLevel) && wrapper->clangModule &&
4655
4671
isCxxStdModule (wrapper->clangModule )) {
4656
- // The CxxStdlib overlay re-exports the clang module std, which in recent
4657
- // libc++ versions re-exports top-level modules for different std headers
4672
+ // The CxxStdlib overlay re-exports the clang module std, which in libc++
4673
+ // versions 17-19 re-exports top-level modules for different std headers
4658
4674
// (std_string, std_vector, etc). The overlay module for each of the std
4659
4675
// modules is the CxxStdlib module itself. Make sure we return the actual
4660
4676
// clang modules (std_xyz) as transitive dependencies instead of just
@@ -8759,7 +8775,7 @@ bool importer::isCxxStdModule(const clang::Module *module) {
8759
8775
bool importer::isCxxStdModule (StringRef moduleName, bool IsSystem) {
8760
8776
if (moduleName == " std" )
8761
8777
return true ;
8762
- // In recent libc++ versions the module is split into multiple top-level
8778
+ // In libc++ versions 17-19 the module is split into multiple top-level
8763
8779
// modules (std_vector, std_utility, etc).
8764
8780
if (IsSystem && moduleName.starts_with (" std_" )) {
8765
8781
if (moduleName == " std_errno_h" )
@@ -8769,7 +8785,7 @@ bool importer::isCxxStdModule(StringRef moduleName, bool IsSystem) {
8769
8785
return false ;
8770
8786
}
8771
8787
8772
- ImportPath::Builder importer:: getSwiftModulePath (ASTContext &SwiftContext, const clang::Module *M) {
8788
+ ImportPath::Builder ClangImporter::Implementation:: getSwiftModulePath (const clang::Module *M) {
8773
8789
ImportPath::Builder builder;
8774
8790
while (M) {
8775
8791
if (!M->isSubModule () && isCxxStdModule (M))
@@ -8782,10 +8798,6 @@ ImportPath::Builder importer::getSwiftModulePath(ASTContext &SwiftContext, const
8782
8798
return builder;
8783
8799
}
8784
8800
8785
- ImportPath::Builder ClangImporter::Implementation::getSwiftModulePath (const clang::Module *M) {
8786
- return ::getSwiftModulePath (SwiftContext, M);
8787
- }
8788
-
8789
8801
std::optional<clang::QualType>
8790
8802
importer::getCxxReferencePointeeTypeOrNone (const clang::Type *type) {
8791
8803
if (type->isReferenceType ())
0 commit comments