Skip to content

Commit 1799d31

Browse files
committed
Auto merge of rust-lang#74876 - oli-obk:lumberjack_disable, r=RalfJung
Replace all uses of `log::log_enabled` with `Debug` printers cc @RalfJung this touches a bunch of logging in the miri engine. There are some visual changes, mainly that in several cases we stop prepending lines with the module path and just have a newline.
2 parents 6e50a22 + b81d164 commit 1799d31

File tree

11 files changed

+266
-200
lines changed

11 files changed

+266
-200
lines changed

src/librustc_interface/passes.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::interface::{Compiler, Result};
22
use crate::proc_macro_decls;
33
use crate::util;
44

5-
use log::{info, log_enabled, warn};
5+
use log::{info, warn};
66
use once_cell::sync::Lazy;
77
use rustc_ast::mut_visit::MutVisitor;
88
use rustc_ast::{self, ast, visit};
@@ -1015,21 +1015,15 @@ pub fn start_codegen<'tcx>(
10151015
tcx: TyCtxt<'tcx>,
10161016
outputs: &OutputFilenames,
10171017
) -> Box<dyn Any> {
1018-
if log_enabled!(::log::Level::Info) {
1019-
println!("Pre-codegen");
1020-
tcx.print_debug_stats();
1021-
}
1018+
info!("Pre-codegen\n{:?}", tcx.debug_stats());
10221019

10231020
let (metadata, need_metadata_module) = encode_and_write_metadata(tcx, outputs);
10241021

10251022
let codegen = tcx.sess.time("codegen_crate", move || {
10261023
codegen_backend.codegen_crate(tcx, metadata, need_metadata_module)
10271024
});
10281025

1029-
if log_enabled!(::log::Level::Info) {
1030-
println!("Post-codegen");
1031-
tcx.print_debug_stats();
1032-
}
1026+
info!("Post-codegen\n{:?}", tcx.debug_stats());
10331027

10341028
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
10351029
if let Err(e) = mir::transform::dump_mir::emit_mir(tcx, outputs) {

src/librustc_metadata/creader.rs

+32-22
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_span::symbol::{sym, Symbol};
2626
use rustc_span::{Span, DUMMY_SP};
2727
use rustc_target::spec::{PanicStrategy, TargetTriple};
2828

29-
use log::{debug, info, log_enabled};
29+
use log::{debug, info};
3030
use proc_macro::bridge::client::ProcMacro;
3131
use std::path::Path;
3232
use std::{cmp, env, fs};
@@ -82,24 +82,36 @@ impl std::ops::Deref for CrateMetadataRef<'_> {
8282
}
8383
}
8484

85-
fn dump_crates(cstore: &CStore) {
86-
info!("resolved crates:");
87-
cstore.iter_crate_data(|cnum, data| {
88-
info!(" name: {}", data.name());
89-
info!(" cnum: {}", cnum);
90-
info!(" hash: {}", data.hash());
91-
info!(" reqd: {:?}", data.dep_kind());
92-
let CrateSource { dylib, rlib, rmeta } = data.source();
93-
if let Some(dylib) = dylib {
94-
info!(" dylib: {}", dylib.0.display());
95-
}
96-
if let Some(rlib) = rlib {
97-
info!(" rlib: {}", rlib.0.display());
98-
}
99-
if let Some(rmeta) = rmeta {
100-
info!(" rmeta: {}", rmeta.0.display());
101-
}
102-
});
85+
struct CrateDump<'a>(&'a CStore);
86+
87+
impl<'a> std::fmt::Debug for CrateDump<'a> {
88+
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89+
writeln!(fmt, "resolved crates:")?;
90+
// `iter_crate_data` does not allow returning values. Thus we use a mutable variable here
91+
// that aggregates the value (and any errors that could happen).
92+
let mut res = Ok(());
93+
self.0.iter_crate_data(|cnum, data| {
94+
res = res.and(
95+
try {
96+
writeln!(fmt, " name: {}", data.name())?;
97+
writeln!(fmt, " cnum: {}", cnum)?;
98+
writeln!(fmt, " hash: {}", data.hash())?;
99+
writeln!(fmt, " reqd: {:?}", data.dep_kind())?;
100+
let CrateSource { dylib, rlib, rmeta } = data.source();
101+
if let Some(dylib) = dylib {
102+
writeln!(fmt, " dylib: {}", dylib.0.display())?;
103+
}
104+
if let Some(rlib) = rlib {
105+
writeln!(fmt, " rlib: {}", rlib.0.display())?;
106+
}
107+
if let Some(rmeta) = rmeta {
108+
writeln!(fmt, " rmeta: {}", rmeta.0.display())?;
109+
}
110+
},
111+
);
112+
});
113+
res
114+
}
103115
}
104116

105117
impl CStore {
@@ -864,9 +876,7 @@ impl<'a> CrateLoader<'a> {
864876
self.inject_allocator_crate(krate);
865877
self.inject_panic_runtime(krate);
866878

867-
if log_enabled!(log::Level::Info) {
868-
dump_crates(&self.cstore);
869-
}
879+
info!("{:?}", CrateDump(&self.cstore));
870880

871881
self.report_unused_deps(krate);
872882
}

src/librustc_metadata/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(proc_macro_internals)]
1010
#![feature(min_specialization)]
1111
#![feature(stmt_expr_attributes)]
12+
#![feature(try_blocks)]
1213
#![feature(never_type)]
1314
#![recursion_limit = "256"]
1415

src/librustc_middle/ty/context.rs

+52-37
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ pub mod tls {
18311831
}
18321832

