@@ -13,7 +13,7 @@ use rustc_ast::expand::allocator::AllocatorKind;
1313use rustc_ast:: { self as ast, * } ;
1414use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
1515use rustc_data_structures:: svh:: Svh ;
16- use rustc_data_structures:: sync:: Lrc ;
16+ use rustc_data_structures:: sync:: { Lrc , ReadGuard } ;
1717use rustc_expand:: base:: SyntaxExtension ;
1818use rustc_hir:: def_id:: { CrateNum , LocalDefId , StableCrateId , LOCAL_CRATE } ;
1919use rustc_hir:: definitions:: Definitions ;
@@ -68,11 +68,12 @@ impl std::fmt::Debug for CStore {
6868pub struct CrateLoader < ' a > {
6969 // Immutable configuration.
7070 sess : & ' a Session ,
71- metadata_loader : Box < MetadataLoaderDyn > ,
71+ metadata_loader : & ' a MetadataLoaderDyn ,
72+ definitions : ReadGuard < ' a , Definitions > ,
7273 local_crate_name : Symbol ,
7374 // Mutable output.
74- cstore : CStore ,
75- used_extern_options : FxHashSet < Symbol > ,
75+ cstore : & ' a mut CStore ,
76+ used_extern_options : & ' a mut FxHashSet < Symbol > ,
7677}
7778
7879pub enum LoadedMacro {
@@ -239,47 +240,49 @@ impl CStore {
239240 ) ;
240241 }
241242 }
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+ }
242262}
243263
244264impl < ' a > CrateLoader < ' a > {
245265 pub fn new (
246266 sess : & ' a Session ,
247- metadata_loader : Box < MetadataLoaderDyn > ,
267+ metadata_loader : & ' a MetadataLoaderDyn ,
248268 local_crate_name : Symbol ,
269+ cstore : & ' a mut CStore ,
270+ definitions : ReadGuard < ' a , Definitions > ,
271+ used_extern_options : & ' a mut FxHashSet < Symbol > ,
249272 ) -> Self {
250- let mut stable_crate_ids = FxHashMap :: default ( ) ;
251- stable_crate_ids. insert ( sess. local_stable_crate_id ( ) , LOCAL_CRATE ) ;
252-
253273 CrateLoader {
254274 sess,
255275 metadata_loader,
256276 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,
272280 }
273281 }
274-
275282 pub fn cstore ( & self ) -> & CStore {
276283 & self . cstore
277284 }
278285
279- pub fn into_cstore ( self ) -> CStore {
280- self . cstore
281- }
282-
283286 fn existing_match ( & self , name : Symbol , hash : Option < Svh > , kind : PathKind ) -> Option < CrateNum > {
284287 for ( cnum, data) in self . cstore . iter_crate_data ( ) {
285288 if data. name ( ) != name {
@@ -989,7 +992,6 @@ impl<'a> CrateLoader<'a> {
989992 pub fn process_extern_crate (
990993 & mut self ,
991994 item : & ast:: Item ,
992- definitions : & Definitions ,
993995 def_id : LocalDefId ,
994996 ) -> Option < CrateNum > {
995997 match item. kind {
@@ -1013,7 +1015,7 @@ impl<'a> CrateLoader<'a> {
10131015
10141016 let cnum = self . resolve_crate ( name, item. span , dep_kind) ?;
10151017
1016- let path_len = definitions. def_path ( def_id) . data . len ( ) ;
1018+ let path_len = self . definitions . def_path ( def_id) . data . len ( ) ;
10171019 self . update_extern_crate (
10181020 cnum,
10191021 ExternCrate {
0 commit comments