@@ -647,30 +647,7 @@ impl<'tcx> tr for MethodOrigin<'tcx> {
647647}
648648
649649pub fn encode_closure_kind ( ebml_w : & mut Encoder , kind : ty:: ClosureKind ) {
650- use serialize:: Encoder ;
651-
652- ebml_w. emit_enum ( "ClosureKind" , |ebml_w| {
653- match kind {
654- ty:: FnClosureKind => {
655- ebml_w. emit_enum_variant ( "FnClosureKind" , 0 , 3 , |_| {
656- Ok ( ( ) )
657- } )
658- }
659- ty:: FnMutClosureKind => {
660- ebml_w. emit_enum_variant ( "FnMutClosureKind" , 1 , 3 , |_| {
661- Ok ( ( ) )
662- } )
663- }
664- ty:: FnOnceClosureKind => {
665- ebml_w. emit_enum_variant ( "FnOnceClosureKind" ,
666- 2 ,
667- 3 ,
668- |_| {
669- Ok ( ( ) )
670- } )
671- }
672- }
673- } ) . unwrap ( )
650+ kind. encode ( ebml_w) . unwrap ( ) ;
674651}
675652
676653pub trait vtable_decoder_helpers < ' tcx > {
@@ -1310,12 +1287,20 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
13101287 } )
13111288 }
13121289
1313- for closure in tcx. closures . borrow ( ) . get ( & ast_util:: local_def ( id) ) . iter ( ) {
1314- rbml_w. tag ( c:: tag_table_closures, |rbml_w| {
1290+ for & closure_type in tcx. closure_tys . borrow ( ) . get ( & ast_util:: local_def ( id) ) . iter ( ) {
1291+ rbml_w. tag ( c:: tag_table_closure_tys, |rbml_w| {
1292+ rbml_w. id ( id) ;
1293+ rbml_w. tag ( c:: tag_table_val, |rbml_w| {
1294+ rbml_w. emit_closure_type ( ecx, closure_type) ;
1295+ } )
1296+ } )
1297+ }
1298+
1299+ for & & closure_kind in tcx. closure_kinds . borrow ( ) . get ( & ast_util:: local_def ( id) ) . iter ( ) {
1300+ rbml_w. tag ( c:: tag_table_closure_kinds, |rbml_w| {
13151301 rbml_w. id ( id) ;
13161302 rbml_w. tag ( c:: tag_table_val, |rbml_w| {
1317- rbml_w. emit_closure_type ( ecx, & closure. closure_type ) ;
1318- encode_closure_kind ( rbml_w, closure. kind )
1303+ encode_closure_kind ( rbml_w, closure_kind)
13191304 } )
13201305 } )
13211306 }
@@ -1354,8 +1339,10 @@ trait rbml_decoder_decoder_helpers<'tcx> {
13541339 -> subst:: Substs < ' tcx > ;
13551340 fn read_auto_adjustment < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
13561341 -> ty:: AutoAdjustment < ' tcx > ;
1357- fn read_closure < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1358- -> ty:: Closure < ' tcx > ;
1342+ fn read_closure_kind < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1343+ -> ty:: ClosureKind ;
1344+ fn read_closure_ty < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1345+ -> ty:: ClosureTy < ' tcx > ;
13591346 fn read_auto_deref_ref < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
13601347 -> ty:: AutoDerefRef < ' tcx > ;
13611348 fn read_autoref < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
@@ -1782,35 +1769,23 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
17821769 } ) . unwrap ( )
17831770 }
17841771
1785- fn read_closure < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1786- -> ty:: Closure < ' tcx > {
1787- let closure_type = self . read_opaque ( |this, doc| {
1772+ fn read_closure_kind < ' b , ' c > ( & mut self , _dcx : & DecodeContext < ' b , ' c , ' tcx > )
1773+ -> ty:: ClosureKind
1774+ {
1775+ Decodable :: decode ( self ) . ok ( ) . unwrap ( )
1776+ }
1777+
1778+ fn read_closure_ty < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1779+ -> ty:: ClosureTy < ' tcx >
1780+ {
1781+ self . read_opaque ( |this, doc| {
17881782 Ok ( tydecode:: parse_ty_closure_data (
17891783 doc. data ,
17901784 dcx. cdata . cnum ,
17911785 doc. start ,
17921786 dcx. tcx ,
17931787 |s, a| this. convert_def_id ( dcx, s, a) ) )
1794- } ) . unwrap ( ) ;
1795- let variants = & [
1796- "FnClosureKind" ,
1797- "FnMutClosureKind" ,
1798- "FnOnceClosureKind"
1799- ] ;
1800- let kind = self . read_enum ( "ClosureKind" , |this| {
1801- this. read_enum_variant ( variants, |_, i| {
1802- Ok ( match i {
1803- 0 => ty:: FnClosureKind ,
1804- 1 => ty:: FnMutClosureKind ,
1805- 2 => ty:: FnOnceClosureKind ,
1806- _ => panic ! ( "bad enum variant for ty::ClosureKind" ) ,
1807- } )
1808- } )
1809- } ) . unwrap ( ) ;
1810- ty:: Closure {
1811- closure_type : closure_type,
1812- kind : kind,
1813- }
1788+ } ) . unwrap ( )
18141789 }
18151790
18161791 /// Converts a def-id that appears in a type. The correct
@@ -1937,11 +1912,17 @@ fn decode_side_tables(dcx: &DecodeContext,
19371912 let adj: ty:: AutoAdjustment = val_dsr. read_auto_adjustment ( dcx) ;
19381913 dcx. tcx . adjustments . borrow_mut ( ) . insert ( id, adj) ;
19391914 }
1940- c:: tag_table_closures => {
1941- let closure =
1942- val_dsr. read_closure ( dcx) ;
1943- dcx. tcx . closures . borrow_mut ( ) . insert ( ast_util:: local_def ( id) ,
1944- closure) ;
1915+ c:: tag_table_closure_tys => {
1916+ let closure_ty =
1917+ val_dsr. read_closure_ty ( dcx) ;
1918+ dcx. tcx . closure_tys . borrow_mut ( ) . insert ( ast_util:: local_def ( id) ,
1919+ closure_ty) ;
1920+ }
1921+ c:: tag_table_closure_kinds => {
1922+ let closure_kind =
1923+ val_dsr. read_closure_kind ( dcx) ;
1924+ dcx. tcx . closure_kinds . borrow_mut ( ) . insert ( ast_util:: local_def ( id) ,
1925+ closure_kind) ;
19451926 }
19461927 _ => {
19471928 dcx. tcx . sess . bug (
0 commit comments