@@ -103,8 +103,6 @@ pub struct DefMap {
103103 /// but that attribute is nightly and when used in a block, it affects resolution globally
104104 /// so we aren't handling this correctly anyways).
105105 prelude : Option < ModuleId > ,
106- /// The extern prelude is only populated for non-block DefMaps
107- extern_prelude : FxHashMap < Name , ModuleId > ,
108106 /// `macro_use` prelude that contains macros from `#[macro_use]`'d external crates. Note that
109107 /// this contains all kinds of macro, not just `macro_rules!` macro.
110108 macro_use_prelude : FxHashMap < Name , MacroId > ,
@@ -115,12 +113,13 @@ pub struct DefMap {
115113
116114 diagnostics : Vec < DefDiagnostic > ,
117115
118- // FIXME: Arc this so we can share it with block def maps
119116 data : Arc < CrateData > ,
120117}
121118
122119#[ derive( Clone , Debug , PartialEq , Eq ) ]
123120struct CrateData {
121+ extern_prelude : FxHashMap < Name , ModuleId > ,
122+
124123 /// Side table for resolving derive helpers.
125124 exported_derives : FxHashMap < MacroDefId , Box < [ Name ] > > ,
126125 fn_proc_macro_mapping : FxHashMap < FunctionId , ProcMacroId > ,
@@ -141,9 +140,11 @@ struct CrateData {
141140 edition : Edition ,
142141 recursion_limit : Option < u32 > ,
143142}
143+
144144impl CrateData {
145145 fn shrink_to_fit ( & mut self ) {
146146 let Self {
147+ extern_prelude,
147148 exported_derives,
148149 fn_proc_macro_mapping,
149150 registered_attrs,
@@ -156,6 +157,7 @@ impl CrateData {
156157 edition : _,
157158 recursion_limit : _,
158159 } = self ;
160+ extern_prelude. shrink_to_fit ( ) ;
159161 exported_derives. shrink_to_fit ( ) ;
160162 fn_proc_macro_mapping. shrink_to_fit ( ) ;
161163 registered_attrs. shrink_to_fit ( ) ;
@@ -181,7 +183,11 @@ struct BlockRelativeModuleId {
181183
182184impl BlockRelativeModuleId {
183185 fn def_map ( self , db : & dyn DefDatabase , krate : CrateId ) -> Arc < DefMap > {
184- ModuleId { krate, block : self . block , local_id : self . local_id } . def_map ( db)
186+ self . into_module ( krate) . def_map ( db)
187+ }
188+
189+ fn into_module ( self , krate : CrateId ) -> ModuleId {
190+ ModuleId { krate, block : self . block , local_id : self . local_id }
185191 }
186192}
187193
@@ -330,15 +336,14 @@ impl DefMap {
330336 DefMap {
331337 _c : Count :: new ( ) ,
332338 block : None ,
339+ modules,
333340 krate,
334- extern_prelude : FxHashMap :: default ( ) ,
341+ prelude : None ,
335342 macro_use_prelude : FxHashMap :: default ( ) ,
336343 derive_helpers_in_scope : FxHashMap :: default ( ) ,
337- prelude : None ,
338- modules,
339344 diagnostics : Vec :: new ( ) ,
340345 data : Arc :: new ( CrateData {
341- recursion_limit : None ,
346+ extern_prelude : FxHashMap :: default ( ) ,
342347 exported_derives : FxHashMap :: default ( ) ,
343348 fn_proc_macro_mapping : FxHashMap :: default ( ) ,
344349 proc_macro_loading_error : None ,
@@ -349,6 +354,7 @@ impl DefMap {
349354 no_core : false ,
350355 no_std : false ,
351356 edition,
357+ recursion_limit : None ,
352358 } ) ,
353359 }
354360 }
@@ -412,7 +418,7 @@ impl DefMap {
412418 }
413419
414420 pub ( crate ) fn extern_prelude ( & self ) -> impl Iterator < Item = ( & Name , ModuleId ) > + ' _ {
415- self . extern_prelude . iter ( ) . map ( |( name, def) | ( name, * def) )
421+ self . data . extern_prelude . iter ( ) . map ( |( name, def) | ( name, * def) )
416422 }
417423
418424 pub ( crate ) fn macro_use_prelude ( & self ) -> impl Iterator < Item = ( & Name , MacroId ) > + ' _ {
@@ -573,7 +579,6 @@ impl DefMap {
573579 // Exhaustive match to require handling new fields.
574580 let Self {
575581 _c : _,
576- extern_prelude,
577582 macro_use_prelude,
578583 diagnostics,
579584 modules,
@@ -584,7 +589,6 @@ impl DefMap {
584589 data : _,
585590 } = self ;
586591
587- extern_prelude. shrink_to_fit ( ) ;
588592 macro_use_prelude. shrink_to_fit ( ) ;
589593 diagnostics. shrink_to_fit ( ) ;
590594 modules. shrink_to_fit ( ) ;
0 commit comments