-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add Dump
functions to Check, Parse, and Lex
#4669
Conversation
…ffer These methods are useful for calling in a debugger, and will dump verbose information from an id value. Currently this is done in a pretty simple manner. The Lex and Parse methods are each replicated onto the Check::Context class manually (and same for Lex onto Parse::Tree). The DumpId methods are implemented in this PR for: - Lex::TokenIndex - Parse::NodeId - SemIR::LocId
Cool thanks for figuring out the free functions approach with bazel. If this merges would it just take the commit description and author from the first commit or will it apply co-authored correctly? We can reword the first commit to describe what the PR ended up doing? |
toolchain/check/BUILD
Outdated
@@ -93,6 +91,24 @@ cc_library( | |||
"//toolchain/sem_ir:typed_insts", | |||
"@llvm-project//llvm:Support", | |||
], | |||
alwayslink = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a comment why this is here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this one was missed, I also wondered if it's actually needed since dump was moved to another cc_library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I wasn't looking closely enough because I just assumed I'd already removed this set. Removed.
"//toolchain/parse:tree", | ||
"//toolchain/sem_ir:file", | ||
], | ||
alwayslink = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a comment why this is here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
cc_library( | ||
name = "dump_id", | ||
srcs = ["dump_id.cpp"], | ||
copts = ["-Wno-missing-prototypes"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a comment why this is here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
":tokenized_buffer", | ||
"//common:ostream", | ||
], | ||
alwayslink = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a comment why this is here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
"//common:ostream", | ||
"//toolchain/lex:dump_id", | ||
], | ||
alwayslink = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment why this is here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
toolchain/parse/dump_id.cpp
Outdated
@@ -26,4 +27,19 @@ auto DumpIdImpl(const Tree& tree, NodeId node_id) -> void { | |||
llvm::errs() << ")"; | |||
} | |||
|
|||
// A set of DumpId() overloads that dump an object to stderr, useful for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Lex, this is moved to the header, should this comment move to the header here too? Or can we make it consistent either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a more complete comment to each header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also a mention in docs/
toolchain/check/dump_id.cpp
Outdated
|
||
// A set of DumpId() overloads that dump an object to stderr, useful for | ||
// calling inside a debugger. | ||
LLVM_DUMP_METHOD auto DumpId(const Context& context, Lex::TokenIndex token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description says "this provides Check::Dump(context, arg) and similar" which is a typo (no Id) that we keep making. And we'll want to dump things other than Ids (like PendingBlock). So maybe we should drop the Id suffix. This is also fine for now, but I'm not happy with the naming forever yet. I was also talking with Geoff about maybe renaming "Dump" in Printable (Dump->Print and Print->PrintTo?) or something to avoid the name collisions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLVM typically calls it dump
, which is where the name Dump
came from:
https://github.com/search?q=repo%3Allvm%2Fllvm-project%20LLVM_DUMP_METHOD&type=code
(ed: to be clear, I think there's significant value in consistency)
You're correct the PR description doesn't match, I'll change the call though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, removing Dump
from Printable
would seem fine to me (I only added it for debugging, for others), I'm just meaning that if there's going to be a function that does dumping, it should probably use the familiar name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right yeah I don't want to diverge from LLVM too much either. My full opinion state here is that I'd prefer Dump to be used for the place that includes as much info as possible. The dump() in LLVM does include comprehensive amount of info generally everything you need when debugging, similarly. I'd personally be fine with renaming or removing the Dump function from Printable. I haven't had a lot of use of calling Dump explicitly on Printable types, as they are already streamable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(to be sure, I'm assuming this'll be resolved separately)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, me too
Sure, and since it sounds like you're okay proceeding with this approach, would it make sense to close #4620? AFAIU GitHub adds Co-authored-by lines automatically. You can find examples in PRs such as #4623 -- note that I have commits in that branch, and GitHub attributes me in daba2c7 |
toolchain/check/BUILD
Outdated
@@ -93,6 +91,24 @@ cc_library( | |||
"//toolchain/sem_ir:typed_insts", | |||
"@llvm-project//llvm:Support", | |||
], | |||
alwayslink = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this one was missed, I also wondered if it's actually needed since dump was moved to another cc_library.
toolchain/check/context.h
Outdated
@@ -6,6 +6,7 @@ | |||
#define CARBON_TOOLCHAIN_CHECK_CONTEXT_H_ | |||
|
|||
#include "common/map.h" | |||
#include "common/ostream.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer used in this PR and can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing
toolchain/check/BUILD
Outdated
@@ -72,6 +72,7 @@ cc_library( | |||
"//common:array_stack", | |||
"//common:check", | |||
"//common:map", | |||
"//common:ostream", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer used in this PR and can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing
DumpId
functions to Check, Parse, and LexDump
functions to Check, Parse, and Lex
- Provide `Check::Dump(context, arg)` and similar. - gdb and lldb should do contextual lookup, and `call Dump(*this, Lex::TokenIndex::Invalid)` has been tested with gdb. - Since this is only for debug, keeps the functions fully separated from code. - Uses alwayslink to ensure objects are correctly linked, even though there are no calls. - `-Wno-missing-prototypes` is needed when we don't have forward declarations. - Code is not linked in opt builds, using `#ifndef NDEBUG`. - This probably could be doing something in BUILD files with a `select()`, but the `#ifndef` seemed easier. This is based on carbon-language#4620, but uses free functions instead of member functions. Co-authored-by: Dana Jansens <[email protected]> --------- Co-authored-by: danakj <[email protected]>
Follow-on to #4669 . Did some manual testing, but may have not exercised all code paths. --------- Co-authored-by: Josh L <[email protected]>
Check::Dump(context, arg)
and similar.call Dump(*this, Lex::TokenIndex::Invalid)
has been tested with gdb.-Wno-missing-prototypes
is needed when we don't have forward declarations.#ifndef NDEBUG
.select()
, but the#ifndef
seemed easier.This is based on #4620, but uses free functions instead of member functions.
Co-authored-by: Dana Jansens [email protected]