@@ -21,11 +21,9 @@ use hir::map as hir_map;
21
21
use hir:: map:: DefPathHash ;
22
22
use lint:: { self , Lint } ;
23
23
use ich:: { self , StableHashingContext , NodeIdHashingMode } ;
24
- <<<<<<< 817 e1b81e230d599585f860cdcad96c5ed83b93e
25
24
use 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 ;
29
27
use middle:: free_region:: FreeRegionMap ;
30
28
use middle:: lang_items;
31
29
use middle:: resolve_lifetime:: { self , ObjectLifetimeDefault } ;
@@ -56,6 +54,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
56
54
use arena:: { TypedArena , DroplessArena } ;
57
55
use rustc_const_math:: { ConstInt , ConstUsize } ;
58
56
use rustc_data_structures:: indexed_vec:: IndexVec ;
57
+ use std:: any:: Any ;
59
58
use std:: borrow:: Borrow ;
60
59
use std:: cell:: { Cell , RefCell } ;
61
60
use std:: cmp:: Ordering ;
@@ -915,10 +914,6 @@ impl<'tcx> GlobalCtxt<'tcx> {
915
914
}
916
915
917
916
impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
918
- pub fn cstore_untracked( & self ) -> & CrateStore {
919
- & * self . cstore
920
- }
921
-
922
917
pub fn alloc_generics ( self , generics : ty:: Generics ) -> & ' gcx ty:: Generics {
923
918
self . global_arenas . generics . alloc ( generics)
924
919
}
@@ -1183,6 +1178,54 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
1183
1178
pub fn crates ( self ) -> Rc < Vec < CrateNum > > {
1184
1179
self . all_crate_nums ( LOCAL_CRATE )
1185
1180
}
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
+ }
1186
1229
}
1187
1230
1188
1231
impl < ' gcx : ' tcx , ' tcx > GlobalCtxt < ' gcx > {
@@ -2163,4 +2206,16 @@ pub fn provide(providers: &mut ty::maps::Providers) {
2163
2206
let id = tcx. hir . definitions ( ) . def_index_to_hir_id ( id. index ) ;
2164
2207
tcx. stability ( ) . local_deprecation_entry ( id)
2165
2208
} ;
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
+ } ;
2166
2221
}
0 commit comments