Skip to content
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

Reduce HIR debug output #105558

Merged
merged 1 commit into from
Jan 3, 2023
Merged

Reduce HIR debug output #105558

merged 1 commit into from
Jan 3, 2023

Conversation

Noratrieb
Copy link
Member

@Noratrieb Noratrieb commented Dec 11, 2022

HIR debug output is currently very verbose, especially when used with the alternate (#) flag. This commit reduces the amount of noisy newlines by forcing a few small key types to stay on one line, which makes the output easier to read and scroll by.

$ rustc +after hello_world.rs -Zunpretty=hir-tree | wc -l
582
$ rustc +before hello_world.rs -Zunpretty=hir-tree | wc -l
932

@rustbot
Copy link
Collaborator

rustbot commented Dec 11, 2022

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 11, 2022
@Noratrieb
Copy link
Member Author

                    parents: [
                        "(0, Some(4294967040))",
                        "(1, Some(0))",
                        "(2, Some(0))",
                        "(3, Some(0))",
                        "(4, Some(0))",
                    ],

it's not great that this looks like a string now. I wasn't able to use format_args itself because of the local copy that it can't capture :/

@SkiFire13
Copy link
Contributor

it's not great that this looks like a string now. I wasn't able to use format_args itself because of the local copy that it can't capture :/

You can create a new local struct with two fields and manually implement Debug for it which does write!(fmt, "({}, {})"), self.id, self.parented_node). In my projects I often define a function like this to simplify the code (however with Display instead of Debug), though I'm not sure where to put it in rustc:

fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug {
    struct DebugFn<F>(F);
    impl<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Debug for DebugFn<F> {
        fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
            (self.0)(fmt)
        }
    }
    DebugFn(f)
}

Rustdoc seems to also have something similar already:

pub(crate) fn display_fn(
f: impl FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result,
) -> impl fmt::Display {
struct WithFormatter<F>(Cell<Option<F>>);
impl<F> fmt::Display for WithFormatter<F>
where
F: FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
(self.0.take()).unwrap()(f)
}
}
WithFormatter(Cell::new(Some(f)))
}

@Noratrieb Noratrieb force-pushed the less-spam-hir-tree branch 2 times, most recently from 8855b85 to bfd0a03 Compare December 11, 2022 16:08
@Noratrieb
Copy link
Member Author

Noratrieb commented Dec 11, 2022

I didn't think of that, thanks! No idea where the best place would be to put the function, I just put it at the bottom of the file (which is probably a bad idea).

Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

Thanks. That will definitely be useful. Can we pull this thread a bit more?

compiler/rustc_hir/src/hir_id.rs Outdated Show resolved Hide resolved
compiler/rustc_hir/src/hir_id.rs Outdated Show resolved Hide resolved
@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 25, 2022
@Noratrieb Noratrieb added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 2, 2023
compiler/rustc_hir/src/hir_id.rs Outdated Show resolved Hide resolved
compiler/rustc_hir/src/hir_id.rs Outdated Show resolved Hide resolved
HIR debug output is currently very verbose, especially when used with
the alternate (`#`) flag. This commit reduces the amount of noisy
newlines by forcing a few small key types to stay on one line, which
makes the output easier to read and scroll by.

```
$ rustc +after hello_world.rs -Zunpretty=hir-tree | wc -l
582
$ rustc +before hello_world.rs -Zunpretty=hir-tree | wc -l
932
```
@cjgillot
Copy link
Contributor

cjgillot commented Jan 2, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Jan 2, 2023

📌 Commit e1787f5 has been approved by cjgillot

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 2, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 3, 2023
…mpiler-errors

Rollup of 8 pull requests

Successful merges:

 - rust-lang#95985 (Add PhantomData marker to Context to make Context !Send and !Sync)
 - rust-lang#104298 (Add notes and examples about non-intuitive `PathBuf::set_extension` behavior)
 - rust-lang#105558 (Reduce HIR debug output)
 - rust-lang#106315 (Cleanup `mingw-tidy` docker job)
 - rust-lang#106354 (Rustdoc-Json: Report discriminant on all kinds of enum variant.)
 - rust-lang#106366 (Fix rustdoc ICE on bad typedef with mismatching types)
 - rust-lang#106376 (Update books)
 - rust-lang#106383 (Document some of the AST nodes)

Failed merges:

 - rust-lang#106356 (clean: Remove `ctor_kind` from `VariantStruct`.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit fbffaa9 into rust-lang:master Jan 3, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 3, 2023
@Noratrieb Noratrieb deleted the less-spam-hir-tree branch January 3, 2023 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants