@@ -40,7 +40,8 @@ std::string_view getTypeKindStr(const swift::TypeBase* type) {
4040
4141} // namespace
4242
43- std::unordered_map<const swift::Decl*, unsigned > SwiftMangler::preloadedExtensionIndexes;
43+ std::unordered_map<const swift::Decl*, SwiftMangler::ExtensionIndex>
44+ SwiftMangler::preloadedExtensionIndexes;
4445
4546SwiftMangledName SwiftMangler::initMangled (const swift::TypeBase* type) {
4647 return {getTypeKindStr (type), ' _' };
@@ -104,15 +105,15 @@ SwiftMangledName SwiftMangler::visitExtensionDecl(const swift::ExtensionDecl* de
104105
105106 auto parent = getParent (decl);
106107 auto target = decl->getExtendedType ();
107- return initMangled (decl) << fetch (target) << getExtensionIndex (decl, parent);
108+ auto index = getExtensionIndex (decl, parent);
109+ return initMangled (decl) << fetch (target) << index.index
110+ << (index.kind == ExtensionKind::clang ? " _clang" : " " );
108111}
109112
110- unsigned SwiftMangler::getExtensionIndex (const swift::ExtensionDecl* decl,
111- const swift::Decl* parent) {
113+ SwiftMangler::ExtensionIndex SwiftMangler::getExtensionIndex (const swift::ExtensionDecl* decl,
114+ const swift::Decl* parent) {
112115 // to avoid iterating multiple times on the parent of multiple extensions, we preload extension
113116 // indexes once for each encountered parent into the `preloadedExtensionIndexes` mapping.
114- // Because we mangle declarations only once in a given trap/dispatcher context, we can safely
115- // discard preloaded indexes on use
116117 if (auto found = SwiftMangler::preloadedExtensionIndexes.find (decl);
117118 found != SwiftMangler::preloadedExtensionIndexes.end ()) {
118119 return found->second ;
@@ -141,8 +142,8 @@ void SwiftMangler::indexExtensions(llvm::ArrayRef<swift::Decl*> siblings) {
141142 auto index = 0u ;
142143 for (auto sibling : siblings) {
143144 if (sibling->getKind () == swift::DeclKind::Extension) {
144- SwiftMangler::preloadedExtensionIndexes.emplace (sibling, index);
145- index += 2 ;
145+ SwiftMangler::preloadedExtensionIndexes.try_emplace (sibling, ExtensionKind::swift , index);
146+ index++ ;
146147 }
147148 }
148149}
@@ -153,15 +154,15 @@ void SwiftMangler::indexClangExtensions(const clang::Module* clangModule,
153154 return ;
154155 }
155156
156- auto index = 1u ;
157+ auto index = 0u ;
157158 for (const auto & submodule : clangModule->submodules ()) {
158159 if (auto * swiftSubmodule = moduleLoader->getWrapperForModule (submodule)) {
159160 llvm::SmallVector<swift::Decl*> children;
160161 swiftSubmodule->getTopLevelDecls (children);
161162 for (const auto child : children) {
162163 if (child->getKind () == swift::DeclKind::Extension) {
163- SwiftMangler::preloadedExtensionIndexes.emplace (child, index);
164- index += 2 ;
164+ SwiftMangler::preloadedExtensionIndexes.try_emplace (child, ExtensionKind::clang , index);
165+ index++ ;
165166 }
166167 }
167168 }
0 commit comments