@@ -13,7 +13,7 @@ use rustc_ast::expand::allocator::AllocatorKind;
13
13
use rustc_ast:: { self as ast, * } ;
14
14
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
15
15
use rustc_data_structures:: svh:: Svh ;
16
- use rustc_data_structures:: sync:: Lrc ;
16
+ use rustc_data_structures:: sync:: { Lrc , ReadGuard } ;
17
17
use rustc_expand:: base:: SyntaxExtension ;
18
18
use rustc_hir:: def_id:: { CrateNum , LocalDefId , StableCrateId , LOCAL_CRATE } ;
19
19
use rustc_hir:: definitions:: Definitions ;
@@ -68,11 +68,12 @@ impl std::fmt::Debug for CStore {
68
68
pub struct CrateLoader < ' a > {
69
69
// Immutable configuration.
70
70
sess : & ' a Session ,
71
- metadata_loader : Box < MetadataLoaderDyn > ,
71
+ metadata_loader : & ' a MetadataLoaderDyn ,
72
+ definitions : ReadGuard < ' a , Definitions > ,
72
73
local_crate_name : Symbol ,
73
74
// Mutable output.
74
- cstore : CStore ,
75
- used_extern_options : FxHashSet < Symbol > ,
75
+ cstore : & ' a mut CStore ,
76
+ used_extern_options : & ' a mut FxHashSet < Symbol > ,
76
77
}
77
78
78
79
pub enum LoadedMacro {
@@ -239,47 +240,49 @@ impl CStore {
239
240
) ;
240
241
}
241
242
}
243
+
244
+ pub fn new ( sess : & Session ) -> CStore {
245
+ let mut stable_crate_ids = FxHashMap :: default ( ) ;
246
+ stable_crate_ids. insert ( sess. local_stable_crate_id ( ) , LOCAL_CRATE ) ;
247
+ CStore {
248
+ // We add an empty entry for LOCAL_CRATE (which maps to zero) in
249
+ // order to make array indices in `metas` match with the
250
+ // corresponding `CrateNum`. This first entry will always remain
251
+ // `None`.
252
+ metas : IndexVec :: from_elem_n ( None , 1 ) ,
253
+ injected_panic_runtime : None ,
254
+ allocator_kind : None ,
255
+ alloc_error_handler_kind : None ,
256
+ has_global_allocator : false ,
257
+ has_alloc_error_handler : false ,
258
+ stable_crate_ids,
259
+ unused_externs : Vec :: new ( ) ,
260
+ }
261
+ }
242
262
}
243
263
244
264
impl < ' a > CrateLoader < ' a > {
245
265
pub fn new (
246
266
sess : & ' a Session ,
247
- metadata_loader : Box < MetadataLoaderDyn > ,
267
+ metadata_loader : & ' a MetadataLoaderDyn ,
248
268
local_crate_name : Symbol ,
269
+ cstore : & ' a mut CStore ,
270
+ definitions : ReadGuard < ' a , Definitions > ,
271
+ used_extern_options : & ' a mut FxHashSet < Symbol > ,
249
272
) -> Self {
250
- let mut stable_crate_ids = FxHashMap :: default ( ) ;
251
- stable_crate_ids. insert ( sess. local_stable_crate_id ( ) , LOCAL_CRATE ) ;
252
-
253
273
CrateLoader {
254
274
sess,
255
275
metadata_loader,
256
276
local_crate_name,
257
- cstore : CStore {
258
- // We add an empty entry for LOCAL_CRATE (which maps to zero) in
259
- // order to make array indices in `metas` match with the
260
- // corresponding `CrateNum`. This first entry will always remain
261
- // `None`.
262
- metas : IndexVec :: from_elem_n ( None , 1 ) ,
263
- injected_panic_runtime : None ,
264
- allocator_kind : None ,
265
- alloc_error_handler_kind : None ,
266
- has_global_allocator : false ,
267
- has_alloc_error_handler : false ,
268
- stable_crate_ids,
269
- unused_externs : Vec :: new ( ) ,
270
- } ,
271
- used_extern_options : Default :: default ( ) ,
277
+ cstore,
278
+ used_extern_options,
279
+ definitions,
272
280
}
273
281
}
274
-
275
282
pub fn cstore ( & self ) -> & CStore {
276
283
& self . cstore
277
284
}
278
285
279
- pub fn into_cstore ( self ) -> CStore {
280
- self . cstore
281
- }
282
-
283
286
fn existing_match ( & self , name : Symbol , hash : Option < Svh > , kind : PathKind ) -> Option < CrateNum > {
284
287
for ( cnum, data) in self . cstore . iter_crate_data ( ) {
285
288
if data. name ( ) != name {
@@ -989,7 +992,6 @@ impl<'a> CrateLoader<'a> {
989
992
pub fn process_extern_crate (
990
993
& mut self ,
991
994
item : & ast:: Item ,
992
- definitions : & Definitions ,
993
995
def_id : LocalDefId ,
994
996
) -> Option < CrateNum > {
995
997
match item. kind {
@@ -1013,7 +1015,7 @@ impl<'a> CrateLoader<'a> {
1013
1015
1014
1016
let cnum = self . resolve_crate ( name, item. span , dep_kind) ?;
1015
1017
1016
- let path_len = definitions. def_path ( def_id) . data . len ( ) ;
1018
+ let path_len = self . definitions . def_path ( def_id) . data . len ( ) ;
1017
1019
self . update_extern_crate (
1018
1020
cnum,
1019
1021
ExternCrate {
0 commit comments