@@ -22,7 +22,7 @@ use middle::typeck;
22
22
use middle;
23
23
24
24
use std:: cast;
25
- use std:: cell:: RefCell ;
25
+ use std:: cell:: { Cell , RefCell } ;
26
26
use std:: hashmap:: { HashMap , HashSet } ;
27
27
use std:: io:: mem:: MemWriter ;
28
28
use std:: io:: { Writer , Seek , Decorator } ;
@@ -69,25 +69,23 @@ pub struct EncodeParams<'a> {
69
69
}
70
70
71
71
struct Stats {
72
- inline_bytes : u64 ,
73
- attr_bytes : u64 ,
74
- dep_bytes : u64 ,
75
- lang_item_bytes : u64 ,
76
- native_lib_bytes : u64 ,
77
- impl_bytes : u64 ,
78
- misc_bytes : u64 ,
79
- item_bytes : u64 ,
80
- index_bytes : u64 ,
81
- zero_bytes : u64 ,
82
- total_bytes : u64 ,
83
-
84
- n_inlines : uint
72
+ inline_bytes : Cell < u64 > ,
73
+ attr_bytes : Cell < u64 > ,
74
+ dep_bytes : Cell < u64 > ,
75
+ lang_item_bytes : Cell < u64 > ,
76
+ native_lib_bytes : Cell < u64 > ,
77
+ impl_bytes : Cell < u64 > ,
78
+ misc_bytes : Cell < u64 > ,
79
+ item_bytes : Cell < u64 > ,
80
+ index_bytes : Cell < u64 > ,
81
+ zero_bytes : Cell < u64 > ,
82
+ total_bytes : Cell < u64 > ,
85
83
}
86
84
87
85
pub struct EncodeContext < ' a > {
88
86
diag : @mut span_handler ,
89
87
tcx : ty:: ctxt ,
90
- stats : @mut Stats ,
88
+ stats : @Stats ,
91
89
reexports2 : middle:: resolve:: ExportMap2 ,
92
90
item_symbols : & ' a RefCell < HashMap < ast:: NodeId , ~str > > ,
93
91
non_inlineable_statics : & ' a RefCell < HashSet < ast:: NodeId > > ,
@@ -1796,18 +1794,17 @@ pub static metadata_encoding_version : &'static [u8] =
1796
1794
pub fn encode_metadata ( parms : EncodeParams , crate : & Crate ) -> ~[ u8 ] {
1797
1795
let mut wr = MemWriter :: new ( ) ;
1798
1796
let stats = Stats {
1799
- inline_bytes : 0 ,
1800
- attr_bytes : 0 ,
1801
- dep_bytes : 0 ,
1802
- lang_item_bytes : 0 ,
1803
- native_lib_bytes : 0 ,
1804
- impl_bytes : 0 ,
1805
- misc_bytes : 0 ,
1806
- item_bytes : 0 ,
1807
- index_bytes : 0 ,
1808
- zero_bytes : 0 ,
1809
- total_bytes : 0 ,
1810
- n_inlines : 0
1797
+ inline_bytes : Cell :: new ( 0 ) ,
1798
+ attr_bytes : Cell :: new ( 0 ) ,
1799
+ dep_bytes : Cell :: new ( 0 ) ,
1800
+ lang_item_bytes : Cell :: new ( 0 ) ,
1801
+ native_lib_bytes : Cell :: new ( 0 ) ,
1802
+ impl_bytes : Cell :: new ( 0 ) ,
1803
+ misc_bytes : Cell :: new ( 0 ) ,
1804
+ item_bytes : Cell :: new ( 0 ) ,
1805
+ index_bytes : Cell :: new ( 0 ) ,
1806
+ zero_bytes : Cell :: new ( 0 ) ,
1807
+ total_bytes : Cell :: new ( 0 ) ,
1811
1808
} ;
1812
1809
let EncodeParams {
1813
1810
item_symbols,
@@ -1822,7 +1819,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
1822
1819
..
1823
1820
} = parms;
1824
1821
let type_abbrevs = @RefCell :: new ( HashMap :: new ( ) ) ;
1825
- let stats = @mut stats;
1822
+ let stats = @stats;
1826
1823
let ecx = EncodeContext {
1827
1824
diag : diag,
1828
1825
tcx : tcx,
@@ -1844,65 +1841,65 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
1844
1841
let mut i = ebml_w. writer . tell ( ) ;
1845
1842
let crate_attrs = synthesize_crate_attrs ( & ecx, crate ) ;
1846
1843
encode_attributes ( & mut ebml_w, crate_attrs) ;
1847
- ecx. stats . attr_bytes = ebml_w. writer . tell ( ) - i;
1844
+ ecx. stats . attr_bytes . set ( ebml_w. writer . tell ( ) - i) ;
1848
1845
1849
1846
i = ebml_w. writer . tell ( ) ;
1850
1847
encode_crate_deps ( & ecx, & mut ebml_w, ecx. cstore ) ;
1851
- ecx. stats . dep_bytes = ebml_w. writer . tell ( ) - i;
1848
+ ecx. stats . dep_bytes . set ( ebml_w. writer . tell ( ) - i) ;
1852
1849
1853
1850
// Encode the language items.
1854
1851
i = ebml_w. writer . tell ( ) ;
1855
1852
encode_lang_items ( & ecx, & mut ebml_w) ;
1856
- ecx. stats . lang_item_bytes = ebml_w. writer . tell ( ) - i;
1853
+ ecx. stats . lang_item_bytes . set ( ebml_w. writer . tell ( ) - i) ;
1857
1854
1858
1855
// Encode the native libraries used
1859
1856
i = ebml_w. writer . tell ( ) ;
1860
1857
encode_native_libraries ( & ecx, & mut ebml_w) ;
1861
- ecx. stats . native_lib_bytes = ebml_w. writer . tell ( ) - i;
1858
+ ecx. stats . native_lib_bytes . set ( ebml_w. writer . tell ( ) - i) ;
1862
1859
1863
1860
// Encode the def IDs of impls, for coherence checking.
1864
1861
i = ebml_w. writer . tell ( ) ;
1865
1862
encode_impls ( & ecx, crate , & mut ebml_w) ;
1866
- ecx. stats . impl_bytes = ebml_w. writer . tell ( ) - i;
1863
+ ecx. stats . impl_bytes . set ( ebml_w. writer . tell ( ) - i) ;
1867
1864
1868
1865
// Encode miscellaneous info.
1869
1866
i = ebml_w. writer . tell ( ) ;
1870
1867
encode_misc_info ( & ecx, crate , & mut ebml_w) ;
1871
- ecx. stats . misc_bytes = ebml_w. writer . tell ( ) - i;
1868
+ ecx. stats . misc_bytes . set ( ebml_w. writer . tell ( ) - i) ;
1872
1869
1873
1870
// Encode and index the items.
1874
1871
ebml_w. start_tag ( tag_items) ;
1875
1872
i = ebml_w. writer . tell ( ) ;
1876
1873
let items_index = encode_info_for_items ( & ecx, & mut ebml_w, crate ) ;
1877
- ecx. stats . item_bytes = ebml_w. writer . tell ( ) - i;
1874
+ ecx. stats . item_bytes . set ( ebml_w. writer . tell ( ) - i) ;
1878
1875
1879
1876
i = ebml_w. writer . tell ( ) ;
1880
1877
let items_buckets = create_index ( items_index) ;
1881
1878
encode_index ( & mut ebml_w, items_buckets, write_i64) ;
1882
- ecx. stats . index_bytes = ebml_w. writer . tell ( ) - i;
1879
+ ecx. stats . index_bytes . set ( ebml_w. writer . tell ( ) - i) ;
1883
1880
ebml_w. end_tag ( ) ;
1884
1881
1885
- ecx. stats . total_bytes = ebml_w. writer . tell ( ) ;
1882
+ ecx. stats . total_bytes . set ( ebml_w. writer . tell ( ) ) ;
1886
1883
1887
1884
if ( tcx. sess . meta_stats ( ) ) {
1888
1885
for e in ebml_w. writer . inner_ref ( ) . iter ( ) {
1889
1886
if * e == 0 {
1890
- ecx. stats . zero_bytes += 1 ;
1887
+ ecx. stats . zero_bytes . set ( ecx . stats . zero_bytes . get ( ) + 1 ) ;
1891
1888
}
1892
1889
}
1893
1890
1894
1891
println ( "metadata stats:" ) ;
1895
- println ! ( " inline bytes: {}" , ecx. stats. inline_bytes) ;
1896
- println ! ( " attribute bytes: {}" , ecx. stats. attr_bytes) ;
1897
- println ! ( " dep bytes: {}" , ecx. stats. dep_bytes) ;
1898
- println ! ( " lang item bytes: {}" , ecx. stats. lang_item_bytes) ;
1899
- println ! ( " native bytes: {}" , ecx. stats. native_lib_bytes) ;
1900
- println ! ( " impl bytes: {}" , ecx. stats. impl_bytes) ;
1901
- println ! ( " misc bytes: {}" , ecx. stats. misc_bytes) ;
1902
- println ! ( " item bytes: {}" , ecx. stats. item_bytes) ;
1903
- println ! ( " index bytes: {}" , ecx. stats. index_bytes) ;
1904
- println ! ( " zero bytes: {}" , ecx. stats. zero_bytes) ;
1905
- println ! ( " total bytes: {}" , ecx. stats. total_bytes) ;
1892
+ println ! ( " inline bytes: {}" , ecx. stats. inline_bytes. get ( ) ) ;
1893
+ println ! ( " attribute bytes: {}" , ecx. stats. attr_bytes. get ( ) ) ;
1894
+ println ! ( " dep bytes: {}" , ecx. stats. dep_bytes. get ( ) ) ;
1895
+ println ! ( " lang item bytes: {}" , ecx. stats. lang_item_bytes. get ( ) ) ;
1896
+ println ! ( " native bytes: {}" , ecx. stats. native_lib_bytes. get ( ) ) ;
1897
+ println ! ( " impl bytes: {}" , ecx. stats. impl_bytes. get ( ) ) ;
1898
+ println ! ( " misc bytes: {}" , ecx. stats. misc_bytes. get ( ) ) ;
1899
+ println ! ( " item bytes: {}" , ecx. stats. item_bytes. get ( ) ) ;
1900
+ println ! ( " index bytes: {}" , ecx. stats. index_bytes. get ( ) ) ;
1901
+ println ! ( " zero bytes: {}" , ecx. stats. zero_bytes. get ( ) ) ;
1902
+ println ! ( " total bytes: {}" , ecx. stats. total_bytes. get ( ) ) ;
1906
1903
}
1907
1904
1908
1905
// Pad this, since something (LLVM, presumably) is cutting off the
0 commit comments