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_ty/src/db.rs | 1 - crates/ra_hir_ty/src/lower.rs | 2 +- crates/ra_hir_ty/src/test_db.rs | 31 ++++++++++++++----------------- crates/ra_hir_ty/src/tests.rs | 4 ++-- crates/ra_hir_ty/src/traits/chalk/tls.rs | 2 +- 5 files changed, 18 insertions(+), 22 deletions(-) (limited to 'crates/ra_hir_ty') diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index dc06c0ee7..84afe0484 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs @@ -19,7 +19,6 @@ use crate::{ use hir_expand::name::Name; #[salsa::query_group(HirDatabaseStorage)] -#[salsa::requires(salsa::Database)] pub trait HirDatabase: DefDatabase + Upcast { #[salsa::invoke(infer_wait)] #[salsa::transparent] diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index 3dc154e92..0fa0f7908 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs @@ -1216,7 +1216,7 @@ pub(crate) fn impl_trait_query(db: &dyn HirDatabase, impl_id: ImplId) -> Option< } pub(crate) fn return_type_impl_traits( - db: &impl HirDatabase, + db: &dyn HirDatabase, def: hir_def::FunctionId, ) -> Option>> { // FIXME unify with fn_sig_for_fn instead of doing lowering twice, maybe diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs index fddf0604d..dc447955f 100644 --- a/crates/ra_hir_ty/src/test_db.rs +++ b/crates/ra_hir_ty/src/test_db.rs @@ -1,7 +1,7 @@ //! Database used for testing `hir`. use std::{ - panic, + fmt, panic, sync::{Arc, Mutex}, }; @@ -26,10 +26,15 @@ use crate::{ hir_def::db::DefDatabaseStorage, crate::db::HirDatabaseStorage )] -#[derive(Debug, Default)] +#[derive(Default)] pub struct TestDB { - events: Mutex>>>, - runtime: salsa::Runtime, + storage: salsa::Storage, + events: Mutex>>, +} +impl fmt::Debug for TestDB { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("TestDB").finish() + } } impl Upcast for TestDB { @@ -45,18 +50,10 @@ 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); } } } @@ -64,8 +61,8 @@ impl salsa::Database for TestDB { impl salsa::ParallelDatabase for TestDB { fn snapshot(&self) -> salsa::Snapshot { salsa::Snapshot::new(TestDB { + storage: self.storage.snapshot(), events: Default::default(), - runtime: self.runtime.snapshot(self), }) } } @@ -182,7 +179,7 @@ impl TestDB { } impl TestDB { - 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() @@ -196,7 +193,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, }) diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index eeac34d14..69f2d7667 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs @@ -21,7 +21,7 @@ use hir_def::{ }; use hir_expand::{db::AstDatabase, InFile}; use insta::assert_snapshot; -use ra_db::{fixture::WithFixture, salsa::Database, FileRange, SourceDatabase}; +use ra_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt}; use ra_syntax::{ algo, ast::{self, AstNode}, @@ -317,7 +317,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() { " .to_string(); - db.query_mut(ra_db::FileTextQuery).set(pos.file_id, Arc::new(new_text)); + db.set_file_text(pos.file_id, Arc::new(new_text)); { let events = db.log_executed(|| { diff --git a/crates/ra_hir_ty/src/traits/chalk/tls.rs b/crates/ra_hir_ty/src/traits/chalk/tls.rs index 556af7098..e6a9d3211 100644 --- a/crates/ra_hir_ty/src/traits/chalk/tls.rs +++ b/crates/ra_hir_ty/src/traits/chalk/tls.rs @@ -10,7 +10,7 @@ use hir_def::{AdtId, AssocContainerId, DefWithBodyId, Lookup, TypeAliasId}; pub use unsafe_tls::{set_current_program, with_current_program}; -pub struct DebugContext<'a>(&'a (dyn HirDatabase + 'a)); +pub struct DebugContext<'a>(&'a dyn HirDatabase); impl DebugContext<'_> { pub fn debug_struct_id( -- cgit v1.2.3