Skip to content

AST: Rename debugger pretty printer Type::dumpPrint to print #77920

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
Mar 25, 2025
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
2 changes: 1 addition & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
SWIFT_DEBUG_DUMP;
void dump(raw_ostream &os, unsigned indent = 0) const;

SWIFT_DEBUG_DUMPER(dumpPrint());
SWIFT_DEBUG_DUMPER(print());
void print(raw_ostream &OS,
const PrintOptions &PO = PrintOptions()) const;
void print(ASTPrinter &Printer, const PrintOptions &PO) const;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7633,7 +7633,7 @@ std::string TypeBase::getStringAsComponent(const PrintOptions &PO) const {
return OS.str();
}

void TypeBase::dumpPrint() const {
void TypeBase::print() const {
Copy link
Contributor

@gottesmm gottesmm Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually inconsistent. "print" is never used for debug dumping. You can see this by doing a git grep of SWIFT_DEBUG_DUMPER in the code base. Just a small sample:

swift % git grep SWIFT_DEBUG_DUMPER
include/swift/AST/ActorIsolation.h:  SWIFT_DEBUG_DUMPER(dump());
include/swift/AST/ActorIsolation.h:  SWIFT_DEBUG_DUMPER(dumpForDiagnostics());
include/swift/AST/Attr.h:  SWIFT_DEBUG_DUMPER(dump(const Decl *D = nullptr));
include/swift/AST/Attr.h:  SWIFT_DEBUG_DUMPER(dump());
include/swift/AST/AvailabilityScope.h:  SWIFT_DEBUG_DUMPER(dump(SourceManager &SrcMgr));
include/swift/AST/Decl.h:  SWIFT_DEBUG_DUMPER(dump(const char *filename));
include/swift/AST/Decl.h:  SWIFT_DEBUG_DUMPER(dumpRef());
include/swift/AST/DeclContext.h:  SWIFT_DEBUG_DUMPER(dumpContext());
include/swift/AST/FileUnit.h:  SWIFT_DEBUG_DUMPER(dumpDisplayDecls());
include/swift/AST/FileUnit.h:  SWIFT_DEBUG_DUMPER(dumpTopLevelDecls());

It is always some variant of "dumpX". print is always used for the non-debug dump variant that can be called programatically.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in that sense the name is inconsistent. But is that an intentional consistency? I personally find print useful for debugging and want to be able to call it on AST nodes from the debugger by the same name (just as I would by print debugging) without it forcing me to provide arguments, only to fail to resolve some LLVM symbols because my LLVM build is RelWithDebInfo. I also don’t want other contributors to have a hard time figuring out how to spell these out in the debugger.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beccadax Hey Becca, I would appreciate an opinion on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dump() means "print detailed s-expression notation" while print() is "print this node as Swift source". Renaming dumpPrint() to print() is fine, because it just calls the other overload of print().

We similarly overload dump() for no arguments vs a stream argument as well.

print(llvm::errs());
llvm::errs() << '\n';
}
Expand Down