@@ -527,6 +527,12 @@ pub struct GlobalCtxt<'tcx> {
527
527
528
528
pub sess : & ' tcx Session ,
529
529
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 ,
530
536
531
537
/// This only ever stores a `LintStore` but we don't want a dependency on that type here.
532
538
///
@@ -688,6 +694,7 @@ impl<'tcx> TyCtxt<'tcx> {
688
694
pub fn create_global_ctxt (
689
695
s : & ' tcx Session ,
690
696
crate_types : Vec < CrateType > ,
697
+ stable_crate_id : StableCrateId ,
691
698
lint_store : Lrc < dyn Any + sync:: DynSend + sync:: DynSync > ,
692
699
arena : & ' tcx WorkerLocal < Arena < ' tcx > > ,
693
700
hir_arena : & ' tcx WorkerLocal < hir:: Arena < ' tcx > > ,
@@ -707,6 +714,7 @@ impl<'tcx> TyCtxt<'tcx> {
707
714
GlobalCtxt {
708
715
sess : s,
709
716
crate_types,
717
+ stable_crate_id,
710
718
lint_store,
711
719
arena,
712
720
hir_arena,
@@ -842,7 +850,7 @@ impl<'tcx> TyCtxt<'tcx> {
842
850
#[ inline]
843
851
pub fn stable_crate_id ( self , crate_num : CrateNum ) -> StableCrateId {
844
852
if crate_num == LOCAL_CRATE {
845
- self . sess . local_stable_crate_id ( )
853
+ self . stable_crate_id
846
854
} else {
847
855
self . cstore_untracked ( ) . stable_crate_id ( crate_num)
848
856
}
@@ -852,7 +860,7 @@ impl<'tcx> TyCtxt<'tcx> {
852
860
/// that the crate in question has already been loaded by the CrateStore.
853
861
#[ inline]
854
862
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 ) {
856
864
LOCAL_CRATE
857
865
} else {
858
866
self . cstore_untracked ( ) . stable_crate_id_to_crate_num ( stable_crate_id)
@@ -869,7 +877,7 @@ impl<'tcx> TyCtxt<'tcx> {
869
877
870
878
// If this is a DefPathHash from the local crate, we can look up the
871
879
// 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 ) {
873
881
self . untracked . definitions . read ( ) . local_def_path_hash_to_def_id ( hash, err) . to_def_id ( )
874
882
} else {
875
883
// If this is a DefPathHash from an upstream crate, let the CrateStore map
@@ -886,7 +894,7 @@ impl<'tcx> TyCtxt<'tcx> {
886
894
// statements within the query system and we'd run into endless
887
895
// recursion otherwise.
888
896
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 ) )
890
898
} else {
891
899
let cstore = & * self . cstore_untracked ( ) ;
892
900
( cstore. crate_name ( def_id. krate ) , cstore. stable_crate_id ( def_id. krate ) )
0 commit comments