Skip to content

Commit bab4eee

Browse files
committed
Swift: deduplicate accessors and params correctly
1 parent c42e65c commit bab4eee

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

swift/extractor/mangler/SwiftMangler.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,17 @@ SwiftMangledName SwiftMangler::visitValueDecl(const swift::ValueDecl* decl, bool
6565
auto ret = initMangled(decl);
6666
std::string name;
6767
llvm::raw_string_ostream oss{name};
68-
decl->getName().print(oss);
68+
oss << decl->getName();
6969
ret << name;
7070
if (decl->isStatic()) {
7171
ret << "|static";
7272
}
7373
return ret;
7474
}
7575

76-
SwiftMangledName SwiftMangler::visitTypeDiscriminatedValueDecl(const swift::ValueDecl* decl) {
77-
if (auto ret = visitValueDecl(decl)) {
76+
SwiftMangledName SwiftMangler::visitTypeDiscriminatedValueDecl(const swift::ValueDecl* decl,
77+
bool force) {
78+
if (auto ret = visitValueDecl(decl, force)) {
7879
ret << fetch(decl->getInterfaceType()->getCanonicalType());
7980
return ret;
8081
}
@@ -85,6 +86,13 @@ SwiftMangledName SwiftMangler::visitAbstractFunctionDecl(const swift::AbstractFu
8586
return visitTypeDiscriminatedValueDecl(decl);
8687
}
8788

89+
SwiftMangledName SwiftMangler::visitAccessorDecl(const swift::AccessorDecl* decl) {
90+
std::string name;
91+
llvm::raw_string_ostream oss{name};
92+
decl->printUserFacingName(oss);
93+
return visitTypeDiscriminatedValueDecl(decl, /*force=*/true) << '_' << name;
94+
}
95+
8896
SwiftMangledName SwiftMangler::visitSubscriptDecl(const swift::SubscriptDecl* decl) {
8997
return visitTypeDiscriminatedValueDecl(decl);
9098
}
@@ -93,6 +101,10 @@ SwiftMangledName SwiftMangler::visitVarDecl(const swift::VarDecl* decl) {
93101
return visitTypeDiscriminatedValueDecl(decl);
94102
}
95103

104+
SwiftMangledName SwiftMangler::visitParamDecl(const swift::ParamDecl* decl) {
105+
return visitTypeDiscriminatedValueDecl(decl, /*force=*/true);
106+
}
107+
96108
SwiftMangledName SwiftMangler::visitExtensionDecl(const swift::ExtensionDecl* decl) {
97109
if (decl->getDeclContext()->isLocalContext()) {
98110
return {};

swift/extractor/mangler/SwiftMangler.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,
5858
SwiftMangledName visitModuleDecl(const swift::ModuleDecl* decl);
5959
SwiftMangledName visitExtensionDecl(const swift::ExtensionDecl* decl);
6060
SwiftMangledName visitAbstractFunctionDecl(const swift::AbstractFunctionDecl* decl);
61+
SwiftMangledName visitAccessorDecl(const swift::AccessorDecl* decl);
6162
SwiftMangledName visitSubscriptDecl(const swift::SubscriptDecl* decl);
6263
SwiftMangledName visitVarDecl(const swift::VarDecl* decl);
64+
SwiftMangledName visitParamDecl(const swift::ParamDecl* decl);
6365
SwiftMangledName visitAbstractTypeParamDecl(const swift::AbstractTypeParamDecl* decl);
6466
SwiftMangledName visitGenericTypeParamDecl(const swift::GenericTypeParamDecl* decl);
6567

@@ -111,7 +113,8 @@ class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,
111113
unsigned int getExtensionIndex(const swift::ExtensionDecl* decl, const swift::Decl* parent);
112114
static SwiftMangledName initMangled(const swift::TypeBase* type);
113115
SwiftMangledName initMangled(const swift::Decl* decl);
114-
SwiftMangledName visitTypeDiscriminatedValueDecl(const swift::ValueDecl* decl);
116+
SwiftMangledName visitTypeDiscriminatedValueDecl(const swift::ValueDecl* decl,
117+
bool force = false);
115118
};
116119

117120
// This implementation is indented for use in defining trap keys. In this case fetching gives

0 commit comments

Comments
 (0)