diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-24 13:16:17 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-24 13:16:17 +0100 |
commit | 0e5095d3cac11d4b569c6e1594bd07937556c812 (patch) | |
tree | 0f7f092a20440cf912a70114ea352152dd5c6b5b /crates/ra_hir/src | |
parent | 5febf27110460a1a554bd5c33aa35e2948f7688e (diff) | |
parent | a432f87d66bdfb8e9eef4f6d38d3d5efc2488c1f (diff) |
Merge #5519
5519: Cache macro expansion in semantics r=matklad a=matklad
#5497 accidentally made syntax highlighting quadratic, due to
repeated tokentreeizing of macros.
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/semantics.rs | 16 |
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> { | |||
89 | pub struct SemanticsImpl<'db> { | 89 | pub 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 | ||
276 | impl<'db> SemanticsImpl<'db> { | 277 | impl<'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(¯o_call))?; | 336 | let file_id = sa.expand(self.db, token.with_value(¯o_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 | ||