@@ -1831,7 +1831,7 @@ pub mod tls {
18311831}
18321832
18331833macro_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
19061906impl < ' 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
0 commit comments