@@ -21,7 +21,8 @@ use hir::map as hir_map;
2121use hir:: map:: DefPathHash ;
2222use lint:: { self , Lint } ;
2323use ich:: { self , StableHashingContext , NodeIdHashingMode } ;
24- use middle:: cstore:: CrateStore ;
24+ use middle:: cstore:: { CrateStore , LinkMeta , EncodedMetadataHashes } ;
25+ use middle:: cstore:: EncodedMetadata ;
2526use middle:: free_region:: FreeRegionMap ;
2627use middle:: lang_items;
2728use middle:: resolve_lifetime:: { self , ObjectLifetimeDefault } ;
@@ -51,6 +52,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
5152
5253use arena:: { TypedArena , DroplessArena } ;
5354use rustc_data_structures:: indexed_vec:: IndexVec ;
55+ use std:: any:: Any ;
5456use std:: borrow:: Borrow ;
5557use std:: cell:: { Cell , RefCell } ;
5658use std:: cmp:: Ordering ;
@@ -907,10 +909,6 @@ impl<'tcx> GlobalCtxt<'tcx> {
907909}
908910
909911impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
910- pub fn cstore_untracked ( & self ) -> & CrateStore {
911- & * self . cstore
912- }
913-
914912 pub fn alloc_generics ( self , generics : ty:: Generics ) -> & ' gcx ty:: Generics {
915913 self . global_arenas . generics . alloc ( generics)
916914 }
@@ -1134,6 +1132,54 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11341132 pub fn crates ( self ) -> Rc < Vec < CrateNum > > {
11351133 self . all_crate_nums ( LOCAL_CRATE )
11361134 }
1135+
1136+ pub fn def_key ( self , id : DefId ) -> hir_map:: DefKey {
1137+ if id. is_local ( ) {
1138+ self . hir . def_key ( id)
1139+ } else {
1140+ self . cstore . def_key ( id)
1141+ }
1142+ }
1143+
1144+ /// Convert a `DefId` into its fully expanded `DefPath` (every
1145+ /// `DefId` is really just an interned def-path).
1146+ ///
1147+ /// Note that if `id` is not local to this crate, the result will
1148+ /// be a non-local `DefPath`.
1149+ pub fn def_path ( self , id : DefId ) -> hir_map:: DefPath {
1150+ if id. is_local ( ) {
1151+ self . hir . def_path ( id)
1152+ } else {
1153+ self . cstore . def_path ( id)
1154+ }
1155+ }
1156+
1157+ #[ inline]
1158+ pub fn def_path_hash ( self , def_id : DefId ) -> hir_map:: DefPathHash {
1159+ if def_id. is_local ( ) {
1160+ self . hir . definitions ( ) . def_path_hash ( def_id. index )
1161+ } else {
1162+ self . cstore . def_path_hash ( def_id)
1163+ }
1164+ }
1165+
1166+ pub fn metadata_encoding_version ( self ) -> Vec < u8 > {
1167+ self . cstore . metadata_encoding_version ( ) . to_vec ( )
1168+ }
1169+
1170+ // Note that this is *untracked* and should only be used within the query
1171+ // system if the result is otherwise tracked through queries
1172+ pub fn crate_data_as_rc_any ( self , cnum : CrateNum ) -> Rc < Any > {
1173+ self . cstore . crate_data_as_rc_any ( cnum)
1174+ }
1175+ }
1176+
1177+ impl < ' a , ' tcx > TyCtxt < ' a , ' tcx , ' tcx > {
1178+ pub fn encode_metadata ( self , link_meta : & LinkMeta , reachable : & NodeSet )
1179+ -> ( EncodedMetadata , EncodedMetadataHashes )
1180+ {
1181+ self . cstore . encode_metadata ( self , link_meta, reachable)
1182+ }
11371183}
11381184
11391185impl < ' gcx : ' tcx , ' tcx > GlobalCtxt < ' gcx > {
@@ -2069,4 +2115,16 @@ pub fn provide(providers: &mut ty::maps::Providers) {
20692115 let id = tcx. hir . definitions ( ) . def_index_to_hir_id ( id. index ) ;
20702116 tcx. stability ( ) . local_deprecation_entry ( id)
20712117 } ;
2118+ providers. extern_mod_stmt_cnum = |tcx, id| {
2119+ let id = tcx. hir . definitions ( ) . find_node_for_hir_id ( id) ;
2120+ tcx. cstore . extern_mod_stmt_cnum_untracked ( id)
2121+ } ;
2122+ providers. all_crate_nums = |tcx, cnum| {
2123+ assert_eq ! ( cnum, LOCAL_CRATE ) ;
2124+ Rc :: new ( tcx. cstore . crates_untracked ( ) )
2125+ } ;
2126+ providers. postorder_cnums = |tcx, cnum| {
2127+ assert_eq ! ( cnum, LOCAL_CRATE ) ;
2128+ Rc :: new ( tcx. cstore . postorder_cnums_untracked ( ) )
2129+ } ;
20722130}
0 commit comments