Skip to content

Commit 2e4f66a

Browse files
committed
Make dump_{alloc,allocs,local}() no-ops when tracing is disabled.
Because they traverse data structures and build up strings, which is wasted effort if those strings aren't printed. The patch also removes some now-unnecessary log_enabled! tests at call sites.
1 parent cc79420 commit 2e4f66a

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/librustc_mir/interpret/eval_context.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
749749
}
750750
}
751751

752-
if log_enabled!(::log::Level::Trace) {
753-
self.dump_local(dest);
754-
}
752+
self.dump_local(dest);
755753

756754
Ok(())
757755
}
@@ -1538,6 +1536,9 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
15381536

15391537
pub fn dump_local(&self, place: Place) {
15401538
// Debug output
1539+
if !log_enabled!(::log::Level::Trace) {
1540+
return;
1541+
}
15411542
match place {
15421543
Place::Local { frame, local } => {
15431544
let mut allocs = Vec::new();

src/librustc_mir/interpret/memory.rs

+6
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,17 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
334334

335335
/// For debugging, print an allocation and all allocations it points to, recursively.
336336
pub fn dump_alloc(&self, id: AllocId) {
337+
if !log_enabled!(::log::Level::Trace) {
338+
return;
339+
}
337340
self.dump_allocs(vec![id]);
338341
}
339342

340343
/// For debugging, print a list of allocations and all allocations they point to, recursively.
341344
pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
345+
if !log_enabled!(::log::Level::Trace) {
346+
return;
347+
}
342348
use std::fmt::Write;
343349
allocs.sort();
344350
allocs.dedup();

src/librustc_mir/interpret/place.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
218218
}
219219
};
220220

221-
if log_enabled!(::log::Level::Trace) {
222-
self.dump_local(place);
223-
}
221+
self.dump_local(place);
224222

225223
Ok(place)
226224
}

0 commit comments

Comments
 (0)