@@ -35,7 +35,6 @@ use middle::def_id::{DefId, LOCAL_CRATE};
3535use middle:: privacy:: { AllPublic , LastMod } ;
3636use middle:: region;
3737use middle:: subst;
38- use middle:: subst:: VecPerParamSpace ;
3938use middle:: ty:: { self , Ty } ;
4039
4140use syntax:: { ast, ast_util, codemap} ;
@@ -167,6 +166,7 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
167166 name) ;
168167 region:: resolve_inlined_item ( & tcx. sess , & tcx. region_maps , ii) ;
169168 decode_side_tables ( dcx, ast_doc) ;
169+ copy_item_types ( dcx, ii) ;
170170 match * ii {
171171 InlinedItem :: Item ( ref i) => {
172172 debug ! ( ">>> DECODED ITEM >>>\n {}\n <<< DECODED ITEM <<<" ,
@@ -205,6 +205,17 @@ impl<'a, 'b, 'tcx> DecodeContext<'a, 'b, 'tcx> {
205205 ( id. wrapping_sub ( self . from_id_range . min ) . wrapping_add ( self . to_id_range . min ) )
206206 }
207207
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+
208219 /// Translates an EXTERNAL def-id, converting the crate number from the one used in the encoded
209220 /// data to the current crate numbers.. By external, I mean that it be translated to a
210221 /// 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) {
576587 kind. encode ( ebml_w) . unwrap ( ) ;
577588}
578589
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-
609590// ______________________________________________________________________
610591// Encoding and decoding the side tables
611592
@@ -632,14 +613,10 @@ trait rbml_writer_helpers<'tcx> {
632613 fn emit_tys < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > , tys : & [ Ty < ' tcx > ] ) ;
633614 fn emit_type_param_def < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
634615 type_param_def : & ty:: TypeParameterDef < ' tcx > ) ;
635- fn emit_region_param_def ( & mut self , ecx : & e:: EncodeContext ,
636- region_param_def : & ty:: RegionParameterDef ) ;
637616 fn emit_predicate < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
638617 predicate : & ty:: Predicate < ' tcx > ) ;
639618 fn emit_trait_ref < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
640619 ty : & ty:: TraitRef < ' tcx > ) ;
641- fn emit_type_scheme < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
642- type_scheme : ty:: TypeScheme < ' tcx > ) ;
643620 fn emit_substs < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
644621 substs : & subst:: Substs < ' tcx > ) ;
645622 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> {
688665 type_param_def) )
689666 } ) ;
690667 }
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+
699669 fn emit_predicate < ' b > ( & mut self , ecx : & e:: EncodeContext < ' b , ' tcx > ,
700670 predicate : & ty:: Predicate < ' tcx > ) {
701671 self . emit_opaque ( |this| {
@@ -705,32 +675,6 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
705675 } ) ;
706676 }
707677
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-
734678 fn emit_existential_bounds < ' b > ( & mut self , ecx : & e:: EncodeContext < ' b , ' tcx > ,
735679 bounds : & ty:: ExistentialBounds < ' tcx > ) {
736680 self . emit_opaque ( |this| Ok ( tyencode:: enc_existential_bounds ( this,
@@ -950,14 +894,6 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
950894 }
951895 }
952896
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-
961897 if let Some ( type_param_def) = tcx. ty_param_defs . borrow ( ) . get ( & id) {
962898 rbml_w. tag ( c:: tag_table_param_defs, |rbml_w| {
963899 rbml_w. id ( id) ;
@@ -1051,12 +987,8 @@ trait rbml_decoder_decoder_helpers<'tcx> {
1051987 -> ty:: PolyTraitRef < ' tcx > ;
1052988 fn read_type_param_def < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1053989 -> ty:: TypeParameterDef < ' tcx > ;
1054- fn read_region_param_def ( & mut self , dcx : & DecodeContext )
1055- -> ty:: RegionParameterDef ;
1056990 fn read_predicate < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1057991 -> ty:: Predicate < ' tcx > ;
1058- fn read_type_scheme < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1059- -> ty:: TypeScheme < ' tcx > ;
1060992 fn read_existential_bounds < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1061993 -> ty:: ExistentialBounds < ' tcx > ;
1062994 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> {
11771109 -> ty:: TypeParameterDef < ' tcx > {
11781110 self . read_ty_encoded ( dcx, |decoder| decoder. parse_type_param_def ( ) )
11791111 }
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+
11841113 fn read_predicate < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
11851114 -> ty:: Predicate < ' tcx >
11861115 {
11871116 self . read_ty_encoded ( dcx, |decoder| decoder. parse_predicate ( ) )
11881117 }
11891118
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-
12181119 fn read_existential_bounds < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
12191120 -> ty:: ExistentialBounds < ' tcx >
12201121 {
@@ -1450,11 +1351,6 @@ fn decode_side_tables(dcx: &DecodeContext,
14501351 let ub = val_dsr. read_upvar_capture ( dcx) ;
14511352 dcx. tcx . tables . borrow_mut ( ) . upvar_capture_map . insert ( upvar_id, ub) ;
14521353 }
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- }
14581354 c:: tag_table_param_defs => {
14591355 let bounds = val_dsr. read_type_param_def ( dcx) ;
14601356 dcx. tcx . ty_param_defs . borrow_mut ( ) . insert ( id, bounds) ;
@@ -1506,6 +1402,43 @@ fn decode_side_tables(dcx: &DecodeContext,
15061402 }
15071403}
15081404
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+
15091442// ______________________________________________________________________
15101443// Testing of astencode_gen
15111444
0 commit comments