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

Improve -Zunpretty=hir for parsed attrs #138063

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Mar 5, 2025

  1. Rename print_something to should_render to make it distinct from print_attribute in that it doesn't print anything, it's just a way to probe if a type renders anything.
  2. Fixes a few bugs in the PrintAttribute derive. Namely, the __printed_anything variable was entangled with the should_render call, leading us to always render field names but never render commas.
  3. Remove the outermost "" from the attr.
  4. Debug print Symbols. I know that this is redundant for some parsed attributes, but there's no good way to distinguish symbols that are ident-like and symbols which are cooked string literals. We could perhaps conditionally to fall back to a debug printing if the symbol doesn't match an ident? But seems like overkill.

Based on #138060, only review the commits not in that one.

@rustbot
Copy link
Collaborator

rustbot commented Mar 5, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Mar 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 5, 2025

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

@compiler-errors
Copy link
Member Author

@bors delegate=jdonszelmann

@bors
Copy link
Contributor

bors commented Mar 5, 2025

✌️ @jdonszelmann, you can now approve this pull request!

If @compiler-errors told you to "r=me" after making some further change, please make that change, then do @bors r=@compiler-errors

@@ -5,17 +5,21 @@ extern crate std;
//@ compile-flags: -Zunpretty=hir
//@ check-pass

#[deprecated]
#[attr = Deprecation {deprecation: Deprecation {since: Unspecified}}]
Copy link
Member Author

@compiler-errors compiler-errors Mar 5, 2025

Choose a reason for hiding this comment

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

some of the spacing is a bit tighter than i'd like, but the pp_hir machinery is annoying lol

