Skip to content

Improve rustc_parse::Parser's debuggability #124779

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 3 commits into from
May 8, 2024

Conversation

workingjubilee
Copy link
Member

@workingjubilee workingjubilee commented May 6, 2024

The main event is the final commit where I add Parser::debug_lookahead. Everything else was basically cleaning up things that bugged me (debugging, as it were) until I felt comfortable enough to actually work on it.

The motivation is that it's annoying as hell to try to figure out how the debug infra works in rustc without having basic queries like debug!(?parser); come up "empty". However, Parser has a lot of fields that are mostly irrelevant for most debugging, like the entire ParseSess. I think Parser::debug_lookahead with a capped lookahead might be fine as a general-purpose Debug impl, but this adapter version was suggested to allow more choice, and admittedly, it's a refined version of what I was already handrolling just to get some insight going.

This was added as pub in 2021 and remains only privately used in 2024!
@rustbot
Copy link
Collaborator

rustbot commented May 6, 2024

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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 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 May 6, 2024
@rust-log-analyzer

This comment has been minimized.

@workingjubilee workingjubilee force-pushed the debug-formatting-my-beloved branch from 6f20e45 to fe3ad37 Compare May 6, 2024 00:20
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

I'd prefer if you dropped the changews for #[derive(Default)] for Collect, and #[derive(PartialEq)] for Recovery.

@@ -211,9 +211,10 @@ pub type ReplaceRange = (Range<u32>, Vec<(FlatToken, Spacing)>);
/// Controls how we capture tokens. Capturing can be expensive,
/// so we try to avoid performing capturing in cases where
/// we will never need an `AttrTokenStream`.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Default)]
Copy link
Member

Choose a reason for hiding this comment

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

Is this default used anywhere? If not, please let's keep this explicit. I think "this is the default mode" doesn't mean "this needs a Default impl", it just means "this is what's used in Parser::new").

Copy link
Member Author

Choose a reason for hiding this comment

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

Mmkay!

@@ -121,7 +121,7 @@ macro_rules! maybe_recover_from_interpolated_ty_qpath {
};
}

#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq)]
Copy link
Member

Choose a reason for hiding this comment

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

Why? I would prefer if people just write matches! here.

Copy link
Member Author

Choose a reason for hiding this comment

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

tbh, no particularly strong reason, my bias is just to prefer to implement traits that seem applicable unless I can articulate my reservations about doing so, and I couldn't figure out that here.

if let Some(subparser) = parser.subparser_name {
dbg_fmt.field("subparser_name", &subparser);
}
if parser.recovery == Recovery::Forbidden {
Copy link
Member

Choose a reason for hiding this comment

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

Make this an exhaustive match or a matches!()

It's annoying to debug the parser if you have to stop every five seconds
to add a Debug impl.
I tried debugging a parser-related issue but found it annoying to not be
able to easily peek into the Parser's token stream.

Add a convenience fn that offers an opinionated view into the parser,
but one that is useful for answering basic questions about parser state.
@workingjubilee workingjubilee force-pushed the debug-formatting-my-beloved branch from fe3ad37 to 5e67a37 Compare May 8, 2024 02:12
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented May 8, 2024

📌 Commit 5e67a37 has been approved by compiler-errors

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 May 8, 2024
@bors
Copy link
Collaborator

bors commented May 8, 2024

⌛ Testing commit 5e67a37 with merge 5ce96b1...

@bors
Copy link
Collaborator

bors commented May 8, 2024

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 5ce96b1 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 8, 2024
@bors bors merged commit 5ce96b1 into rust-lang:master May 8, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 8, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5ce96b1): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.2% [3.2%, 3.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 676.869s -> 676.306s (-0.08%)
Artifact size: 315.94 MiB -> 315.93 MiB (-0.00%)

@workingjubilee workingjubilee deleted the debug-formatting-my-beloved branch May 8, 2024 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

7 participants