From 4bbc385277bcab509c321b1374f72f1ef19d7750 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 7 Jul 2020 10:14:48 +0200 Subject: Switch to fully dynamically dispatched salsa This improves compile times quite a bit --- crates/ra_hir_def/src/data.rs | 2 +- crates/ra_hir_def/src/test_db.rs | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir_def/src') 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 { } impl FunctionData { - pub(crate) fn fn_data_query(db: &impl DefDatabase, func: FunctionId) -> Arc { + pub(crate) fn fn_data_query(db: &dyn DefDatabase, func: FunctionId) -> Arc { let loc = func.lookup(db); let item_tree = db.item_tree(loc.id.file_id); 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 @@ //! Database used for testing `hir_def`. use std::{ - panic, + fmt, panic, sync::{Arc, Mutex}, }; @@ -18,10 +18,10 @@ use crate::db::DefDatabase; crate::db::InternDatabaseStorage, crate::db::DefDatabaseStorage )] -#[derive(Debug, Default)] +#[derive(Default)] pub struct TestDB { - runtime: salsa::Runtime, - events: Mutex>>>, + storage: salsa::Storage, + events: Mutex>>, } impl Upcast for TestDB { @@ -37,20 +37,20 @@ impl Upcast for TestDB { } impl salsa::Database for TestDB { - fn salsa_runtime(&self) -> &salsa::Runtime { - &self.runtime - } - fn salsa_runtime_mut(&mut self) -> &mut salsa::Runtime { - &mut self.runtime - } - fn salsa_event(&self, event: impl Fn() -> salsa::Event) { + fn salsa_event(&self, event: salsa::Event) { let mut events = self.events.lock().unwrap(); if let Some(events) = &mut *events { - events.push(event()); + events.push(event); } } } +impl fmt::Debug for TestDB { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("TestDB").finish() + } +} + impl panic::RefUnwindSafe for TestDB {} impl FileLoader for TestDB { @@ -78,7 +78,7 @@ impl TestDB { panic!("Can't find module for file") } - pub fn log(&self, f: impl FnOnce()) -> Vec> { + pub fn log(&self, f: impl FnOnce()) -> Vec { *self.events.lock().unwrap() = Some(Vec::new()); f(); self.events.lock().unwrap().take().unwrap() @@ -92,7 +92,7 @@ impl TestDB { // This pretty horrible, but `Debug` is the only way to inspect // QueryDescriptor at the moment. salsa::EventKind::WillExecute { database_key } => { - Some(format!("{:?}", database_key)) + Some(format!("{:?}", database_key.debug(self))) } _ => None, }) -- cgit v1.2.3