@@ -103,8 +103,6 @@ pub struct DefMap {
103
103
/// but that attribute is nightly and when used in a block, it affects resolution globally
104
104
/// so we aren't handling this correctly anyways).
105
105
prelude : Option < ModuleId > ,
106
- /// The extern prelude is only populated for non-block DefMaps
107
- extern_prelude : FxHashMap < Name , ModuleId > ,
108
106
/// `macro_use` prelude that contains macros from `#[macro_use]`'d external crates. Note that
109
107
/// this contains all kinds of macro, not just `macro_rules!` macro.
110
108
macro_use_prelude : FxHashMap < Name , MacroId > ,
@@ -115,12 +113,13 @@ pub struct DefMap {
115
113
116
114
diagnostics : Vec < DefDiagnostic > ,
117
115
118
- // FIXME: Arc this so we can share it with block def maps
119
116
data : Arc < CrateData > ,
120
117
}
121
118
122
119
#[ derive( Clone , Debug , PartialEq , Eq ) ]
123
120
struct CrateData {
121
+ extern_prelude : FxHashMap < Name , ModuleId > ,
122
+
124
123
/// Side table for resolving derive helpers.
125
124
exported_derives : FxHashMap < MacroDefId , Box < [ Name ] > > ,
126
125
fn_proc_macro_mapping : FxHashMap < FunctionId , ProcMacroId > ,
@@ -141,9 +140,11 @@ struct CrateData {
141
140
edition : Edition ,
142
141
recursion_limit : Option < u32 > ,
143
142
}
143
+
144
144
impl CrateData {
145
145
fn shrink_to_fit ( & mut self ) {
146
146
let Self {
147
+ extern_prelude,
147
148
exported_derives,
148
149
fn_proc_macro_mapping,
149
150
registered_attrs,
@@ -156,6 +157,7 @@ impl CrateData {
156
157
edition : _,
157
158
recursion_limit : _,
158
159
} = self ;
160
+ extern_prelude. shrink_to_fit ( ) ;
159
161
exported_derives. shrink_to_fit ( ) ;
160
162
fn_proc_macro_mapping. shrink_to_fit ( ) ;
161
163
registered_attrs. shrink_to_fit ( ) ;
@@ -181,7 +183,11 @@ struct BlockRelativeModuleId {
181
183
182
184
impl BlockRelativeModuleId {
183
185
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 }
185
191
}
186
192
}
187
193
@@ -330,15 +336,14 @@ impl DefMap {
330
336
DefMap {
331
337
_c : Count :: new ( ) ,
332
338
block : None ,
339
+ modules,
333
340
krate,
334
- extern_prelude : FxHashMap :: default ( ) ,
341
+ prelude : None ,
335
342
macro_use_prelude : FxHashMap :: default ( ) ,
336
343
derive_helpers_in_scope : FxHashMap :: default ( ) ,
337
- prelude : None ,
338
- modules,
339
344
diagnostics : Vec :: new ( ) ,
340
345
data : Arc :: new ( CrateData {
341
- recursion_limit : None ,
346
+ extern_prelude : FxHashMap :: default ( ) ,
342
347
exported_derives : FxHashMap :: default ( ) ,
343
348
fn_proc_macro_mapping : FxHashMap :: default ( ) ,
344
349
proc_macro_loading_error : None ,
@@ -349,6 +354,7 @@ impl DefMap {
349
354
no_core : false ,
350
355
no_std : false ,
351
356
edition,
357
+ recursion_limit : None ,
352
358
} ) ,
353
359
}
354
360
}
@@ -412,7 +418,7 @@ impl DefMap {
412
418
}
413
419
414
420
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) )
416
422
}
417
423
418
424
pub ( crate ) fn macro_use_prelude ( & self ) -> impl Iterator < Item = ( & Name , MacroId ) > + ' _ {
@@ -573,7 +579,6 @@ impl DefMap {
573
579
// Exhaustive match to require handling new fields.
574
580
let Self {
575
581
_c : _,
576
- extern_prelude,
577
582
macro_use_prelude,
578
583
diagnostics,
579
584
modules,
@@ -584,7 +589,6 @@ impl DefMap {
584
589
data : _,
585
590
} = self ;
586
591
587
- extern_prelude. shrink_to_fit ( ) ;
588
592
macro_use_prelude. shrink_to_fit ( ) ;
589
593
diagnostics. shrink_to_fit ( ) ;
590
594
modules. shrink_to_fit ( ) ;
0 commit comments