Skip to content

Improve information sharing across SB diagnostics #2454

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 4 commits into from
Aug 18, 2022

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Aug 1, 2022

Previous Stacked Borrows diagnostics were missing a lot of information about the state of the interpreter, and it was difficult to add additional state because it was threaded through all the intervening function signatures.

This change factors a lot of the arguments which used to be passed individually to many stacked borrows functions into a single DiagnosticCx, which is built in Stacks::for_each, and since it wraps a handle to AllocHistory, we can now handle more nuanced things like heterogeneous borrow of !Freeze types.

@RalfJung RalfJung added the S-waiting-on-review Status: Waiting for a review to complete label Aug 3, 2022
@saethlin
Copy link
Member Author

saethlin commented Aug 6, 2022

I was reminded that this can probably be used to produce better tag-tracking diagnostics. Might implement that later...

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

I'm a big fan of the more detailed errors! However, I hope we can find a way to implement that that does not reply on passing information implicitly through global state...

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

Yes, much better. :)

@saethlin
Copy link
Member Author

FYI this is now about a 10% perf regression on all benchmarks, on account of the requires_caller_location calls. Here's a profile of the backtraces benchmark if you're curious: flamegraph.svg.gz

I don't know why that function is so expensive, but the disassembly is massive.

@saethlin saethlin force-pushed the diagnostics-cleanup branch from 1590eea to 8ccb139 Compare August 14, 2022 04:25
@RalfJung
Copy link
Member

RalfJung commented Aug 14, 2022

Oh wow. Okay then let's do that yet, instead please open an issue to track further investigation.

@saethlin saethlin force-pushed the diagnostics-cleanup branch from 8ccb139 to b47c1f8 Compare August 14, 2022 12:57
@saethlin
Copy link
Member Author

Fresh brain in the morning. I realized that I was pointlessly checking for #[track_caller] on a lot of frames. I just amended with this diff:

diff --git a/src/helpers.rs b/src/helpers.rs
index e3142caa..bf536c24 100644
--- a/src/helpers.rs
+++ b/src/helpers.rs
@@ -923,6 +923,8 @@ impl<'a, 'mir: 'a, 'tcx: 'a + 'mir> CurrentSpan<'a, 'mir, 'tcx> {
             .unwrap_or(rustc_span::DUMMY_SP)
     }
 
+    // Find the position of the inner-most frame which is part of the crate being
+    // compiled/executed, part of the Cargo workspace, and is also not #[track_caller].
     fn current_span_index(tcx: TyCtxt<'_>, machine: &Evaluator<'_, '_>) -> usize {
         machine
             .threads
@@ -930,11 +932,11 @@ impl<'a, 'mir: 'a, 'tcx: 'a + 'mir> CurrentSpan<'a, 'mir, 'tcx> {
             .iter()
             .enumerate()
             .rev()
-            // Skip #[track_caller] frames
-            .filter(|(_, frame)| !frame.instance.def.requires_caller_location(tcx))
             .find_map(|(idx, frame)| {
                 let def_id = frame.instance.def_id();
-                if def_id.is_local() || machine.local_crates.contains(&def_id.krate) {
+                if (def_id.is_local() || machine.local_crates.contains(&def_id.krate))
+                    && !frame.instance.def.requires_caller_location(tcx)
+                {
                     Some(idx)
                 } else {
                     None

This is now on average perf-neutral, with some small improvements and regressions. requires_caller_location is now ~1% of cycles which is still oddly high but not concerning for us at the moment IMO.

@RalfJung
Copy link
Member

(Please don't rebase+amend unless there are conflicts. Rebasing destroys being able to get decent diffs from github for what you changed between revisions.)

@saethlin
Copy link
Member Author

saethlin commented Aug 16, 2022

Please don't rebase+amend unless there are conflicts.

I was wondering how you were dealing with this before, sorry about that 🙃

@RalfJung
Copy link
Member

For big PRs like this, ideally just keep adding new commits, then even after a rebase it's easy to see what is new. Squashing is an optimization that can happen when we are done. :)

@bors
Copy link
Contributor

bors commented Aug 16, 2022

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

@RalfJung
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Aug 17, 2022
Previous Stacked Borrows diagnostics were missing a lot of information
about the state of the interpreter, and it was difficult to add
additional state because it was threaded through all the intervening
function signatures.

This change factors a lot of the arguments which used to be passed
individually to many stacked borrows functions into a single
`DiagnosticCx`, which is built in `Stacks::for_each`, and since it
wraps a handle to `AllocHistory`, we can now handle more nuanced
things like heterogeneous borrow of `!Freeze` types.
@RalfJung RalfJung force-pushed the diagnostics-cleanup branch from f8d8ab8 to 0e5a53d Compare August 18, 2022 19:20
@RalfJung
Copy link
Member

I took the liberty to take care of the last nit, so that the nicer diagnostics can be part of the next Miri update. :)

@bors r+

@bors
Copy link
Contributor

bors commented Aug 18, 2022

📌 Commit 0e5a53d has been approved by RalfJung

It is now in the queue for this repository.

bors added a commit that referenced this pull request Aug 18, 2022
Improve information sharing across SB diagnostics

Previous Stacked Borrows diagnostics were missing a lot of information about the state of the interpreter, and it was difficult to add additional state because it was threaded through all the intervening function signatures.

This change factors a lot of the arguments which used to be passed individually to many stacked borrows functions into a single `DiagnosticCx`, which is built in `Stacks::for_each`, and since it wraps a handle to `AllocHistory`, we can now handle more nuanced things like heterogeneous borrow of `!Freeze` types.
@bors
Copy link
Contributor

bors commented Aug 18, 2022

⌛ Testing commit 0e5a53d with merge bf38971...

@bors
Copy link
Contributor

bors commented Aug 18, 2022

💔 Test failed - checks-actions

@RalfJung RalfJung force-pushed the diagnostics-cleanup branch from ba9d8d2 to 7397c8e Compare August 18, 2022 20:37
@RalfJung
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 18, 2022

📌 Commit 7397c8e has been approved by RalfJung

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 18, 2022

⌛ Testing commit 7397c8e with merge 09118da...

@bors
Copy link
Contributor

bors commented Aug 18, 2022

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 09118da to master...

@bors bors merged commit 09118da into rust-lang:master Aug 18, 2022
@saethlin
Copy link
Member Author

Thanks for taking care of this!

@saethlin saethlin deleted the diagnostics-cleanup branch August 30, 2022 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: Waiting for the PR author to address review comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants