@@ -20,8 +20,6 @@ use error::{EvalError, EvalResult};
20
20
use memory:: { Memory , Pointer } ;
21
21
use primval:: { self , PrimVal } ;
22
22
23
- const TRACE_EXECUTION : bool = true ;
24
-
25
23
struct GlobalEvalContext < ' a , ' tcx : ' a > {
26
24
/// The results of the type checker, from rustc.
27
25
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -168,32 +166,24 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
168
166
r
169
167
}
170
168
171
- fn log < F > ( & self , extra_indent : usize , f : F ) where F : FnOnce ( ) {
172
- let indent = self . stack . len ( ) + extra_indent;
173
- if !TRACE_EXECUTION { return ; }
174
- for _ in 0 ..indent { print ! ( " " ) ; }
175
- f ( ) ;
176
- println ! ( "" ) ;
177
- }
178
-
179
169
fn run ( & mut self ) -> EvalResult < ( ) > {
180
170
' outer: while !self . stack . is_empty ( ) {
181
171
let mut current_block = self . frame ( ) . next_block ;
182
172
183
173
loop {
184
- self . log ( 0 , || print ! ( "// {:?}" , current_block) ) ;
174
+ trace ! ( "// {:?}" , current_block) ;
185
175
let current_mir = self . mir ( ) . clone ( ) ; // Cloning a reference.
186
176
let block_data = current_mir. basic_block_data ( current_block) ;
187
177
188
178
for stmt in & block_data. statements {
189
- self . log ( 0 , || print ! ( "{:?}" , stmt) ) ;
179
+ trace ! ( "{:?}" , stmt) ;
190
180
let mir:: StatementKind :: Assign ( ref lvalue, ref rvalue) = stmt. kind ;
191
181
let result = self . eval_assignment ( lvalue, rvalue) ;
192
182
self . maybe_report ( stmt. span , result) ?;
193
183
}
194
184
195
185
let terminator = block_data. terminator ( ) ;
196
- self . log ( 0 , || print ! ( "{:?}" , terminator. kind) ) ;
186
+ trace ! ( "{:?}" , terminator. kind) ;
197
187
198
188
let result = self . eval_terminator ( terminator) ;
199
189
match self . maybe_report ( terminator. span , result) ? {
@@ -245,6 +235,8 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
245
235
let num_args = mir. arg_decls . len ( ) ;
246
236
let num_vars = mir. var_decls . len ( ) ;
247
237
238
+ :: log_settings:: settings ( ) . indentation += 1 ;
239
+
248
240
self . stack . push ( Frame {
249
241
mir : mir. clone ( ) ,
250
242
next_block : mir:: START_BLOCK ,
@@ -256,6 +248,7 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
256
248
}
257
249
258
250
fn pop_stack_frame ( & mut self ) {
251
+ :: log_settings:: settings ( ) . indentation -= 1 ;
259
252
let _frame = self . stack . pop ( ) . expect ( "tried to pop a stack frame, but there were none" ) ;
260
253
// TODO(solson): Deallocate local variables.
261
254
self . substs_stack . pop ( ) ;
@@ -419,10 +412,10 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
419
412
420
413
fn drop ( & mut self , ptr : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ( ) > {
421
414
if !self . type_needs_drop ( ty) {
422
- self . log ( 1 , || print ! ( "no need to drop {:?}" , ty) ) ;
415
+ debug ! ( "no need to drop {:?}" , ty) ;
423
416
return Ok ( ( ) ) ;
424
417
}
425
- self . log ( 1 , || print ! ( "need to drop {:?}" , ty) ) ;
418
+ trace ! ( "- need to drop {:?}" , ty) ;
426
419
427
420
// TODO(solson): Call user-defined Drop::drop impls.
428
421
@@ -431,7 +424,7 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
431
424
match self . memory . read_ptr ( ptr) {
432
425
Ok ( contents_ptr) => {
433
426
self . drop ( contents_ptr, contents_ty) ?;
434
- self . log ( 1 , || print ! ( "deallocating box" ) ) ;
427
+ trace ! ( "- deallocating box" ) ;
435
428
self . memory . deallocate ( contents_ptr) ?;
436
429
}
437
430
Err ( EvalError :: ReadBytesAsPointer ) => {
@@ -1421,32 +1414,29 @@ pub fn interpret_start_points<'a, 'tcx>(
1421
1414
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1422
1415
mir_map : & MirMap < ' tcx > ,
1423
1416
) {
1417
+ let initial_indentation = :: log_settings:: settings ( ) . indentation ;
1424
1418
for ( & id, mir) in & mir_map. map {
1425
1419
for attr in tcx. map . attrs ( id) {
1426
1420
use syntax:: attr:: AttrMetaMethods ;
1427
1421
if attr. check_name ( "miri_run" ) {
1428
1422
let item = tcx. map . expect_item ( id) ;
1429
1423
1430
- if TRACE_EXECUTION {
1431
- println ! ( "Interpreting: {}" , item . name ) ;
1432
- }
1424
+ :: log_settings :: settings ( ) . indentation = initial_indentation ;
1425
+
1426
+ debug ! ( "Interpreting: {}" , item . name ) ;
1433
1427
1434
1428
let mut gecx = GlobalEvalContext :: new ( tcx, mir_map) ;
1435
1429
let mut fecx = FnEvalContext :: new ( & mut gecx) ;
1436
1430
match fecx. call_nested ( mir) {
1437
- Ok ( Some ( return_ptr) ) => if TRACE_EXECUTION {
1431
+ Ok ( Some ( return_ptr) ) => if log_enabled ! ( :: log :: LogLevel :: Debug ) {
1438
1432
fecx. memory . dump ( return_ptr. alloc_id ) ;
1439
1433
} ,
1440
- Ok ( None ) => println ! ( "( diverging function returned) " ) ,
1434
+ Ok ( None ) => warn ! ( "diverging function returned" ) ,
1441
1435
Err ( _e) => {
1442
1436
// TODO(solson): Detect whether the error was already reported or not.
1443
1437
// tcx.sess.err(&e.to_string());
1444
1438
}
1445
1439
}
1446
-
1447
- if TRACE_EXECUTION {
1448
- println ! ( "" ) ;
1449
- }
1450
1440
}
1451
1441
}
1452
1442
}
0 commit comments