expose span to M::assert_panic, and provide helper to turn that into CallerLocation

This commit is contained in:
Ralf Jung 2019-11-29 10:13:40 +01:00
parent b1aa3cac5b
commit a8eea623f5
6 changed files with 20 additions and 10 deletions

View File

@ -397,6 +397,7 @@ fn call_intrinsic(
fn assert_panic(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
_span: Span,
msg: &AssertMessage<'tcx>,
_unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {

View File

@ -110,13 +110,7 @@ pub fn emulate_intrinsic(
match intrinsic_name {
"caller_location" => {
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
let location = self.alloc_caller_location(
Symbol::intern(&caller.file.name.to_string()),
caller.line as u32,
caller.col_display as u32 + 1,
)?;
let location = self.alloc_caller_location_for_span(span)?;
self.write_scalar(location.ptr, dest)?;
}

View File

@ -2,12 +2,12 @@
use rustc::mir::interpret::{Pointer, PointerArithmetic, Scalar};
use rustc::ty::subst::Subst;
use rustc_target::abi::{LayoutOf, Size};
use syntax_pos::Symbol;
use syntax_pos::{Symbol, Span};
use crate::interpret::{MemoryKind, MPlaceTy, intrinsics::{InterpCx, InterpResult, Machine}};
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
pub fn alloc_caller_location(
crate fn alloc_caller_location(
&mut self,
filename: Symbol,
line: u32,
@ -47,4 +47,17 @@ pub fn alloc_caller_location(
Ok(location)
}
pub fn alloc_caller_location_for_span(
&mut self,
span: Span,
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
self.alloc_caller_location(
Symbol::intern(&caller.file.name.to_string()),
caller.line as u32,
caller.col_display as u32 + 1,
)
}
}

View File

@ -178,6 +178,7 @@ fn call_intrinsic(
/// Called to evaluate `Assert` MIR terminators that trigger a panic.
fn assert_panic(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
span: Span,
msg: &AssertMessage<'tcx>,
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx>;

View File

@ -122,7 +122,7 @@ pub(super) fn eval_terminator(
if expected == cond_val {
self.go_to_block(target);
} else {
M::assert_panic(self, msg, cleanup)?;
M::assert_panic(self, terminator.source_info.span, msg, cleanup)?;
}
}

View File

@ -158,6 +158,7 @@ fn call_intrinsic(
fn assert_panic(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_span: Span,
_msg: &rustc::mir::interpret::AssertMessage<'tcx>,
_unwind: Option<rustc::mir::BasicBlock>,
) -> InterpResult<'tcx> {