@@ -21,11 +21,9 @@ use hir::map as hir_map;
2121use hir:: map:: DefPathHash ;
2222use lint:: { self , Lint } ;
2323use ich:: { self , StableHashingContext , NodeIdHashingMode } ;
24- <<<<<<< 817 e1b81e230d599585f860cdcad96c5ed83b93e
2524use middle:: const_val:: ConstVal ;
26- =======
27- use middle:: cstore:: CrateStore ;
28- >>>>>>> Remove the `cstore` reference from Session in order to prepare encapsulating CrateStore access in tcx.
25+ use middle:: cstore:: { CrateStore , LinkMeta , EncodedMetadataHashes } ;
26+ use middle:: cstore:: EncodedMetadata ;
2927use middle:: free_region:: FreeRegionMap ;
3028use middle:: lang_items;
3129use middle:: resolve_lifetime:: { self , ObjectLifetimeDefault } ;
@@ -56,6 +54,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
5654use arena:: { TypedArena , DroplessArena } ;
5755use rustc_const_math:: { ConstInt , ConstUsize } ;
5856use rustc_data_structures:: indexed_vec:: IndexVec ;
57+ use std:: any:: Any ;
5958use std:: borrow:: Borrow ;
6059use std:: cell:: { Cell , RefCell } ;
6160use std:: cmp:: Ordering ;
@@ -915,10 +914,6 @@ impl<'tcx> GlobalCtxt<'tcx> {
915914}
916915
917916impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
918- pub fn cstore_untracked( & self ) -> & CrateStore {
919- & * self . cstore
920- }
921-
922917 pub fn alloc_generics ( self , generics : ty:: Generics ) -> & ' gcx ty:: Generics {
923918 self . global_arenas . generics . alloc ( generics)
924919 }
@@ -1183,6 +1178,54 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11831178 pub fn crates ( self ) -> Rc < Vec < CrateNum > > {
11841179 self . all_crate_nums ( LOCAL_CRATE )
11851180 }
1181+
1182+ pub fn def_key ( self , id : DefId ) -> hir_map:: DefKey {
1183+ if id. is_local ( ) {
1184+ self . hir . def_key ( id)
1185+ } else {
1186+ self . cstore . def_key ( id)
1187+ }
1188+ }
1189+
1190+ /// Convert a `DefId` into its fully expanded `DefPath` (every
1191+ /// `DefId` is really just an interned def-path).
1192+ ///
1193+ /// Note that if `id` is not local to this crate, the result will
1194+ /// be a non-local `DefPath`.
1195+ pub fn def_path ( self , id : DefId ) -> hir_map:: DefPath {
1196+ if id. is_local ( ) {
1197+ self . hir . def_path ( id)
1198+ } else {
1199+ self . cstore . def_path ( id)
1200+ }
1201+ }
1202+
1203+ #[ inline]
1204+ pub fn def_path_hash ( self , def_id : DefId ) -> hir_map:: DefPathHash {
1205+ if def_id. is_local ( ) {
1206+ self . hir . definitions ( ) . def_path_hash ( def_id. index )
1207+ } else {
1208+ self . cstore . def_path_hash ( def_id)
1209+ }
1210+ }
1211+
1212+ pub fn metadata_encoding_version ( self ) -> Vec < u8 > {
1213+ self . cstore . metadata_encoding_version ( ) . to_vec ( )
1214+ }
1215+
1216+ // Note that this is *untracked* and should only be used within the query
1217+ // system if the result is otherwise tracked through queries
1218+ pub fn crate_data_as_rc_any ( self , cnum : CrateNum ) -> Rc < Any > {
1219+ self . cstore . crate_data_as_rc_any ( cnum)
1220+ }
1221+ }
1222+
1223+ impl < ' a , ' tcx > TyCtxt < ' a , ' tcx , ' tcx > {
1224+ pub fn encode_metadata ( self , link_meta : & LinkMeta , reachable : & NodeSet )
1225+ -> ( EncodedMetadata , EncodedMetadataHashes )
1226+ {
1227+ self . cstore . encode_metadata ( self , link_meta, reachable)
1228+ }
11861229}
11871230
11881231impl < ' gcx : ' tcx , ' tcx > GlobalCtxt < ' gcx > {
@@ -2163,4 +2206,16 @@ pub fn provide(providers: &mut ty::maps::Providers) {
21632206 let id = tcx. hir . definitions ( ) . def_index_to_hir_id ( id. index ) ;
21642207 tcx. stability ( ) . local_deprecation_entry ( id)
21652208 } ;
2209+ providers. extern_mod_stmt_cnum = |tcx, id| {
2210+ let id = tcx. hir . as_local_node_id ( id) . unwrap ( ) ;
2211+ tcx. cstore . extern_mod_stmt_cnum_untracked ( id)
2212+ } ;
2213+ providers. all_crate_nums = |tcx, cnum| {
2214+ assert_eq ! ( cnum, LOCAL_CRATE ) ;
2215+ Rc :: new ( tcx. cstore . crates_untracked ( ) )
2216+ } ;
2217+ providers. postorder_cnums = |tcx, cnum| {
2218+ assert_eq ! ( cnum, LOCAL_CRATE ) ;
2219+ Rc :: new ( tcx. cstore . postorder_cnums_untracked ( ) )
2220+ } ;
21662221}
0 commit comments