From d6c2a59538c83b6141f7ab9596a9fde64f94c116 Mon Sep 17 00:00:00 2001 From: Michal Terepeta Date: Fri, 3 Jan 2020 17:02:08 +0100 Subject: Split `infer` query into two for better profiling This is the same change as we did with `crate_def_map` and it does seem that we mostly spend time in salsa, without recomputing much on rust-analyzer side. Example output: ``` 233ms - handle_inlay_hints 163ms - get_inlay_hints 163ms - SourceAnalyzer::new 67ms - def_with_body_from_child_node 67ms - analyze_container 67ms - analyze_container 67ms - Module::from_definition 67ms - Module::from_file 67ms - crate_def_map 0ms - parse_macro_query (6 calls) 0ms - raw_items_query (1 calls) 66ms - ??? 0ms - crate_def_map (1 calls) 0ms - crate_def_map (1 calls) 96ms - infer 2ms - trait_solve_query (2 calls) 94ms - ??? 0ms - body_with_source_map_query (1 calls) 0ms - crate_def_map (1 calls) [...] ``` Signed-off-by: Michal Terepeta --- crates/ra_hir_ty/src/db.rs | 11 ++++++++++- crates/ra_hir_ty/src/infer.rs | 4 ++-- crates/ra_hir_ty/src/lib.rs | 2 +- 3 files changed, 13 insertions(+), 4 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 d52f65b83..eb521c7a0 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs @@ -7,6 +7,7 @@ use hir_def::{ }; use ra_arena::map::ArenaMap; use ra_db::{salsa, CrateId}; +use ra_prof::profile; use crate::{ method_resolution::CrateImplBlocks, @@ -18,9 +19,12 @@ use crate::{ #[salsa::query_group(HirDatabaseStorage)] #[salsa::requires(salsa::Database)] pub trait HirDatabase: DefDatabase { - #[salsa::invoke(crate::infer_query)] + #[salsa::transparent] fn infer(&self, def: DefWithBodyId) -> Arc; + #[salsa::invoke(crate::do_infer_query)] + fn do_infer(&self, def: DefWithBodyId) -> Arc; + #[salsa::invoke(crate::lower::ty_query)] #[salsa::cycle(crate::lower::ty_recover)] fn ty(&self, def: TyDefId) -> Ty; @@ -104,6 +108,11 @@ pub trait HirDatabase: DefDatabase { ) -> Option; } +fn infer(db: &impl HirDatabase, def: DefWithBodyId) -> Arc { + let _p = profile("infer"); + db.do_infer(def) +} + #[test] fn hir_database_is_object_safe() { fn _assert_object_safe(_: &dyn HirDatabase) {} diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 37e69599d..e2eda3134 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -62,8 +62,8 @@ mod pat; mod coerce; /// The entry point of type inference. -pub fn infer_query(db: &impl HirDatabase, def: DefWithBodyId) -> Arc { - let _p = profile("infer_query"); +pub fn do_infer_query(db: &impl HirDatabase, def: DefWithBodyId) -> Arc { + let _p = profile("do_infer"); let resolver = def.resolver(db); let mut ctx = InferenceContext::new(db, def, resolver); diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 55b6dd836..d63f862dc 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -58,7 +58,7 @@ use crate::{ use display::{HirDisplay, HirFormatter}; pub use autoderef::autoderef; -pub use infer::{infer_query, InferTy, InferenceResult}; +pub use infer::{do_infer_query, InferTy, InferenceResult}; pub use lower::CallableDef; pub use lower::{callable_item_sig, TyDefId, ValueTyDefId}; pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; -- cgit v1.2.3