@@ -29,7 +29,7 @@ use middle::check_const::ConstQualif;
29
29
use middle:: privacy:: { AllPublic , LastMod } ;
30
30
use middle:: subst;
31
31
use middle:: subst:: VecPerParamSpace ;
32
- use middle:: ty:: { self , Ty } ;
32
+ use middle:: ty:: { self , Ty , MethodCall , MethodCallee , MethodOrigin } ;
33
33
34
34
use syntax:: { ast, ast_util, codemap, fold} ;
35
35
use syntax:: codemap:: Span ;
@@ -600,21 +600,21 @@ impl tr for ty::UpvarCapture {
600
600
601
601
trait read_method_callee_helper < ' tcx > {
602
602
fn read_method_callee < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
603
- -> ( u32 , ty :: MethodCallee < ' tcx > ) ;
603
+ -> ( u32 , MethodCallee < ' tcx > ) ;
604
604
}
605
605
606
606
fn encode_method_callee < ' a , ' tcx > ( ecx : & e:: EncodeContext < ' a , ' tcx > ,
607
607
rbml_w : & mut Encoder ,
608
608
autoderef : u32 ,
609
- method : & ty :: MethodCallee < ' tcx > ) {
609
+ method : & MethodCallee < ' tcx > ) {
610
610
use serialize:: Encoder ;
611
611
612
612
rbml_w. emit_struct ( "MethodCallee" , 4 , |rbml_w| {
613
613
rbml_w. emit_struct_field ( "autoderef" , 0 , |rbml_w| {
614
614
autoderef. encode ( rbml_w)
615
615
} ) ;
616
- rbml_w. emit_struct_field ( "def_id " , 1 , |rbml_w| {
617
- Ok ( rbml_w. emit_def_id ( method. def_id ) )
616
+ rbml_w. emit_struct_field ( "origin " , 1 , |rbml_w| {
617
+ Ok ( rbml_w. emit_method_origin ( ecx , & method. origin ) )
618
618
} ) ;
619
619
rbml_w. emit_struct_field ( "ty" , 2 , |rbml_w| {
620
620
Ok ( rbml_w. emit_ty ( ecx, method. ty ) )
@@ -627,20 +627,21 @@ fn encode_method_callee<'a, 'tcx>(ecx: &e::EncodeContext<'a, 'tcx>,
627
627
628
628
impl < ' a , ' tcx > read_method_callee_helper < ' tcx > for reader:: Decoder < ' a > {
629
629
fn read_method_callee < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
630
- -> ( u32 , ty :: MethodCallee < ' tcx > ) {
630
+ -> ( u32 , MethodCallee < ' tcx > ) {
631
631
632
632
self . read_struct ( "MethodCallee" , 4 , |this| {
633
- let autoderef = this. read_struct_field ( "autoderef" , 0 ,
634
- Decodable :: decode) . unwrap ( ) ;
635
- Ok ( ( autoderef, ty:: MethodCallee {
636
- def_id : this. read_struct_field ( "def_id" , 1 , |this| {
637
- Ok ( this. read_def_id ( dcx) )
633
+ let autoderef = this. read_struct_field ( "autoderef" , 0 , |this| {
634
+ Decodable :: decode ( this)
635
+ } ) . unwrap ( ) ;
636
+ Ok ( ( autoderef, MethodCallee {
637
+ origin : this. read_struct_field ( "origin" , 1 , |this| {
638
+ Ok ( this. read_method_origin ( dcx) )
638
639
} ) . unwrap ( ) ,
639
640
ty : this. read_struct_field ( "ty" , 2 , |this| {
640
641
Ok ( this. read_ty ( dcx) )
641
642
} ) . unwrap ( ) ,
642
643
substs : this. read_struct_field ( "substs" , 3 , |this| {
643
- Ok ( dcx . tcx . mk_substs ( this. read_substs ( dcx) ) )
644
+ Ok ( this. read_substs ( dcx) )
644
645
} ) . unwrap ( )
645
646
} ) )
646
647
} ) . unwrap ( )
@@ -706,6 +707,9 @@ impl<'a, 'tcx> get_ty_str_ctxt<'tcx> for e::EncodeContext<'a, 'tcx> {
706
707
trait rbml_writer_helpers < ' tcx > {
707
708
fn emit_closure_type < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
708
709
closure_type : & ty:: ClosureTy < ' tcx > ) ;
710
+ fn emit_method_origin < ' a > ( & mut self ,
711
+ ecx : & e:: EncodeContext < ' a , ' tcx > ,
712
+ method_origin : & ty:: MethodOrigin < ' tcx > ) ;
709
713
fn emit_ty < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > , ty : Ty < ' tcx > ) ;
710
714
fn emit_tys < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > , tys : & [ Ty < ' tcx > ] ) ;
711
715
fn emit_type_param_def < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
@@ -737,6 +741,73 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
737
741
} ) ;
738
742
}
739
743
744
+ fn emit_method_origin < ' b > ( & mut self ,
745
+ ecx : & e:: EncodeContext < ' b , ' tcx > ,
746
+ method_origin : & ty:: MethodOrigin < ' tcx > )
747
+ {
748
+ use serialize:: Encoder ;
749
+
750
+ self . emit_enum ( "MethodOrigin" , |this| {
751
+ match * method_origin {
752
+ ty:: MethodStatic ( def_id) => {
753
+ this. emit_enum_variant ( "MethodStatic" , 0 , 1 , |this| {
754
+ Ok ( this. emit_def_id ( def_id) )
755
+ } )
756
+ }
757
+
758
+ ty:: MethodStaticClosure ( def_id) => {
759
+ this. emit_enum_variant ( "MethodStaticClosure" , 1 , 1 , |this| {
760
+ Ok ( this. emit_def_id ( def_id) )
761
+ } )
762
+ }
763
+
764
+ ty:: MethodTypeParam ( ref p) => {
765
+ this. emit_enum_variant ( "MethodTypeParam" , 2 , 1 , |this| {
766
+ this. emit_struct ( "MethodParam" , 2 , |this| {
767
+ try!( this. emit_struct_field ( "trait_ref" , 0 , |this| {
768
+ Ok ( this. emit_trait_ref ( ecx, & p. trait_ref ) )
769
+ } ) ) ;
770
+ try!( this. emit_struct_field ( "method_num" , 0 , |this| {
771
+ this. emit_uint ( p. method_num )
772
+ } ) ) ;
773
+ try!( this. emit_struct_field ( "impl_def_id" , 0 , |this| {
774
+ this. emit_option ( |this| {
775
+ match p. impl_def_id {
776
+ None => this. emit_option_none ( ) ,
777
+ Some ( did) => this. emit_option_some ( |this| {
778
+ Ok ( this. emit_def_id ( did) )
779
+ } )
780
+ }
781
+ } )
782
+ } ) ) ;
783
+ Ok ( ( ) )
784
+ } )
785
+ } )
786
+ }
787
+
788
+ ty:: MethodTraitObject ( ref o) => {
789
+ this. emit_enum_variant ( "MethodTraitObject" , 3 , 1 , |this| {
790
+ this. emit_struct ( "MethodObject" , 2 , |this| {
791
+ try!( this. emit_struct_field ( "trait_ref" , 0 , |this| {
792
+ Ok ( this. emit_trait_ref ( ecx, & o. trait_ref ) )
793
+ } ) ) ;
794
+ try!( this. emit_struct_field ( "object_trait_id" , 0 , |this| {
795
+ Ok ( this. emit_def_id ( o. object_trait_id ) )
796
+ } ) ) ;
797
+ try!( this. emit_struct_field ( "method_num" , 0 , |this| {
798
+ this. emit_uint ( o. method_num )
799
+ } ) ) ;
800
+ try!( this. emit_struct_field ( "vtable_index" , 0 , |this| {
801
+ this. emit_uint ( o. vtable_index )
802
+ } ) ) ;
803
+ Ok ( ( ) )
804
+ } )
805
+ } )
806
+ }
807
+ }
808
+ } ) ;
809
+ }
810
+
740
811
fn emit_ty < ' b > ( & mut self , ecx : & e:: EncodeContext < ' b , ' tcx > , ty : Ty < ' tcx > ) {
741
812
self . emit_opaque ( |this| Ok ( e:: write_type ( ecx, this, ty) ) ) ;
742
813
}
@@ -1006,7 +1077,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
1006
1077
} )
1007
1078
}
1008
1079
1009
- let method_call = ty :: MethodCall :: expr ( id) ;
1080
+ let method_call = MethodCall :: expr ( id) ;
1010
1081
if let Some ( method) = tcx. tables . borrow ( ) . method_map . get ( & method_call) {
1011
1082
rbml_w. tag ( c:: tag_table_method_map, |rbml_w| {
1012
1083
rbml_w. id ( id) ;
@@ -1018,7 +1089,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
1018
1089
match * adjustment {
1019
1090
ty:: AdjustDerefRef ( ref adj) => {
1020
1091
for autoderef in 0 ..adj. autoderefs {
1021
- let method_call = ty :: MethodCall :: autoderef ( id, autoderef as u32 ) ;
1092
+ let method_call = MethodCall :: autoderef ( id, autoderef as u32 ) ;
1022
1093
if let Some ( method) = tcx. tables . borrow ( ) . method_map . get ( & method_call) {
1023
1094
rbml_w. tag ( c:: tag_table_method_map, |rbml_w| {
1024
1095
rbml_w. id ( id) ;
@@ -1079,6 +1150,8 @@ impl<'a> doc_decoder_helpers for rbml::Doc<'a> {
1079
1150
}
1080
1151
1081
1152
trait rbml_decoder_decoder_helpers < ' tcx > {
1153
+ fn read_method_origin < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1154
+ -> ty:: MethodOrigin < ' tcx > ;
1082
1155
fn read_ty < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > ) -> Ty < ' tcx > ;
1083
1156
fn read_tys < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > ) -> Vec < Ty < ' tcx > > ;
1084
1157
fn read_trait_ref < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
@@ -1162,6 +1235,88 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
1162
1235
} ) . unwrap ( )
1163
1236
}
1164
1237
1238
+ fn read_method_origin < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1239
+ -> ty:: MethodOrigin < ' tcx >
1240
+ {
1241
+ self . read_enum ( "MethodOrigin" , |this| {
1242
+ let variants = & [ "MethodStatic" , "MethodStaticClosure" ,
1243
+ "MethodTypeParam" , "MethodTraitObject" ] ;
1244
+ this. read_enum_variant ( variants, |this, i| {
1245
+ Ok ( match i {
1246
+ 0 => {
1247
+ let def_id = this. read_def_id ( dcx) ;
1248
+ ty:: MethodStatic ( def_id)
1249
+ }
1250
+
1251
+ 1 => {
1252
+ let def_id = this. read_def_id ( dcx) ;
1253
+ ty:: MethodStaticClosure ( def_id)
1254
+ }
1255
+
1256
+ 2 => {
1257
+ this. read_struct ( "MethodTypeParam" , 2 , |this| {
1258
+ Ok ( ty:: MethodTypeParam (
1259
+ ty:: MethodParam {
1260
+ trait_ref : {
1261
+ this. read_struct_field ( "trait_ref" , 0 , |this| {
1262
+ Ok ( this. read_trait_ref ( dcx) )
1263
+ } ) . unwrap ( )
1264
+ } ,
1265
+ method_num : {
1266
+ this. read_struct_field ( "method_num" , 1 , |this| {
1267
+ this. read_uint ( )
1268
+ } ) . unwrap ( )
1269
+ } ,
1270
+ impl_def_id : {
1271
+ this. read_struct_field ( "impl_def_id" , 2 , |this| {
1272
+ this. read_option ( |this, b| {
1273
+ if b {
1274
+ Ok ( Some ( this. read_def_id ( dcx) ) )
1275
+ } else {
1276
+ Ok ( None )
1277
+ }
1278
+ } )
1279
+ } ) . unwrap ( )
1280
+ }
1281
+ } ) )
1282
+ } ) . unwrap ( )
1283
+ }
1284
+
1285
+ 3 => {
1286
+ this. read_struct ( "MethodTraitObject" , 2 , |this| {
1287
+ Ok ( ty:: MethodTraitObject (
1288
+ ty:: MethodObject {
1289
+ trait_ref : {
1290
+ this. read_struct_field ( "trait_ref" , 0 , |this| {
1291
+ Ok ( this. read_trait_ref ( dcx) )
1292
+ } ) . unwrap ( )
1293
+ } ,
1294
+ object_trait_id : {
1295
+ this. read_struct_field ( "object_trait_id" , 1 , |this| {
1296
+ Ok ( this. read_def_id ( dcx) )
1297
+ } ) . unwrap ( )
1298
+ } ,
1299
+ method_num : {
1300
+ this. read_struct_field ( "method_num" , 2 , |this| {
1301
+ this. read_uint ( )
1302
+ } ) . unwrap ( )
1303
+ } ,
1304
+ vtable_index : {
1305
+ this. read_struct_field ( "vtable_index" , 3 , |this| {
1306
+ this. read_uint ( )
1307
+ } ) . unwrap ( )
1308
+ } ,
1309
+ } ) )
1310
+ } ) . unwrap ( )
1311
+ }
1312
+
1313
+ _ => panic ! ( ".." )
1314
+ } )
1315
+ } )
1316
+ } ) . unwrap ( )
1317
+ }
1318
+
1319
+
1165
1320
fn read_ty < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > ) -> Ty < ' tcx > {
1166
1321
// Note: regions types embed local node ids. In principle, we
1167
1322
// should translate these node ids into the new decode
@@ -1508,7 +1663,7 @@ fn decode_side_tables(dcx: &DecodeContext,
1508
1663
}
1509
1664
c:: tag_table_method_map => {
1510
1665
let ( autoderef, method) = val_dsr. read_method_callee ( dcx) ;
1511
- let method_call = ty :: MethodCall {
1666
+ let method_call = MethodCall {
1512
1667
expr_id : id,
1513
1668
autoderef : autoderef
1514
1669
} ;
0 commit comments