@@ -35,7 +35,6 @@ use middle::def_id::{DefId, LOCAL_CRATE};
35
35
use middle:: privacy:: { AllPublic , LastMod } ;
36
36
use middle:: region;
37
37
use middle:: subst;
38
- use middle:: subst:: VecPerParamSpace ;
39
38
use middle:: ty:: { self , Ty } ;
40
39
41
40
use syntax:: { ast, ast_util, codemap} ;
@@ -167,6 +166,7 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
167
166
name) ;
168
167
region:: resolve_inlined_item ( & tcx. sess , & tcx. region_maps , ii) ;
169
168
decode_side_tables ( dcx, ast_doc) ;
169
+ copy_item_types ( dcx, ii) ;
170
170
match * ii {
171
171
InlinedItem :: Item ( ref i) => {
172
172
debug ! ( ">>> DECODED ITEM >>>\n {}\n <<< DECODED ITEM <<<" ,
@@ -205,6 +205,17 @@ impl<'a, 'b, 'tcx> DecodeContext<'a, 'b, 'tcx> {
205
205
( id. wrapping_sub ( self . from_id_range . min ) . wrapping_add ( self . to_id_range . min ) )
206
206
}
207
207
208
+ /// Gets the original crate's DefId from a translated internal
209
+ /// def-id.
210
+ pub fn reverse_tr_id ( & self , id : ast:: NodeId ) -> DefId {
211
+ // from_id_range should be non-empty
212
+ assert ! ( !self . from_id_range. empty( ) ) ;
213
+ // Use wrapping arithmetic because otherwise it introduces control flow.
214
+ // Maybe we should just have the control flow? -- aatch
215
+ let node = id. wrapping_sub ( self . to_id_range . min ) . wrapping_add ( self . from_id_range . min ) ;
216
+ DefId { krate : self . cdata . cnum , node : node }
217
+ }
218
+
208
219
/// Translates an EXTERNAL def-id, converting the crate number from the one used in the encoded
209
220
/// data to the current crate numbers.. By external, I mean that it be translated to a
210
221
/// reference to the item in its original crate, as opposed to being translated to a reference
@@ -576,36 +587,6 @@ pub fn encode_cast_kind(ebml_w: &mut Encoder, kind: cast::CastKind) {
576
587
kind. encode ( ebml_w) . unwrap ( ) ;
577
588
}
578
589
579
- pub trait vtable_decoder_helpers < ' tcx > {
580
- fn read_vec_per_param_space < T , F > ( & mut self , f : F ) -> VecPerParamSpace < T > where
581
- F : FnMut ( & mut Self ) -> T ;
582
- }
583
-
584
- impl < ' tcx , ' a > vtable_decoder_helpers < ' tcx > for reader:: Decoder < ' a > {
585
- fn read_vec_per_param_space < T , F > ( & mut self , mut f : F ) -> VecPerParamSpace < T > where
586
- F : FnMut ( & mut reader:: Decoder < ' a > ) -> T ,
587
- {
588
- let types = self . read_to_vec ( |this| Ok ( f ( this) ) ) . unwrap ( ) ;
589
- let selfs = self . read_to_vec ( |this| Ok ( f ( this) ) ) . unwrap ( ) ;
590
- let fns = self . read_to_vec ( |this| Ok ( f ( this) ) ) . unwrap ( ) ;
591
- VecPerParamSpace :: new ( types, selfs, fns)
592
- }
593
- }
594
-
595
- // ___________________________________________________________________________
596
- //
597
-
598
- fn encode_vec_per_param_space < T , F > ( rbml_w : & mut Encoder ,
599
- v : & subst:: VecPerParamSpace < T > ,
600
- mut f : F ) where
601
- F : FnMut ( & mut Encoder , & T ) ,
602
- {
603
- for & space in & subst:: ParamSpace :: all ( ) {
604
- rbml_w. emit_from_vec ( v. get_slice ( space) ,
605
- |rbml_w, n| Ok ( f ( rbml_w, n) ) ) . unwrap ( ) ;
606
- }
607
- }
608
-
609
590
// ______________________________________________________________________
610
591
// Encoding and decoding the side tables
611
592
@@ -632,14 +613,10 @@ trait rbml_writer_helpers<'tcx> {
632
613
fn emit_tys < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > , tys : & [ Ty < ' tcx > ] ) ;
633
614
fn emit_type_param_def < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
634
615
type_param_def : & ty:: TypeParameterDef < ' tcx > ) ;
635
- fn emit_region_param_def ( & mut self , ecx : & e:: EncodeContext ,
636
- region_param_def : & ty:: RegionParameterDef ) ;
637
616
fn emit_predicate < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
638
617
predicate : & ty:: Predicate < ' tcx > ) ;
639
618
fn emit_trait_ref < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
640
619
ty : & ty:: TraitRef < ' tcx > ) ;
641
- fn emit_type_scheme < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
642
- type_scheme : ty:: TypeScheme < ' tcx > ) ;
643
620
fn emit_substs < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
644
621
substs : & subst:: Substs < ' tcx > ) ;
645
622
fn emit_existential_bounds < ' b > ( & mut self , ecx : & e:: EncodeContext < ' b , ' tcx > ,
@@ -688,14 +665,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
688
665
type_param_def) )
689
666
} ) ;
690
667
}
691
- fn emit_region_param_def ( & mut self , ecx : & e:: EncodeContext ,
692
- region_param_def : & ty:: RegionParameterDef ) {
693
- self . emit_opaque ( |this| {
694
- Ok ( tyencode:: enc_region_param_def ( this,
695
- & ecx. ty_str_ctxt ( ) ,
696
- region_param_def) )
697
- } ) ;
698
- }
668
+
699
669
fn emit_predicate < ' b > ( & mut self , ecx : & e:: EncodeContext < ' b , ' tcx > ,
700
670
predicate : & ty:: Predicate < ' tcx > ) {
701
671
self . emit_opaque ( |this| {
@@ -705,32 +675,6 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
705
675
} ) ;
706
676
}
707
677
708
- fn emit_type_scheme < ' b > ( & mut self ,
709
- ecx : & e:: EncodeContext < ' b , ' tcx > ,
710
- type_scheme : ty:: TypeScheme < ' tcx > ) {
711
- use serialize:: Encoder ;
712
-
713
- self . emit_struct ( "TypeScheme" , 2 , |this| {
714
- this. emit_struct_field ( "generics" , 0 , |this| {
715
- this. emit_struct ( "Generics" , 2 , |this| {
716
- this. emit_struct_field ( "types" , 0 , |this| {
717
- Ok ( encode_vec_per_param_space (
718
- this, & type_scheme. generics . types ,
719
- |this, def| this. emit_type_param_def ( ecx, def) ) )
720
- } ) ;
721
- this. emit_struct_field ( "regions" , 1 , |this| {
722
- Ok ( encode_vec_per_param_space (
723
- this, & type_scheme. generics . regions ,
724
- |this, def| this. emit_region_param_def ( ecx, def) ) )
725
- } )
726
- } )
727
- } ) ;
728
- this. emit_struct_field ( "ty" , 1 , |this| {
729
- Ok ( this. emit_ty ( ecx, type_scheme. ty ) )
730
- } )
731
- } ) ;
732
- }
733
-
734
678
fn emit_existential_bounds < ' b > ( & mut self , ecx : & e:: EncodeContext < ' b , ' tcx > ,
735
679
bounds : & ty:: ExistentialBounds < ' tcx > ) {
736
680
self . emit_opaque ( |this| Ok ( tyencode:: enc_existential_bounds ( this,
@@ -950,14 +894,6 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
950
894
}
951
895
}
952
896
953
- let lid = DefId { krate : LOCAL_CRATE , node : id } ;
954
- if let Some ( type_scheme) = tcx. tcache . borrow ( ) . get ( & lid) {
955
- rbml_w. tag ( c:: tag_table_tcache, |rbml_w| {
956
- rbml_w. id ( id) ;
957
- rbml_w. emit_type_scheme ( ecx, type_scheme. clone ( ) ) ;
958
- } )
959
- }
960
-
961
897
if let Some ( type_param_def) = tcx. ty_param_defs . borrow ( ) . get ( & id) {
962
898
rbml_w. tag ( c:: tag_table_param_defs, |rbml_w| {
963
899
rbml_w. id ( id) ;
@@ -1051,12 +987,8 @@ trait rbml_decoder_decoder_helpers<'tcx> {
1051
987
-> ty:: PolyTraitRef < ' tcx > ;
1052
988
fn read_type_param_def < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1053
989
-> ty:: TypeParameterDef < ' tcx > ;
1054
- fn read_region_param_def ( & mut self , dcx : & DecodeContext )
1055
- -> ty:: RegionParameterDef ;
1056
990
fn read_predicate < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1057
991
-> ty:: Predicate < ' tcx > ;
1058
- fn read_type_scheme < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1059
- -> ty:: TypeScheme < ' tcx > ;
1060
992
fn read_existential_bounds < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1061
993
-> ty:: ExistentialBounds < ' tcx > ;
1062
994
fn read_substs < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
@@ -1177,44 +1109,13 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
1177
1109
-> ty:: TypeParameterDef < ' tcx > {
1178
1110
self . read_ty_encoded ( dcx, |decoder| decoder. parse_type_param_def ( ) )
1179
1111
}
1180
- fn read_region_param_def ( & mut self , dcx : & DecodeContext )
1181
- -> ty:: RegionParameterDef {
1182
- self . read_ty_encoded ( dcx, |decoder| decoder. parse_region_param_def ( ) )
1183
- }
1112
+
1184
1113
fn read_predicate < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1185
1114
-> ty:: Predicate < ' tcx >
1186
1115
{
1187
1116
self . read_ty_encoded ( dcx, |decoder| decoder. parse_predicate ( ) )
1188
1117
}
1189
1118
1190
- fn read_type_scheme < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1191
- -> ty:: TypeScheme < ' tcx > {
1192
- self . read_struct ( "TypeScheme" , 3 , |this| {
1193
- Ok ( ty:: TypeScheme {
1194
- generics : this. read_struct_field ( "generics" , 0 , |this| {
1195
- this. read_struct ( "Generics" , 2 , |this| {
1196
- Ok ( ty:: Generics {
1197
- types :
1198
- this. read_struct_field ( "types" , 0 , |this| {
1199
- Ok ( this. read_vec_per_param_space (
1200
- |this| this. read_type_param_def ( dcx) ) )
1201
- } ) . unwrap ( ) ,
1202
-
1203
- regions :
1204
- this. read_struct_field ( "regions" , 1 , |this| {
1205
- Ok ( this. read_vec_per_param_space (
1206
- |this| this. read_region_param_def ( dcx) ) )
1207
- } ) . unwrap ( ) ,
1208
- } )
1209
- } )
1210
- } ) . unwrap ( ) ,
1211
- ty : this. read_struct_field ( "ty" , 1 , |this| {
1212
- Ok ( this. read_ty ( dcx) )
1213
- } ) . unwrap ( )
1214
- } )
1215
- } ) . unwrap ( )
1216
- }
1217
-
1218
1119
fn read_existential_bounds < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1219
1120
-> ty:: ExistentialBounds < ' tcx >
1220
1121
{
@@ -1450,11 +1351,6 @@ fn decode_side_tables(dcx: &DecodeContext,
1450
1351
let ub = val_dsr. read_upvar_capture ( dcx) ;
1451
1352
dcx. tcx . tables . borrow_mut ( ) . upvar_capture_map . insert ( upvar_id, ub) ;
1452
1353
}
1453
- c:: tag_table_tcache => {
1454
- let type_scheme = val_dsr. read_type_scheme ( dcx) ;
1455
- let lid = DefId { krate : LOCAL_CRATE , node : id } ;
1456
- dcx. tcx . register_item_type ( lid, type_scheme) ;
1457
- }
1458
1354
c:: tag_table_param_defs => {
1459
1355
let bounds = val_dsr. read_type_param_def ( dcx) ;
1460
1356
dcx. tcx . ty_param_defs . borrow_mut ( ) . insert ( id, bounds) ;
@@ -1506,6 +1402,43 @@ fn decode_side_tables(dcx: &DecodeContext,
1506
1402
}
1507
1403
}
1508
1404
1405
+ // copy the tcache entries from the original item to the new
1406
+ // inlined item
1407
+ fn copy_item_types ( dcx : & DecodeContext , ii : & InlinedItem ) {
1408
+ fn copy_item_type ( dcx : & DecodeContext , inlined_node : ast:: NodeId ) {
1409
+ let inlined_did = DefId :: local ( inlined_node) ;
1410
+ let remote_did = dcx. reverse_tr_id ( inlined_node) ;
1411
+ dcx. tcx . register_item_type ( inlined_did,
1412
+ dcx. tcx . lookup_item_type ( remote_did) ) ;
1413
+
1414
+ }
1415
+ // copy the entry for the item itself
1416
+ let item_node_id = match ii {
1417
+ & InlinedItem :: Item ( ref i) => i. id ,
1418
+ & InlinedItem :: TraitItem ( _, ref ti) => ti. id ,
1419
+ & InlinedItem :: ImplItem ( _, ref ii) => ii. id ,
1420
+ & InlinedItem :: Foreign ( ref fi) => fi. id
1421
+ } ;
1422
+ copy_item_type ( dcx, item_node_id) ;
1423
+
1424
+ // copy the entries of inner items
1425
+ if let & InlinedItem :: Item ( ref item) = ii {
1426
+ match item. node {
1427
+ hir:: ItemEnum ( ref def, _) => {
1428
+ for variant in & def. variants {
1429
+ copy_item_type ( dcx, variant. node . id ) ;
1430
+ }
1431
+ }
1432
+ hir:: ItemStruct ( ref def, _) => {
1433
+ if let Some ( ctor_id) = def. ctor_id {
1434
+ copy_item_type ( dcx, ctor_id) ;
1435
+ }
1436
+ }
1437
+ _ => { }
1438
+ }
1439
+ }
1440
+ }
1441
+
1509
1442
// ______________________________________________________________________
1510
1443
// Testing of astencode_gen
1511
1444
0 commit comments