Skip to content

Commit e860ab2

Browse files
committed
Tweak logging
- The logging in step.rs becomes debug! to make it stand out a bit more - Dump value of operands (in `eval_operands`) - Try to log a bit less verbose
1 parent 0807ad1 commit e860ab2

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed

src/librustc_mir/interpret/operand.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,21 +395,23 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
395395
}
396396

397397
/// Evaluate the operand, returning a place where you can then find the data.
398-
pub fn eval_operand(&mut self, op: &mir::Operand<'tcx>) -> EvalResult<'tcx, OpTy<'tcx>> {
398+
pub fn eval_operand(&mut self, mir_op: &mir::Operand<'tcx>) -> EvalResult<'tcx, OpTy<'tcx>> {
399399
use rustc::mir::Operand::*;
400-
match *op {
400+
let op = match *mir_op {
401401
// FIXME: do some more logic on `move` to invalidate the old location
402402
Copy(ref place) |
403403
Move(ref place) =>
404-
self.eval_place_to_op(place),
404+
self.eval_place_to_op(place)?,
405405

406406
Constant(ref constant) => {
407-
let ty = self.monomorphize(op.ty(self.mir(), *self.tcx), self.substs());
407+
let ty = self.monomorphize(mir_op.ty(self.mir(), *self.tcx), self.substs());
408408
let layout = self.layout_of(ty)?;
409409
let op = self.const_value_to_op(constant.literal.val)?;
410-
Ok(OpTy { op, layout })
410+
OpTy { op, layout }
411411
}
412-
}
412+
};
413+
trace!("{:?}: {:?}", mir_op, *op);
414+
Ok(op)
413415
}
414416

415417
/// Evaluate a bunch of operands at once

src/librustc_mir/interpret/place.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
516516
src_val: Value,
517517
dest : PlaceTy<'tcx>,
518518
) -> EvalResult<'tcx> {
519+
trace!("write_value: {:?} <- {:?}", *dest, src_val);
519520
// See if we can avoid an allocation. This is the counterpart to `try_read_value`,
520521
// but not factored as a separate function.
521522
match dest.place {
@@ -543,7 +544,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
543544
value: Value,
544545
dest: MPlaceTy<'tcx>,
545546
) -> EvalResult<'tcx> {
546-
trace!("write_value_to_ptr: {:#?}, {:#?}", value, dest.layout);
547547
assert_eq!(dest.extra, PlaceExtra::None);
548548
// Note that it is really important that the type here is the right one, and matches the type things are read at.
549549
// In case `src_val` is a `ScalarPair`, we don't do any magic here to handle padding properly, which is only
@@ -584,8 +584,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
584584
src: OpTy<'tcx>,
585585
dest: PlaceTy<'tcx>,
586586
) -> EvalResult<'tcx> {
587-
trace!("Copying {:?} to {:?}", src, dest);
588-
assert_eq!(src.layout.size, dest.layout.size, "Size mismatch when copying!");
587+
assert_eq!(src.layout.size, dest.layout.size,
588+
"Size mismatch when copying!\nsrc: {:#?}\ndest: {:#?}", src, dest);
589589

590590
// Let us see if the layout is simple so we take a shortcut, avoid force_allocation.
591591
let (src_ptr, src_align) = match self.try_read_value(src)? {
@@ -595,6 +595,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
595595
Err(mplace) => mplace.to_scalar_ptr_align(),
596596
};
597597
// Slow path, this does not fit into an immediate. Just memcpy.
598+
trace!("copy_op: {:?} <- {:?}", *dest, *src);
598599
let (dest_ptr, dest_align) = self.force_allocation(dest)?.to_scalar_ptr_align();
599600
self.memory.copy(
600601
src_ptr, src_align,

src/librustc_mir/interpret/step.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
6767
}
6868

6969
fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> EvalResult<'tcx> {
70-
trace!("{:?}", stmt);
70+
debug!("{:?}", stmt);
7171

7272
use rustc::mir::StatementKind::*;
7373

@@ -281,12 +281,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
281281
}
282282

283283
fn terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> EvalResult<'tcx> {
284-
trace!("{:?}", terminator.kind);
284+
debug!("{:?}", terminator.kind);
285285
self.tcx.span = terminator.source_info.span;
286286
self.memory.tcx.span = terminator.source_info.span;
287287
self.eval_terminator(terminator)?;
288288
if !self.stack.is_empty() {
289-
trace!("// {:?}", self.frame().block);
289+
debug!("// {:?}", self.frame().block);
290290
}
291291
Ok(())
292292
}

src/librustc_mir/interpret/terminator/drop.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
1313
span: Span,
1414
target: BasicBlock,
1515
) -> EvalResult<'tcx> {
16-
trace!("drop_place: {:#?}", place);
1716
// We take the address of the object. This may well be unaligned, which is fine for us here.
1817
// However, unaligned accesses will probably make the actual drop implementation fail -- a problem shared
1918
// by rustc.
@@ -29,7 +28,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
2928
span: Span,
3029
target: BasicBlock,
3130
) -> EvalResult<'tcx> {
32-
trace!("drop: {:#?}, {:?}, {:?}", arg, ty.sty, instance.def);
31+
trace!("drop: {:?},\n {:?}, {:?}", arg, ty.sty, instance.def);
3332

3433
let instance = match ty.sty {
3534
ty::TyDynamic(..) => {

src/librustc_mir/interpret/terminator/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
3838
} => {
3939
let discr_val = self.eval_operand(discr)?;
4040
let discr = self.read_value(discr_val)?;
41-
trace!("SwitchInt({:#?})", *discr);
41+
trace!("SwitchInt({:?})", *discr);
4242

4343
// Branch to the `otherwise` case by default, if no match is found.
4444
let mut target_block = targets[targets.len() - 1];
@@ -286,10 +286,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
286286
// and need to pack arguments
287287
Abi::Rust => {
288288
trace!(
289-
"arg_locals: {:#?}",
290-
self.frame().mir.args_iter().collect::<Vec<_>>()
289+
"args: {:#?}",
290+
self.frame().mir.args_iter().zip(args.iter())
291+
.map(|(local, arg)| (local, **arg, arg.layout.ty)).collect::<Vec<_>>()
291292
);
292-
trace!("args: {:#?}", args);
293293
let local = arg_locals.nth(1).unwrap();
294294
for (i, &op) in args.into_iter().enumerate() {
295295
let dest = self.eval_place(&mir::Place::Local(local).field(
@@ -319,10 +319,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
319319
let mut arg_locals = self.frame().mir.args_iter();
320320
trace!("ABI: {:?}", sig.abi);
321321
trace!(
322-
"arg_locals: {:#?}",
323-
self.frame().mir.args_iter().collect::<Vec<_>>()
322+
"args: {:#?}",
323+
self.frame().mir.args_iter().zip(args.iter())
324+
.map(|(local, arg)| (local, **arg, arg.layout.ty)).collect::<Vec<_>>()
324325
);
325-
trace!("args: {:#?}", args);
326326
match sig.abi {
327327
Abi::RustCall => {
328328
assert_eq!(args.len(), 2);

0 commit comments

Comments
 (0)