-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,7 +398,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
|
||
#[inline(always)] | ||
pub fn cur_span(&self) -> Span { | ||
self.stack().last().map_or(self.tcx.span, |f| f.current_span()) | ||
self.stack() | ||
.iter() | ||
.rev() | ||
.find(|frame| !frame.instance.def.requires_caller_location(*self.tcx)) | ||
.map_or(self.tcx.span, |f| f.current_span()) | ||
} | ||
|
||
#[inline(always)] | ||
|
@@ -927,7 +931,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
#[must_use] | ||
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> { | ||
let mut frames = Vec::new(); | ||
for frame in self.stack().iter().rev() { | ||
for frame in self | ||
.stack() | ||
.iter() | ||
.rev() | ||
.skip_while(|frame| frame.instance.def.requires_caller_location(*self.tcx)) | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh.. right. we should limit this to panics There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
let lint_root = frame.current_source_info().and_then(|source_info| { | ||
match &frame.body.source_scopes[source_info.scope].local_data { | ||
mir::ClearCrossCrate::Set(data) => Some(data.lint_root), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#![feature(const_panic)] | ||
#![allow(non_fmt_panics)] | ||
#![crate_type = "lib"] | ||
|
||
#[track_caller] | ||
const fn a() -> u32 { | ||
panic!("hey") | ||
} | ||
|
||
#[track_caller] | ||
const fn b() -> u32 { | ||
a() | ||
} | ||
|
||
const fn c() -> u32 { | ||
b() | ||
//~^ ERROR evaluation of constant value failed | ||
//~| NOTE the evaluated program panicked | ||
//~| NOTE inside | ||
} | ||
|
||
const X: u32 = c(); | ||
//~^ NOTE inside |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/const_panic_track_caller.rs:16:5 | ||
| | ||
LL | b() | ||
| ^^^ | ||
| | | ||
| the evaluated program panicked at 'hey', $DIR/const_panic_track_caller.rs:16:5 | ||
| inside `c` at $DIR/const_panic_track_caller.rs:16:5 | ||
... | ||
LL | const X: u32 = c(); | ||
| --- inside `X` at $DIR/const_panic_track_caller.rs:22:16 | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
There was a problem hiding this comment.
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.