@@ -21,6 +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 , LinkMeta , EncodedMetadataHashes } ;
25+ use middle:: cstore:: EncodedMetadata ;
2426use middle:: free_region:: FreeRegionMap ;
2527use middle:: lang_items;
2628use middle:: resolve_lifetime:: { self , ObjectLifetimeDefault } ;
@@ -50,6 +52,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
5052
5153use arena:: { TypedArena , DroplessArena } ;
5254use rustc_data_structures:: indexed_vec:: IndexVec ;
55+ use std:: any:: Any ;
5356use std:: borrow:: Borrow ;
5457use std:: cell:: { Cell , RefCell } ;
5558use std:: cmp:: Ordering ;
@@ -806,8 +809,11 @@ pub struct GlobalCtxt<'tcx> {
806809 global_arenas : & ' tcx GlobalArenas < ' tcx > ,
807810 global_interners : CtxtInterners < ' tcx > ,
808811
812+ cstore : & ' tcx CrateStore ,
813+
809814 pub sess : & ' tcx Session ,
810815
816+
811817 pub trans_trait_caches : traits:: trans:: TransTraitCaches < ' tcx > ,
812818
813819 pub dep_graph : DepGraph ,
@@ -979,6 +985,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
979985 /// value (types, substs, etc.) can only be used while `ty::tls` has a valid
980986 /// reference to the context, to allow formatting values that need it.
981987 pub fn create_and_enter < F , R > ( s : & ' tcx Session ,
988+ cstore : & ' tcx CrateStore ,
982989 local_providers : ty:: maps:: Providers < ' tcx > ,
983990 extern_providers : ty:: maps:: Providers < ' tcx > ,
984991 mir_passes : Rc < Passes > ,
@@ -995,16 +1002,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
9951002 let interners = CtxtInterners :: new ( arena) ;
9961003 let common_types = CommonTypes :: new ( & interners) ;
9971004 let dep_graph = hir. dep_graph . clone ( ) ;
998- let max_cnum = s . cstore . crates_untracked ( ) . iter ( ) . map ( |c| c. as_usize ( ) ) . max ( ) . unwrap_or ( 0 ) ;
1005+ let max_cnum = cstore. crates_untracked ( ) . iter ( ) . map ( |c| c. as_usize ( ) ) . max ( ) . unwrap_or ( 0 ) ;
9991006 let mut providers = IndexVec :: from_elem_n ( extern_providers, max_cnum + 1 ) ;
10001007 providers[ LOCAL_CRATE ] = local_providers;
10011008
10021009 let def_path_hash_to_def_id = if s. opts . build_dep_graph ( ) {
1003- let upstream_def_path_tables: Vec < ( CrateNum , Rc < _ > ) > = s
1004- . cstore
1010+ let upstream_def_path_tables: Vec < ( CrateNum , Rc < _ > ) > = cstore
10051011 . crates_untracked ( )
10061012 . iter ( )
1007- . map ( |& cnum| ( cnum, s . cstore . def_path_table ( cnum) ) )
1013+ . map ( |& cnum| ( cnum, cstore. def_path_table ( cnum) ) )
10081014 . collect ( ) ;
10091015
10101016 let def_path_tables = || {
@@ -1034,6 +1040,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10341040
10351041 tls:: enter_global ( GlobalCtxt {
10361042 sess : s,
1043+ cstore,
10371044 trans_trait_caches : traits:: trans:: TransTraitCaches :: new ( dep_graph. clone ( ) ) ,
10381045 global_arenas : arenas,
10391046 global_interners : interners,
@@ -1126,6 +1133,54 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11261133 pub fn crates ( self ) -> Rc < Vec < CrateNum > > {
11271134 self . all_crate_nums ( LOCAL_CRATE )
11281135 }
1136+
1137+ pub fn def_key ( self , id : DefId ) -> hir_map:: DefKey {
1138+ if id. is_local ( ) {
1139+ self . hir . def_key ( id)
1140+ } else {
1141+ self . cstore . def_key ( id)
1142+ }
1143+ }
1144+
1145+ /// Convert a `DefId` into its fully expanded `DefPath` (every
1146+ /// `DefId` is really just an interned def-path).
1147+ ///
1148+ /// Note that if `id` is not local to this crate, the result will
1149+ /// be a non-local `DefPath`.
1150+ pub fn def_path ( self , id : DefId ) -> hir_map:: DefPath {
1151+ if id. is_local ( ) {
1152+ self . hir . def_path ( id)
1153+ } else {
1154+ self . cstore . def_path ( id)
1155+ }
1156+ }
1157+
1158+ #[ inline]
1159+ pub fn def_path_hash ( self , def_id : DefId ) -> hir_map:: DefPathHash {
1160+ if def_id. is_local ( ) {
1161+ self . hir . definitions ( ) . def_path_hash ( def_id. index )
1162+ } else {
1163+ self . cstore . def_path_hash ( def_id)
1164+ }
1165+ }
1166+
1167+ pub fn metadata_encoding_version ( self ) -> Vec < u8 > {
1168+ self . cstore . metadata_encoding_version ( ) . to_vec ( )
1169+ }
1170+
1171+ // Note that this is *untracked* and should only be used within the query
1172+ // system if the result is otherwise tracked through queries
1173+ pub fn crate_data_as_rc_any ( self , cnum : CrateNum ) -> Rc < Any > {
1174+ self . cstore . crate_data_as_rc_any ( cnum)
1175+ }
1176+ }
1177+
1178+ impl < ' a , ' tcx > TyCtxt < ' a , ' tcx , ' tcx > {
1179+ pub fn encode_metadata ( self , link_meta : & LinkMeta , reachable : & NodeSet )
1180+ -> ( EncodedMetadata , EncodedMetadataHashes )
1181+ {
1182+ self . cstore . encode_metadata ( self , link_meta, reachable)
1183+ }
11291184}
11301185
11311186impl < ' gcx : ' tcx , ' tcx > GlobalCtxt < ' gcx > {
@@ -2061,4 +2116,16 @@ pub fn provide(providers: &mut ty::maps::Providers) {
20612116 let id = tcx. hir . definitions ( ) . def_index_to_hir_id ( id. index ) ;
20622117 tcx. stability ( ) . local_deprecation_entry ( id)
20632118 } ;
2119+ providers. extern_mod_stmt_cnum = |tcx, id| {
2120+ let id = tcx. hir . definitions ( ) . find_node_for_hir_id ( id) ;
2121+ tcx. cstore . extern_mod_stmt_cnum_untracked ( id)
2122+ } ;
2123+ providers. all_crate_nums = |tcx, cnum| {
2124+ assert_eq ! ( cnum, LOCAL_CRATE ) ;
2125+ Rc :: new ( tcx. cstore . crates_untracked ( ) )
2126+ } ;
2127+ providers. postorder_cnums = |tcx, cnum| {
2128+ assert_eq ! ( cnum, LOCAL_CRATE ) ;
2129+ Rc :: new ( tcx. cstore . postorder_cnums_untracked ( ) )
2130+ } ;
20642131}
0 commit comments