-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Skip redundant frames in const recursion errors #136649
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
base: master
Are you sure you want to change the base?
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use std::mem; | ||
|
||
use rustc_data_structures::fx::FxHashSet; | ||
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, Diagnostic, IntoDiagArg}; | ||
use rustc_middle::mir::AssertKind; | ||
use rustc_middle::mir::interpret::{Provenance, ReportedErrorInfo}; | ||
|
@@ -9,7 +10,7 @@ use rustc_middle::ty::{ConstInt, TyCtxt}; | |
use rustc_span::{Span, Symbol}; | ||
|
||
use super::CompileTimeMachine; | ||
use crate::errors::{self, FrameNote, ReportErrorExt}; | ||
use crate::errors::{FrameNote, ReportErrorExt}; | ||
use crate::interpret::{ | ||
ErrorHandled, Frame, InterpErrorInfo, InterpErrorKind, MachineStopType, err_inval, | ||
err_machine_stop, | ||
|
@@ -68,7 +69,7 @@ impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind { | |
pub fn get_span_and_frames<'tcx>( | ||
tcx: TyCtxtAt<'tcx>, | ||
stack: &[Frame<'tcx, impl Provenance, impl Sized>], | ||
) -> (Span, Vec<errors::FrameNote>) { | ||
) -> (Span, Vec<FrameNote>) { | ||
let mut stacktrace = Frame::generate_stacktrace_from_stack(stack); | ||
// Filter out `requires_caller_location` frames. | ||
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*tcx)); | ||
|
@@ -79,8 +80,8 @@ pub fn get_span_and_frames<'tcx>( | |
// Add notes to the backtrace. Don't print a single-line backtrace though. | ||
if stacktrace.len() > 1 { | ||
// Helper closure to print duplicated lines. | ||
let mut add_frame = |mut frame: errors::FrameNote| { | ||
frames.push(errors::FrameNote { times: 0, ..frame.clone() }); | ||
let mut add_frame = |mut frame: FrameNote| { | ||
frames.push(FrameNote { times: 0, ..frame.clone() }); | ||
// Don't print [... additional calls ...] if the number of lines is small | ||
if frame.times < 3 { | ||
let times = frame.times; | ||
|
@@ -91,21 +92,19 @@ pub fn get_span_and_frames<'tcx>( | |
} | ||
}; | ||
|
||
let mut last_frame: Option<errors::FrameNote> = None; | ||
let mut last_frame: Option<FrameNote> = None; | ||
let mut seen = FxHashSet::default(); | ||
for frame_info in &stacktrace { | ||
let frame = frame_info.as_note(*tcx); | ||
match last_frame.as_mut() { | ||
Some(last_frame) | ||
if last_frame.span == frame.span | ||
&& last_frame.where_ == frame.where_ | ||
&& last_frame.instance == frame.instance => | ||
{ | ||
Some(last_frame) if !seen.insert(frame.clone()) => { | ||
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. Please add comments explaining what is done and why. I am not sure I agree with removing duplicates from a backtrace -- that seems like it could be quite confusing. I can't quite follow the logic for printing the "N frames skipped" here, is that always printed when seeing a duplicate? This new logic abuses the |
||
last_frame.times += 1; | ||
} | ||
Some(last_frame) => { | ||
add_frame(mem::replace(last_frame, frame)); | ||
} | ||
None => { | ||
seen.insert(frame.clone()); | ||
last_frame = Some(frame); | ||
} | ||
} | ||
|
@@ -184,7 +183,7 @@ pub(super) fn lint<'tcx, L>( | |
tcx: TyCtxtAt<'tcx>, | ||
machine: &CompileTimeMachine<'tcx>, | ||
lint: &'static rustc_session::lint::Lint, | ||
decorator: impl FnOnce(Vec<errors::FrameNote>) -> L, | ||
decorator: impl FnOnce(Vec<FrameNote>) -> L, | ||
) where | ||
L: for<'a> rustc_errors::LintDiagnostic<'a, ()>, | ||
{ | ||
|
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.
Is this logic still correct? It seems to be we could now have a situation where we see 2 frames that both have been seen already, so
last_frame.times
is 2, but these were actually 2 different frames and then this here will print the wrong thing.