Skip to content

Revert "Emit mangled names for public symbols into the .swiftinterface" #77579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,6 @@ struct PrintOptions {
/// with types sharing a name with a module.
bool AliasModuleNames = false;

/// Print some ABI details for public symbols as comments that can be
/// parsed by another tool.
bool PrintABIComments = false;

/// Name of the modules that have been aliased in AliasModuleNames mode.
/// Ideally we would use something other than a string to identify a module,
/// but since one alias can apply to more than one module, strings happen
Expand Down Expand Up @@ -725,8 +721,7 @@ struct PrintOptions {
bool useExportedModuleNames,
bool aliasModuleNames,
llvm::SmallSet<StringRef, 4>
*aliasModuleNamesTargets,
bool abiComments
*aliasModuleNamesTargets
);

/// Retrieve the set of options suitable for "Generated Interfaces", which
Expand Down
4 changes: 0 additions & 4 deletions include/swift/Frontend/ModuleInterfaceSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ struct ModuleInterfaceOptions {
/// [TODO: Clang-type-plumbing] This check should go away.
bool PrintFullConvention = false;

/// Print some ABI details for public symbols as comments that can be
/// parsed by another tool.
bool ABIComments = false;

struct InterfaceFlags {
/// Copy of all the command-line flags passed at .swiftinterface
/// generation time, re-applied to CompilerInvocation when reading
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -1050,9 +1050,6 @@ def disable_alias_module_names_in_module_interface :
Flag<["-"], "disable-alias-module-names-in-module-interface">,
HelpText<"When emitting a module interface, disable disambiguating modules "
"using distinct alias names">;
def abi_comments_in_module_interface :
Flag<["-"], "abi-comments-in-module-interface">,
HelpText<"When emitting a module interface, emit comments with ABI details">;

def experimental_spi_imports :
Flag<["-"], "experimental-spi-imports">,
Expand Down
84 changes: 11 additions & 73 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
bool useExportedModuleNames,
bool aliasModuleNames,
llvm::SmallSet<StringRef, 4>
*aliasModuleNamesTargets,
bool abiComments) {
*aliasModuleNamesTargets
) {
PrintOptions result;
result.IsForSwiftInterface = true;
result.PrintLongAttrsOnSeparateLines = true;
Expand All @@ -242,7 +242,6 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
result.PreferTypeRepr = preferTypeRepr;
result.AliasModuleNames = aliasModuleNames;
result.AliasModuleNamesTargets = aliasModuleNamesTargets;
result.PrintABIComments = abiComments;
if (printFullConvention)
result.PrintFunctionRepresentationAttrs =
PrintOptions::FunctionRepresentationMode::Full;
Expand Down Expand Up @@ -783,28 +782,19 @@ class PrintAST : public ASTVisitor<PrintAST> {
printRawComment(RC);
}

/// If we should print a mangled name for this declaration, return that
/// mangled name.
std::optional<std::string> mangledNameToPrint(const Decl *D);

void printDocumentationComment(const Decl *D) {
if (Options.PrintDocumentationComments) {
// Try to print a comment from Clang.
auto MaybeClangNode = D->getClangNode();
if (MaybeClangNode) {
if (auto *CD = MaybeClangNode.getAsDecl())
printClangDocumentationComment(CD);
return;
}
if (!Options.PrintDocumentationComments)
return;

printSwiftDocumentationComment(D);
// Try to print a comment from Clang.
auto MaybeClangNode = D->getClangNode();
if (MaybeClangNode) {
if (auto *CD = MaybeClangNode.getAsDecl())
printClangDocumentationComment(CD);
return;
}

if (auto mangledName = mangledNameToPrint(D)) {
indent();
Printer << "// MANGLED NAME: " << *mangledName;
Printer.printNewline();
}
printSwiftDocumentationComment(D);
}

void printStaticKeyword(StaticSpellingKind StaticSpelling) {
Expand Down Expand Up @@ -3130,58 +3120,6 @@ void PrintAST::printExtension(ExtensionDecl *decl) {
}
}

std::optional<std::string> PrintAST::mangledNameToPrint(const Decl *D) {
using ASTMangler = Mangle::ASTMangler;

if (!Options.PrintABIComments)
return std::nullopt;

auto valueDecl = dyn_cast<ValueDecl>(D);
if (!valueDecl)
return std::nullopt;

// Anything with an access level less than "package" isn't meant to be
// referenced from source code outside the module.
if (valueDecl->getEffectiveAccess() < AccessLevel::Package)
return std::nullopt;

// For functions, mangle the entity directly.
if (auto func = dyn_cast<FuncDecl>(D)) {
ASTMangler mangler;
return mangler.mangleEntity(func);
}

// For initializers, mangle the allocating initializer.
if (auto init = dyn_cast<ConstructorDecl>(D)) {
ASTMangler mangler;
return mangler.mangleConstructorEntity(init, /*isAllocating=*/true);
}

// For variables, mangle the entity directly.
if (auto var = dyn_cast<VarDecl>(D)) {
ASTMangler mangler;
return mangler.mangleEntity(var);
}

// For subscripts, mangle the entity directly.
if (auto subscript = dyn_cast<SubscriptDecl>(D)) {
ASTMangler mangler;
return mangler.mangleEntity(subscript);
}

// For nominal types, mangle the type metadata accessor.
if (auto nominal = dyn_cast<NominalTypeDecl>(D)) {
if (!isa<ProtocolDecl>(nominal) && !nominal->getGenericSignature()) {
ASTMangler mangler;
std::string name = mangler.mangleNominalType(nominal);
name += "Ma";
return name;
}
}

return std::nullopt;
}

static void suppressingFeatureIsolatedAny(PrintOptions &options,
llvm::function_ref<void()> action) {
llvm::SaveAndRestore<bool> scope(options.SuppressIsolatedAny, true);
Expand Down
1 change: 0 additions & 1 deletion lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ static void ParseModuleInterfaceArgs(ModuleInterfaceOptions &Opts,
Args.hasArg(OPT_debug_emit_invalid_swiftinterface_syntax);
Opts.PrintMissingImports =
!Args.hasArg(OPT_disable_print_missing_imports_in_module_interface);
Opts.ABIComments = Args.hasArg(OPT_abi_comments_in_module_interface);

if (const Arg *A = Args.getLastArg(OPT_library_level)) {
StringRef contents = A->getValue();
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/ModuleInterfaceSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ bool swift::emitSwiftInterface(raw_ostream &out,
M, Opts.PreserveTypesAsWritten, Opts.PrintFullConvention,
Opts.InterfaceContentMode,
useExportedModuleNames,
Opts.AliasModuleNames, &aliasModuleNamesTargets, Opts.ABIComments);
Opts.AliasModuleNames, &aliasModuleNamesTargets);
InheritedProtocolCollector::PerTypeMap inheritedProtocolMap;

SmallVector<Decl *, 16> topLevelDecls;
Expand Down
42 changes: 0 additions & 42 deletions test/ModuleInterface/abi-comments.swift

This file was deleted.