aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-07 09:14:48 +0100
committerAleksey Kladov <[email protected]>2020-07-07 09:14:48 +0100
commit4bbc385277bcab509c321b1374f72f1ef19d7750 (patch)
tree74488258fb566dc4344165ade6067d8f2ce7298f /crates/ra_hir_def/src
parentd4bc2f25de6297c75f7b7f029df224b650ef3143 (diff)
Switch to fully dynamically dispatched salsa
This improves compile times quite a bit
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/data.rs2
-rw-r--r--crates/ra_hir_def/src/test_db.rs28
2 files changed, 15 insertions, 15 deletions
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index 282ade2a3..aa335f1e3 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -31,7 +31,7 @@ pub struct FunctionData {
31} 31}
32 32
33impl FunctionData { 33impl FunctionData {
34 pub(crate) fn fn_data_query(db: &impl DefDatabase, func: FunctionId) -> Arc<FunctionData> { 34 pub(crate) fn fn_data_query(db: &dyn DefDatabase, func: FunctionId) -> Arc<FunctionData> {
35 let loc = func.lookup(db); 35 let loc = func.lookup(db);
36 let item_tree = db.item_tree(loc.id.file_id); 36 let item_tree = db.item_tree(loc.id.file_id);
37 let func = &item_tree[loc.id.value]; 37 let func = &item_tree[loc.id.value];
diff --git a/crates/ra_hir_def/src/test_db.rs b/crates/ra_hir_def/src/test_db.rs
index 4581d8745..339f819b8 100644
--- a/crates/ra_hir_def/src/test_db.rs
+++ b/crates/ra_hir_def/src/test_db.rs
@@ -1,7 +1,7 @@
1//! Database used for testing `hir_def`. 1//! Database used for testing `hir_def`.
2 2
3use std::{ 3use std::{
4 panic, 4 fmt, panic,
5 sync::{Arc, Mutex}, 5 sync::{Arc, Mutex},
6}; 6};
7 7
@@ -18,10 +18,10 @@ use crate::db::DefDatabase;
18 crate::db::InternDatabaseStorage, 18 crate::db::InternDatabaseStorage,
19 crate::db::DefDatabaseStorage 19 crate::db::DefDatabaseStorage
20)] 20)]
21#[derive(Debug, Default)] 21#[derive(Default)]
22pub struct TestDB { 22pub struct TestDB {
23 runtime: salsa::Runtime<TestDB>, 23 storage: salsa::Storage<TestDB>,
24 events: Mutex<Option<Vec<salsa::Event<TestDB>>>>, 24 events: Mutex<Option<Vec<salsa::Event>>>,
25} 25}
26 26
27impl Upcast<dyn AstDatabase> for TestDB { 27impl Upcast<dyn AstDatabase> for TestDB {
@@ -37,20 +37,20 @@ impl Upcast<dyn DefDatabase> for TestDB {
37} 37}
38 38
39impl salsa::Database for TestDB { 39impl salsa::Database for TestDB {
40 fn salsa_runtime(&self) -> &salsa::Runtime<Self> { 40 fn salsa_event(&self, event: salsa::Event) {
41 &self.runtime
42 }
43 fn salsa_runtime_mut(&mut self) -> &mut salsa::Runtime<Self> {
44 &mut self.runtime
45 }
46 fn salsa_event(&self, event: impl Fn() -> salsa::Event<TestDB>) {
47 let mut events = self.events.lock().unwrap(); 41 let mut events = self.events.lock().unwrap();
48 if let Some(events) = &mut *events { 42 if let Some(events) = &mut *events {
49 events.push(event()); 43 events.push(event);
50 } 44 }
51 } 45 }
52} 46}
53 47
48impl fmt::Debug for TestDB {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 f.debug_struct("TestDB").finish()
51 }
52}
53
54impl panic::RefUnwindSafe for TestDB {} 54impl panic::RefUnwindSafe for TestDB {}
55 55
56impl FileLoader for TestDB { 56impl FileLoader for TestDB {
@@ -78,7 +78,7 @@ impl TestDB {
78 panic!("Can't find module for file") 78 panic!("Can't find module for file")
79 } 79 }
80 80
81 pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<TestDB>> { 81 pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event> {
82 *self.events.lock().unwrap() = Some(Vec::new()); 82 *self.events.lock().unwrap() = Some(Vec::new());
83 f(); 83 f();
84 self.events.lock().unwrap().take().unwrap() 84 self.events.lock().unwrap().take().unwrap()
@@ -92,7 +92,7 @@ impl TestDB {
92 // This pretty horrible, but `Debug` is the only way to inspect 92 // This pretty horrible, but `Debug` is the only way to inspect
93 // QueryDescriptor at the moment. 93 // QueryDescriptor at the moment.
94 salsa::EventKind::WillExecute { database_key } => { 94 salsa::EventKind::WillExecute { database_key } => {
95 Some(format!("{:?}", database_key)) 95 Some(format!("{:?}", database_key.debug(self)))
96 } 96 }
97 _ => None, 97 _ => None,
98 }) 98 })