diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-07 09:15:40 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-07 09:15:40 +0100 |
commit | 7a8597bc20292f81bd8dce8b5ec09aababee4a7d (patch) | |
tree | 74488258fb566dc4344165ade6067d8f2ce7298f /crates/ra_ide_db/src/lib.rs | |
parent | d4bc2f25de6297c75f7b7f029df224b650ef3143 (diff) | |
parent | 4bbc385277bcab509c321b1374f72f1ef19d7750 (diff) |
Merge #5242
5242: Switch to fully dynamically dispatched salsa r=matklad a=matklad
This improves compile times quite a bit
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_db/src/lib.rs')
-rw-r--r-- | crates/ra_ide_db/src/lib.rs | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index c78071ad6..6900cac73 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -11,11 +11,11 @@ pub mod imports_locator; | |||
11 | pub mod source_change; | 11 | pub mod source_change; |
12 | mod wasm_shims; | 12 | mod wasm_shims; |
13 | 13 | ||
14 | use std::sync::Arc; | 14 | use std::{fmt, sync::Arc}; |
15 | 15 | ||
16 | use hir::db::{AstDatabase, DefDatabase, HirDatabase}; | 16 | use hir::db::{AstDatabase, DefDatabase, HirDatabase}; |
17 | use ra_db::{ | 17 | use ra_db::{ |
18 | salsa::{self, Database, Durability}, | 18 | salsa::{self, Durability}, |
19 | Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, | 19 | Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, |
20 | Upcast, | 20 | Upcast, |
21 | }; | 21 | }; |
@@ -33,13 +33,18 @@ use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase}; | |||
33 | hir::db::DefDatabaseStorage, | 33 | hir::db::DefDatabaseStorage, |
34 | hir::db::HirDatabaseStorage | 34 | hir::db::HirDatabaseStorage |
35 | )] | 35 | )] |
36 | #[derive(Debug)] | ||
37 | pub struct RootDatabase { | 36 | pub struct RootDatabase { |
38 | runtime: salsa::Runtime<RootDatabase>, | 37 | storage: salsa::Storage<RootDatabase>, |
39 | pub last_gc: crate::wasm_shims::Instant, | 38 | pub last_gc: crate::wasm_shims::Instant, |
40 | pub last_gc_check: crate::wasm_shims::Instant, | 39 | pub last_gc_check: crate::wasm_shims::Instant, |
41 | } | 40 | } |
42 | 41 | ||
42 | impl fmt::Debug for RootDatabase { | ||
43 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
44 | f.debug_struct("RootDatabase").finish() | ||
45 | } | ||
46 | } | ||
47 | |||
43 | impl Upcast<dyn AstDatabase> for RootDatabase { | 48 | impl Upcast<dyn AstDatabase> for RootDatabase { |
44 | fn upcast(&self) -> &(dyn AstDatabase + 'static) { | 49 | fn upcast(&self) -> &(dyn AstDatabase + 'static) { |
45 | &*self | 50 | &*self |
@@ -71,17 +76,11 @@ impl FileLoader for RootDatabase { | |||
71 | } | 76 | } |
72 | 77 | ||
73 | impl salsa::Database for RootDatabase { | 78 | impl salsa::Database for RootDatabase { |
74 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { | ||
75 | &self.runtime | ||
76 | } | ||
77 | fn salsa_runtime_mut(&mut self) -> &mut salsa::Runtime<Self> { | ||
78 | &mut self.runtime | ||
79 | } | ||
80 | fn on_propagated_panic(&self) -> ! { | 79 | fn on_propagated_panic(&self) -> ! { |
81 | Canceled::throw() | 80 | Canceled::throw() |
82 | } | 81 | } |
83 | fn salsa_event(&self, event: impl Fn() -> salsa::Event<RootDatabase>) { | 82 | fn salsa_event(&self, event: salsa::Event) { |
84 | match event().kind { | 83 | match event.kind { |
85 | salsa::EventKind::DidValidateMemoizedValue { .. } | 84 | salsa::EventKind::DidValidateMemoizedValue { .. } |
86 | | salsa::EventKind::WillExecute { .. } => { | 85 | | salsa::EventKind::WillExecute { .. } => { |
87 | self.check_canceled(); | 86 | self.check_canceled(); |
@@ -100,7 +99,7 @@ impl Default for RootDatabase { | |||
100 | impl RootDatabase { | 99 | impl RootDatabase { |
101 | pub fn new(lru_capacity: Option<usize>) -> RootDatabase { | 100 | pub fn new(lru_capacity: Option<usize>) -> RootDatabase { |
102 | let mut db = RootDatabase { | 101 | let mut db = RootDatabase { |
103 | runtime: salsa::Runtime::default(), | 102 | storage: salsa::Storage::default(), |
104 | last_gc: crate::wasm_shims::Instant::now(), | 103 | last_gc: crate::wasm_shims::Instant::now(), |
105 | last_gc_check: crate::wasm_shims::Instant::now(), | 104 | last_gc_check: crate::wasm_shims::Instant::now(), |
106 | }; | 105 | }; |
@@ -113,16 +112,16 @@ impl RootDatabase { | |||
113 | 112 | ||
114 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { | 113 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { |
115 | let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); | 114 | let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); |
116 | self.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity); | 115 | ra_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity); |
117 | self.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_capacity); | 116 | hir::db::ParseMacroQuery.in_db_mut(self).set_lru_capacity(lru_capacity); |
118 | self.query_mut(hir::db::MacroExpandQuery).set_lru_capacity(lru_capacity); | 117 | hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(lru_capacity); |
119 | } | 118 | } |
120 | } | 119 | } |
121 | 120 | ||
122 | impl salsa::ParallelDatabase for RootDatabase { | 121 | impl salsa::ParallelDatabase for RootDatabase { |
123 | fn snapshot(&self) -> salsa::Snapshot<RootDatabase> { | 122 | fn snapshot(&self) -> salsa::Snapshot<RootDatabase> { |
124 | salsa::Snapshot::new(RootDatabase { | 123 | salsa::Snapshot::new(RootDatabase { |
125 | runtime: self.runtime.snapshot(self), | 124 | storage: self.storage.snapshot(), |
126 | last_gc: self.last_gc, | 125 | last_gc: self.last_gc, |
127 | last_gc_check: self.last_gc_check, | 126 | last_gc_check: self.last_gc_check, |
128 | }) | 127 | }) |
@@ -134,7 +133,7 @@ pub trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled { | |||
134 | fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; | 133 | fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; |
135 | } | 134 | } |
136 | 135 | ||
137 | fn line_index(db: &impl LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> { | 136 | fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> { |
138 | let text = db.file_text(file_id); | 137 | let text = db.file_text(file_id); |
139 | Arc::new(LineIndex::new(&*text)) | 138 | Arc::new(LineIndex::new(&*text)) |
140 | } | 139 | } |