[AST] Remove respectOriginallyDefinedIn parameter from mangleAnyDecl

This was always set to `true` except for USR mangling, where we already
have it set to `false` for IDE USRs. The other clients were:

- AutoDiff, which is just using the resulting string as a dictionary
key, so don't seem to have any preference.
- The ClangImporter, which always overrides `@_originallyDefinedIn`
anyway.
This commit is contained in:
Hamish Knight
2025-10-23 09:11:17 +01:00
parent b607ec7a2f
commit a1e1656ed5
5 changed files with 12 additions and 18 deletions

View File

@@ -398,8 +398,7 @@ public:
std::string mangleTypeAsContextUSR(const NominalTypeDecl *type); std::string mangleTypeAsContextUSR(const NominalTypeDecl *type);
void appendAnyDecl(const ValueDecl *Decl); void appendAnyDecl(const ValueDecl *Decl);
std::string mangleAnyDecl(const ValueDecl *Decl, bool prefix, std::string mangleAnyDecl(const ValueDecl *decl, bool addPrefix);
bool respectOriginallyDefinedIn = false);
std::string mangleDeclAsUSR(const ValueDecl *Decl, StringRef USRPrefix); std::string mangleDeclAsUSR(const ValueDecl *Decl, StringRef USRPrefix);
std::string mangleAccessorEntityAsUSR(AccessorKind kind, std::string mangleAccessorEntityAsUSR(AccessorKind kind,

View File

@@ -1120,8 +1120,7 @@ static StringRef calculateMangledName(SDKContext &Ctx, ValueDecl *VD) {
return Ctx.buffer(attr->Name); return Ctx.buffer(attr->Name);
} }
Mangle::ASTMangler NewMangler(VD->getASTContext()); Mangle::ASTMangler NewMangler(VD->getASTContext());
return Ctx.buffer(NewMangler.mangleAnyDecl(VD, true, return Ctx.buffer(NewMangler.mangleAnyDecl(VD, /*addPrefix*/ true));
/*bool respectOriginallyDefinedIn*/true));
} }
static StringRef calculateLocation(SDKContext &SDKCtx, Decl *D) { static StringRef calculateLocation(SDKContext &SDKCtx, Decl *D) {

View File

@@ -993,31 +993,28 @@ void ASTMangler::appendAnyDecl(const ValueDecl *Decl) {
} }
} }
std::string std::string ASTMangler::mangleAnyDecl(const ValueDecl *decl, bool addPrefix) {
ASTMangler::mangleAnyDecl(const ValueDecl *Decl,
bool prefix,
bool respectOriginallyDefinedIn) {
DWARFMangling = true; DWARFMangling = true;
RespectOriginallyDefinedIn = respectOriginallyDefinedIn; if (addPrefix) {
if (prefix) {
beginMangling(); beginMangling();
} else { } else {
beginManglingWithoutPrefix(); beginManglingWithoutPrefix();
} }
llvm::SaveAndRestore<bool> allowUnnamedRAII(AllowNamelessEntities, true); llvm::SaveAndRestore<bool> allowUnnamedRAII(AllowNamelessEntities, true);
appendAnyDecl(Decl); appendAnyDecl(decl);
// We have a custom prefix, so finalize() won't verify for us. If we're not // We have a custom prefix, so finalize() won't verify for us. If we're not
// in invalid code (coming from an IDE caller) verify manually. // in invalid code (coming from an IDE caller) verify manually.
if (CONDITIONAL_ASSERT_enabled() && !prefix && !Decl->isInvalid()) if (CONDITIONAL_ASSERT_enabled() && !addPrefix && !decl->isInvalid())
verify(Storage.str(), Flavor); verify(Storage.str(), Flavor);
return finalize(); return finalize();
} }
std::string ASTMangler::mangleDeclAsUSR(const ValueDecl *Decl, std::string ASTMangler::mangleDeclAsUSR(const ValueDecl *Decl,
StringRef USRPrefix) { StringRef USRPrefix) {
return (llvm::Twine(USRPrefix) + mangleAnyDecl(Decl, false)).str(); return (llvm::Twine(USRPrefix) + mangleAnyDecl(Decl, /*addPrefix*/ false))
.str();
} }
std::string ASTMangler::mangleAccessorEntityAsUSR(AccessorKind kind, std::string ASTMangler::mangleAccessorEntityAsUSR(AccessorKind kind,

View File

@@ -1348,9 +1348,9 @@ void PrintAST::printAttributes(const Decl *D) {
if (Options.PrintSyntheticSILGenName if (Options.PrintSyntheticSILGenName
&& !D->getAttrs().hasAttribute<SILGenNameAttr>()) { && !D->getAttrs().hasAttribute<SILGenNameAttr>()) {
if (canPrintSyntheticSILGenName(D)) { if (canPrintSyntheticSILGenName(D)) {
auto mangledName = Mangle::ASTMangler(D->getASTContext()) auto mangledName =
.mangleAnyDecl(cast<ValueDecl>(D), /*prefix=*/true, Mangle::ASTMangler(D->getASTContext())
/*respectOriginallyDefinedIn=*/true); .mangleAnyDecl(cast<ValueDecl>(D), /*addPrefix*/ true);
Printer.printAttrName("@_silgen_name"); Printer.printAttrName("@_silgen_name");
Printer << "("; Printer << "(";
Printer.printEscapedStringLiteral(mangledName); Printer.printEscapedStringLiteral(mangledName);

View File

@@ -155,8 +155,7 @@ static std::string getMangledNameString(const Decl *D) {
if (!VD) if (!VD)
return std::string(); return std::string();
Mangle::ASTMangler mangler(VD->getASTContext()); Mangle::ASTMangler mangler(VD->getASTContext());
return mangler.mangleAnyDecl(VD, /*prefix=*/true, return mangler.mangleAnyDecl(VD, /*addPrefix*/ true);
/*respectOriginallyDefinedIn=*/true);
} }
static std::string getTypeString(const ValueDecl *VD) { static std::string getTypeString(const ValueDecl *VD) {