18331833
macro_rules! sty_debug_print {
1834-
($ctxt: expr, $($variant: ident),*) => {{
1834+
($fmt: expr, $ctxt: expr, $($variant: ident),*) => {{
18351835
// Curious inner module to allow variant names to be used as
18361836
// variable names.
18371837
#[allow(non_snake_case)]
@@ -1848,7 +1848,7 @@ macro_rules! sty_debug_print {
18481848
all_infer: usize,
18491849
}
18501850

1851-
pub fn go(tcx: TyCtxt<'_>) {
1851+
pub fn go(fmt: &mut std::fmt::Formatter<'_>, tcx: TyCtxt<'_>) -> std::fmt::Result {
18521852
let mut total = DebugStat {
18531853
total: 0,
18541854
lt_infer: 0,
@@ -1878,18 +1878,18 @@ macro_rules! sty_debug_print {
18781878
if ct { total.ct_infer += 1; variant.ct_infer += 1 }
18791879
if lt && ty && ct { total.all_infer += 1; variant.all_infer += 1 }
18801880
}
1881-
println!("Ty interner total ty lt ct all");
1882-
$(println!(" {:18}: {uses:6} {usespc:4.1}%, \
1881+
writeln!(fmt, "Ty interner total ty lt ct all")?;
1882+
$(writeln!(fmt, " {:18}: {uses:6} {usespc:4.1}%, \
18831883
{ty:4.1}% {lt:5.1}% {ct:4.1}% {all:4.1}%",
18841884
stringify!($variant),
18851885
uses = $variant.total,
18861886
usespc = $variant.total as f64 * 100.0 / total.total as f64,
18871887
ty = $variant.ty_infer as f64 * 100.0 / total.total as f64,
18881888
lt = $variant.lt_infer as f64 * 100.0 / total.total as f64,
18891889
ct = $variant.ct_infer as f64 * 100.0 / total.total as f64,
1890-
all = $variant.all_infer as f64 * 100.0 / total.total as f64);
1890+
all = $variant.all_infer as f64 * 100.0 / total.total as f64)?;
18911891
)*
1892-
println!(" total {uses:6} \
1892+
writeln!(fmt, " total {uses:6} \
18931893
{ty:4.1}% {lt:5.1}% {ct:4.1}% {all:4.1}%",
18941894
uses = total.total,
18951895
ty = total.ty_infer as f64 * 100.0 / total.total as f64,
@@ -1899,41 +1899,56 @@ macro_rules! sty_debug_print {
18991899
}
19001900
}
19011901

1902-
inner::go($ctxt)
1902+
inner::go($fmt, $ctxt)
19031903
}}
19041904
}
19051905

19061906
impl<'tcx> TyCtxt<'tcx> {
1907-
pub fn print_debug_stats(self) {
1908-
sty_debug_print!(
1909-
self,
1910-
Adt,
1911-
Array,
1912-
Slice,
1913-
RawPtr,
1914-
Ref,
1915-
FnDef,
1916-
FnPtr,
1917-
Placeholder,
1918-
Generator,
1919-
GeneratorWitness,
1920-
Dynamic,
1921-
Closure,
1922-
Tuple,
1923-
Bound,
1924-
Param,
1925-
Infer,
1926-
Projection,
1927-
Opaque,
1928-
Foreign
1929-
);
1930-
1931-
println!("InternalSubsts interner: #{}", self.interners.substs.len());
1932-
println!("Region interner: #{}", self.interners.region.len());
1933-
println!("Stability interner: #{}", self.stability_interner.len());
1934-
println!("Const Stability interner: #{}", self.const_stability_interner.len());
1935-
println!("Allocation interner: #{}", self.allocation_interner.len());
1936-
println!("Layout interner: #{}", self.layout_interner.len());
1907+
pub fn debug_stats(self) -> impl std::fmt::Debug + 'tcx {
1908+
struct DebugStats<'tcx>(TyCtxt<'tcx>);
1909+
1910+
impl std::fmt::Debug for DebugStats<'tcx> {
1911+
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1912+
sty_debug_print!(
1913+
fmt,
1914+
self.0,
1915+
Adt,
1916+
Array,
1917+
Slice,
1918+
RawPtr,
1919+
Ref,
1920+
FnDef,
1921+
FnPtr,
1922+
Placeholder,
1923+
Generator,
1924+
GeneratorWitness,
1925+
Dynamic,
1926+
Closure,
1927+
Tuple,
1928+
Bound,
1929+
Param,
1930+
Infer,
1931+
Projection,
1932+
Opaque,
1933+
Foreign
1934+
)?;
1935+
1936+
writeln!(fmt, "InternalSubsts interner: #{}", self.0.interners.substs.len())?;
1937+
writeln!(fmt, "Region interner: #{}", self.0.interners.region.len())?;
1938+
writeln!(fmt, "Stability interner: #{}", self.0.stability_interner.len())?;
1939+
writeln!(
1940+
fmt,
1941+
"Const Stability interner: #{}",
1942+
self.0.const_stability_interner.len()
1943+
)?;
1944+
writeln!(fmt, "Allocation interner: #{}", self.0.allocation_interner.len())?;
1945+
writeln!(fmt, "Layout interner: #{}", self.0.layout_interner.len())?;
1946+
1947+
Ok(())
1948+
}
1949+
}
1950+
1951+
DebugStats(self)
19371952
}
19381953
}
19391954

src/librustc_mir/const_eval/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
5656
self.copy_op(place.into(), dest)?;
5757

5858
self.return_to_block(ret.map(|r| r.1))?;
59-
self.dump_place(*dest);
59+
trace!("{:?}", self.dump_place(*dest));
6060
Ok(true)
6161
}
6262

0 commit comments

Comments
 (0)