@@ -3805,7 +3805,23 @@ ImportDecl *swift::createImportDecl(ASTContext &Ctx,
38053805 auto *ImportedMod = ClangN.getClangModule ();
38063806 assert (ImportedMod);
38073807
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 ());
38093825
38103826 bool IsExported = false ;
38113827 for (auto *ExportedMod : Exported) {
@@ -4653,8 +4669,8 @@ void ClangModuleUnit::getImportedModulesForLookup(
46534669 if (owner.SwiftContext .LangOpts .EnableCXXInterop && topLevel &&
46544670 isCxxStdModule (topLevel) && wrapper->clangModule &&
46554671 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
46584674 // (std_string, std_vector, etc). The overlay module for each of the std
46594675 // modules is the CxxStdlib module itself. Make sure we return the actual
46604676 // clang modules (std_xyz) as transitive dependencies instead of just
@@ -8759,7 +8775,7 @@ bool importer::isCxxStdModule(const clang::Module *module) {
87598775bool importer::isCxxStdModule (StringRef moduleName, bool IsSystem) {
87608776 if (moduleName == " std" )
87618777 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
87638779 // modules (std_vector, std_utility, etc).
87648780 if (IsSystem && moduleName.starts_with (" std_" )) {
87658781 if (moduleName == " std_errno_h" )
@@ -8769,7 +8785,7 @@ bool importer::isCxxStdModule(StringRef moduleName, bool IsSystem) {
87698785 return false ;
87708786}
87718787
8772- ImportPath::Builder importer:: getSwiftModulePath (ASTContext &SwiftContext, const clang::Module *M) {
8788+ ImportPath::Builder ClangImporter::Implementation:: getSwiftModulePath (const clang::Module *M) {
87738789 ImportPath::Builder builder;
87748790 while (M) {
87758791 if (!M->isSubModule () && isCxxStdModule (M))
@@ -8782,10 +8798,6 @@ ImportPath::Builder importer::getSwiftModulePath(ASTContext &SwiftContext, const
87828798 return builder;
87838799}
87848800
8785- ImportPath::Builder ClangImporter::Implementation::getSwiftModulePath (const clang::Module *M) {
8786- return ::getSwiftModulePath (SwiftContext, M);
8787- }
8788-
87898801std::optional<clang::QualType>
87908802importer::getCxxReferencePointeeTypeOrNone (const clang::Type *type) {
87918803 if (type->isReferenceType ())
0 commit comments