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

interpret: do not prune requires_caller_location stack frames quite so early #98549

Merged
merged 1 commit into from
Jun 29, 2022

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Jun 26, 2022

#87000 made the interpreter skip caller_location frames for its stacktraces and cur_span. However, those functions are used for much more than just panic reporting, and e.g. when Miri reports UB somewhere, it probably wants to point inside caller_location frames. (And if it did not, it would want to have its own logic to decide that, not be forced into it by the core interpreter engine.) This fixes some rare ICEs in Miri that say "we should never pop more than one frame at once".

So let's remove all caller_location logic from the core interpreter, and instead move it to CTFE error reporting. This does not change user-visible behavior. That's the first commit.

We might additionally want to change CTFE error reporting to treat panics differently from other errors: only prune caller_location frames for panics. The second commit does that. But honestly I am not sure if this is an improvement.

r? @oli-obk

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 26, 2022
@rust-highfive
Copy link
Collaborator

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 26, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Jun 27, 2022

@bors r+

oh yea, I was wondering where the detailed UB trace when recently

@bors
Copy link
Contributor

bors commented Jun 27, 2022

📌 Commit bbcd2e2be94dfd5f13a170940cde31558e691db4 has been approved by oli-obk

@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 Jun 27, 2022
Comment on lines 2 to 7
--> $SRC_DIR/core/src/mem/maybe_uninit.rs:LL:COL
|
LL | intrinsics::assert_inhabited::<T>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| aborted execution: attempted to instantiate uninhabited type `!`
| inside `MaybeUninit::<!>::assume_init` at $SRC_DIR/core/src/mem/maybe_uninit.rs:LL:COL
| inside `_BAD1` at $DIR/assert-type-intrinsics.rs:14:9
|
::: $DIR/assert-type-intrinsics.rs:13:5
|
LL | / const _BAD1: () = unsafe {
LL | | MaybeUninit::<!>::uninit().assume_init();
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to instantiate uninhabited type `!`
LL | | };
Copy link
Member Author

@RalfJung RalfJung Jun 27, 2022

Choose a reason for hiding this comment

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

So you think this is better than before?

I honestly think hiding these frames here (as we did before) makes the error look better, and was wondering if it would make sense to do this in Miri, too (unless MIRI_BACKTRACE=full is set), because the user rarely wants to see stdlib frames.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm... I did not consider what happens when libstd source is not available. Likely that will make the first block of this diagnostic just disappear silently, along with the backtrace. So users will be lacking most of the information they need in order to debug the issue. That's an orthogonal issue to what you're asking though.

so... we don't prune regular backtraces either... and that has been a frequent issue imo. All those iterator, option and whatnot paths in the backtrace are really not helping anyone.

Copy link
Member Author

Choose a reason for hiding this comment

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

Even with std sources, I feel like pointing at assume_init is better than pointing at its insides.

so... we don't prune regular backtraces either...

True. But it is much easier for CTFE and Miri to do that so we might as well?

Copy link
Member

Choose a reason for hiding this comment

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

Even with std sources, I feel like pointing at assume_init is better than pointing at its insides.

I very much agree. Otherwise the error points users at code that they've never even seen, when they make a simple error. That's exactly why we're using #[track_caller] in so many places in std, to make sure a useful location is reported.

Copy link
Member

Choose a reason for hiding this comment

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

we don't prune regular backtraces either...

This isn't really a regular backtrace, though. This is part of a compiler diagonstic, where we are (and can be) much friendlier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I took out the last commit.

@oli-obk is that fine for you?

@RalfJung
Copy link
Member Author

@bors r-
still something to discuss

@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 Jun 27, 2022
@RalfJung RalfJung 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 Jun 27, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Jun 27, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jun 27, 2022

📌 Commit 852a111 has been approved by oli-obk

@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 Jun 27, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 28, 2022
…li-obk

interpret: do not prune requires_caller_location stack frames quite so early

rust-lang#87000 made the interpreter skip `caller_location` frames for its stacktraces and `cur_span`. However, those functions are used for much more than just panic reporting, and e.g. when Miri reports UB somewhere, it probably wants to point inside `caller_location` frames. (And if it did not, it would want to have its own logic to decide that, not be forced into it by the core interpreter engine.) This fixes some rare ICEs in Miri that say "we should never pop more than one frame at once".

So let's remove all `caller_location` logic from the core interpreter, and instead move it to CTFE error reporting. This does not change user-visible behavior. That's the first commit.

We might additionally want to change CTFE error reporting to treat panics differently from other errors: only prune `caller_location` frames for panics. The second commit does that. But honestly I am not sure if this is an improvement.

r? `@oli-obk`
This was referenced Jun 28, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 29, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#97423 (Simplify memory ordering intrinsics)
 - rust-lang#97542 (Use typed indices in argument mismatch algorithm)
 - rust-lang#97786 (Account for `-Z simulate-remapped-rust-src-base` when resolving remapped paths)
 - rust-lang#98277 (Fix trait object reborrow suggestion)
 - rust-lang#98525 (Add regression test for rust-lang#79224)
 - rust-lang#98549 (interpret: do not prune requires_caller_location stack frames quite so early)
 - rust-lang#98603 (Some borrowck diagnostic fixes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 021d21c into rust-lang:master Jun 29, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jun 29, 2022
@RalfJung RalfJung mentioned this pull request Jun 29, 2022
bors added a commit to rust-lang/miri that referenced this pull request Jun 29, 2022
Rustup

Fix our stacktrace after rust-lang/rust#98549. Now we can control whether `caller_location` should be pruned!
bors added a commit to rust-lang/miri that referenced this pull request Jun 29, 2022
Rustup

Fix our stacktrace after rust-lang/rust#98549. Now we can control whether `caller_location` should be pruned!
@RalfJung RalfJung deleted the interpret-stacktraces branch June 30, 2022 02:13
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