aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-24 13:12:13 +0100
committerAleksey Kladov <[email protected]>2020-07-24 13:12:13 +0100
commita432f87d66bdfb8e9eef4f6d38d3d5efc2488c1f (patch)
tree0f7f092a20440cf912a70114ea352152dd5c6b5b /crates/ra_hir
parentb9ef6cf29518fb59d3a05b1d4b45999f08ad0aeb (diff)
Cache macro expansion in semantics
#5497 accidentally made syntax highlighting quadratic, due to repeated tokentreeizing of macros.
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/semantics.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 02d83e0d9..1436b1afe 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -89,6 +89,7 @@ pub struct Semantics<'db, DB> {
89pub struct SemanticsImpl<'db> { 89pub struct SemanticsImpl<'db> {
90 pub db: &'db dyn HirDatabase, 90 pub db: &'db dyn HirDatabase,
91 s2d_cache: RefCell<SourceToDefCache>, 91 s2d_cache: RefCell<SourceToDefCache>,
92 expansion_info_cache: RefCell<FxHashMap<HirFileId, Option<ExpansionInfo>>>,
92 cache: RefCell<FxHashMap<SyntaxNode, HirFileId>>, 93 cache: RefCell<FxHashMap<SyntaxNode, HirFileId>>,
93} 94}
94 95
@@ -275,7 +276,12 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
275 276
276impl<'db> SemanticsImpl<'db> { 277impl<'db> SemanticsImpl<'db> {
277 fn new(db: &'db dyn HirDatabase) -> Self { 278 fn new(db: &'db dyn HirDatabase) -> Self {
278 Self { db, s2d_cache: Default::default(), cache: Default::default() } 279 SemanticsImpl {
280 db,
281 s2d_cache: Default::default(),
282 cache: Default::default(),
283 expansion_info_cache: Default::default(),
284 }
279 } 285 }
280 286
281 fn parse(&self, file_id: FileId) -> ast::SourceFile { 287 fn parse(&self, file_id: FileId) -> ast::SourceFile {
@@ -328,7 +334,13 @@ impl<'db> SemanticsImpl<'db> {
328 return None; 334 return None;
329 } 335 }
330 let file_id = sa.expand(self.db, token.with_value(&macro_call))?; 336 let file_id = sa.expand(self.db, token.with_value(&macro_call))?;
331 let token = file_id.expansion_info(self.db.upcast())?.map_token_down(token.as_ref())?; 337 let token = self
338 .expansion_info_cache
339 .borrow_mut()
340 .entry(file_id)
341 .or_insert_with(|| file_id.expansion_info(self.db.upcast()))
342 .as_ref()?
343 .map_token_down(token.as_ref())?;
332 344
333 self.cache(find_root(&token.value.parent()), token.file_id); 345 self.cache(find_root(&token.value.parent()), token.file_id);
334 346