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

Use #[track_caller] in const panic diagnostics. #87000

Merged
merged 1 commit into from
Jul 9, 2021

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Jul 9, 2021

This change stops const panic diagnostics from reporting inside #[track_caller] functions by skipping over them.

It was already used for the message. This also uses it for the spans
used for the error and backtrace.
@m-ou-se m-ou-se added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-const-eval Area: constant evaluation (mir interpretation) labels Jul 9, 2021
@rust-highfive
Copy link
Collaborator

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rust-highfive
Copy link
Collaborator

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

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

oli-obk commented Jul 9, 2021

r? @oli-obk

@rust-highfive rust-highfive assigned oli-obk and unassigned jackh726 Jul 9, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Jul 9, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Jul 9, 2021

📌 Commit 0a4b53f 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 Jul 9, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 9, 2021
Rollup of 5 pull requests

Successful merges:

 - rust-lang#86855 (Fix comments about unique borrows)
 - rust-lang#86881 (Inline implementation of lookup_line)
 - rust-lang#86937 (Change linked tracking issue for more_qualified_paths)
 - rust-lang#86994 (Update the comment on `lower_expr_try`)
 - rust-lang#87000 (Use #[track_caller] in const panic diagnostics.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2152c14 into rust-lang:master Jul 9, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 9, 2021
@m-ou-se m-ou-se deleted the const-panic-track-caller branch July 9, 2021 20:37
.iter()
.rev()
.skip_while(|frame| frame.instance.def.requires_caller_location(*self.tcx))
{
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK this is also used for Miri error messages... do we really want those backtraces to skip frames? That sounds rather confusing. When we get a panic at runtime, with RUST_BACKTRACE we also show the full trace, not just the non-caller-location frames, right?

Copy link
Member

@RalfJung RalfJung Jul 10, 2021

Choose a reason for hiding this comment

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

Even during CTFE, while this makes sense for panics, note that this logic is used for all CTFE errors. I am not sure if that's always what we want.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh.. right. we should limit this to panics

Copy link
Member

Choose a reason for hiding this comment

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

Turns out this is also the source of some Miri panics in our diagnostics code which didn't expect pruned backtraces.

If we want this kind of pruning, we should not to it in the lowest-level generate_stacktrace function.

.iter()
.rev()
.find(|frame| !frame.instance.def.requires_caller_location(*self.tcx))
.map_or(self.tcx.span, |f| f.current_span())
Copy link
Member

Choose a reason for hiding this comment

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

This function at least used to be hot, we should have done a perf run... oh well.

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`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 29, 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``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-diagnostics Area: Messages for errors, warnings, and lints 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