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

Track where diagnostics were created. #103217

Merged
merged 7 commits into from
Nov 1, 2022
Merged

Track where diagnostics were created. #103217

merged 7 commits into from
Nov 1, 2022

Conversation

mejrs
Copy link
Contributor

@mejrs mejrs commented Oct 18, 2022

This implements the -Ztrack-diagnostics flag, which uses #[track_caller] to track where diagnostics are created. It is meant as a debugging tool much like -Ztreat-err-as-bug.

For example, the following code...

struct A;
struct B;

fn main(){
    let _: A = B;
}

...now emits the following error message:

error[E0308]: mismatched types
 --> src\main.rs:5:16
  |
5 |     let _: A = B;
  |            -   ^ expected struct `A`, found struct `B`
  |            |
  |            expected due to this
-Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Oct 18, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 18, 2022

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eholk (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 18, 2022
@@ -1211,6 +1211,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
false,
None,
false,
false,
Copy link
Member

Choose a reason for hiding this comment

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

this is getting to be a lot of arguments, maybe add a Config struct? Doesn't need to block this PR though

compiler/rustc_errors/src/emitter.rs Outdated Show resolved Hide resolved
src/librustdoc/core.rs Outdated Show resolved Hide resolved
src/test/ui/track-diagnostics/track.rs Show resolved Hide resolved
@@ -691,6 +691,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
false,
None,
false,
false,
Copy link
Member

Choose a reason for hiding this comment

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

Same for clippy and rustfmt.

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

Not sure about -Z flags, but does this need an MCP?

fallback_bundle,
None,
false,
false,
Copy link
Member

Choose a reason for hiding this comment

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

I think if you don't set this for JSON output, it won't show up when using cargo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean with that. Afaik most code that calls this function doesn't have the sessions options available to it (because it's creating it). So i'm not sure what to do here.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, this is in early_error, I misread. Ok, seems fine to skip for now. I think it shouldn't be too hard to add it though, nearly every place that calls this has access to Options and those that don't can still call matches.opt_get("track-diagnostics") before calling the error code.

@davidtwco
Copy link
Member

Not sure about -Z flags, but does this need an MCP?

-Z flags don't need an MCP to the best of my knowledge

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@eholk
Copy link
Contributor

eholk commented Oct 25, 2022

I'm starting to look over this PR. One general question, is adding #[track_caller] to several functions going to cause issues if these ever panic or do Option::unwrap() or something like that? Will this make debugging those issues trickier?

@eholk
Copy link
Contributor

eholk commented Oct 25, 2022

I think this looks pretty good! The main thing left is to make sure all of @jyn514's comments get addressed (it looks like the hardcoding changes for clippy and rustfmt are the main ones).

@camsteffen
Copy link
Contributor

When would this be used rather than treat-err-as-bug? I think in my experience I always just want to know where one specific error comes from, and with a whole stack trace.

@jyn514
Copy link
Member

jyn514 commented Oct 29, 2022

@camsteffen this can be used in a compiler that has debug symbols disabled, and without reading through 200 lines of stack trace from rustc_query_impl.

@rustbot rustbot added the A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic label Oct 31, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2022

rustc_macros::diagnostics was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki

@mejrs
Copy link
Contributor Author

mejrs commented Oct 31, 2022

@jyn514 have I addressed all of your comments? I sort of lost track because I bit off small pieces here and there over the last week and I'm not totally sure I understood everything completely.

I'm starting to look over this PR. One general question, is adding #[track_caller] to several functions going to cause issues if these ever panic or do Option::unwrap() or something like that? Will this make debugging those issues trickier?

That could be a bit annoying if it happens but I don't think it's an issue. Most of the functions that have it now just call into_diagnostic or call something that does. Given that most of these impls are macro generated rather than hand written I don't expect mistakes to be made in them.

@jyn514
Copy link
Member

jyn514 commented Oct 31, 2022

@jyn514 have I addressed all of your comments? I sort of lost track because I bit off small pieces here and there over the last week and I'm not totally sure I understood everything completely.

Hmm, the only one I had left was #103217 (comment), but it looks like clippy is emitting -Ztrack-diagnostics notes even though you always pass in false? Not sure what's going on there.

@mejrs
Copy link
Contributor Author

mejrs commented Nov 1, 2022

