internal: Remove allocation in DefCollector::reseed_with_unresolved_attribute
This commit is contained in:
parent
5af3ef527c
commit
25090f0e6d
@ -270,9 +270,10 @@ macro_rules! check_changed {
|
||||
$glob_imports:ident [ $lookup:ident ],
|
||||
$def_import_type:ident
|
||||
) => {{
|
||||
if let Some(fld) = $def.$field {
|
||||
let existing = $this.$field.entry($lookup.1.clone());
|
||||
match (existing, $def.$field) {
|
||||
(Entry::Vacant(entry), Some(_)) => {
|
||||
match existing {
|
||||
Entry::Vacant(entry) => {
|
||||
match $def_import_type {
|
||||
ImportType::Glob => {
|
||||
$glob_imports.$field.insert($lookup.clone());
|
||||
@ -282,24 +283,21 @@ macro_rules! check_changed {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(fld) = $def.$field {
|
||||
entry.insert(fld);
|
||||
}
|
||||
$changed = true;
|
||||
}
|
||||
(Entry::Occupied(mut entry), Some(_))
|
||||
Entry::Occupied(mut entry)
|
||||
if $glob_imports.$field.contains(&$lookup)
|
||||
&& matches!($def_import_type, ImportType::Named) =>
|
||||
{
|
||||
cov_mark::hit!(import_shadowed);
|
||||
$glob_imports.$field.remove(&$lookup);
|
||||
if let Some(fld) = $def.$field {
|
||||
entry.insert(fld);
|
||||
}
|
||||
$changed = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
|
@ -395,9 +395,8 @@ fn collect(&mut self) {
|
||||
// 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`
|
||||
// correctly
|
||||
let partial_resolved = self.indeterminate_imports.drain(..).filter_map(|mut directive| {
|
||||
directive.status = PartialResolvedImport::Unresolved;
|
||||
Some(directive)
|
||||
let partial_resolved = self.indeterminate_imports.drain(..).map(|directive| {
|
||||
ImportDirective { status: PartialResolvedImport::Unresolved, ..directive }
|
||||
});
|
||||
self.unresolved_imports.extend(partial_resolved);
|
||||
self.resolve_imports();
|
||||
@ -434,9 +433,11 @@ fn collect(&mut self) {
|
||||
fn reseed_with_unresolved_attribute(&mut self) -> ReachedFixedPoint {
|
||||
cov_mark::hit!(unresolved_attribute_fallback);
|
||||
|
||||
let mut unresolved_macros = mem::take(&mut self.unresolved_macros);
|
||||
let pos = unresolved_macros.iter().position(|directive| {
|
||||
if let MacroDirectiveKind::Attr { ast_id, mod_item, attr, tree } = &directive.kind {
|
||||
let unresolved_attr =
|
||||
self.unresolved_macros.iter().enumerate().find_map(|(idx, directive)| match &directive
|
||||
.kind
|
||||
{
|
||||
MacroDirectiveKind::Attr { ast_id, mod_item, attr, tree } => {
|
||||
self.def_map.diagnostics.push(DefDiagnostic::unresolved_macro_call(
|
||||
directive.module_id,
|
||||
MacroCallKind::Attr {
|
||||
@ -450,34 +451,30 @@ fn reseed_with_unresolved_attribute(&mut self) -> ReachedFixedPoint {
|
||||
|
||||
self.skip_attrs.insert(ast_id.ast_id.with_value(*mod_item), attr.id);
|
||||
|
||||
let item_tree = tree.item_tree(self.db);
|
||||
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
|
||||
Some((idx, directive, *mod_item, *tree))
|
||||
}
|
||||
_ => None,
|
||||
});
|
||||
|
||||
if let Some(pos) = pos {
|
||||
unresolved_macros.swap_remove(pos);
|
||||
match unresolved_attr {
|
||||
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);
|
||||
|
||||
if pos.is_some() {
|
||||
self.unresolved_macros.swap_remove(pos);
|
||||
// Continue name resolution with the new data.
|
||||
ReachedFixedPoint::No
|
||||
} else {
|
||||
ReachedFixedPoint::Yes
|
||||
}
|
||||
None => ReachedFixedPoint::Yes,
|
||||
}
|
||||
}
|
||||
|
||||
@ -722,7 +719,8 @@ fn import_all_macros_exported(&mut self, current_module_id: LocalModuleId, krate
|
||||
fn resolve_imports(&mut self) -> ReachedFixedPoint {
|
||||
let mut res = ReachedFixedPoint::Yes;
|
||||
let imports = mem::take(&mut self.unresolved_imports);
|
||||
let imports = imports
|
||||
|
||||
self.unresolved_imports = imports
|
||||
.into_iter()
|
||||
.filter_map(|mut directive| {
|
||||
directive.status = self.resolve_import(directive.module_id, &directive.import);
|
||||
@ -742,7 +740,6 @@ fn resolve_imports(&mut self) -> ReachedFixedPoint {
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
self.unresolved_imports = imports;
|
||||
res
|
||||
}
|
||||
|
||||
@ -1034,7 +1031,7 @@ fn update_recursive(
|
||||
.glob_imports
|
||||
.get(&module_id)
|
||||
.into_iter()
|
||||
.flat_map(|v| v.iter())
|
||||
.flatten()
|
||||
.filter(|(glob_importing_module, _)| {
|
||||
// we know all resolutions have the same visibility (`vis`), so we
|
||||
// just need to check that once
|
||||
|
Loading…
Reference in New Issue
Block a user