From 3f0cf6ebe1a42c3a38f3ab8a7b2e10110ed91ee1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 23 Mar 2019 15:37:04 +0300 Subject: rename persistent hir database -> def database --- crates/ra_batch/src/lib.rs | 6 +- crates/ra_hir/src/adt.rs | 19 +++--- crates/ra_hir/src/code_model_api.rs | 83 ++++++++++++--------------- crates/ra_hir/src/code_model_impl/function.rs | 7 +-- crates/ra_hir/src/code_model_impl/konst.rs | 6 +- crates/ra_hir/src/code_model_impl/krate.rs | 9 +-- crates/ra_hir/src/code_model_impl/module.rs | 15 ++--- crates/ra_hir/src/db.rs | 6 +- crates/ra_hir/src/generics.rs | 4 +- crates/ra_hir/src/ids.rs | 28 ++++----- crates/ra_hir/src/impl_block.rs | 29 ++++------ crates/ra_hir/src/lib.rs | 2 +- crates/ra_hir/src/mock.rs | 6 +- crates/ra_hir/src/nameres.rs | 15 ++--- crates/ra_hir/src/nameres/collector.rs | 13 ++--- crates/ra_hir/src/nameres/raw.rs | 9 +-- crates/ra_hir/src/type_alias.rs | 7 +-- crates/ra_ide_api/src/db.rs | 2 +- 18 files changed, 106 insertions(+), 160 deletions(-) diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index deb9f95d7..3bbcdb0b8 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs @@ -16,11 +16,7 @@ use vfs_filter::IncludeRustFiles; type Result = std::result::Result; -#[salsa::database( - ra_db::SourceDatabaseStorage, - db::HirDatabaseStorage, - db::PersistentHirDatabaseStorage -)] +#[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage, db::DefDatabaseStorage)] #[derive(Debug)] pub struct BatchDatabase { runtime: salsa::Runtime, diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 325f1d7b6..78ea8976b 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, PersistentHirDatabase, + type_ref::TypeRef, DefDatabase, }; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -33,7 +33,7 @@ impl AdtDef { } impl Struct { - pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc { + pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc { db.struct_data((*self).into()).variant_data.clone() } } @@ -52,10 +52,7 @@ impl StructData { StructData { name, variant_data } } - pub(crate) fn struct_data_query( - db: &impl PersistentHirDatabase, - struct_: Struct, - ) -> Arc { + pub(crate) fn struct_data_query(db: &impl DefDatabase, struct_: Struct) -> Arc { let (_, struct_def) = struct_.source(db); Arc::new(StructData::new(&*struct_def)) } @@ -68,7 +65,7 @@ fn variants(enum_def: &ast::EnumDef) -> impl Iterator impl EnumVariant { pub(crate) fn source_impl( &self, - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, ) -> (HirFileId, TreeArc) { let (file_id, enum_def) = self.parent.source(db); let var = variants(&*enum_def) @@ -79,7 +76,7 @@ impl EnumVariant { .to_owned(); (file_id, var) } - pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc { + pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc { db.enum_data(self.parent).variants[self.id].variant_data.clone() } } @@ -91,7 +88,7 @@ pub struct EnumData { } impl EnumData { - pub(crate) fn enum_data_query(db: &impl PersistentHirDatabase, e: Enum) -> Arc { + pub(crate) fn enum_data_query(db: &impl DefDatabase, 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) @@ -189,7 +186,7 @@ impl VariantDef { VariantDef::EnumVariant(it) => it.field(db, name), } } - pub(crate) fn variant_data(self, db: &impl PersistentHirDatabase) -> Arc { + pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc { match self { VariantDef::Struct(it) => it.variant_data(db), VariantDef::EnumVariant(it) => it.variant_data(db), @@ -198,7 +195,7 @@ impl VariantDef { } impl StructField { - pub(crate) fn source_impl(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { + pub(crate) fn source_impl(&self, db: &impl DefDatabase) -> (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 62301e4ab..3f2e14bc8 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -6,7 +6,7 @@ use ra_syntax::{ast::self, TreeArc, SyntaxNode}; use crate::{ Name, ScopesWithSourceMap, Ty, HirFileId, - HirDatabase, PersistentHirDatabase, + HirDatabase, DefDatabase, type_ref::TypeRef, nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, expr::{Body, BodySourceMap}, @@ -38,24 +38,21 @@ impl Crate { self.crate_id } - pub fn dependencies(&self, db: &impl PersistentHirDatabase) -> Vec { + pub fn dependencies(&self, db: &impl DefDatabase) -> Vec { self.dependencies_impl(db) } - pub fn root_module(&self, db: &impl PersistentHirDatabase) -> Option { + pub fn root_module(&self, db: &impl DefDatabase) -> Option { self.root_module_impl(db) } - pub fn edition(&self, db: &impl PersistentHirDatabase) -> Edition { + pub fn edition(&self, db: &impl DefDatabase) -> Edition { let crate_graph = db.crate_graph(); crate_graph.edition(self.crate_id) } // FIXME: should this be in source_binder? - pub fn source_root_crates( - db: &impl PersistentHirDatabase, - source_root: SourceRootId, - ) -> Vec { + pub fn source_root_crates(db: &impl DefDatabase, source_root: SourceRootId) -> Vec { let crate_ids = db.source_root_crates(source_root); crate_ids.iter().map(|&crate_id| Crate { crate_id }).collect() } @@ -111,7 +108,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 PersistentHirDatabase) -> (HirFileId, ModuleSource) { + pub fn definition_source(&self, db: &impl DefDatabase) -> (HirFileId, ModuleSource) { self.definition_source_impl(db) } @@ -134,14 +131,14 @@ impl Module { } /// Returns the crate this module is part of. - pub fn krate(&self, _db: &impl PersistentHirDatabase) -> Option { + pub fn krate(&self, _db: &impl DefDatabase) -> Option { Some(self.krate) } /// 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 PersistentHirDatabase) -> Module { + pub fn crate_root(&self, db: &impl DefDatabase) -> Module { self.crate_root_impl(db) } @@ -151,12 +148,12 @@ impl Module { } /// Iterates over all child modules. - pub fn children(&self, db: &impl PersistentHirDatabase) -> impl Iterator { + pub fn children(&self, db: &impl DefDatabase) -> impl Iterator { self.children_impl(db) } /// Finds a parent module. - pub fn parent(&self, db: &impl PersistentHirDatabase) -> Option { + pub fn parent(&self, db: &impl DefDatabase) -> Option { self.parent_impl(db) } @@ -229,7 +226,7 @@ impl StructField { self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() } - pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { + pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, FieldSource) { self.source_impl(db) } @@ -257,7 +254,7 @@ pub struct Struct { } impl Struct { - pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } @@ -289,7 +286,7 @@ impl Struct { .map(|(id, _)| StructField { parent: (*self).into(), id }) } - pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { + pub fn generic_params(&self, db: &impl DefDatabase) -> Arc { db.generic_params((*self).into()) } @@ -325,7 +322,7 @@ pub struct Enum { } impl Enum { - pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } @@ -337,7 +334,7 @@ impl Enum { db.enum_data(*self).name.clone() } - pub fn variants(&self, db: &impl PersistentHirDatabase) -> Vec { + pub fn variants(&self, db: &impl DefDatabase) -> Vec { db.enum_data(*self) .variants .iter() @@ -345,7 +342,7 @@ impl Enum { .collect() } - pub fn variant(&self, db: &impl PersistentHirDatabase, name: &Name) -> Option { + pub fn variant(&self, db: &impl DefDatabase, name: &Name) -> Option { db.enum_data(*self) .variants .iter() @@ -353,7 +350,7 @@ impl Enum { .map(|(id, _)| EnumVariant { parent: *self, id }) } - pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { + pub fn generic_params(&self, db: &impl DefDatabase) -> Arc { db.generic_params((*self).into()) } @@ -386,20 +383,17 @@ pub struct EnumVariant { } impl EnumVariant { - pub fn source( - &self, - db: &impl PersistentHirDatabase, - ) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl DefDatabase) -> (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 PersistentHirDatabase) -> Enum { + pub fn parent_enum(&self, _db: &impl DefDatabase) -> Enum { self.parent } - pub fn name(&self, db: &impl PersistentHirDatabase) -> Option { + pub fn name(&self, db: &impl DefDatabase) -> Option { db.enum_data(self.parent).variants[self.id].name.clone() } @@ -465,11 +459,11 @@ impl FnSignature { } impl Function { - pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } - pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { + pub fn module(&self, db: &impl DefDatabase) -> Module { self.id.module(db) } @@ -503,12 +497,12 @@ impl Function { db.infer(*self) } - pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { + pub fn generic_params(&self, db: &impl DefDatabase) -> Arc { db.generic_params((*self).into()) } /// The containing impl block, if this is a method. - pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option { + pub fn impl_block(&self, db: &impl DefDatabase) -> Option { let module_impls = db.impls_in_module(self.module(db)); ImplBlock::containing(module_impls, (*self).into()) } @@ -540,11 +534,11 @@ pub struct Const { } impl Const { - pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } - pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { + pub fn module(&self, db: &impl DefDatabase) -> Module { self.id.module(db) } @@ -553,7 +547,7 @@ impl Const { } /// The containing impl block, if this is a method. - pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option { + pub fn impl_block(&self, db: &impl DefDatabase) -> Option { let module_impls = db.impls_in_module(self.module(db)); ImplBlock::containing(module_impls, (*self).into()) } @@ -599,11 +593,11 @@ pub struct Static { } impl Static { - pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } - pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { + pub fn module(&self, db: &impl DefDatabase) -> Module { self.id.module(db) } @@ -630,15 +624,15 @@ pub struct Trait { } impl Trait { - pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } - pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { + pub fn module(&self, db: &impl DefDatabase) -> Module { self.id.module(db) } - pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { + pub fn generic_params(&self, db: &impl DefDatabase) -> Arc { db.generic_params((*self).into()) } } @@ -655,28 +649,25 @@ pub struct TypeAlias { } impl TypeAlias { - pub fn source( - &self, - db: &impl PersistentHirDatabase, - ) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc) { self.id.source(db) } - pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { + pub fn generic_params(&self, db: &impl DefDatabase) -> Arc { db.generic_params((*self).into()) } - pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { + pub fn module(&self, db: &impl DefDatabase) -> Module { self.id.module(db) } /// The containing impl block, if this is a method. - pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option { + pub fn impl_block(&self, db: &impl DefDatabase) -> Option { let module_impls = db.impls_in_module(self.module(db)); ImplBlock::containing(module_impls, (*self).into()) } - pub fn type_ref(self, db: &impl PersistentHirDatabase) -> Arc { + pub fn type_ref(self, db: &impl DefDatabase) -> Arc { db.type_alias_ref(self) } diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs index c1654b069..334cb302b 100644 --- a/crates/ra_hir/src/code_model_impl/function.rs +++ b/crates/ra_hir/src/code_model_impl/function.rs @@ -5,14 +5,11 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; use crate::{ Name, AsName, Function, FnSignature, type_ref::{TypeRef, Mutability}, - PersistentHirDatabase, + DefDatabase, }; impl FnSignature { - pub(crate) fn fn_signature_query( - db: &impl PersistentHirDatabase, - func: Function, - ) -> Arc { + pub(crate) fn fn_signature_query(db: &impl DefDatabase, func: Function) -> Arc { let (_, node) = func.source(db); let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); let mut params = Vec::new(); diff --git a/crates/ra_hir/src/code_model_impl/konst.rs b/crates/ra_hir/src/code_model_impl/konst.rs index 8b861a81f..db4e5ce5c 100644 --- a/crates/ra_hir/src/code_model_impl/konst.rs +++ b/crates/ra_hir/src/code_model_impl/konst.rs @@ -5,7 +5,7 @@ use ra_syntax::ast::{NameOwner, TypeAscriptionOwner}; use crate::{ Name, AsName, Const, ConstSignature, Static, type_ref::{TypeRef}, - PersistentHirDatabase, + DefDatabase, }; fn const_signature_for(node: &N) -> Arc { @@ -17,7 +17,7 @@ fn const_signature_for(node: &N) -> Arc Arc { let (_, node) = konst.source(db); @@ -25,7 +25,7 @@ impl ConstSignature { } pub(crate) fn static_signature_query( - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, konst: Static, ) -> Arc { let (_, node) = konst.source(db); diff --git a/crates/ra_hir/src/code_model_impl/krate.rs b/crates/ra_hir/src/code_model_impl/krate.rs index cc87c6f14..914414fc3 100644 --- a/crates/ra_hir/src/code_model_impl/krate.rs +++ b/crates/ra_hir/src/code_model_impl/krate.rs @@ -1,12 +1,9 @@ use crate::{ - Crate, CrateDependency, AsName, Module, PersistentHirDatabase, + Crate, CrateDependency, AsName, Module, DefDatabase, }; impl Crate { - pub(crate) fn dependencies_impl( - &self, - db: &impl PersistentHirDatabase, - ) -> Vec { + pub(crate) fn dependencies_impl(&self, db: &impl DefDatabase) -> Vec { let crate_graph = db.crate_graph(); crate_graph .dependencies(self.crate_id) @@ -17,7 +14,7 @@ impl Crate { }) .collect() } - pub(crate) fn root_module_impl(&self, db: &impl PersistentHirDatabase) -> Option { + pub(crate) fn root_module_impl(&self, db: &impl DefDatabase) -> Option { let module_id = db.crate_def_map(*self).root(); let module = Module { krate: *self, module_id }; Some(module) diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index f7d15c55e..52a33e981 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -4,13 +4,13 @@ use ra_syntax::{ast, SyntaxNode, TreeArc, AstNode}; use crate::{ Module, ModuleSource, Problem, Name, nameres::{CrateModuleId, ImportId}, - HirDatabase, PersistentHirDatabase, + HirDatabase, DefDatabase, HirFileId, SourceItemId, }; impl ModuleSource { pub(crate) fn new( - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, file_id: Option, decl_id: Option, ) -> ModuleSource { @@ -49,7 +49,7 @@ impl Module { pub(crate) fn definition_source_impl( &self, - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, ) -> (HirFileId, ModuleSource) { let def_map = db.crate_def_map(self.krate); let decl_id = def_map[self.module_id].declaration; @@ -80,7 +80,7 @@ impl Module { source_map.get(&source, import) } - pub(crate) fn crate_root_impl(&self, db: &impl PersistentHirDatabase) -> Module { + pub(crate) fn crate_root_impl(&self, db: &impl DefDatabase) -> Module { let def_map = db.crate_def_map(self.krate); self.with_module_id(def_map.root()) } @@ -93,10 +93,7 @@ impl Module { } /// Iterates over all child modules. - pub(crate) fn children_impl( - &self, - db: &impl PersistentHirDatabase, - ) -> impl Iterator { + pub(crate) fn children_impl(&self, db: &impl DefDatabase) -> impl Iterator { let def_map = db.crate_def_map(self.krate); let children = def_map[self.module_id] .children @@ -106,7 +103,7 @@ impl Module { children.into_iter() } - pub(crate) fn parent_impl(&self, db: &impl PersistentHirDatabase) -> Option { + pub(crate) fn parent_impl(&self, db: &impl DefDatabase) -> Option { let def_map = db.crate_def_map(self.krate); let parent_id = def_map[self.module_id].parent?; Some(self.with_module_id(parent_id)) diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index c7bad7e2b..d3908f8ac 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -16,8 +16,8 @@ use crate::{ type_ref::TypeRef, }; -#[salsa::query_group(PersistentHirDatabaseStorage)] -pub trait PersistentHirDatabase: SourceDatabase + AsRef { +#[salsa::query_group(DefDatabaseStorage)] +pub trait DefDatabase: SourceDatabase + AsRef { #[salsa::invoke(HirFileId::hir_parse)] fn hir_parse(&self, file_id: HirFileId) -> TreeArc; @@ -71,7 +71,7 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef { } #[salsa::query_group(HirDatabaseStorage)] -pub trait HirDatabase: PersistentHirDatabase { +pub trait HirDatabase: DefDatabase { #[salsa::invoke(ExprScopes::expr_scopes_query)] fn expr_scopes(&self, func: Function) -> Arc; diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 498ed04f2..84fe94289 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use ra_syntax::ast::{self, NameOwner, TypeParamsOwner}; use crate::{ - db::PersistentHirDatabase, + db::DefDatabase, Name, AsName, Function, Struct, Enum, Trait, TypeAlias, ImplBlock }; @@ -40,7 +40,7 @@ impl_froms!(GenericDef: Function, Struct, Enum, Trait, TypeAlias, ImplBlock); impl GenericParams { pub(crate) fn generic_params_query( - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, 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 3d0a881c2..18401f865 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -10,7 +10,7 @@ use ra_arena::{Arena, RawId, ArenaId, impl_arena_id}; use crate::{ Module, - PersistentHirDatabase, + DefDatabase, }; #[derive(Debug, Default)] @@ -63,7 +63,7 @@ pub struct HirFileId(HirFileIdRepr); impl HirFileId { /// For macro-expansion files, returns the file original source file the /// expansion originated from. - pub fn original_file(self, db: &impl PersistentHirDatabase) -> FileId { + pub fn original_file(self, db: &impl DefDatabase) -> FileId { match self.0 { HirFileIdRepr::File(file_id) => file_id, HirFileIdRepr::Macro(macro_call_id) => { @@ -83,10 +83,7 @@ impl HirFileId { } } - pub(crate) fn hir_parse( - db: &impl PersistentHirDatabase, - file_id: HirFileId, - ) -> TreeArc { + pub(crate) fn hir_parse(db: &impl DefDatabase, file_id: HirFileId) -> TreeArc { match file_id.0 { HirFileIdRepr::File(file_id) => db.parse(file_id), HirFileIdRepr::Macro(macro_call_id) => { @@ -97,10 +94,7 @@ impl HirFileId { } } -fn parse_macro( - db: &impl PersistentHirDatabase, - macro_call_id: MacroCallId, -) -> Option> { +fn parse_macro(db: &impl DefDatabase, macro_call_id: MacroCallId) -> Option> { let loc = macro_call_id.loc(db); let syntax = db.file_item(loc.source_item_id); let macro_call = ast::MacroCall::cast(&syntax).unwrap(); @@ -190,7 +184,7 @@ pub(crate) struct LocationCtx { file_id: HirFileId, } -impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> { +impl<'a, DB: DefDatabase> LocationCtx<&'a DB> { pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> { LocationCtx { db, module, file_id } } @@ -205,13 +199,13 @@ impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> { pub(crate) trait AstItemDef: ArenaId + Clone { fn interner(interner: &HirInterner) -> &LocationInterner, Self>; - fn from_ast(ctx: LocationCtx<&impl PersistentHirDatabase>, ast: &N) -> Self { + fn from_ast(ctx: LocationCtx<&impl DefDatabase>, ast: &N) -> Self { let items = ctx.db.file_items(ctx.file_id); let item_id = items.id_of(ctx.file_id, ast.syntax()); Self::from_source_item_id_unchecked(ctx, item_id) } fn from_source_item_id_unchecked( - ctx: LocationCtx<&impl PersistentHirDatabase>, + ctx: LocationCtx<&impl DefDatabase>, item_id: SourceFileItemId, ) -> Self { let raw = SourceItemId { file_id: ctx.file_id, item_id }; @@ -219,7 +213,7 @@ pub(crate) trait AstItemDef: ArenaId + Clone { Self::interner(ctx.db.as_ref()).loc2id(&loc) } - fn source(self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { + fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc) { let int = Self::interner(db.as_ref()); let loc = int.id2loc(self); let syntax = db.file_item(loc.raw); @@ -227,7 +221,7 @@ pub(crate) trait AstItemDef: ArenaId + Clone { N::cast(&syntax).unwrap_or_else(|| panic!("invalid ItemLoc: {:?}", loc.raw)).to_owned(); (loc.raw.file_id, ast) } - fn module(self, db: &impl PersistentHirDatabase) -> Module { + fn module(self, db: &impl DefDatabase) -> Module { let int = Self::interner(db.as_ref()); let loc = int.id2loc(self); loc.module @@ -324,7 +318,7 @@ pub struct SourceFileItems { impl SourceFileItems { pub(crate) fn file_items_query( - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, file_id: HirFileId, ) -> Arc { let source_file = db.hir_parse(file_id); @@ -332,7 +326,7 @@ impl SourceFileItems { } pub(crate) fn file_item_query( - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, source_item_id: SourceItemId, ) -> TreeArc { let source_file = db.hir_parse(source_item_id.file_id); diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 0d3861a28..40d368cd9 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -9,7 +9,7 @@ use ra_syntax::{ use crate::{ Const, TypeAlias, Function, HirFileId, - HirDatabase, PersistentHirDatabase, + HirDatabase, DefDatabase, ModuleDef, Trait, Resolution, type_ref::TypeRef, ids::LocationCtx, @@ -59,7 +59,7 @@ impl ImplBlock { } /// Returns the syntax of the impl block - pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc) { + pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc) { let source_map = db.impls_in_module_source_map(self.module); let (file_id, source) = self.module.definition_source(db); (file_id, source_map.get(&source, self.impl_id)) @@ -73,11 +73,11 @@ impl ImplBlock { self.module } - pub fn target_trait_ref(&self, db: &impl PersistentHirDatabase) -> Option { + pub fn target_trait_ref(&self, db: &impl DefDatabase) -> Option { db.impls_in_module(self.module).impls[self.impl_id].target_trait().cloned() } - pub fn target_type(&self, db: &impl PersistentHirDatabase) -> TypeRef { + pub fn target_type(&self, db: &impl DefDatabase) -> TypeRef { db.impls_in_module(self.module).impls[self.impl_id].target_type().clone() } @@ -97,11 +97,11 @@ impl ImplBlock { None } - pub fn items(&self, db: &impl PersistentHirDatabase) -> Vec { + pub fn items(&self, db: &impl DefDatabase) -> Vec { db.impls_in_module(self.module).impls[self.impl_id].items().to_vec() } - pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { + pub fn generic_params(&self, db: &impl DefDatabase) -> Arc { db.generic_params((*self).into()) } @@ -124,7 +124,7 @@ pub struct ImplData { impl ImplData { pub(crate) fn from_ast( - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, file_id: HirFileId, module: Module, node: &ast::ImplBlock, @@ -193,11 +193,7 @@ pub struct ModuleImplBlocks { } impl ModuleImplBlocks { - fn collect( - db: &impl PersistentHirDatabase, - module: Module, - source_map: &mut ImplSourceMap, - ) -> Self { + fn collect(db: &impl DefDatabase, module: Module, source_map: &mut ImplSourceMap) -> Self { let mut m = ModuleImplBlocks { module, impls: Arena::default(), @@ -228,7 +224,7 @@ impl ModuleImplBlocks { } pub(crate) fn impls_in_module_with_source_map_query( - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, module: Module, ) -> (Arc, Arc) { let mut source_map = ImplSourceMap::default(); @@ -238,15 +234,12 @@ 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 PersistentHirDatabase, - module: Module, -) -> Arc { +pub(crate) fn impls_in_module(db: &impl DefDatabase, module: Module) -> Arc { db.impls_in_module_with_source_map(module).0 } pub(crate) fn impls_in_module_source_map_query( - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, 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 5926b5758..a89c916f8 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -43,7 +43,7 @@ mod code_model_impl; mod marks; use crate::{ - db::{HirDatabase, PersistentHirDatabase}, + db::{HirDatabase, DefDatabase}, name::{AsName, KnownName}, ids::{SourceItemId, SourceFileItems}, }; diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index f1cad77c5..10d4c1b8c 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs @@ -13,11 +13,7 @@ use crate::{db, HirInterner}; pub const WORKSPACE: SourceRootId = SourceRootId(0); -#[salsa::database( - ra_db::SourceDatabaseStorage, - db::HirDatabaseStorage, - db::PersistentHirDatabaseStorage -)] +#[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage, db::DefDatabaseStorage)] #[derive(Debug)] pub struct MockDatabase { events: Mutex>>>, diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index e9235bc59..d361cf9e6 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -62,7 +62,7 @@ use test_utils::tested_by; use crate::{ ModuleDef, Name, Crate, Module, Problem, - PersistentHirDatabase, Path, PathKind, HirFileId, + DefDatabase, Path, PathKind, HirFileId, ids::{SourceItemId, SourceFileItemId, MacroCallId}, }; @@ -196,10 +196,7 @@ enum ReachedFixedPoint { } impl CrateDefMap { - pub(crate) fn crate_def_map_query( - db: &impl PersistentHirDatabase, - krate: Crate, - ) -> Arc { + pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: Crate) -> Arc { let start = std::time::Instant::now(); let def_map = { let edition = krate.edition(db); @@ -268,7 +265,7 @@ impl CrateDefMap { pub(crate) fn resolve_path( &self, - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, original_module: CrateModuleId, path: &Path, ) -> (PerNs, Option) { @@ -280,7 +277,7 @@ impl CrateDefMap { // the result. fn resolve_path_fp( &self, - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, mode: ResolveMode, original_module: CrateModuleId, path: &Path, @@ -422,7 +419,7 @@ impl CrateDefMap { pub(crate) fn resolve_name_in_module( &self, - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, module: CrateModuleId, name: &Name, ) -> PerNs { @@ -442,7 +439,7 @@ impl CrateDefMap { self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)) } - fn resolve_in_prelude(&self, db: &impl PersistentHirDatabase, name: &Name) -> PerNs { + fn resolve_in_prelude(&self, db: &impl DefDatabase, name: &Name) -> PerNs { if let Some(prelude) = self.prelude { let resolution = if prelude.krate == self.krate { self[prelude.module_id].scope.items.get(name).cloned() diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 3ea8d592c..c5b73cfbe 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -6,7 +6,7 @@ use ra_db::FileId; use crate::{ Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias, - PersistentHirDatabase, HirFileId, Name, Path, Problem, Crate, + DefDatabase, HirFileId, Name, Path, Problem, Crate, KnownName, nameres::{Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, raw}, ids::{AstItemDef, LocationCtx, MacroCallLoc, SourceItemId, MacroCallId}, @@ -14,10 +14,7 @@ use crate::{ use super::{CrateDefMap, CrateModuleId, ModuleData, CrateMacroId}; -pub(super) fn collect_defs( - db: &impl PersistentHirDatabase, - mut def_map: CrateDefMap, -) -> CrateDefMap { +pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { // populate external prelude for dep in def_map.krate.dependencies(db) { log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate); @@ -57,7 +54,7 @@ struct DefCollector { impl<'a, DB> DefCollector<&'a DB> where - DB: PersistentHirDatabase, + DB: DefDatabase, { fn collect(&mut self) { let crate_graph = self.db.crate_graph(); @@ -370,7 +367,7 @@ struct ModCollector<'a, D> { impl ModCollector<'_, &'_ mut DefCollector<&'_ DB>> where - DB: PersistentHirDatabase, + DB: DefDatabase, { fn collect(&mut self, items: &[raw::RawItem]) { for item in items { @@ -523,7 +520,7 @@ fn is_macro_rules(path: &Path) -> bool { } fn resolve_submodule( - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, file_id: HirFileId, name: &Name, is_root: bool, diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 3226bbf0d..f8ba398ec 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs @@ -12,7 +12,7 @@ use ra_syntax::{ }; use crate::{ - PersistentHirDatabase, Name, AsName, Path, HirFileId, ModuleSource, + DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, ids::{SourceFileItemId, SourceFileItems}, }; @@ -47,15 +47,12 @@ impl ImportSourceMap { } impl RawItems { - pub(crate) fn raw_items_query( - db: &impl PersistentHirDatabase, - file_id: FileId, - ) -> Arc { + pub(crate) fn raw_items_query(db: &impl DefDatabase, file_id: FileId) -> Arc { db.raw_items_with_source_map(file_id).0 } pub(crate) fn raw_items_with_source_map_query( - db: &impl PersistentHirDatabase, + db: &impl DefDatabase, file_id: FileId, ) -> (Arc, Arc) { let mut collector = RawItemsCollector { diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs index d02762d20..e35adcb2f 100644 --- a/crates/ra_hir/src/type_alias.rs +++ b/crates/ra_hir/src/type_alias.rs @@ -2,12 +2,9 @@ use std::sync::Arc; -use crate::{TypeAlias, db::PersistentHirDatabase, type_ref::TypeRef}; +use crate::{TypeAlias, db::DefDatabase, type_ref::TypeRef}; -pub(crate) fn type_alias_ref_query( - db: &impl PersistentHirDatabase, - typ: TypeAlias, -) -> Arc { +pub(crate) fn type_alias_ref_query(db: &impl DefDatabase, typ: TypeAlias) -> Arc { let (_, node) = typ.source(db); Arc::new(TypeRef::from_ast_opt(node.type_ref())) } diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index 00f4bdfd2..ea4255d35 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs @@ -15,7 +15,7 @@ use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}}; LineIndexDatabaseStorage, symbol_index::SymbolsDatabaseStorage, hir::db::HirDatabaseStorage, - hir::db::PersistentHirDatabaseStorage + hir::db::DefDatabaseStorage )] #[derive(Debug)] pub(crate) struct RootDatabase { -- cgit v1.2.3