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