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

Make backtrace function names and spans match up #1283

Merged
merged 4 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
235938d1acdd93d6641a741c81f64e415b786751
b793f403bdfbcc0ff3e15ed8177a81d79ba4a29b
15 changes: 6 additions & 9 deletions src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,12 @@ fn report_msg<'tcx, 'mir>(
err.help(help);
}
// Add backtrace
let frames = ecx.generate_stacktrace(None);
// We iterate with indices because we need to look at the next frame (the caller).
for idx in 0..frames.len() {
let frame_info = &frames[idx];
let call_site_is_local = frames
.get(idx + 1)
.map_or(false, |caller_info| caller_info.instance.def_id().is_local());
if call_site_is_local {
err.span_note(frame_info.call_site, &frame_info.to_string());
let frames = ecx.generate_stacktrace();
for (idx, frame_info) in frames.iter().enumerate() {
let is_local = frame_info.instance.def_id().is_local();
// No span for non-local frames and the first frame (which is the error site).
if is_local && idx > 0 {
err.span_note(frame_info.span, &frame_info.to_string());
} else {
err.note(&frame_info.to_string());
}
Expand Down
15 changes: 4 additions & 11 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use rustc_middle::ty::{
List, TyCtxt,
};
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
use rustc_span::source_map::DUMMY_SP;

use rand::RngCore;

Expand Down Expand Up @@ -170,13 +169,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx

// Push frame.
let mir = &*this.load_mir(f.def, None)?;
let span = this
.stack()
.last()
.and_then(Frame::current_source_info)
.map(|si| si.span)
.unwrap_or(DUMMY_SP);
this.push_stack_frame(f, span, mir, dest, stack_pop)?;
this.push_stack_frame(f, mir, dest, stack_pop)?;

// Initialize arguments.
let mut callee_args = this.frame().body.args_iter();
Expand Down Expand Up @@ -331,19 +324,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fields: impl Iterator<Item = InterpResult<'tcx, MPlaceTy<'tcx, Tag>>>,
) -> InterpResult<'tcx> {
match place.layout.fields {
layout::FieldPlacement::Array { .. } => {
layout::FieldsShape::Array { .. } => {
// For the array layout, we know the iterator will yield sorted elements so
// we can avoid the allocation.
self.walk_aggregate(place, fields)
}
layout::FieldPlacement::Arbitrary { .. } => {
layout::FieldsShape::Arbitrary { .. } => {
// Gather the subplaces and sort them before visiting.
let mut places =
fields.collect::<InterpResult<'tcx, Vec<MPlaceTy<'tcx, Tag>>>>()?;
places.sort_by_key(|place| place.ptr.assert_ptr().offset);
self.walk_aggregate(place, places.into_iter().map(Ok))
}
layout::FieldPlacement::Union { .. } => {
layout::FieldsShape::Union { .. } => {
// Uh, what?
bug!("a union is not an aggregate we should ever visit")
}
Expand Down
6 changes: 2 additions & 4 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_middle::ty::{
Ty,
};
use rustc_ast::attr;
use rustc_span::{source_map::Span, symbol::{sym, Symbol}};
use rustc_span::symbol::{sym, Symbol};

use crate::*;

Expand Down Expand Up @@ -253,7 +253,6 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
#[inline(always)]
fn find_mir_or_eval_fn(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
_span: Span,
instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
Expand All @@ -276,13 +275,12 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
#[inline(always)]
fn call_intrinsic(
ecx: &mut rustc_mir::interpret::InterpCx<'mir, 'tcx, Self>,
span: Span,
instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {
ecx.call_intrinsic(span, instance, args, ret, unwind)
ecx.call_intrinsic(instance, args, ret, unwind)
}

#[inline(always)]
Expand Down
4 changes: 1 addition & 3 deletions src/shims/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ use rustc_middle::mir;
use rustc_middle::ty;
use rustc_middle::ty::layout::{Align, LayoutOf};
use rustc_apfloat::Float;
use rustc_span::source_map::Span;

use crate::*;

impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
fn call_intrinsic(
&mut self,
span: Span,
instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
if this.emulate_intrinsic(span, instance, args, ret)? {
if this.emulate_intrinsic(instance, args, ret)? {
return Ok(());
}
let substs = instance.substs;
Expand Down
4 changes: 2 additions & 2 deletions src/shims/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();

trace!("miri_start_panic: {:?}", this.frame().span);
trace!("miri_start_panic: {:?}", this.frame().instance);

// Get the raw pointer stored in arg[0] (the panic payload).
let payload = this.read_scalar(args[0])?.not_undef()?;
Expand Down Expand Up @@ -133,7 +133,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
if let (true, Some(catch_unwind)) = (unwinding, extra.catch_unwind.take()) {
// We've just popped a frame that was pushed by `try`,
// and we are unwinding, so we should catch that.
trace!("unwinding: found catch_panic frame during unwinding: {:?}", this.frame().span);
trace!("unwinding: found catch_panic frame during unwinding: {:?}", this.frame().instance);

// We set the return value of `try` to 1, since there was a panic.
this.write_scalar(Scalar::from_i32(1), catch_unwind.dest)?;
Expand Down
4 changes: 2 additions & 2 deletions tests/compile-fail/never_transmute_void.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
enum Void {}

fn f(v: Void) -> ! {
match v {} //~ ERROR entering unreachable code
match v {} //~ ERROR entering unreachable code
}

fn main() {
let v: Void = unsafe {
std::mem::transmute::<(), Void>(())
};
f(v); //~ inside call to `f`
f(v); //~ inside `main`
}