@@ -13,10 +13,10 @@ use rustc_data_structures::sync::{self, FreezeReadGuard, FreezeWriteGuard};
13
13
use rustc_errors:: DiagCtxt ;
14
14
use rustc_expand:: base:: SyntaxExtension ;
15
15
use rustc_fs_util:: try_canonicalize;
16
- use rustc_hir:: def_id:: { CrateNum , LocalDefId , StableCrateId , StableCrateIdMap , LOCAL_CRATE } ;
16
+ use rustc_hir:: def_id:: { CrateNum , LocalDefId , StableCrateId , LOCAL_CRATE } ;
17
17
use rustc_hir:: definitions:: Definitions ;
18
18
use rustc_index:: IndexVec ;
19
- use rustc_middle:: ty:: TyCtxt ;
19
+ use rustc_middle:: ty:: { TyCtxt , TyCtxtFeed } ;
20
20
use rustc_session:: config:: { self , CrateType , ExternLocation } ;
21
21
use rustc_session:: cstore:: { CrateDepKind , CrateSource , ExternCrate , ExternCrateSource } ;
22
22
use rustc_session:: lint;
@@ -62,9 +62,6 @@ pub struct CStore {
62
62
/// This crate has a `#[alloc_error_handler]` item.
63
63
has_alloc_error_handler : bool ,
64
64
65
- /// The interned [StableCrateId]s.
66
- pub ( crate ) stable_crate_ids : StableCrateIdMap ,
67
-
68
65
/// Unused externs of the crate
69
66
unused_externs : Vec < Symbol > ,
70
67
}
@@ -165,25 +162,27 @@ impl CStore {
165
162
} )
166
163
}
167
164
168
- fn intern_stable_crate_id ( & mut self , root : & CrateRoot ) -> Result < CrateNum , CrateError > {
169
- assert_eq ! ( self . metas. len( ) , self . stable_crate_ids. len( ) ) ;
170
- let num = CrateNum :: new ( self . stable_crate_ids . len ( ) ) ;
171
- if let Some ( & existing) = self . stable_crate_ids . get ( & root. stable_crate_id ( ) ) {
165
+ fn intern_stable_crate_id < ' tcx > (
166
+ & mut self ,
167
+ root : & CrateRoot ,
168
+ tcx : TyCtxt < ' tcx > ,
169
+ ) -> Result < TyCtxtFeed < ' tcx , CrateNum > , CrateError > {
170
+ assert_eq ! ( self . metas. len( ) , tcx. untracked( ) . stable_crate_ids. read( ) . len( ) ) ;
171
+ let num = tcx. create_crate_num ( root. stable_crate_id ( ) ) . map_err ( |existing| {
172
172
// Check for (potential) conflicts with the local crate
173
173
if existing == LOCAL_CRATE {
174
- Err ( CrateError :: SymbolConflictsCurrent ( root. name ( ) ) )
174
+ CrateError :: SymbolConflictsCurrent ( root. name ( ) )
175
175
} else if let Some ( crate_name1) = self . metas [ existing] . as_ref ( ) . map ( |data| data. name ( ) )
176
176
{
177
177
let crate_name0 = root. name ( ) ;
178
- Err ( CrateError :: StableCrateIdCollision ( crate_name0, crate_name1) )
178
+ CrateError :: StableCrateIdCollision ( crate_name0, crate_name1)
179
179
} else {
180
- Err ( CrateError :: NotFound ( root. name ( ) ) )
180
+ CrateError :: NotFound ( root. name ( ) )
181
181
}
182
- } else {
183
- self . metas . push ( None ) ;
184
- self . stable_crate_ids . insert ( root. stable_crate_id ( ) , num) ;
185
- Ok ( num)
186
- }
182
+ } ) ?;
183
+
184
+ self . metas . push ( None ) ;
185
+ Ok ( num)
187
186
}
188
187
189
188
pub fn has_crate_data ( & self , cnum : CrateNum ) -> bool {
@@ -289,12 +288,7 @@ impl CStore {
289
288
}
290
289
}
291
290
292
- pub fn new (
293
- metadata_loader : Box < MetadataLoaderDyn > ,
294
- local_stable_crate_id : StableCrateId ,
295
- ) -> CStore {
296
- let mut stable_crate_ids = StableCrateIdMap :: default ( ) ;
297
- stable_crate_ids. insert ( local_stable_crate_id, LOCAL_CRATE ) ;
291
+ pub fn new ( metadata_loader : Box < MetadataLoaderDyn > ) -> CStore {
298
292
CStore {
299
293
metadata_loader,
300
294
// We add an empty entry for LOCAL_CRATE (which maps to zero) in
@@ -307,7 +301,6 @@ impl CStore {
307
301
alloc_error_handler_kind : None ,
308
302
has_global_allocator : false ,
309
303
has_alloc_error_handler : false ,
310
- stable_crate_ids,
311
304
unused_externs : Vec :: new ( ) ,
312
305
}
313
306
}
@@ -416,7 +409,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
416
409
let private_dep = self . is_private_dep ( name. as_str ( ) , private_dep) ;
417
410
418
411
// Claim this crate number and cache it
419
- let cnum = self . cstore . intern_stable_crate_id ( & crate_root) ?;
412
+ let feed = self . cstore . intern_stable_crate_id ( & crate_root, self . tcx ) ?;
413
+ let cnum = feed. key ( ) ;
420
414
421
415
info ! (
422
416
"register crate `{}` (cnum = {}. private_dep = {})" ,
0 commit comments