mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Auto merge of #12772 - Veykril:nameres, r=Veykril
internal: Remove allocation in DefCollector::reseed_with_unresolved_attribute
This commit is contained in:
commit
d3796adeaa
2 changed files with 60 additions and 65 deletions
|
@ -270,9 +270,10 @@ impl ItemScope {
|
||||||
$glob_imports:ident [ $lookup:ident ],
|
$glob_imports:ident [ $lookup:ident ],
|
||||||
$def_import_type:ident
|
$def_import_type:ident
|
||||||
) => {{
|
) => {{
|
||||||
|
if let Some(fld) = $def.$field {
|
||||||
let existing = $this.$field.entry($lookup.1.clone());
|
let existing = $this.$field.entry($lookup.1.clone());
|
||||||
match (existing, $def.$field) {
|
match existing {
|
||||||
(Entry::Vacant(entry), Some(_)) => {
|
Entry::Vacant(entry) => {
|
||||||
match $def_import_type {
|
match $def_import_type {
|
||||||
ImportType::Glob => {
|
ImportType::Glob => {
|
||||||
$glob_imports.$field.insert($lookup.clone());
|
$glob_imports.$field.insert($lookup.clone());
|
||||||
|
@ -282,24 +283,21 @@ impl ItemScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(fld) = $def.$field {
|
|
||||||
entry.insert(fld);
|
entry.insert(fld);
|
||||||
}
|
|
||||||
$changed = true;
|
$changed = true;
|
||||||
}
|
}
|
||||||
(Entry::Occupied(mut entry), Some(_))
|
Entry::Occupied(mut entry)
|
||||||
if $glob_imports.$field.contains(&$lookup)
|
if $glob_imports.$field.contains(&$lookup)
|
||||||
&& matches!($def_import_type, ImportType::Named) =>
|
&& matches!($def_import_type, ImportType::Named) =>
|
||||||
{
|
{
|
||||||
cov_mark::hit!(import_shadowed);
|
cov_mark::hit!(import_shadowed);
|
||||||
$glob_imports.$field.remove(&$lookup);
|
$glob_imports.$field.remove(&$lookup);
|
||||||
if let Some(fld) = $def.$field {
|
|
||||||
entry.insert(fld);
|
entry.insert(fld);
|
||||||
}
|
|
||||||
$changed = true;
|
$changed = true;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -395,9 +395,8 @@ 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.indeterminate_imports.drain(..).filter_map(|mut directive| {
|
let partial_resolved = self.indeterminate_imports.drain(..).map(|directive| {
|
||||||
directive.status = PartialResolvedImport::Unresolved;
|
ImportDirective { status: PartialResolvedImport::Unresolved, ..directive }
|
||||||
Some(directive)
|
|
||||||
});
|
});
|
||||||
self.unresolved_imports.extend(partial_resolved);
|
self.unresolved_imports.extend(partial_resolved);
|
||||||
self.resolve_imports();
|
self.resolve_imports();
|
||||||
|
@ -434,9 +433,11 @@ impl DefCollector<'_> {
|
||||||
fn reseed_with_unresolved_attribute(&mut self) -> ReachedFixedPoint {
|
fn reseed_with_unresolved_attribute(&mut self) -> ReachedFixedPoint {
|
||||||
cov_mark::hit!(unresolved_attribute_fallback);
|
cov_mark::hit!(unresolved_attribute_fallback);
|
||||||
|
|
||||||
let mut unresolved_macros = mem::take(&mut self.unresolved_macros);
|
let unresolved_attr =
|
||||||
let pos = unresolved_macros.iter().position(|directive| {
|
self.unresolved_macros.iter().enumerate().find_map(|(idx, directive)| match &directive
|
||||||
if let MacroDirectiveKind::Attr { ast_id, mod_item, attr, tree } = &directive.kind {
|
.kind
|
||||||
|
{
|
||||||
|
MacroDirectiveKind::Attr { ast_id, mod_item, attr, tree } => {
|
||||||
self.def_map.diagnostics.push(DefDiagnostic::unresolved_macro_call(
|
self.def_map.diagnostics.push(DefDiagnostic::unresolved_macro_call(
|
||||||
directive.module_id,
|
directive.module_id,
|
||||||
MacroCallKind::Attr {
|
MacroCallKind::Attr {
|
||||||
|
@ -450,34 +451,30 @@ impl DefCollector<'_> {
|
||||||
|
|
||||||
self.skip_attrs.insert(ast_id.ast_id.with_value(*mod_item), attr.id);
|
self.skip_attrs.insert(ast_id.ast_id.with_value(*mod_item), attr.id);
|
||||||
|
|
||||||
let item_tree = tree.item_tree(self.db);
|
Some((idx, directive, *mod_item, *tree))
|
||||||
let mod_dir = self.mod_dirs[&directive.module_id].clone();
|
|
||||||
ModCollector {
|
|
||||||
def_collector: self,
|
|
||||||
macro_depth: directive.depth,
|
|
||||||
module_id: directive.module_id,
|
|
||||||
tree_id: *tree,
|
|
||||||
item_tree: &item_tree,
|
|
||||||
mod_dir,
|
|
||||||
}
|
|
||||||
.collect(&[*mod_item], directive.container);
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
_ => None,
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(pos) = pos {
|
match unresolved_attr {
|
||||||
unresolved_macros.swap_remove(pos);
|
Some((pos, &MacroDirective { module_id, depth, container, .. }, mod_item, tree_id)) => {
|
||||||
|
let item_tree = &tree_id.item_tree(self.db);
|
||||||
|
let mod_dir = self.mod_dirs[&module_id].clone();
|
||||||
|
ModCollector {
|
||||||
|
def_collector: self,
|
||||||
|
macro_depth: depth,
|
||||||
|
module_id,
|
||||||
|
tree_id,
|
||||||
|
item_tree,
|
||||||
|
mod_dir,
|
||||||
}
|
}
|
||||||
|
.collect(&[mod_item], container);
|
||||||
|
|
||||||
self.unresolved_macros.extend(unresolved_macros);
|
self.unresolved_macros.swap_remove(pos);
|
||||||
|
|
||||||
if pos.is_some() {
|
|
||||||
// Continue name resolution with the new data.
|
// Continue name resolution with the new data.
|
||||||
ReachedFixedPoint::No
|
ReachedFixedPoint::No
|
||||||
} else {
|
}
|
||||||
ReachedFixedPoint::Yes
|
None => ReachedFixedPoint::Yes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,7 +719,8 @@ impl DefCollector<'_> {
|
||||||
fn resolve_imports(&mut self) -> ReachedFixedPoint {
|
fn resolve_imports(&mut self) -> ReachedFixedPoint {
|
||||||
let mut res = ReachedFixedPoint::Yes;
|
let mut res = ReachedFixedPoint::Yes;
|
||||||
let imports = mem::take(&mut self.unresolved_imports);
|
let imports = mem::take(&mut self.unresolved_imports);
|
||||||
let imports = imports
|
|
||||||
|
self.unresolved_imports = imports
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|mut directive| {
|
.filter_map(|mut directive| {
|
||||||
directive.status = self.resolve_import(directive.module_id, &directive.import);
|
directive.status = self.resolve_import(directive.module_id, &directive.import);
|
||||||
|
@ -742,7 +740,6 @@ impl DefCollector<'_> {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
self.unresolved_imports = imports;
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1034,7 +1031,7 @@ impl DefCollector<'_> {
|
||||||
.glob_imports
|
.glob_imports
|
||||||
.get(&module_id)
|
.get(&module_id)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|v| v.iter())
|
.flatten()
|
||||||
.filter(|(glob_importing_module, _)| {
|
.filter(|(glob_importing_module, _)| {
|
||||||
// we know all resolutions have the same visibility (`vis`), so we
|
// we know all resolutions have the same visibility (`vis`), so we
|
||||||
// just need to check that once
|
// just need to check that once
|
||||||
|
|
Loading…
Reference in a new issue