it looks like clippy is emitting -Ztrack-diagnostics notes even though you always pass in false? Not sure what's going on there.

It looks like clippy uses the compiler's machinery for that, and just provides a callback to add its configuration? The change I made in clippy driver just passes in false if an ice is reported.

@jyn514
Copy link
Member

jyn514 commented Nov 1, 2022

Ok, great. I'm still not sure rustfmt is handling the option properly, but we can always add it later if someone complains.

I think this looks pretty good! The main thing left is to make sure all of @jyn514's comments get addressed (it looks like the hardcoding changes for clippy and rustfmt are the main ones).

@bors r=eholk rollup=iffy

@bors
Copy link
Contributor

bors commented Nov 1, 2022

📌 Commit cbeb244 has been approved by eholk

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 Nov 1, 2022
@bors
Copy link
Contributor

bors commented Nov 1, 2022

⌛ Testing commit cbeb244 with merge 11ebe65...

@bors
Copy link
Contributor

bors commented Nov 1, 2022

☀️ Test successful - checks-actions
Approved by: eholk
Pushing 11ebe65 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 1, 2022
@bors bors merged commit 11ebe65 into rust-lang:master Nov 1, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 1, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (11ebe65): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.2% [1.6%, 2.8%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

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)
4.2% [4.2%, 4.2%] 1
Improvements ✅
(primary)
-0.5% [-0.5%, -0.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.5% [-0.5%, -0.5%] 1

Cycles

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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.9% [-5.9%, -5.9%] 1
All ❌✅ (primary) - - 0

@rustbot rustbot added the perf-regression Performance regression. label Nov 2, 2022
@lqd
Copy link
Member

lqd commented Nov 2, 2022

I think deeply-nested-multi may be becoming noisy.

@rylev
Copy link
Member

rylev commented Nov 2, 2022

I think the likelihood that this is noise is pretty high as you can see from the end of this graph. I think we should assume noise in this case. If it's true regression it's small enough to not be a big deal.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Nov 2, 2022
@calebcartwright
Copy link
Member

Ok, great. I'm still not sure rustfmt is handling the option properly, but we can always add it later if someone complains.

Possibly easier to chat in Zulip, but could you help me understand what you mean by this @jyn514? Admit I've only done a cursory pass through this PR but it's not clear to me

@jyn514
Copy link
Member

jyn514 commented Nov 2, 2022

@calebcartwright I mean I'm not sure that running rustfmt -Ztrack-diagnostics will print the new message @mejrs added, since it's passing in false unconditionally. It should be something that's easy to test, I just haven't had time.

@calebcartwright
Copy link
Member

@calebcartwright I mean I'm not sure that running rustfmt -Ztrack-diagnostics will print the new message @mejrs added, since it's passing in false unconditionally. It should be something that's easy to test, I just haven't had time.

Gotcha. I can't conjure up a persona that I think would need that right now, so I'm happy to punt this to a future caleb on the off chance anyone ever does come up with a need

flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 21, 2022
Track where diagnostics were created.

This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`.

For example, the following code...

```rust
struct A;
struct B;

fn main(){
    let _: A = B;
}
```
...now emits the following error message:

```
error[E0308]: mismatched types
 --> src\main.rs:5:16
  |
5 |     let _: A = B;
  |            -   ^ expected struct `A`, found struct `B`
  |            |
  |            expected due to this
-Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31
```
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
Track where diagnostics were created.

This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`.

For example, the following code...

```rust
struct A;
struct B;

fn main(){
    let _: A = B;
}
```
...now emits the following error message:

```
error[E0308]: mismatched types
 --> src\main.rs:5:16
  |
5 |     let _: A = B;
  |            -   ^ expected struct `A`, found struct `B`
  |            |
  |            expected due to this
-Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31
```
calebcartwright pushed a commit to calebcartwright/rust that referenced this pull request Jan 24, 2023
Track where diagnostics were created.

This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`.

For example, the following code...

```rust
struct A;
struct B;

fn main(){
    let _: A = B;
}
```
...now emits the following error message:

```
error[E0308]: mismatched types
 --> src\main.rs:5:16
  |
5 |     let _: A = B;
  |            -   ^ expected struct `A`, found struct `B`
  |            |
  |            expected due to this
-Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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 Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.