@@ -21,7 +21,8 @@ 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
- use middle:: cstore:: CrateStore ;
24
+ use middle:: cstore:: { CrateStore , LinkMeta , EncodedMetadataHashes } ;
25
+ use middle:: cstore:: EncodedMetadata ;
25
26
use middle:: free_region:: FreeRegionMap ;
26
27
use middle:: lang_items;
27
28
use middle:: resolve_lifetime:: { self , ObjectLifetimeDefault } ;
@@ -51,6 +52,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
51
52
52
53
use arena:: { TypedArena , DroplessArena } ;
53
54
use rustc_data_structures:: indexed_vec:: IndexVec ;
55
+ use std:: any:: Any ;
54
56
use std:: borrow:: Borrow ;
55
57
use std:: cell:: { Cell , RefCell } ;
56
58
use std:: cmp:: Ordering ;
@@ -907,10 +909,6 @@ impl<'tcx> GlobalCtxt<'tcx> {
907
909
}
908
910
909
911
impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
910
- pub fn cstore_untracked ( & self ) -> & CrateStore {
911
- & * self . cstore
912
- }
913
-
914
912
pub fn alloc_generics ( self , generics : ty:: Generics ) -> & ' gcx ty:: Generics {
915
913
self . global_arenas . generics . alloc ( generics)
916
914
}
@@ -1134,6 +1132,54 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
1134
1132
pub fn crates ( self ) -> Rc < Vec < CrateNum > > {
1135
1133
self . all_crate_nums ( LOCAL_CRATE )
1136
1134
}
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
+ }
1137
1183
}
1138
1184
1139
1185
impl < ' gcx : ' tcx , ' tcx > GlobalCtxt < ' gcx > {
@@ -2069,4 +2115,16 @@ pub fn provide(providers: &mut ty::maps::Providers) {
2069
2115
let id = tcx. hir . definitions ( ) . def_index_to_hir_id ( id. index ) ;
2070
2116
tcx. stability ( ) . local_deprecation_entry ( id)
2071
2117
} ;
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
+ } ;
2072
2130
}
0 commit comments