@@ -1831,7 +1831,7 @@ pub mod tls {
1831
1831
}
1832
1832
1833
1833
macro_rules! sty_debug_print {
1834
- ( $ctxt: expr, $( $variant: ident) ,* ) => { {
1834
+ ( $fmt : expr , $ ctxt: expr, $( $variant: ident) ,* ) => { {
1835
1835
// Curious inner module to allow variant names to be used as
1836
1836
// variable names.
1837
1837
#[ allow( non_snake_case) ]
@@ -1848,7 +1848,7 @@ macro_rules! sty_debug_print {
1848
1848
all_infer: usize ,
1849
1849
}
1850
1850
1851
- pub fn go( tcx: TyCtxt <' _>) {
1851
+ pub fn go( fmt : & mut std :: fmt :: Formatter < ' _> , tcx: TyCtxt <' _>) -> std :: fmt :: Result {
1852
1852
let mut total = DebugStat {
1853
1853
total: 0 ,
1854
1854
lt_infer: 0 ,
@@ -1878,18 +1878,18 @@ macro_rules! sty_debug_print {
1878
1878
if ct { total. ct_infer += 1 ; variant. ct_infer += 1 }
1879
1879
if lt && ty && ct { total. all_infer += 1 ; variant. all_infer += 1 }
1880
1880
}
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}%, \
1883
1883
{ty:4.1}% {lt:5.1}% {ct:4.1}% {all:4.1}%",
1884
1884
stringify!( $variant) ,
1885
1885
uses = $variant. total,
1886
1886
usespc = $variant. total as f64 * 100.0 / total. total as f64 ,
1887
1887
ty = $variant. ty_infer as f64 * 100.0 / total. total as f64 ,
1888
1888
lt = $variant. lt_infer as f64 * 100.0 / total. total as f64 ,
1889
1889
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 ) ? ;
1891
1891
) *
1892
- println! ( " total {uses:6} \
1892
+ writeln! ( fmt , " total {uses:6} \
1893
1893
{ty:4.1}% {lt:5.1}% {ct:4.1}% {all:4.1}%",
1894
1894
uses = total. total,
1895
1895
ty = total. ty_infer as f64 * 100.0 / total. total as f64 ,
@@ -1899,41 +1899,56 @@ macro_rules! sty_debug_print {
1899
1899
}
1900
1900
}
1901
1901
1902
- inner:: go( $ctxt)
1902
+ inner:: go( $fmt , $ ctxt)
1903
1903
} }
1904
1904
}
1905
1905
1906
1906
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 )
1937
1952
}
1938
1953
}
1939
1954
0 commit comments