Report a best guess span if no stack is available anymore

This commit is contained in:
Oliver Schneider
2018-02-06 15:35:43 +01:00
parent f363e08c9d
commit 1e653aa96b
2 changed files with 19 additions and 8 deletions
+4 -3
View File
@@ -24,7 +24,7 @@ pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>(
) -> EvalResult<'tcx, EvalContext<'a, 'mir, 'tcx, CompileTimeEvaluator>> {
debug!("mk_borrowck_eval_cx: {:?}", instance);
let param_env = tcx.param_env(instance.def_id());
let mut ecx = EvalContext::new(tcx, param_env, CompileTimeEvaluator, ());
let mut ecx = EvalContext::new(tcx, param_env, CompileTimeEvaluator, (), span);
// insert a stack frame so any queries have the correct substs
ecx.push_stack_frame(
instance,
@@ -42,7 +42,8 @@ pub fn mk_eval_cx<'a, 'tcx>(
param_env: ty::ParamEnv<'tcx>,
) -> EvalResult<'tcx, EvalContext<'a, 'tcx, 'tcx, CompileTimeEvaluator>> {
debug!("mk_eval_cx: {:?}, {:?}", instance, param_env);
let mut ecx = EvalContext::new(tcx, param_env, CompileTimeEvaluator, ());
let span = tcx.def_span(instance.def_id());
let mut ecx = EvalContext::new(tcx, param_env, CompileTimeEvaluator, (), span);
let mir = ecx.load_mir(instance.def)?;
// insert a stack frame so any queries have the correct substs
ecx.push_stack_frame(
@@ -93,10 +94,10 @@ fn eval_body_and_ecx<'a, 'mir, 'tcx>(
param_env: ty::ParamEnv<'tcx>,
) -> (EvalResult<'tcx, (Value, Pointer, Ty<'tcx>)>, EvalContext<'a, 'mir, 'tcx, CompileTimeEvaluator>) {
debug!("eval_body: {:?}, {:?}", cid, param_env);
let mut ecx = EvalContext::new(tcx, param_env, CompileTimeEvaluator, ());
// we start out with the best span we have
// and try improving it down the road when more information is available
let mut span = tcx.def_span(cid.instance.def_id());
let mut ecx = EvalContext::new(tcx, param_env, CompileTimeEvaluator, (), mir.map(|mir| mir.span).unwrap_or(span));
let res = (|| {
let mut mir = match mir {
Some(mir) => mir,
+15 -5
View File
@@ -45,6 +45,11 @@ pub struct EvalContext<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
/// This prevents infinite loops and huge computations from freezing up const eval.
/// Remove once halting problem is solved.
pub(crate) steps_remaining: usize,
/// The span that is used if no more stack frames are available
///
/// This happens after successful evaluation when the result is inspected
root_span: codemap::Span,
}
/// A stack frame.
@@ -186,6 +191,7 @@ pub fn new(
param_env: ty::ParamEnv<'tcx>,
machine: M,
memory_data: M::MemoryData,
root_span: codemap::Span,
) -> Self {
EvalContext {
machine,
@@ -195,6 +201,7 @@ pub fn new(
stack: Vec::new(),
stack_limit: tcx.sess.const_eval_stack_frame_limit.get(),
steps_remaining: tcx.sess.const_eval_step_limit.get(),
root_span,
}
}
@@ -1594,12 +1601,15 @@ pub fn generate_stacktrace(&self, explicit_span: Option<Span>) -> (Vec<FrameInfo
};
frames.push(FrameInfo { span, location });
}
let frame = self.frame();
let bb = &frame.mir.basic_blocks()[frame.block];
let span = if let Some(stmt) = bb.statements.get(frame.stmt) {
stmt.source_info.span
let span = if let Some(frame) = self.stack().last() {
let bb = &frame.mir.basic_blocks()[frame.block];
if let Some(stmt) = bb.statements.get(frame.stmt) {
stmt.source_info.span
} else {
bb.terminator().source_info.span
}
} else {
bb.terminator().source_info.span
self.root_span
};
trace!("generate stacktrace: {:#?}, {:?}", frames, explicit_span);
(frames, span)