mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-08 07:57:40 +00:00
internal: Remove Interned
usage from nameres collector
This commit is contained in:
parent
02c2377229
commit
7913ae69b9
@ -29,7 +29,6 @@ use crate::{
|
|||||||
attr_macro_as_call_id,
|
attr_macro_as_call_id,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
derive_macro_as_call_id,
|
derive_macro_as_call_id,
|
||||||
intern::Interned,
|
|
||||||
item_scope::{ImportType, PerNsGlobImports},
|
item_scope::{ImportType, PerNsGlobImports},
|
||||||
item_tree::{
|
item_tree::{
|
||||||
self, Fields, FileItemTreeId, ImportKind, ItemTree, ItemTreeId, ItemTreeNode, MacroCall,
|
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
|
|||||||
deps,
|
deps,
|
||||||
glob_imports: FxHashMap::default(),
|
glob_imports: FxHashMap::default(),
|
||||||
unresolved_imports: Vec::new(),
|
unresolved_imports: Vec::new(),
|
||||||
resolved_imports: Vec::new(),
|
indeterminate_imports: Vec::new(),
|
||||||
unresolved_macros: Vec::new(),
|
unresolved_macros: Vec::new(),
|
||||||
mod_dirs: FxHashMap::default(),
|
mod_dirs: FxHashMap::default(),
|
||||||
cfg_options,
|
cfg_options,
|
||||||
@ -142,9 +141,9 @@ enum ImportSource {
|
|||||||
ExternCrate(ItemTreeId<item_tree::ExternCrate>),
|
ExternCrate(ItemTreeId<item_tree::ExternCrate>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
struct Import {
|
struct Import {
|
||||||
path: Interned<ModPath>,
|
path: ModPath,
|
||||||
alias: Option<ImportAlias>,
|
alias: Option<ImportAlias>,
|
||||||
visibility: RawVisibility,
|
visibility: RawVisibility,
|
||||||
kind: ImportKind,
|
kind: ImportKind,
|
||||||
@ -169,7 +168,7 @@ impl Import {
|
|||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
it.use_tree.expand(|idx, path, kind, alias| {
|
it.use_tree.expand(|idx, path, kind, alias| {
|
||||||
res.push(Self {
|
res.push(Self {
|
||||||
path: Interned::new(path), // FIXME this makes little sense
|
path,
|
||||||
alias,
|
alias,
|
||||||
visibility: visibility.clone(),
|
visibility: visibility.clone(),
|
||||||
kind,
|
kind,
|
||||||
@ -192,10 +191,7 @@ impl Import {
|
|||||||
let attrs = &tree.attrs(db, krate, ModItem::from(id.value).into());
|
let attrs = &tree.attrs(db, krate, ModItem::from(id.value).into());
|
||||||
let visibility = &tree[it.visibility];
|
let visibility = &tree[it.visibility];
|
||||||
Self {
|
Self {
|
||||||
path: Interned::new(ModPath::from_segments(
|
path: ModPath::from_segments(PathKind::Plain, iter::once(it.name.clone())),
|
||||||
PathKind::Plain,
|
|
||||||
iter::once(it.name.clone()),
|
|
||||||
)),
|
|
||||||
alias: it.alias.clone(),
|
alias: it.alias.clone(),
|
||||||
visibility: visibility.clone(),
|
visibility: visibility.clone(),
|
||||||
kind: ImportKind::Plain,
|
kind: ImportKind::Plain,
|
||||||
@ -207,7 +203,7 @@ impl Import {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
struct ImportDirective {
|
struct ImportDirective {
|
||||||
module_id: LocalModuleId,
|
module_id: LocalModuleId,
|
||||||
import: Import,
|
import: Import,
|
||||||
@ -236,7 +232,7 @@ struct DefCollector<'a> {
|
|||||||
deps: FxHashMap<Name, ModuleId>,
|
deps: FxHashMap<Name, ModuleId>,
|
||||||
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>,
|
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>,
|
||||||
unresolved_imports: Vec<ImportDirective>,
|
unresolved_imports: Vec<ImportDirective>,
|
||||||
resolved_imports: Vec<ImportDirective>,
|
indeterminate_imports: Vec<ImportDirective>,
|
||||||
unresolved_macros: Vec<MacroDirective>,
|
unresolved_macros: Vec<MacroDirective>,
|
||||||
mod_dirs: FxHashMap<LocalModuleId, ModDir>,
|
mod_dirs: FxHashMap<LocalModuleId, ModDir>,
|
||||||
cfg_options: &'a CfgOptions,
|
cfg_options: &'a CfgOptions,
|
||||||
@ -352,30 +348,32 @@ impl DefCollector<'_> {
|
|||||||
|
|
||||||
// main name resolution fixed-point loop.
|
// main name resolution fixed-point loop.
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
'outer: loop {
|
'resolve_attr: loop {
|
||||||
loop {
|
'resolve_macros: loop {
|
||||||
self.db.unwind_if_cancelled();
|
self.db.unwind_if_cancelled();
|
||||||
|
|
||||||
{
|
{
|
||||||
let _p = profile::span("resolve_imports loop");
|
let _p = profile::span("resolve_imports loop");
|
||||||
loop {
|
|
||||||
|
'resolve_imports: loop {
|
||||||
if self.resolve_imports() == ReachedFixedPoint::Yes {
|
if self.resolve_imports() == ReachedFixedPoint::Yes {
|
||||||
break;
|
break 'resolve_imports;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.resolve_macros() == ReachedFixedPoint::Yes {
|
if self.resolve_macros() == ReachedFixedPoint::Yes {
|
||||||
break;
|
break 'resolve_macros;
|
||||||
}
|
}
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
if FIXED_POINT_LIMIT.check(i).is_err() {
|
if FIXED_POINT_LIMIT.check(i).is_err() {
|
||||||
tracing::error!("name resolution is stuck");
|
tracing::error!("name resolution is stuck");
|
||||||
break 'outer;
|
break 'resolve_attr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.reseed_with_unresolved_attribute() == ReachedFixedPoint::Yes {
|
if self.reseed_with_unresolved_attribute() == ReachedFixedPoint::Yes {
|
||||||
break;
|
break 'resolve_attr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -389,14 +387,9 @@ impl DefCollector<'_> {
|
|||||||
// As some of the macros will expand newly import shadowing partial resolved imports
|
// As some of the macros will expand newly import shadowing partial resolved imports
|
||||||
// FIXME: We maybe could skip this, if we handle the indeterminate imports in `resolve_imports`
|
// FIXME: We maybe could skip this, if we handle the indeterminate imports in `resolve_imports`
|
||||||
// correctly
|
// correctly
|
||||||
let partial_resolved = self.resolved_imports.iter().filter_map(|directive| {
|
let partial_resolved = self.indeterminate_imports.drain(..).filter_map(|mut directive| {
|
||||||
if let PartialResolvedImport::Indeterminate(_) = directive.status {
|
directive.status = PartialResolvedImport::Unresolved;
|
||||||
let mut directive = directive.clone();
|
Some(directive)
|
||||||
directive.status = PartialResolvedImport::Unresolved;
|
|
||||||
Some(directive)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
self.unresolved_imports.extend(partial_resolved);
|
self.unresolved_imports.extend(partial_resolved);
|
||||||
self.resolve_imports();
|
self.resolve_imports();
|
||||||
@ -717,15 +710,12 @@ impl DefCollector<'_> {
|
|||||||
match directive.status {
|
match directive.status {
|
||||||
PartialResolvedImport::Indeterminate(_) => {
|
PartialResolvedImport::Indeterminate(_) => {
|
||||||
self.record_resolved_import(&directive);
|
self.record_resolved_import(&directive);
|
||||||
// FIXME: For avoid performance regression,
|
self.indeterminate_imports.push(directive);
|
||||||
// we consider an imported resolved if it is indeterminate (i.e not all namespace resolved)
|
|
||||||
self.resolved_imports.push(directive);
|
|
||||||
res = ReachedFixedPoint::No;
|
res = ReachedFixedPoint::No;
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
PartialResolvedImport::Resolved(_) => {
|
PartialResolvedImport::Resolved(_) => {
|
||||||
self.record_resolved_import(&directive);
|
self.record_resolved_import(&directive);
|
||||||
self.resolved_imports.push(directive);
|
|
||||||
res = ReachedFixedPoint::No;
|
res = ReachedFixedPoint::No;
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -2102,7 +2092,7 @@ mod tests {
|
|||||||
deps: FxHashMap::default(),
|
deps: FxHashMap::default(),
|
||||||
glob_imports: FxHashMap::default(),
|
glob_imports: FxHashMap::default(),
|
||||||
unresolved_imports: Vec::new(),
|
unresolved_imports: Vec::new(),
|
||||||
resolved_imports: Vec::new(),
|
indeterminate_imports: Vec::new(),
|
||||||
unresolved_macros: Vec::new(),
|
unresolved_macros: Vec::new(),
|
||||||
mod_dirs: FxHashMap::default(),
|
mod_dirs: FxHashMap::default(),
|
||||||
cfg_options: &CfgOptions::default(),
|
cfg_options: &CfgOptions::default(),
|
||||||
|
Loading…
Reference in New Issue
Block a user