@@ -29,7 +29,6 @@ use crate::{
29
29
attr_macro_as_call_id,
30
30
db:: DefDatabase ,
31
31
derive_macro_as_call_id,
32
- intern:: Interned ,
33
32
item_scope:: { ImportType , PerNsGlobImports } ,
34
33
item_tree:: {
35
34
self , Fields , FileItemTreeId , ImportKind , ItemTree , ItemTreeId , ItemTreeNode , MacroCall ,
@@ -96,7 +95,7 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap, tree_id: T
96
95
deps,
97
96
glob_imports : FxHashMap :: default ( ) ,
98
97
unresolved_imports : Vec :: new ( ) ,
99
- resolved_imports : Vec :: new ( ) ,
98
+ indeterminate_imports : Vec :: new ( ) ,
100
99
unresolved_macros : Vec :: new ( ) ,
101
100
mod_dirs : FxHashMap :: default ( ) ,
102
101
cfg_options,
@@ -142,9 +141,9 @@ enum ImportSource {
142
141
ExternCrate ( ItemTreeId < item_tree:: ExternCrate > ) ,
143
142
}
144
143
145
- #[ derive( Clone , Debug , Eq , PartialEq ) ]
144
+ #[ derive( Debug , Eq , PartialEq ) ]
146
145
struct Import {
147
- path : Interned < ModPath > ,
146
+ path : ModPath ,
148
147
alias : Option < ImportAlias > ,
149
148
visibility : RawVisibility ,
150
149
kind : ImportKind ,
@@ -169,7 +168,7 @@ impl Import {
169
168
let mut res = Vec :: new ( ) ;
170
169
it. use_tree . expand ( |idx, path, kind, alias| {
171
170
res. push ( Self {
172
- path : Interned :: new ( path ) , // FIXME this makes little sense
171
+ path,
173
172
alias,
174
173
visibility : visibility. clone ( ) ,
175
174
kind,
@@ -192,10 +191,7 @@ impl Import {
192
191
let attrs = & tree. attrs ( db, krate, ModItem :: from ( id. value ) . into ( ) ) ;
193
192
let visibility = & tree[ it. visibility ] ;
194
193
Self {
195
- path : Interned :: new ( ModPath :: from_segments (
196
- PathKind :: Plain ,
197
- iter:: once ( it. name . clone ( ) ) ,
198
- ) ) ,
194
+ path : ModPath :: from_segments ( PathKind :: Plain , iter:: once ( it. name . clone ( ) ) ) ,
199
195
alias : it. alias . clone ( ) ,
200
196
visibility : visibility. clone ( ) ,
201
197
kind : ImportKind :: Plain ,
@@ -207,7 +203,7 @@ impl Import {
207
203
}
208
204
}
209
205
210
- #[ derive( Clone , Debug , Eq , PartialEq ) ]
206
+ #[ derive( Debug , Eq , PartialEq ) ]
211
207
struct ImportDirective {
212
208
module_id : LocalModuleId ,
213
209
import : Import ,
@@ -236,7 +232,7 @@ struct DefCollector<'a> {
236
232
deps : FxHashMap < Name , ModuleId > ,
237
233
glob_imports : FxHashMap < LocalModuleId , Vec < ( LocalModuleId , Visibility ) > > ,
238
234
unresolved_imports : Vec < ImportDirective > ,
239
- resolved_imports : Vec < ImportDirective > ,
235
+ indeterminate_imports : Vec < ImportDirective > ,
240
236
unresolved_macros : Vec < MacroDirective > ,
241
237
mod_dirs : FxHashMap < LocalModuleId , ModDir > ,
242
238
cfg_options : & ' a CfgOptions ,
@@ -352,30 +348,32 @@ impl DefCollector<'_> {
352
348
353
349
// main name resolution fixed-point loop.
354
350
let mut i = 0 ;
355
- ' outer : loop {
356
- loop {
351
+ ' resolve_attr : loop {
352
+ ' resolve_macros : loop {
357
353
self . db . unwind_if_cancelled ( ) ;
354
+
358
355
{
359
356
let _p = profile:: span ( "resolve_imports loop" ) ;
360
- loop {
357
+
358
+ ' resolve_imports: loop {
361
359
if self . resolve_imports ( ) == ReachedFixedPoint :: Yes {
362
- break ;
360
+ break ' resolve_imports ;
363
361
}
364
362
}
365
363
}
366
364
if self . resolve_macros ( ) == ReachedFixedPoint :: Yes {
367
- break ;
365
+ break ' resolve_macros ;
368
366
}
369
367
370
368
i += 1 ;
371
369
if FIXED_POINT_LIMIT . check ( i) . is_err ( ) {
372
370
tracing:: error!( "name resolution is stuck" ) ;
373
- break ' outer ;
371
+ break ' resolve_attr ;
374
372
}
375
373
}
376
374
377
375
if self . reseed_with_unresolved_attribute ( ) == ReachedFixedPoint :: Yes {
378
- break ;
376
+ break ' resolve_attr ;
379
377
}
380
378
}
381
379
}
@@ -389,14 +387,9 @@ impl DefCollector<'_> {
389
387
// As some of the macros will expand newly import shadowing partial resolved imports
390
388
// FIXME: We maybe could skip this, if we handle the indeterminate imports in `resolve_imports`
391
389
// correctly
392
- let partial_resolved = self . resolved_imports . iter ( ) . filter_map ( |directive| {
393
- if let PartialResolvedImport :: Indeterminate ( _) = directive. status {
394
- let mut directive = directive. clone ( ) ;
395
- directive. status = PartialResolvedImport :: Unresolved ;
396
- Some ( directive)
397
- } else {
398
- None
399
- }
390
+ let partial_resolved = self . indeterminate_imports . drain ( ..) . filter_map ( |mut directive| {
391
+ directive. status = PartialResolvedImport :: Unresolved ;
392
+ Some ( directive)
400
393
} ) ;
401
394
self . unresolved_imports . extend ( partial_resolved) ;
402
395
self . resolve_imports ( ) ;
@@ -717,15 +710,12 @@ impl DefCollector<'_> {
717
710
match directive. status {
718
711
PartialResolvedImport :: Indeterminate ( _) => {
719
712
self . record_resolved_import ( & directive) ;
720
- // FIXME: For avoid performance regression,
721
- // we consider an imported resolved if it is indeterminate (i.e not all namespace resolved)
722
- self . resolved_imports . push ( directive) ;
713
+ self . indeterminate_imports . push ( directive) ;
723
714
res = ReachedFixedPoint :: No ;
724
715
None
725
716
}
726
717
PartialResolvedImport :: Resolved ( _) => {
727
718
self . record_resolved_import ( & directive) ;
728
- self . resolved_imports . push ( directive) ;
729
719
res = ReachedFixedPoint :: No ;
730
720
None
731
721
}
@@ -2102,7 +2092,7 @@ mod tests {
2102
2092
deps : FxHashMap :: default ( ) ,
2103
2093
glob_imports : FxHashMap :: default ( ) ,
2104
2094
unresolved_imports : Vec :: new ( ) ,
2105
- resolved_imports : Vec :: new ( ) ,
2095
+ indeterminate_imports : Vec :: new ( ) ,
2106
2096
unresolved_macros : Vec :: new ( ) ,
2107
2097
mod_dirs : FxHashMap :: default ( ) ,
2108
2098
cfg_options : & CfgOptions :: default ( ) ,
0 commit comments