hir::Attribute::Parsed(pa) => {
self.word("#[attr=\"");
self.word("#[attr = ");
Copy link
Member Author

Choose a reason for hiding this comment

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

this isn't grammatical (#[attr = {}]) but renders better than a string :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I do prefer it though, so nice change :)

@compiler-errors compiler-errors added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 5, 2025
if parens {
p.word("(");
}

let mut printed_anything = $t.print_something();
let mut printed_anything = $t.should_render();
Copy link
Contributor

Choose a reason for hiding this comment

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

is printed_anything doing anything here? I may have misremembered my own code but can't find a usage atm


$t.print_attribute(p);

$(
if printed_anything && $ts.print_something() {
if $ts.should_render() {
Copy link
Contributor

Choose a reason for hiding this comment

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

the check isn't here anymore, which could be correct

Copy link
Member Author

Choose a reason for hiding this comment

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

oh yes, that is necessary, but we need to push the if printed_anything into the block like the other fixes.

@@ -126,7 +126,7 @@ macro_rules! print_tup {
let ($t, $($ts),*) = self;
let parens = print_tup!(num_should_render $t $($ts)*) > 1;
if parens {
p.word("(");
p.popen();
Copy link
Contributor

Choose a reason for hiding this comment

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

oh didn't know these existed, neat :3

hir::Attribute::Parsed(pa) => {
self.word("#[attr=\"");
self.word("#[attr = ");
Copy link
Contributor

Choose a reason for hiding this comment

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

I do prefer it though, so nice change :)

@@ -35,6 +37,7 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
return;
}

__p.nbsp();
__p.word("{");
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we could add some spaces (when #disps.len() > 0) here at the braces to make things slightly less tight?

Copy link
Member Author

Choose a reason for hiding this comment

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

It may lead to other spacing awkwardness, so let's keep it as is.

@bors
Copy link
Contributor

bors commented Mar 7, 2025

☔ The latest upstream changes (presumably #138155) made this pull request unmergeable. Please resolve the merge conflicts.

@compiler-errors compiler-errors force-pushed the improve-attr-unpretty branch from 914ad9e to 9ae9453 Compare March 7, 2025 18:42
@jdonszelmann
Copy link
Contributor

I see ya did the spaces change anyway, nice! Looks like that addresses everything @bors r+

@bors
Copy link
Contributor

bors commented Mar 7, 2025

📌 Commit 9ae9453 has been approved by jdonszelmann

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-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Mar 7, 2025
@compiler-errors
Copy link
Member Author

@bors rollup since this does not really affect stable code

compiler-errors added a commit to compiler-errors/rust that referenced this pull request Mar 7, 2025
…tty, r=jdonszelmann

Improve `-Zunpretty=hir` for parsed attrs

0. Rename `print_something` to `should_render` to make it distinct from `print_attribute` in that it doesn't print anything, it's just a way to probe if a type renders anything.
1. Fixes a few bugs in the `PrintAttribute` derive. Namely, the `__printed_anything` variable was entangled with the `should_render` call, leading us to always render field names but never render commas.
2. Remove the outermost `""` from the attr.
3. Debug print `Symbol`s. I know that this is redundant for some parsed attributes, but there's no good way to distinguish symbols that are ident-like and symbols which are cooked string literals. We could perhaps *conditionally* to fall back to a debug printing if the symbol doesn't match an ident? But seems like overkill.

Based on rust-lang#138060, only review the commits not in that one.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 7, 2025
…mpiler-errors

Rollup of 10 pull requests

Successful merges:

 - rust-lang#135651 (Support for `wasm32-wali-linux-musl` Tier-3 target)
 - rust-lang#136642 (Put the alloc unit tests in a separate alloctests package)
 - rust-lang#137337 (Add verbatim linker to AIXLinker)
 - rust-lang#137549 (Clean up various LLVM FFI things in codegen_llvm)
 - rust-lang#137957 (Remove i586-pc-windows-msvc)
 - rust-lang#138063 (Improve `-Zunpretty=hir` for parsed attrs)
 - rust-lang#138137 (setTargetTriple now accepts Triple rather than string)
 - rust-lang#138141 (tests: fix some typos in comment)
 - rust-lang#138150 (Streamline HIR intravisit `visit_id` calls for items)
 - rust-lang#138173 (Delay bug for negative auto trait rather than ICEing)

r? `@ghost`
`@rustbot` modify labels: rollup
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Mar 7, 2025
…tty, r=jdonszelmann

Improve `-Zunpretty=hir` for parsed attrs

0. Rename `print_something` to `should_render` to make it distinct from `print_attribute` in that it doesn't print anything, it's just a way to probe if a type renders anything.
1. Fixes a few bugs in the `PrintAttribute` derive. Namely, the `__printed_anything` variable was entangled with the `should_render` call, leading us to always render field names but never render commas.
2. Remove the outermost `""` from the attr.
3. Debug print `Symbol`s. I know that this is redundant for some parsed attributes, but there's no good way to distinguish symbols that are ident-like and symbols which are cooked string literals. We could perhaps *conditionally* to fall back to a debug printing if the symbol doesn't match an ident? But seems like overkill.

Based on rust-lang#138060, only review the commits not in that one.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 7, 2025
…mpiler-errors

Rollup of 8 pull requests

Successful merges:

 - rust-lang#136642 (Put the alloc unit tests in a separate alloctests package)
 - rust-lang#137337 (Add verbatim linker to AIXLinker)
 - rust-lang#137363 (compiler: factor Windows x86-32 ABI impl into its own file)
 - rust-lang#137685 (self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux)
 - rust-lang#138000 (atomic: clarify that failing conditional RMW operations are not 'writes')
 - rust-lang#138063 (Improve `-Zunpretty=hir` for parsed attrs)
 - rust-lang#138137 (setTargetTriple now accepts Triple rather than string)
 - rust-lang#138173 (Delay bug for negative auto trait rather than ICEing)

r? `@ghost`
`@rustbot` modify labels: rollup
@compiler-errors
Copy link
Member Author

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 8, 2025
@jdonszelmann
Copy link
Contributor

jdonszelmann commented Mar 8, 2025

fix hir pretty printing

diff --git a/tests/pretty/hir-pretty-attr.pp b/tests/pretty/hir-pretty-attr.pp
index 586810b0046..d8cc8c424ca 100644
--- a/tests/pretty/hir-pretty-attr.pp
+++ b/tests/pretty/hir-pretty-attr.pp
@@ -6,6 +6,6 @@ extern crate std;
 //@ pretty-mode:hir
 //@ pp-exact:hir-pretty-attr.pp

-#[attr="Repr([ReprC, ReprPacked(Align(4 bytes)), ReprTransparent])")]
+#[attr = Repr([ReprC, ReprPacked(Align(4 bytes)), ReprTransparent])]

what is a PR but a series of patches anyway. can't push, can comment 🤷

@compiler-errors compiler-errors force-pushed the improve-attr-unpretty branch from 9ae9453 to 9c7821b Compare March 8, 2025 18:38
@compiler-errors
Copy link
Member Author

@bors r=jdonszelmann

@bors
Copy link
Contributor

bors commented Mar 8, 2025

📌 Commit 9c7821b has been approved by jdonszelmann

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 8, 2025
@compiler-errors
Copy link
Member Author

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 8, 2025
@compiler-errors compiler-errors force-pushed the improve-attr-unpretty branch from 9c7821b to 382b76d Compare March 9, 2025 01:59
@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend A-rustdoc-search Area: Rustdoc's search feature labels Mar 9, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2025

Some changes occurred in tests/rustdoc-json

cc @aDotInTheVoid

@rustbot rustbot added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Mar 9, 2025
@compiler-errors
Copy link
Member Author

@bors r=jdonszelmann

@bors
Copy link
Contributor

bors commented Mar 9, 2025

📌 Commit 382b76d has been approved by jdonszelmann

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend A-rustdoc-search Area: Rustdoc's search feature 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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants