@@ -527,6 +527,12 @@ pub struct GlobalCtxt<'tcx> {
527527
528528 pub sess : & ' tcx Session ,
529529 crate_types : Vec < CrateType > ,
530+ /// The `stable_crate_id` is constructed out of the crate name and all the
531+ /// `-C metadata` arguments passed to the compiler. Its value forms a unique
532+ /// global identifier for the crate. It is used to allow multiple crates
533+ /// with the same name to coexist. See the
534+ /// `rustc_symbol_mangling` crate for more information.
535+ stable_crate_id : StableCrateId ,
530536
531537 /// This only ever stores a `LintStore` but we don't want a dependency on that type here.
532538 ///
@@ -688,6 +694,7 @@ impl<'tcx> TyCtxt<'tcx> {
688694 pub fn create_global_ctxt (
689695 s : & ' tcx Session ,
690696 crate_types : Vec < CrateType > ,
697+ stable_crate_id : StableCrateId ,
691698 lint_store : Lrc < dyn Any + sync:: DynSend + sync:: DynSync > ,
692699 arena : & ' tcx WorkerLocal < Arena < ' tcx > > ,
693700 hir_arena : & ' tcx WorkerLocal < hir:: Arena < ' tcx > > ,
@@ -707,6 +714,7 @@ impl<'tcx> TyCtxt<'tcx> {
707714 GlobalCtxt {
708715 sess : s,
709716 crate_types,
717+ stable_crate_id,
710718 lint_store,
711719 arena,
712720 hir_arena,
@@ -842,7 +850,7 @@ impl<'tcx> TyCtxt<'tcx> {
842850 #[ inline]
843851 pub fn stable_crate_id ( self , crate_num : CrateNum ) -> StableCrateId {
844852 if crate_num == LOCAL_CRATE {
845- self . sess . local_stable_crate_id ( )
853+ self . stable_crate_id
846854 } else {
847855 self . cstore_untracked ( ) . stable_crate_id ( crate_num)
848856 }
@@ -852,7 +860,7 @@ impl<'tcx> TyCtxt<'tcx> {
852860 /// that the crate in question has already been loaded by the CrateStore.
853861 #[ inline]
854862 pub fn stable_crate_id_to_crate_num ( self , stable_crate_id : StableCrateId ) -> CrateNum {
855- if stable_crate_id == self . sess . local_stable_crate_id ( ) {
863+ if stable_crate_id == self . stable_crate_id ( LOCAL_CRATE ) {
856864 LOCAL_CRATE
857865 } else {
858866 self . cstore_untracked ( ) . stable_crate_id_to_crate_num ( stable_crate_id)
@@ -869,7 +877,7 @@ impl<'tcx> TyCtxt<'tcx> {
869877
870878 // If this is a DefPathHash from the local crate, we can look up the
871879 // DefId in the tcx's `Definitions`.
872- if stable_crate_id == self . sess . local_stable_crate_id ( ) {
880+ if stable_crate_id == self . stable_crate_id ( LOCAL_CRATE ) {
873881 self . untracked . definitions . read ( ) . local_def_path_hash_to_def_id ( hash, err) . to_def_id ( )
874882 } else {
875883 // If this is a DefPathHash from an upstream crate, let the CrateStore map
@@ -886,7 +894,7 @@ impl<'tcx> TyCtxt<'tcx> {
886894 // statements within the query system and we'd run into endless
887895 // recursion otherwise.
888896 let ( crate_name, stable_crate_id) = if def_id. is_local ( ) {
889- ( self . crate_name ( LOCAL_CRATE ) , self . sess . local_stable_crate_id ( ) )
897+ ( self . crate_name ( LOCAL_CRATE ) , self . stable_crate_id ( LOCAL_CRATE ) )
890898 } else {
891899 let cstore = & * self . cstore_untracked ( ) ;
892900 ( cstore. crate_name ( def_id. krate ) , cstore. stable_crate_id ( def_id. krate ) )
0 commit comments