mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 15:14:32 +00:00
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 <michal.terepeta@gmail.com>
This commit is contained in:
parent
15d94cbffc
commit
d6c2a59538
5 changed files with 19 additions and 10 deletions
|
@ -12,10 +12,10 @@ pub use hir_expand::db::{
|
|||
ParseMacroQuery,
|
||||
};
|
||||
pub use hir_ty::db::{
|
||||
AssociatedTyDataQuery, CallableItemSignatureQuery, FieldTypesQuery, GenericDefaultsQuery,
|
||||
GenericPredicatesQuery, HirDatabase, HirDatabaseStorage, ImplDatumQuery, ImplsForTraitQuery,
|
||||
ImplsInCrateQuery, InferQuery, StructDatumQuery, TraitDatumQuery, TraitSolveQuery, TyQuery,
|
||||
ValueTyQuery,
|
||||
AssociatedTyDataQuery, CallableItemSignatureQuery, DoInferQuery, FieldTypesQuery,
|
||||
GenericDefaultsQuery, GenericPredicatesQuery, HirDatabase, HirDatabaseStorage, ImplDatumQuery,
|
||||
ImplsForTraitQuery, ImplsInCrateQuery, StructDatumQuery, TraitDatumQuery, TraitSolveQuery,
|
||||
TyQuery, ValueTyQuery,
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -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<InferenceResult>;
|
||||
|
||||
#[salsa::invoke(crate::do_infer_query)]
|
||||
fn do_infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
|
||||
|
||||
#[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<crate::traits::Solution>;
|
||||
}
|
||||
|
||||
fn infer(db: &impl HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
|
||||
let _p = profile("infer");
|
||||
db.do_infer(def)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hir_database_is_object_safe() {
|
||||
fn _assert_object_safe(_: &dyn HirDatabase) {}
|
||||
|
|
|
@ -62,8 +62,8 @@ mod pat;
|
|||
mod coerce;
|
||||
|
||||
/// The entry point of type inference.
|
||||
pub fn infer_query(db: &impl HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
|
||||
let _p = profile("infer_query");
|
||||
pub fn do_infer_query(db: &impl HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
|
||||
let _p = profile("do_infer");
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx = InferenceContext::new(db, def, resolver);
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -273,7 +273,7 @@ impl RootDatabase {
|
|||
self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep);
|
||||
|
||||
self.query(hir::db::ExprScopesQuery).sweep(sweep);
|
||||
self.query(hir::db::InferQuery).sweep(sweep);
|
||||
self.query(hir::db::DoInferQuery).sweep(sweep);
|
||||
self.query(hir::db::BodyQuery).sweep(sweep);
|
||||
}
|
||||
|
||||
|
@ -320,7 +320,7 @@ impl RootDatabase {
|
|||
hir::db::LangItemQuery
|
||||
hir::db::DocumentationQuery
|
||||
hir::db::ExprScopesQuery
|
||||
hir::db::InferQuery
|
||||
hir::db::DoInferQuery
|
||||
hir::db::TyQuery
|
||||
hir::db::ValueTyQuery
|
||||
hir::db::FieldTypesQuery
|
||||
|
|
Loading…
Reference in a new issue