mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #718
718: split HirDatabase r=matklad a=csmoe Closes #706 Co-authored-by: csmoe <csmoe@msn.com>
This commit is contained in:
commit
2b5c226e86
21 changed files with 165 additions and 118 deletions
|
@ -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<VariantData> {
|
||||
pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc<VariantData> {
|
||||
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<StructData> {
|
||||
pub(crate) fn struct_data_query(
|
||||
db: &impl PersistentHirDatabase,
|
||||
struct_: Struct,
|
||||
) -> Arc<StructData> {
|
||||
let (_, struct_def) = struct_.source(db);
|
||||
Arc::new(StructData::new(&*struct_def))
|
||||
}
|
||||
|
@ -68,7 +71,7 @@ fn variants(enum_def: &ast::EnumDef) -> impl Iterator<Item = &ast::EnumVariant>
|
|||
impl EnumVariant {
|
||||
pub(crate) fn source_impl(
|
||||
&self,
|
||||
db: &impl HirDatabase,
|
||||
db: &impl PersistentHirDatabase,
|
||||
) -> (HirFileId, TreeArc<ast::EnumVariant>) {
|
||||
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<VariantData> {
|
||||
pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc<VariantData> {
|
||||
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<EnumData> {
|
||||
pub(crate) fn enum_data_query(db: &impl PersistentHirDatabase, e: Enum) -> Arc<EnumData> {
|
||||
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<VariantData> {
|
||||
pub(crate) fn variant_data(self, db: &impl PersistentHirDatabase) -> Arc<VariantData> {
|
||||
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;
|
||||
|
|
|
@ -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<CrateDependency> {
|
||||
pub fn dependencies(&self, db: &impl PersistentHirDatabase) -> Vec<CrateDependency> {
|
||||
self.dependencies_impl(db)
|
||||
}
|
||||
pub fn root_module(&self, db: &impl HirDatabase) -> Option<Module> {
|
||||
pub fn root_module(&self, db: &impl PersistentHirDatabase) -> Option<Module> {
|
||||
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<Item = Module> {
|
||||
pub fn children(&self, db: &impl PersistentHirDatabase) -> impl Iterator<Item = Module> {
|
||||
self.children_impl(db)
|
||||
}
|
||||
|
||||
/// Finds a parent module.
|
||||
pub fn parent(&self, db: &impl HirDatabase) -> Option<Module> {
|
||||
pub fn parent(&self, db: &impl PersistentHirDatabase) -> Option<Module> {
|
||||
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<ModuleDef> {
|
||||
pub fn resolve_path(&self, db: &impl PersistentHirDatabase, path: &Path) -> PerNs<ModuleDef> {
|
||||
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<ast::StructDef>) {
|
||||
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StructDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ impl Struct {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
|
||||
pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
|
||||
db.generic_params((*self).into())
|
||||
}
|
||||
|
||||
|
@ -296,7 +296,7 @@ pub struct Enum {
|
|||
}
|
||||
|
||||
impl Enum {
|
||||
pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) {
|
||||
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ impl Enum {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn variant(&self, db: &impl HirDatabase, name: &Name) -> Option<EnumVariant> {
|
||||
pub fn variant(&self, db: &impl PersistentHirDatabase, name: &Name) -> Option<EnumVariant> {
|
||||
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<GenericParams> {
|
||||
pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
|
||||
db.generic_params((*self).into())
|
||||
}
|
||||
|
||||
|
@ -346,13 +346,16 @@ pub struct EnumVariant {
|
|||
}
|
||||
|
||||
impl EnumVariant {
|
||||
pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumVariant>) {
|
||||
pub fn source(
|
||||
&self,
|
||||
db: &impl PersistentHirDatabase,
|
||||
) -> (HirFileId, TreeArc<ast::EnumVariant>) {
|
||||
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<ast::FnDef>) {
|
||||
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::FnDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
|
@ -463,7 +466,7 @@ impl Function {
|
|||
db.infer(*self)
|
||||
}
|
||||
|
||||
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
|
||||
pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
|
||||
db.generic_params((*self).into())
|
||||
}
|
||||
}
|
||||
|
@ -480,7 +483,7 @@ pub struct Const {
|
|||
}
|
||||
|
||||
impl Const {
|
||||
pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
|
||||
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
}
|
||||
|
@ -497,7 +500,7 @@ pub struct Static {
|
|||
}
|
||||
|
||||
impl Static {
|
||||
pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
|
||||
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
}
|
||||
|
@ -514,11 +517,11 @@ pub struct Trait {
|
|||
}
|
||||
|
||||
impl Trait {
|
||||
pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) {
|
||||
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
|
||||
pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
|
||||
db.generic_params((*self).into())
|
||||
}
|
||||
}
|
||||
|
@ -535,11 +538,11 @@ pub struct Type {
|
|||
}
|
||||
|
||||
impl Type {
|
||||
pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) {
|
||||
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
|
||||
pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
|
||||
db.generic_params((*self).into())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<FnSignature> {
|
||||
pub(crate) fn fn_signature_query(
|
||||
db: &impl PersistentHirDatabase,
|
||||
func: Function,
|
||||
) -> Arc<FnSignature> {
|
||||
let (_, node) = func.source(db);
|
||||
let name = node
|
||||
.name()
|
||||
|
|
|
@ -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<CrateDependency> {
|
||||
pub(crate) fn dependencies_impl(
|
||||
&self,
|
||||
db: &impl PersistentHirDatabase,
|
||||
) -> Vec<CrateDependency> {
|
||||
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<Module> {
|
||||
pub(crate) fn root_module_impl(&self, db: &impl PersistentHirDatabase) -> Option<Module> {
|
||||
let module_tree = db.module_tree(*self);
|
||||
let module_id = module_tree.modules().next()?;
|
||||
|
||||
|
|
|
@ -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<Item = Module> {
|
||||
pub(crate) fn children_impl(
|
||||
&self,
|
||||
db: &impl PersistentHirDatabase,
|
||||
) -> impl Iterator<Item = Module> {
|
||||
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<Module> {
|
||||
pub(crate) fn parent_impl(&self, db: &impl PersistentHirDatabase) -> Option<Module> {
|
||||
let module_tree = db.module_tree(self.krate);
|
||||
let parent_id = self.module_id.parent(&module_tree)?;
|
||||
Some(self.with_module_id(parent_id))
|
||||
|
|
|
@ -19,32 +19,20 @@ use crate::{
|
|||
ids::SourceFileItemId,
|
||||
};
|
||||
|
||||
#[salsa::query_group(HirDatabaseStorage)]
|
||||
pub trait HirDatabase: SourceDatabase + AsRef<HirInterner> {
|
||||
#[salsa::query_group(PersistentHirDatabaseStorage)]
|
||||
pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> {
|
||||
#[salsa::invoke(HirFileId::hir_parse)]
|
||||
fn hir_parse(&self, file_id: HirFileId) -> TreeArc<SourceFile>;
|
||||
|
||||
#[salsa::invoke(crate::macros::expand_macro_invocation)]
|
||||
fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option<Arc<MacroExpansion>>;
|
||||
|
||||
#[salsa::invoke(ExprScopes::expr_scopes_query)]
|
||||
fn expr_scopes(&self, func: Function) -> Arc<ExprScopes>;
|
||||
|
||||
#[salsa::invoke(crate::adt::StructData::struct_data_query)]
|
||||
fn struct_data(&self, s: Struct) -> Arc<StructData>;
|
||||
|
||||
#[salsa::invoke(crate::adt::EnumData::enum_data_query)]
|
||||
fn enum_data(&self, e: Enum) -> Arc<EnumData>;
|
||||
|
||||
#[salsa::invoke(crate::ty::infer)]
|
||||
fn infer(&self, func: Function) -> Arc<InferenceResult>;
|
||||
|
||||
#[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<SourceFileItems>;
|
||||
|
||||
|
@ -73,26 +61,17 @@ pub trait HirDatabase: SourceDatabase + AsRef<HirInterner> {
|
|||
#[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)]
|
||||
fn module_tree(&self, krate: Crate) -> Arc<ModuleTree>;
|
||||
|
||||
#[salsa::invoke(crate::impl_block::impls_in_module_with_source_map_query)]
|
||||
fn impls_in_module_with_source_map(
|
||||
&self,
|
||||
module: Module,
|
||||
) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>);
|
||||
|
||||
#[salsa::invoke(crate::impl_block::impls_in_module)]
|
||||
fn impls_in_module(&self, module: Module) -> Arc<ModuleImplBlocks>;
|
||||
|
||||
#[salsa::invoke(crate::impl_block::impls_in_module_source_map_query)]
|
||||
fn impls_in_module_source_map(&self, module: Module) -> Arc<ImplSourceMap>;
|
||||
|
||||
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
|
||||
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
|
||||
|
||||
#[salsa::invoke(crate::expr::body_hir)]
|
||||
fn body_hir(&self, func: Function) -> Arc<crate::expr::Body>;
|
||||
|
||||
#[salsa::invoke(crate::expr::body_syntax_mapping)]
|
||||
fn body_syntax_mapping(&self, func: Function) -> Arc<crate::expr::BodySyntaxMapping>;
|
||||
#[salsa::invoke(crate::impl_block::impls_in_module_with_source_map_query)]
|
||||
fn impls_in_module_with_source_map(
|
||||
&self,
|
||||
module: Module,
|
||||
) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>);
|
||||
|
||||
#[salsa::invoke(crate::generics::GenericParams::generic_params_query)]
|
||||
fn generic_params(&self, def: GenericDef) -> Arc<GenericParams>;
|
||||
|
@ -100,3 +79,27 @@ pub trait HirDatabase: SourceDatabase + AsRef<HirInterner> {
|
|||
#[salsa::invoke(crate::FnSignature::fn_signature_query)]
|
||||
fn fn_signature(&self, func: Function) -> Arc<FnSignature>;
|
||||
}
|
||||
|
||||
#[salsa::query_group(HirDatabaseStorage)]
|
||||
pub trait HirDatabase: PersistentHirDatabase {
|
||||
#[salsa::invoke(ExprScopes::expr_scopes_query)]
|
||||
fn expr_scopes(&self, func: Function) -> Arc<ExprScopes>;
|
||||
|
||||
#[salsa::invoke(crate::ty::infer)]
|
||||
fn infer(&self, func: Function) -> Arc<InferenceResult>;
|
||||
|
||||
#[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<crate::expr::Body>;
|
||||
|
||||
#[salsa::invoke(crate::expr::body_syntax_mapping)]
|
||||
fn body_syntax_mapping(&self, func: Function) -> Arc<crate::expr::BodySyntaxMapping>;
|
||||
|
||||
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
|
||||
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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<GenericParams> {
|
||||
let mut generics = GenericParams::default();
|
||||
|
|
|
@ -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<SourceFile> {
|
||||
pub(crate) fn hir_parse(
|
||||
db: &impl PersistentHirDatabase,
|
||||
file_id: HirFileId,
|
||||
) -> TreeArc<SourceFile> {
|
||||
match file_id.0 {
|
||||
HirFileIdRepr::File(file_id) => db.parse(file_id),
|
||||
HirFileIdRepr::Macro(m) => {
|
||||
|
@ -180,7 +184,7 @@ pub(crate) struct LocationCtx<DB> {
|
|||
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<N: AstNode>: ArenaId + Clone {
|
||||
fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<N>, 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<N: AstNode>: ArenaId + Clone {
|
|||
|
||||
Self::interner(ctx.db.as_ref()).loc2id(&loc)
|
||||
}
|
||||
fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc<N>) {
|
||||
fn source(self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<N>) {
|
||||
let int = Self::interner(db.as_ref());
|
||||
let loc = int.id2loc(self);
|
||||
let syntax = db.file_item(loc.raw);
|
||||
|
|
|
@ -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<ModuleImplBlocks>, Arc<ImplSourceMap>) {
|
||||
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<ModuleImplBlocks> {
|
||||
pub(crate) fn impls_in_module(
|
||||
db: &impl PersistentHirDatabase,
|
||||
module: Module,
|
||||
) -> Arc<ModuleImplBlocks> {
|
||||
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<ImplSourceMap> {
|
||||
db.impls_in_module_with_source_map(module).1
|
||||
|
|
|
@ -44,7 +44,7 @@ mod code_model_impl;
|
|||
mod marks;
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase,
|
||||
db::{HirDatabase, PersistentHirDatabase},
|
||||
name::{AsName, KnownName},
|
||||
ids::{SourceItemId, SourceFileItems},
|
||||
};
|
||||
|
|
|
@ -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<Arc<MacroExpansion>> {
|
||||
let loc = invoc.loc(db);
|
||||
|
|
|
@ -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<Option<Vec<salsa::Event<MockDatabase>>>>,
|
||||
|
|
|
@ -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<SourceFileItemId>,
|
||||
) -> 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<SourceFileItemId>,
|
||||
) -> Arc<Vec<Submodule>> {
|
||||
|
@ -133,7 +134,10 @@ struct LinkData {
|
|||
}
|
||||
|
||||
impl ModuleTree {
|
||||
pub(crate) fn module_tree_query(db: &impl HirDatabase, krate: Crate) -> Arc<ModuleTree> {
|
||||
pub(crate) fn module_tree_query(
|
||||
db: &impl PersistentHirDatabase,
|
||||
krate: Crate,
|
||||
) -> Arc<ModuleTree> {
|
||||
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<LinkId>,
|
||||
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<ast::Module> {
|
||||
pub(crate) fn source(
|
||||
self,
|
||||
tree: &ModuleTree,
|
||||
db: &impl PersistentHirDatabase,
|
||||
) -> TreeArc<ast::Module> {
|
||||
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,
|
||||
|
|
|
@ -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<ItemMap> {
|
||||
pub(crate) fn item_map_query(db: &impl PersistentHirDatabase, krate: Crate) -> Arc<ItemMap> {
|
||||
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<ModuleDef> {
|
||||
|
@ -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<ModuleDef>, ReachedFixedPoint) {
|
||||
|
|
|
@ -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<LoweredModule> {
|
||||
db.lower_module(module).0
|
||||
}
|
||||
|
||||
pub(crate) fn lower_module_source_map_query(
|
||||
db: &impl HirDatabase,
|
||||
db: &impl PersistentHirDatabase,
|
||||
module: Module,
|
||||
) -> Arc<ImportSourceMap> {
|
||||
db.lower_module(module).1
|
||||
}
|
||||
|
||||
pub(crate) fn lower_module_query(
|
||||
db: &impl HirDatabase,
|
||||
db: &impl PersistentHirDatabase,
|
||||
module: Module,
|
||||
) -> (Arc<LoweredModule>, Arc<ImportSourceMap>) {
|
||||
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<Item = ast::ItemOrMacro>,
|
||||
|
@ -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,
|
||||
|
|
|
@ -6,7 +6,7 @@ use test_utils::{assert_eq_text, covers};
|
|||
|
||||
use crate::{
|
||||
ItemMap, Resolution,
|
||||
db::HirDatabase,
|
||||
PersistentHirDatabase,
|
||||
mock::MockDatabase,
|
||||
module_tree::ModuleId,
|
||||
};
|
||||
|
|
|
@ -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<SourceFileItems> {
|
||||
pub(super) fn file_items(
|
||||
db: &impl PersistentHirDatabase,
|
||||
file_id: HirFileId,
|
||||
) -> Arc<SourceFileItems> {
|
||||
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<SyntaxNode> {
|
||||
let source_file = db.hir_parse(source_item_id.file_id);
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue