10703: internal: Don't check items for macro calls if they have no attributes r=Veykril a=Veykril

Turns out when highlighting we currently populate the Dynmaps of pretty much every item in a file, who would've known that would be so costly...
Shaves off 250 ms for the integrated benchmark on `rust-analyzer/src/config.rs`.

We are still looking at a heft `154ms - descend_into_macros (2190 calls)` but I feel like this is slowly nearing towards just call overhead.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-11-05 13:53:59 +00:00 committed by GitHub
commit 274d9f90ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
use smallvec::{smallvec, SmallVec};
use syntax::{
algo::skip_trivia_token,
ast::{self, HasGenericParams, HasLoopBody},
ast::{self, HasAttrs, HasGenericParams, HasLoopBody},
match_ast, AstNode, Direction, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize,
};
@ -588,7 +588,10 @@ impl<'db> SemanticsImpl<'db> {
// are we inside an attribute macro call
let containing_attribute_macro_call = self.with_ctx(|ctx| {
token.value.ancestors().filter_map(ast::Item::cast).find_map(|item| {
// investigate this, seems to be VERY(250ms) expensive in rust-analyzer/src/config.rs?
if item.attrs().next().is_none() {
// Don't force populate the dyn cache for items that don't have an attribute anyways
return None;
}
Some((ctx.item_to_macro_call(token.with_value(item.clone()))?, item))
})
});