@@ -29,7 +29,6 @@ use crate::{
2929 attr_macro_as_call_id,
3030 db:: DefDatabase ,
3131 derive_macro_as_call_id,
32- intern:: Interned ,
3332 item_scope:: { ImportType , PerNsGlobImports } ,
3433 item_tree:: {
3534 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
9695 deps,
9796 glob_imports : FxHashMap :: default ( ) ,
9897 unresolved_imports : Vec :: new ( ) ,
99- resolved_imports : Vec :: new ( ) ,
98+ indeterminate_imports : Vec :: new ( ) ,
10099 unresolved_macros : Vec :: new ( ) ,
101100 mod_dirs : FxHashMap :: default ( ) ,
102101 cfg_options,
@@ -142,9 +141,9 @@ enum ImportSource {
142141 ExternCrate ( ItemTreeId < item_tree:: ExternCrate > ) ,
143142}
144143
145- #[ derive( Clone , Debug , Eq , PartialEq ) ]
144+ #[ derive( Debug , Eq , PartialEq ) ]
146145struct Import {
147- path : Interned < ModPath > ,
146+ path : ModPath ,
148147 alias : Option < ImportAlias > ,
149148 visibility : RawVisibility ,
150149 kind : ImportKind ,
@@ -169,7 +168,7 @@ impl Import {
169168 let mut res = Vec :: new ( ) ;
170169 it. use_tree . expand ( |idx, path, kind, alias| {
171170 res. push ( Self {
172- path : Interned :: new ( path ) , // FIXME this makes little sense
171+ path,
173172 alias,
174173 visibility : visibility. clone ( ) ,
175174 kind,
@@ -192,10 +191,7 @@ impl Import {
192191 let attrs = & tree. attrs ( db, krate, ModItem :: from ( id. value ) . into ( ) ) ;
193192 let visibility = & tree[ it. visibility ] ;
194193 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 ( ) ) ) ,
199195 alias : it. alias . clone ( ) ,
200196 visibility : visibility. clone ( ) ,
201197 kind : ImportKind :: Plain ,
@@ -207,7 +203,7 @@ impl Import {
207203 }
208204}
209205
210- #[ derive( Clone , Debug , Eq , PartialEq ) ]
206+ #[ derive( Debug , Eq , PartialEq ) ]
211207struct ImportDirective {
212208 module_id : LocalModuleId ,
213209 import : Import ,
@@ -236,7 +232,7 @@ struct DefCollector<'a> {
236232 deps : FxHashMap < Name , ModuleId > ,
237233 glob_imports : FxHashMap < LocalModuleId , Vec < ( LocalModuleId , Visibility ) > > ,
238234 unresolved_imports : Vec < ImportDirective > ,
239- resolved_imports : Vec < ImportDirective > ,
235+ indeterminate_imports : Vec < ImportDirective > ,
240236 unresolved_macros : Vec < MacroDirective > ,
241237 mod_dirs : FxHashMap < LocalModuleId , ModDir > ,
242238 cfg_options : & ' a CfgOptions ,
@@ -352,30 +348,32 @@ impl DefCollector<'_> {
352348
353349 // main name resolution fixed-point loop.
354350 let mut i = 0 ;
355- ' outer : loop {
356- loop {
351+ ' resolve_attr : loop {
352+ ' resolve_macros : loop {
357353 self . db . unwind_if_cancelled ( ) ;
354+
358355 {
359356 let _p = profile:: span ( "resolve_imports loop" ) ;
360- loop {
357+
358+ ' resolve_imports: loop {
361359 if self . resolve_imports ( ) == ReachedFixedPoint :: Yes {
362- break ;
360+ break ' resolve_imports ;
363361 }
364362 }
365363 }
366364 if self . resolve_macros ( ) == ReachedFixedPoint :: Yes {
367- break ;
365+ break ' resolve_macros ;
368366 }
369367
370368 i += 1 ;
371369 if FIXED_POINT_LIMIT . check ( i) . is_err ( ) {
372370 tracing:: error!( "name resolution is stuck" ) ;
373- break ' outer ;
371+ break ' resolve_attr ;
374372 }
375373 }
376374
377375 if self . reseed_with_unresolved_attribute ( ) == ReachedFixedPoint :: Yes {
378- break ;
376+ break ' resolve_attr ;
379377 }
380378 }
381379 }
@@ -389,14 +387,9 @@ impl DefCollector<'_> {
389387 // As some of the macros will expand newly import shadowing partial resolved imports
390388 // FIXME: We maybe could skip this, if we handle the indeterminate imports in `resolve_imports`
391389 // 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)
400393 } ) ;
401394 self . unresolved_imports . extend ( partial_resolved) ;
402395 self . resolve_imports ( ) ;
@@ -717,15 +710,12 @@ impl DefCollector<'_> {
717710 match directive. status {
718711 PartialResolvedImport :: Indeterminate ( _) => {
719712 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) ;
723714 res = ReachedFixedPoint :: No ;
724715 None
725716 }
726717 PartialResolvedImport :: Resolved ( _) => {
727718 self . record_resolved_import ( & directive) ;
728- self . resolved_imports . push ( directive) ;
729719 res = ReachedFixedPoint :: No ;
730720 None
731721 }
@@ -2102,7 +2092,7 @@ mod tests {
21022092 deps : FxHashMap :: default ( ) ,
21032093 glob_imports : FxHashMap :: default ( ) ,
21042094 unresolved_imports : Vec :: new ( ) ,
2105- resolved_imports : Vec :: new ( ) ,
2095+ indeterminate_imports : Vec :: new ( ) ,
21062096 unresolved_macros : Vec :: new ( ) ,
21072097 mod_dirs : FxHashMap :: default ( ) ,
21082098 cfg_options : & CfgOptions :: default ( ) ,
0 commit comments