From 5130aa55a2d5e846b491a58a19aad8e00554d61f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 30 Mar 2020 20:15:02 +0200 Subject: [PATCH 1/4] adjust stacktrace printing to rustc changes --- src/diagnostics.rs | 13 +++++-------- tests/compile-fail/never_transmute_void.rs | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/diagnostics.rs b/src/diagnostics.rs index a528960cb2..8595551b6c 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -130,14 +130,11 @@ fn report_msg<'tcx, 'mir>( } // 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()); + 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()); } diff --git a/tests/compile-fail/never_transmute_void.rs b/tests/compile-fail/never_transmute_void.rs index 2a822ab1b5..5e9e2ac204 100644 --- a/tests/compile-fail/never_transmute_void.rs +++ b/tests/compile-fail/never_transmute_void.rs @@ -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` } From f599687f3fdb062a8ff2fe139cbe47249c5f29a1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 30 Mar 2020 22:54:49 +0200 Subject: [PATCH 2/4] adjust for span not being passed around any more --- src/diagnostics.rs | 2 +- src/helpers.rs | 9 +-------- src/machine.rs | 6 ++---- src/shims/intrinsics.rs | 4 +--- src/shims/panic.rs | 4 ++-- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 8595551b6c..9ff4340211 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -129,7 +129,7 @@ fn report_msg<'tcx, 'mir>( err.help(help); } // Add backtrace - let frames = ecx.generate_stacktrace(None); + 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). diff --git a/src/helpers.rs b/src/helpers.rs index 568e9c925d..827bf1f9dd 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -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; @@ -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(); diff --git a/src/machine.rs b/src/machine.rs index 4b7f3a7656..61c9f71407 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -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::*; @@ -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)>, @@ -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, ) -> InterpResult<'tcx> { - ecx.call_intrinsic(span, instance, args, ret, unwind) + ecx.call_intrinsic(instance, args, ret, unwind) } #[inline(always)] diff --git a/src/shims/intrinsics.rs b/src/shims/intrinsics.rs index e0eb0df87c..b7900bfaa5 100644 --- a/src/shims/intrinsics.rs +++ b/src/shims/intrinsics.rs @@ -5,7 +5,6 @@ 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::*; @@ -13,14 +12,13 @@ impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tc 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, ) -> 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; diff --git a/src/shims/panic.rs b/src/shims/panic.rs index 77741b7cca..3474945980 100644 --- a/src/shims/panic.rs +++ b/src/shims/panic.rs @@ -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()?; @@ -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)?; From 165dfd78a94bb5f30e655b51cde633649107ad42 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 2 Apr 2020 09:14:23 +0200 Subject: [PATCH 3/4] rustup --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 9a662aa0c2..6ed19772ca 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -235938d1acdd93d6641a741c81f64e415b786751 +b793f403bdfbcc0ff3e15ed8177a81d79ba4a29b From 5ce2466892126a3ea92138df67f09243a22dcb96 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 2 Apr 2020 09:19:56 +0200 Subject: [PATCH 4/4] fix for FieldPlacement rename --- src/helpers.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 827bf1f9dd..7b1ac1aacf 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -324,19 +324,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx fields: impl Iterator>>, ) -> 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::>>>()?; 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") }