From 12433a78871610edfccc82442846615872747e06 Mon Sep 17 00:00:00 2001 From: csmoe Date: Thu, 31 Jan 2019 22:28:31 +0800 Subject: [PATCH 1/2] split hirdatabase --- crates/ra_hir/src/db.rs | 46 +++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 189649841a..7183b1630d 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -19,8 +19,8 @@ use crate::{ ids::SourceFileItemId, }; -#[salsa::query_group(HirDatabaseStorage)] -pub trait HirDatabase: SourceDatabase + AsRef { +#[salsa::query_group(PersistentHirDatabaseStorage)] +pub trait PersistentHirDatabase: SourceDatabase + AsRef { #[salsa::invoke(HirFileId::hir_parse)] fn hir_parse(&self, file_id: HirFileId) -> TreeArc; @@ -36,21 +36,9 @@ pub trait HirDatabase: SourceDatabase + AsRef { #[salsa::invoke(crate::adt::EnumData::enum_data_query)] fn enum_data(&self, e: Enum) -> Arc; - #[salsa::invoke(crate::ty::infer)] - fn infer(&self, func: Function) -> Arc; - - #[salsa::invoke(crate::ty::type_for_def)] - fn type_for_def(&self, def: TypableDef) -> Ty; - - #[salsa::invoke(crate::ty::type_for_field)] - fn type_for_field(&self, field: StructField) -> Ty; - #[salsa::invoke(query_definitions::file_items)] fn file_items(&self, file_id: HirFileId) -> Arc; - #[salsa::invoke(query_definitions::file_item)] - fn file_item(&self, source_item_id: SourceItemId) -> TreeArc; - #[salsa::invoke(crate::module_tree::Submodule::submodules_query)] fn submodules( &self, @@ -88,15 +76,33 @@ pub trait HirDatabase: SourceDatabase + AsRef { #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] fn impls_in_crate(&self, krate: Crate) -> Arc; - #[salsa::invoke(crate::expr::body_hir)] - fn body_hir(&self, func: Function) -> Arc; - - #[salsa::invoke(crate::expr::body_syntax_mapping)] - fn body_syntax_mapping(&self, func: Function) -> Arc; - #[salsa::invoke(crate::generics::GenericParams::generic_params_query)] fn generic_params(&self, def: GenericDef) -> Arc; #[salsa::invoke(crate::FnSignature::fn_signature_query)] fn fn_signature(&self, func: Function) -> Arc; } + +#[salsa::query_group(HirDatabaseStorage)] +pub trait HirDatabase: PersistentHirDatabase { + #[salsa::invoke(query_definitions::fn_scopes)] + fn fn_scopes(&self, func: Function) -> Arc; + + #[salsa::invoke(query_definitions::file_item)] + fn file_item(&self, source_item_id: SourceItemId) -> TreeArc; + + #[salsa::invoke(crate::ty::infer)] + fn infer(&self, func: Function) -> Arc; + + #[salsa::invoke(crate::ty::type_for_def)] + fn type_for_def(&self, def: TypableDef) -> Ty; + + #[salsa::invoke(crate::ty::type_for_field)] + fn type_for_field(&self, field: StructField) -> Ty; + + #[salsa::invoke(crate::expr::body_hir)] + fn body_hir(&self, func: Function) -> Arc; + + #[salsa::invoke(crate::expr::body_syntax_mapping)] + fn body_syntax_mapping(&self, func: Function) -> Arc; +} From 4dffdcf14abe0c79f9d7a9702be77958be1f75b1 Mon Sep 17 00:00:00 2001 From: csmoe Date: Fri, 1 Feb 2019 18:33:41 +0800 Subject: [PATCH 2/2] split HirDatabase api --- crates/ra_hir/src/adt.rs | 19 ++++--- crates/ra_hir/src/code_model_api.rs | 51 ++++++++++--------- crates/ra_hir/src/code_model_impl/function.rs | 7 ++- crates/ra_hir/src/code_model_impl/krate.rs | 10 ++-- crates/ra_hir/src/code_model_impl/module.rs | 16 ++++-- crates/ra_hir/src/db.rs | 29 +++++------ crates/ra_hir/src/expr.rs | 4 +- crates/ra_hir/src/expr/scope.rs | 2 +- crates/ra_hir/src/generics.rs | 4 +- crates/ra_hir/src/ids.rs | 14 +++-- crates/ra_hir/src/impl_block.rs | 20 +++++--- crates/ra_hir/src/lib.rs | 2 +- crates/ra_hir/src/macros.rs | 4 +- crates/ra_hir/src/mock.rs | 6 ++- crates/ra_hir/src/module_tree.rs | 22 +++++--- crates/ra_hir/src/nameres.rs | 13 +++-- crates/ra_hir/src/nameres/lower.rs | 14 ++--- crates/ra_hir/src/nameres/tests.rs | 2 +- crates/ra_hir/src/query_definitions.rs | 9 ++-- crates/ra_hir/src/ty.rs | 2 +- crates/ra_ide_api/src/db.rs | 3 +- 21 files changed, 147 insertions(+), 106 deletions(-) diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 22bbad964d..c549e2126e 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -12,7 +12,7 @@ use ra_syntax::{ use crate::{ Name, AsName, Struct, Enum, EnumVariant, Crate, HirDatabase, HirFileId, StructField, FieldSource, - type_ref::TypeRef, + type_ref::TypeRef, PersistentHirDatabase, }; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -33,7 +33,7 @@ impl AdtDef { } impl Struct { - pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Arc { + pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc { db.struct_data((*self).into()).variant_data.clone() } } @@ -52,7 +52,10 @@ impl StructData { StructData { name, variant_data } } - pub(crate) fn struct_data_query(db: &impl HirDatabase, struct_: Struct) -> Arc { + pub(crate) fn struct_data_query( + db: &impl PersistentHirDatabase, + struct_: Struct, + ) -> Arc { let (_, struct_def) = struct_.source(db); Arc::new(StructData::new(&*struct_def)) } @@ -68,7 +71,7 @@ fn variants(enum_def: &ast::EnumDef) -> impl Iterator impl EnumVariant { pub(crate) fn source_impl( &self, - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, ) -> (HirFileId, TreeArc) { let (file_id, enum_def) = self.parent.source(db); let var = variants(&*enum_def) @@ -79,7 +82,7 @@ impl EnumVariant { .to_owned(); (file_id, var) } - pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Arc { + pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc { db.enum_data(self.parent).variants[self.id] .variant_data .clone() @@ -93,7 +96,7 @@ pub struct EnumData { } impl EnumData { - pub(crate) fn enum_data_query(db: &impl HirDatabase, e: Enum) -> Arc { + pub(crate) fn enum_data_query(db: &impl PersistentHirDatabase, e: Enum) -> Arc { let (_file_id, enum_def) = e.source(db); let name = enum_def.name().map(|n| n.as_name()); let variants = variants(&*enum_def) @@ -191,7 +194,7 @@ impl VariantDef { VariantDef::EnumVariant(it) => it.field(db, name), } } - pub(crate) fn variant_data(self, db: &impl HirDatabase) -> Arc { + pub(crate) fn variant_data(self, db: &impl PersistentHirDatabase) -> Arc { match self { VariantDef::Struct(it) => it.variant_data(db), VariantDef::EnumVariant(it) => it.variant_data(db), @@ -200,7 +203,7 @@ impl VariantDef { } impl StructField { - pub(crate) fn source_impl(&self, db: &impl HirDatabase) -> (HirFileId, FieldSource) { + pub(crate) fn source_impl(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { let var_data = self.parent.variant_data(db); let fields = var_data.fields().unwrap(); let ss; diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 9405aa8ad6..71123a6983 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -8,7 +8,7 @@ use crate::{ Name, Path, PerNs, ScopesWithSyntaxMapping, Ty, HirFileId, type_ref::TypeRef, nameres::{ModuleScope, lower::ImportId}, - db::HirDatabase, + HirDatabase, PersistentHirDatabase, expr::BodySyntaxMapping, ty::{InferenceResult}, adt::{EnumVariantId, StructFieldId, VariantDef}, @@ -37,10 +37,10 @@ impl Crate { pub fn crate_id(&self) -> CrateId { self.crate_id } - pub fn dependencies(&self, db: &impl HirDatabase) -> Vec { + pub fn dependencies(&self, db: &impl PersistentHirDatabase) -> Vec { self.dependencies_impl(db) } - pub fn root_module(&self, db: &impl HirDatabase) -> Option { + pub fn root_module(&self, db: &impl PersistentHirDatabase) -> Option { self.root_module_impl(db) } } @@ -105,7 +105,7 @@ impl Module { } /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. - pub fn definition_source(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) { + pub fn definition_source(&self, db: &impl PersistentHirDatabase) -> (FileId, ModuleSource) { self.definition_source_impl(db) } @@ -140,7 +140,7 @@ impl Module { /// Topmost parent of this module. Every module has a `crate_root`, but some /// might be missing `krate`. This can happen if a module's file is not included /// in the module tree of any target in Cargo.toml. - pub fn crate_root(&self, db: &impl HirDatabase) -> Module { + pub fn crate_root(&self, db: &impl PersistentHirDatabase) -> Module { self.crate_root_impl(db) } @@ -150,12 +150,12 @@ impl Module { } /// Iterates over all child modules. - pub fn children(&self, db: &impl HirDatabase) -> impl Iterator { + pub fn children(&self, db: &impl PersistentHirDatabase) -> impl Iterator { self.children_impl(db) } /// Finds a parent module. - pub fn parent(&self, db: &impl HirDatabase) -> Option { + pub fn parent(&self, db: &impl PersistentHirDatabase) -> Option { self.parent_impl(db) } @@ -174,7 +174,7 @@ impl Module { db.item_map(self.krate)[self.module_id].clone() } - pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs { + pub fn resolve_path(&self, db: &impl PersistentHirDatabase, path: &Path) -> PerNs { db.item_map(self.krate).resolve_path(db, *self, path) } @@ -209,7 +209,7 @@ impl StructField { .clone() } - pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, FieldSource) { + pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { self.source_impl(db) } @@ -237,7 +237,7 @@ pub struct Struct { } impl Struct { - pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } @@ -275,7 +275,7 @@ impl Struct { }) } - pub fn generic_params(&self, db: &impl HirDatabase) -> Arc { + pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { db.generic_params((*self).into()) } @@ -296,7 +296,7 @@ pub struct Enum { } impl Enum { - pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } @@ -316,7 +316,7 @@ impl Enum { .collect() } - pub fn variant(&self, db: &impl HirDatabase, name: &Name) -> Option { + pub fn variant(&self, db: &impl PersistentHirDatabase, name: &Name) -> Option { db.enum_data(*self) .variants .iter() @@ -324,7 +324,7 @@ impl Enum { .map(|(id, _)| EnumVariant { parent: *self, id }) } - pub fn generic_params(&self, db: &impl HirDatabase) -> Arc { + pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { db.generic_params((*self).into()) } @@ -346,13 +346,16 @@ pub struct EnumVariant { } impl EnumVariant { - pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + pub fn source( + &self, + db: &impl PersistentHirDatabase, + ) -> (HirFileId, TreeArc) { self.source_impl(db) } pub fn module(&self, db: &impl HirDatabase) -> Module { self.parent.module(db) } - pub fn parent_enum(&self, _db: &impl HirDatabase) -> Enum { + pub fn parent_enum(&self, _db: &impl PersistentHirDatabase) -> Enum { self.parent } @@ -430,7 +433,7 @@ impl FnSignature { } impl Function { - pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } @@ -463,7 +466,7 @@ impl Function { db.infer(*self) } - pub fn generic_params(&self, db: &impl HirDatabase) -> Arc { + pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { db.generic_params((*self).into()) } } @@ -480,7 +483,7 @@ pub struct Const { } impl Const { - pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } } @@ -497,7 +500,7 @@ pub struct Static { } impl Static { - pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } } @@ -514,11 +517,11 @@ pub struct Trait { } impl Trait { - pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } - pub fn generic_params(&self, db: &impl HirDatabase) -> Arc { + pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { db.generic_params((*self).into()) } } @@ -535,11 +538,11 @@ pub struct Type { } impl Type { - pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } - pub fn generic_params(&self, db: &impl HirDatabase) -> Arc { + pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { db.generic_params((*self).into()) } } diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs index 4226439961..5b0b31b1d5 100644 --- a/crates/ra_hir/src/code_model_impl/function.rs +++ b/crates/ra_hir/src/code_model_impl/function.rs @@ -5,7 +5,7 @@ use ra_syntax::ast::{self, NameOwner}; use crate::{ HirDatabase, Name, AsName, Function, FnSignature, type_ref::{TypeRef, Mutability}, - expr::Body, + expr::Body, PersistentHirDatabase, impl_block::ImplBlock, }; @@ -22,7 +22,10 @@ impl Function { } impl FnSignature { - pub(crate) fn fn_signature_query(db: &impl HirDatabase, func: Function) -> Arc { + pub(crate) fn fn_signature_query( + db: &impl PersistentHirDatabase, + func: Function, + ) -> Arc { let (_, node) = func.source(db); let name = node .name() diff --git a/crates/ra_hir/src/code_model_impl/krate.rs b/crates/ra_hir/src/code_model_impl/krate.rs index 86f29d959e..1517434b82 100644 --- a/crates/ra_hir/src/code_model_impl/krate.rs +++ b/crates/ra_hir/src/code_model_impl/krate.rs @@ -1,10 +1,12 @@ use crate::{ - Crate, CrateDependency, AsName, Module, - db::HirDatabase, + Crate, CrateDependency, AsName, Module, PersistentHirDatabase, }; impl Crate { - pub(crate) fn dependencies_impl(&self, db: &impl HirDatabase) -> Vec { + pub(crate) fn dependencies_impl( + &self, + db: &impl PersistentHirDatabase, + ) -> Vec { let crate_graph = db.crate_graph(); crate_graph .dependencies(self.crate_id) @@ -17,7 +19,7 @@ impl Crate { }) .collect() } - pub(crate) fn root_module_impl(&self, db: &impl HirDatabase) -> Option { + pub(crate) fn root_module_impl(&self, db: &impl PersistentHirDatabase) -> Option { let module_tree = db.module_tree(*self); let module_id = module_tree.modules().next()?; diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 4a3901b8b7..f487b8532d 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -7,7 +7,7 @@ use crate::{ module_tree::ModuleId, impl_block::ImplId, nameres::{lower::ImportId}, - db::HirDatabase, + HirDatabase, PersistentHirDatabase, }; impl Module { @@ -24,7 +24,10 @@ impl Module { Some(link.name(&module_tree).clone()) } - pub(crate) fn definition_source_impl(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) { + pub(crate) fn definition_source_impl( + &self, + db: &impl PersistentHirDatabase, + ) -> (FileId, ModuleSource) { let module_tree = db.module_tree(self.krate); let file_id = self.module_id.file_id(&module_tree); let decl_id = self.module_id.decl_id(&module_tree); @@ -67,7 +70,7 @@ impl Module { source_map.get(&source, impl_id) } - pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Module { + pub(crate) fn crate_root_impl(&self, db: &impl PersistentHirDatabase) -> Module { let module_tree = db.module_tree(self.krate); let module_id = self.module_id.crate_root(&module_tree); self.with_module_id(module_id) @@ -81,7 +84,10 @@ impl Module { } /// Iterates over all child modules. - pub(crate) fn children_impl(&self, db: &impl HirDatabase) -> impl Iterator { + pub(crate) fn children_impl( + &self, + db: &impl PersistentHirDatabase, + ) -> impl Iterator { let module_tree = db.module_tree(self.krate); let children = self .module_id @@ -91,7 +97,7 @@ impl Module { children.into_iter() } - pub(crate) fn parent_impl(&self, db: &impl HirDatabase) -> Option { + pub(crate) fn parent_impl(&self, db: &impl PersistentHirDatabase) -> Option { let module_tree = db.module_tree(self.krate); let parent_id = self.module_id.parent(&module_tree)?; Some(self.with_module_id(parent_id)) diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 7183b1630d..6b21fe744a 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -27,9 +27,6 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef { #[salsa::invoke(crate::macros::expand_macro_invocation)] fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option>; - #[salsa::invoke(ExprScopes::expr_scopes_query)] - fn expr_scopes(&self, func: Function) -> Arc; - #[salsa::invoke(crate::adt::StructData::struct_data_query)] fn struct_data(&self, s: Struct) -> Arc; @@ -39,6 +36,9 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef { #[salsa::invoke(query_definitions::file_items)] fn file_items(&self, file_id: HirFileId) -> Arc; + #[salsa::invoke(query_definitions::file_item)] + fn file_item(&self, source_item_id: SourceItemId) -> TreeArc; + #[salsa::invoke(crate::module_tree::Submodule::submodules_query)] fn submodules( &self, @@ -61,20 +61,17 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef { #[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)] fn module_tree(&self, krate: Crate) -> Arc; - #[salsa::invoke(crate::impl_block::impls_in_module_with_source_map_query)] - fn impls_in_module_with_source_map( - &self, - module: Module, - ) -> (Arc, Arc); - #[salsa::invoke(crate::impl_block::impls_in_module)] fn impls_in_module(&self, module: Module) -> Arc; #[salsa::invoke(crate::impl_block::impls_in_module_source_map_query)] fn impls_in_module_source_map(&self, module: Module) -> Arc; - #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] - fn impls_in_crate(&self, krate: Crate) -> Arc; + #[salsa::invoke(crate::impl_block::impls_in_module_with_source_map_query)] + fn impls_in_module_with_source_map( + &self, + module: Module, + ) -> (Arc, Arc); #[salsa::invoke(crate::generics::GenericParams::generic_params_query)] fn generic_params(&self, def: GenericDef) -> Arc; @@ -85,11 +82,8 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef { #[salsa::query_group(HirDatabaseStorage)] pub trait HirDatabase: PersistentHirDatabase { - #[salsa::invoke(query_definitions::fn_scopes)] - fn fn_scopes(&self, func: Function) -> Arc; - - #[salsa::invoke(query_definitions::file_item)] - fn file_item(&self, source_item_id: SourceItemId) -> TreeArc; + #[salsa::invoke(ExprScopes::expr_scopes_query)] + fn expr_scopes(&self, func: Function) -> Arc; #[salsa::invoke(crate::ty::infer)] fn infer(&self, func: Function) -> Arc; @@ -105,4 +99,7 @@ pub trait HirDatabase: PersistentHirDatabase { #[salsa::invoke(crate::expr::body_syntax_mapping)] fn body_syntax_mapping(&self, func: Function) -> Arc; + + #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] + fn impls_in_crate(&self, krate: Crate) -> Arc; } diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 37aa24677c..f4a9504184 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -10,8 +10,8 @@ use ra_syntax::{ }; use crate::{ - Path, Name, HirDatabase, Function, - name::AsName, + Path, Name, Function, + name::AsName, HirDatabase, type_ref::{Mutability, TypeRef}, }; use crate::ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy}; diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index f8b5ba581c..b7971088d0 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs @@ -12,7 +12,7 @@ use ra_arena::{Arena, RawId, impl_arena_id}; use crate::{ Name, AsName, Function, expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping}, - db::HirDatabase, + HirDatabase, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 64c20a4622..b0bd735bda 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use ra_syntax::ast::{self, NameOwner, TypeParamsOwner}; -use crate::{db::HirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type}; +use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type}; /// Data about a generic parameter (to a function, struct, impl, ...). #[derive(Clone, PartialEq, Eq, Debug)] @@ -34,7 +34,7 @@ impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type); impl GenericParams { pub(crate) fn generic_params_query( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, def: GenericDef, ) -> Arc { let mut generics = GenericParams::default(); diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 0e4dc62614..95678bf703 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -10,6 +10,7 @@ use ra_arena::{Arena, RawId, ArenaId, impl_arena_id}; use crate::{ HirDatabase, Module, + PersistentHirDatabase, }; #[derive(Debug, Default)] @@ -62,7 +63,7 @@ pub struct HirFileId(HirFileIdRepr); impl HirFileId { /// For macro-expansion files, returns the file original source file the /// expansionoriginated from. - pub fn original_file(self, db: &impl HirDatabase) -> FileId { + pub fn original_file(self, db: &impl PersistentHirDatabase) -> FileId { match self.0 { HirFileIdRepr::File(file_id) => file_id, HirFileIdRepr::Macro(macro_call_id) => { @@ -86,7 +87,10 @@ impl HirFileId { } } - pub(crate) fn hir_parse(db: &impl HirDatabase, file_id: HirFileId) -> TreeArc { + pub(crate) fn hir_parse( + db: &impl PersistentHirDatabase, + file_id: HirFileId, + ) -> TreeArc { match file_id.0 { HirFileIdRepr::File(file_id) => db.parse(file_id), HirFileIdRepr::Macro(m) => { @@ -180,7 +184,7 @@ pub(crate) struct LocationCtx { file_id: HirFileId, } -impl<'a, DB: HirDatabase> LocationCtx<&'a DB> { +impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> { pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> { LocationCtx { db, @@ -199,7 +203,7 @@ impl<'a, DB: HirDatabase> LocationCtx<&'a DB> { pub(crate) trait AstItemDef: ArenaId + Clone { fn interner(interner: &HirInterner) -> &LocationIntener, Self>; - fn from_ast(ctx: LocationCtx<&impl HirDatabase>, ast: &N) -> Self { + fn from_ast(ctx: LocationCtx<&impl PersistentHirDatabase>, ast: &N) -> Self { let items = ctx.db.file_items(ctx.file_id); let raw = SourceItemId { file_id: ctx.file_id, @@ -213,7 +217,7 @@ pub(crate) trait AstItemDef: ArenaId + Clone { Self::interner(ctx.db.as_ref()).loc2id(&loc) } - fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + fn source(self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { let int = Self::interner(db.as_ref()); let loc = int.id2loc(self); let syntax = db.file_item(loc.raw); diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 5fc26324a8..36d72b103b 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -9,7 +9,7 @@ ast::{self, AstNode}}; use crate::{ Const, Type, Function, HirFileId, - db::HirDatabase, + PersistentHirDatabase, type_ref::TypeRef, ids::LocationCtx, }; @@ -91,7 +91,7 @@ pub struct ImplData { impl ImplData { pub(crate) fn from_ast( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, file_id: HirFileId, module: Module, node: &ast::ImplBlock, @@ -174,7 +174,12 @@ impl ModuleImplBlocks { } } - fn collect(&mut self, db: &impl HirDatabase, module: Module, source_map: &mut ImplSourceMap) { + fn collect( + &mut self, + db: &impl PersistentHirDatabase, + module: Module, + source_map: &mut ImplSourceMap, + ) { let (file_id, module_source) = module.definition_source(db); let file_id: HirFileId = file_id.into(); let node = match &module_source { @@ -198,7 +203,7 @@ impl ModuleImplBlocks { } pub(crate) fn impls_in_module_with_source_map_query( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, module: Module, ) -> (Arc, Arc) { let mut source_map = ImplSourceMap::default(); @@ -209,12 +214,15 @@ pub(crate) fn impls_in_module_with_source_map_query( (Arc::new(result), Arc::new(source_map)) } -pub(crate) fn impls_in_module(db: &impl HirDatabase, module: Module) -> Arc { +pub(crate) fn impls_in_module( + db: &impl PersistentHirDatabase, + module: Module, +) -> Arc { db.impls_in_module_with_source_map(module).0 } pub(crate) fn impls_in_module_source_map_query( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, module: Module, ) -> Arc { db.impls_in_module_with_source_map(module).1 diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 0b9ee63bf1..905c53c7dd 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -44,7 +44,7 @@ mod code_model_impl; mod marks; use crate::{ - db::HirDatabase, + db::{HirDatabase, PersistentHirDatabase}, name::{AsName, KnownName}, ids::{SourceItemId, SourceFileItems}, }; diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs index cf72208755..cb8a9312e0 100644 --- a/crates/ra_hir/src/macros.rs +++ b/crates/ra_hir/src/macros.rs @@ -14,7 +14,7 @@ use ra_syntax::{ ast::{self, NameOwner}, }; -use crate::{HirDatabase, MacroCallId}; +use crate::{MacroCallId, PersistentHirDatabase}; // Hard-coded defs for now :-( #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -157,7 +157,7 @@ impl MacroExpansion { } pub(crate) fn expand_macro_invocation( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, invoc: MacroCallId, ) -> Option> { let loc = invoc.loc(db); diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 7da15eca01..17bdd48c6f 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs @@ -11,7 +11,11 @@ use crate::{db, HirInterner}; pub const WORKSPACE: SourceRootId = SourceRootId(0); -#[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage)] +#[salsa::database( + ra_db::SourceDatabaseStorage, + db::HirDatabaseStorage, + db::PersistentHirDatabaseStorage +)] #[derive(Debug)] pub(crate) struct MockDatabase { events: Mutex>>>, diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs index 1f327eeb28..a1aa3d8ce8 100644 --- a/crates/ra_hir/src/module_tree.rs +++ b/crates/ra_hir/src/module_tree.rs @@ -13,13 +13,14 @@ use test_utils::tested_by; use crate::{ Name, AsName, HirDatabase, SourceItemId, HirFileId, Problem, SourceFileItems, ModuleSource, + PersistentHirDatabase, Crate, ids::SourceFileItemId, }; impl ModuleSource { pub(crate) fn new( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, file_id: HirFileId, decl_id: Option, ) -> ModuleSource { @@ -47,7 +48,7 @@ pub struct Submodule { impl Submodule { pub(crate) fn submodules_query( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, file_id: HirFileId, decl_id: Option, ) -> Arc> { @@ -133,7 +134,10 @@ struct LinkData { } impl ModuleTree { - pub(crate) fn module_tree_query(db: &impl HirDatabase, krate: Crate) -> Arc { + pub(crate) fn module_tree_query( + db: &impl PersistentHirDatabase, + krate: Crate, + ) -> Arc { db.check_canceled(); let mut res = ModuleTree::default(); res.init_crate(db, krate); @@ -156,7 +160,7 @@ impl ModuleTree { Some(res) } - fn init_crate(&mut self, db: &impl HirDatabase, krate: Crate) { + fn init_crate(&mut self, db: &impl PersistentHirDatabase, krate: Crate) { let crate_graph = db.crate_graph(); let file_id = crate_graph.crate_root(krate.crate_id); let source_root_id = db.file_source_root(file_id); @@ -167,7 +171,7 @@ impl ModuleTree { fn init_subtree( &mut self, - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, source_root: &SourceRoot, parent: Option, file_id: HirFileId, @@ -287,14 +291,18 @@ impl LinkId { pub(crate) fn name(self, tree: &ModuleTree) -> &Name { &tree.links[self].name } - pub(crate) fn source(self, tree: &ModuleTree, db: &impl HirDatabase) -> TreeArc { + pub(crate) fn source( + self, + tree: &ModuleTree, + db: &impl PersistentHirDatabase, + ) -> TreeArc { let syntax_node = db.file_item(tree.links[self].source); ast::Module::cast(&syntax_node).unwrap().to_owned() } } fn resolve_submodule( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, file_id: HirFileId, name: &Name, is_root: bool, diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 4573a72ba7..f8627acbe0 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -24,9 +24,8 @@ use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ Module, ModuleDef, - Path, PathKind, - HirDatabase, Crate, - Name, + Path, PathKind, Crate, + Name, PersistentHirDatabase, module_tree::{ModuleId, ModuleTree}, nameres::lower::{ImportId, LoweredModule, ImportData}, }; @@ -166,7 +165,7 @@ struct Resolver<'a, DB> { impl<'a, DB> Resolver<'a, DB> where - DB: HirDatabase, + DB: PersistentHirDatabase, { fn new( db: &'a DB, @@ -330,7 +329,7 @@ enum ReachedFixedPoint { } impl ItemMap { - pub(crate) fn item_map_query(db: &impl HirDatabase, krate: Crate) -> Arc { + pub(crate) fn item_map_query(db: &impl PersistentHirDatabase, krate: Crate) -> Arc { let start = time::Instant::now(); let module_tree = db.module_tree(krate); let input = module_tree @@ -352,7 +351,7 @@ impl ItemMap { pub(crate) fn resolve_path( &self, - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, original_module: Module, path: &Path, ) -> PerNs { @@ -363,7 +362,7 @@ impl ItemMap { // the result. fn resolve_path_fp( &self, - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, original_module: Module, path: &Path, ) -> (PerNs, ReachedFixedPoint) { diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs index 8df11a5f41..9a45fa61c4 100644 --- a/crates/ra_hir/src/nameres/lower.rs +++ b/crates/ra_hir/src/nameres/lower.rs @@ -8,10 +8,10 @@ use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; use rustc_hash::FxHashMap; use crate::{ - SourceItemId, Path, ModuleSource, HirDatabase, Name, + SourceItemId, Path, ModuleSource, Name, HirFileId, MacroCallLoc, AsName, PerNs, Function, ModuleDef, Module, Struct, Enum, Const, Static, Trait, Type, - ids::LocationCtx, + ids::LocationCtx, PersistentHirDatabase, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -58,21 +58,21 @@ impl ImportSourceMap { impl LoweredModule { pub(crate) fn lower_module_module_query( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, module: Module, ) -> Arc { db.lower_module(module).0 } pub(crate) fn lower_module_source_map_query( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, module: Module, ) -> Arc { db.lower_module(module).1 } pub(crate) fn lower_module_query( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, module: Module, ) -> (Arc, Arc) { let (file_id, source) = module.definition_source(db); @@ -105,7 +105,7 @@ impl LoweredModule { fn fill( &mut self, source_map: &mut ImportSourceMap, - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, module: Module, file_id: HirFileId, items: &mut Iterator, @@ -137,7 +137,7 @@ impl LoweredModule { fn add_def_id( &mut self, source_map: &mut ImportSourceMap, - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, module: Module, file_id: HirFileId, item: &ast::ModuleItem, diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 9c5ca097ea..1ce7bd146d 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -6,7 +6,7 @@ use test_utils::{assert_eq_text, covers}; use crate::{ ItemMap, Resolution, - db::HirDatabase, + PersistentHirDatabase, mock::MockDatabase, module_tree::ModuleId, }; diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index 734a982820..b4d8da1e65 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs @@ -6,17 +6,20 @@ use ra_syntax::{ use crate::{ SourceFileItems, SourceItemId, HirFileId, - db::HirDatabase, + PersistentHirDatabase, }; -pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc { +pub(super) fn file_items( + db: &impl PersistentHirDatabase, + file_id: HirFileId, +) -> Arc { let source_file = db.hir_parse(file_id); let res = SourceFileItems::new(file_id, &source_file); Arc::new(res) } pub(super) fn file_item( - db: &impl HirDatabase, + db: &impl PersistentHirDatabase, source_item_id: SourceItemId, ) -> TreeArc { let source_file = db.hir_parse(source_item_id.file_id); diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 60c231e825..d3e31981a8 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -35,7 +35,7 @@ use test_utils::tested_by; use crate::{ Module, Function, Struct, StructField, Enum, EnumVariant, Path, Name, ImplBlock, FnSignature, ExprScopes, ModuleDef, AdtDef, - db::HirDatabase, + HirDatabase, type_ref::{TypeRef, Mutability}, name::KnownName, expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat}, diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index 6850811d75..3a9089c22b 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs @@ -14,7 +14,8 @@ use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}}; ra_db::SourceDatabaseStorage, LineIndexDatabaseStorage, symbol_index::SymbolsDatabaseStorage, - hir::db::HirDatabaseStorage + hir::db::HirDatabaseStorage, + hir::db::PersistentHirDatabaseStorage )] #[derive(Debug)] pub(crate) struct RootDatabase {