aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/db.rs60
-rw-r--r--crates/ra_hir/src/ids.rs18
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/mock.rs1
-rw-r--r--crates/ra_hir/src/nameres.rs4
-rw-r--r--crates/ra_hir/src/nameres/collector.rs17
-rw-r--r--crates/ra_ide_api/src/db.rs1
7 files changed, 55 insertions, 48 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index a9840905c..8f4de1c85 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -20,13 +20,41 @@ use crate::{
20 lang_item::{LangItems, LangItemTarget}, type_alias::TypeAliasData, 20 lang_item::{LangItems, LangItemTarget}, type_alias::TypeAliasData,
21}; 21};
22 22
23// This database has access to source code, so queries here are not really 23/// We store all interned things in the single QueryGroup.
24// incremental. 24///
25#[salsa::query_group(AstDatabaseStorage)] 25/// This is done mainly to allow both "volatile" `AstDatabase` and "stable"
26pub trait AstDatabase: SourceDatabase { 26/// `DefDatabase` to access macros, without adding hard dependencies between the
27/// two.
28#[salsa::query_group(InternDatabaseStorage)]
29pub trait InternDatabase: SourceDatabase {
27 #[salsa::interned] 30 #[salsa::interned]
28 fn intern_macro(&self, macro_call: MacroCallLoc) -> ids::MacroCallId; 31 fn intern_macro(&self, macro_call: MacroCallLoc) -> ids::MacroCallId;
32 #[salsa::interned]
33 fn intern_function(&self, loc: ids::ItemLoc<ast::FnDef>) -> ids::FunctionId;
34 #[salsa::interned]
35 fn intern_struct(&self, loc: ids::ItemLoc<ast::StructDef>) -> ids::StructId;
36 #[salsa::interned]
37 fn intern_enum(&self, loc: ids::ItemLoc<ast::EnumDef>) -> ids::EnumId;
38 #[salsa::interned]
39 fn intern_const(&self, loc: ids::ItemLoc<ast::ConstDef>) -> ids::ConstId;
40 #[salsa::interned]
41 fn intern_static(&self, loc: ids::ItemLoc<ast::StaticDef>) -> ids::StaticId;
42 #[salsa::interned]
43 fn intern_trait(&self, loc: ids::ItemLoc<ast::TraitDef>) -> ids::TraitId;
44 #[salsa::interned]
45 fn intern_type_alias(&self, loc: ids::ItemLoc<ast::TypeAliasDef>) -> ids::TypeAliasId;
29 46
47 // Interned IDs for Chalk integration
48 #[salsa::interned]
49 fn intern_type_ctor(&self, type_ctor: TypeCtor) -> ids::TypeCtorId;
50 #[salsa::interned]
51 fn intern_impl_block(&self, impl_block: ImplBlock) -> ids::GlobalImplId;
52}
53
54/// This database has access to source code, so queries here are not really
55/// incremental.
56#[salsa::query_group(AstDatabaseStorage)]
57pub trait AstDatabase: InternDatabase {
30 #[salsa::invoke(crate::source_id::AstIdMap::ast_id_map_query)] 58 #[salsa::invoke(crate::source_id::AstIdMap::ast_id_map_query)]
31 fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>; 59 fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>;
32 #[salsa::transparent] 60 #[salsa::transparent]
@@ -40,7 +68,6 @@ pub trait AstDatabase: SourceDatabase {
40 68
41 #[salsa::invoke(crate::ids::macro_def_query)] 69 #[salsa::invoke(crate::ids::macro_def_query)]
42 fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>; 70 fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>;
43
44 #[salsa::invoke(crate::ids::macro_arg_query)] 71 #[salsa::invoke(crate::ids::macro_arg_query)]
45 fn macro_arg(&self, macro_call: ids::MacroCallId) -> Option<Arc<tt::Subtree>>; 72 fn macro_arg(&self, macro_call: ids::MacroCallId) -> Option<Arc<tt::Subtree>>;
46 73
@@ -51,28 +78,7 @@ pub trait AstDatabase: SourceDatabase {
51// This database uses `AstDatabase` internally, 78// This database uses `AstDatabase` internally,
52#[salsa::query_group(DefDatabaseStorage)] 79#[salsa::query_group(DefDatabaseStorage)]
53#[salsa::requires(AstDatabase)] 80#[salsa::requires(AstDatabase)]
54pub trait DefDatabase: SourceDatabase { 81pub trait DefDatabase: InternDatabase {
55 #[salsa::interned]
56 fn intern_function(&self, loc: ids::ItemLoc<ast::FnDef>) -> ids::FunctionId;
57 #[salsa::interned]
58 fn intern_struct(&self, loc: ids::ItemLoc<ast::StructDef>) -> ids::StructId;
59 #[salsa::interned]
60 fn intern_enum(&self, loc: ids::ItemLoc<ast::EnumDef>) -> ids::EnumId;
61 #[salsa::interned]
62 fn intern_const(&self, loc: ids::ItemLoc<ast::ConstDef>) -> ids::ConstId;
63 #[salsa::interned]
64 fn intern_static(&self, loc: ids::ItemLoc<ast::StaticDef>) -> ids::StaticId;
65 #[salsa::interned]
66 fn intern_trait(&self, loc: ids::ItemLoc<ast::TraitDef>) -> ids::TraitId;
67 #[salsa::interned]
68 fn intern_type_alias(&self, loc: ids::ItemLoc<ast::TypeAliasDef>) -> ids::TypeAliasId;
69
70 // Interned IDs for Chalk integration
71 #[salsa::interned]
72 fn intern_type_ctor(&self, type_ctor: TypeCtor) -> ids::TypeCtorId;
73 #[salsa::interned]
74 fn intern_impl_block(&self, impl_block: ImplBlock) -> ids::GlobalImplId;
75
76 #[salsa::invoke(crate::adt::StructData::struct_data_query)] 82 #[salsa::invoke(crate::adt::StructData::struct_data_query)]
77 fn struct_data(&self, s: Struct) -> Arc<StructData>; 83 fn struct_data(&self, s: Struct) -> Arc<StructData>;
78 84
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 033af1632..b7215ac03 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -9,7 +9,7 @@ use ra_prof::profile;
9use mbe::MacroRules; 9use mbe::MacroRules;
10 10
11use crate::{ 11use crate::{
12 Module, DefDatabase, AstId, FileAstId, AstDatabase, Source, 12 Module, DefDatabase, AstId, FileAstId, AstDatabase, Source, InternDatabase,
13}; 13};
14 14
15/// hir makes heavy use of ids: integer (u32) handlers to various things. You 15/// hir makes heavy use of ids: integer (u32) handlers to various things. You
@@ -37,7 +37,7 @@ pub struct HirFileId(HirFileIdRepr);
37impl HirFileId { 37impl HirFileId {
38 /// For macro-expansion files, returns the file original source file the 38 /// For macro-expansion files, returns the file original source file the
39 /// expansion originated from. 39 /// expansion originated from.
40 pub fn original_file(self, db: &impl AstDatabase) -> FileId { 40 pub fn original_file(self, db: &impl InternDatabase) -> FileId {
41 match self.0 { 41 match self.0 {
42 HirFileIdRepr::File(file_id) => file_id, 42 HirFileIdRepr::File(file_id) => file_id,
43 HirFileIdRepr::Macro(macro_file) => { 43 HirFileIdRepr::Macro(macro_file) => {
@@ -187,7 +187,7 @@ pub struct MacroCallLoc {
187} 187}
188 188
189impl MacroCallId { 189impl MacroCallId {
190 pub(crate) fn loc(self, db: &impl AstDatabase) -> MacroCallLoc { 190 pub(crate) fn loc(self, db: &impl InternDatabase) -> MacroCallLoc {
191 db.lookup_intern_macro(self) 191 db.lookup_intern_macro(self)
192 } 192 }
193 193
@@ -198,7 +198,7 @@ impl MacroCallId {
198} 198}
199 199
200impl MacroCallLoc { 200impl MacroCallLoc {
201 pub(crate) fn id(self, db: &impl AstDatabase) -> MacroCallId { 201 pub(crate) fn id(self, db: &impl InternDatabase) -> MacroCallId {
202 db.intern_macro(self) 202 db.intern_macro(self)
203 } 203 }
204} 204}
@@ -235,10 +235,13 @@ pub(crate) struct LocationCtx<DB> {
235 file_id: HirFileId, 235 file_id: HirFileId,
236} 236}
237 237
238impl<'a, DB: DefDatabase + AstDatabase> LocationCtx<&'a DB> { 238impl<'a, DB: DefDatabase> LocationCtx<&'a DB> {
239 pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> { 239 pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> {
240 LocationCtx { db, module, file_id } 240 LocationCtx { db, module, file_id }
241 } 241 }
242}
243
244impl<'a, DB: DefDatabase + AstDatabase> LocationCtx<&'a DB> {
242 pub(crate) fn to_def<N, DEF>(self, ast: &N) -> DEF 245 pub(crate) fn to_def<N, DEF>(self, ast: &N) -> DEF
243 where 246 where
244 N: AstNode, 247 N: AstNode,
@@ -257,10 +260,7 @@ pub(crate) trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
257 let item_id = items.ast_id(ast); 260 let item_id = items.ast_id(ast);
258 Self::from_ast_id(ctx, item_id) 261 Self::from_ast_id(ctx, item_id)
259 } 262 }
260 fn from_ast_id( 263 fn from_ast_id(ctx: LocationCtx<&impl DefDatabase>, ast_id: FileAstId<N>) -> Self {
261 ctx: LocationCtx<&(impl AstDatabase + DefDatabase)>,
262 ast_id: FileAstId<N>,
263 ) -> Self {
264 let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) }; 264 let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) };
265 Self::intern(ctx.db, loc) 265 Self::intern(ctx.db, loc)
266 } 266 }
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index f07a36926..5afd846f5 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -47,7 +47,7 @@ mod code_model;
47mod marks; 47mod marks;
48 48
49use crate::{ 49use crate::{
50 db::{AstDatabase, DefDatabase, HirDatabase}, 50 db::{InternDatabase, AstDatabase, DefDatabase, HirDatabase},
51 name::{AsName, KnownName}, 51 name::{AsName, KnownName},
52 source_id::{FileAstId, AstId}, 52 source_id::{FileAstId, AstId},
53 resolve::Resolver, 53 resolve::Resolver,
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 5d38ac76c..c57dfbf01 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -15,6 +15,7 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0);
15 15
16#[salsa::database( 16#[salsa::database(
17 ra_db::SourceDatabaseStorage, 17 ra_db::SourceDatabaseStorage,
18 db::InternDatabaseStorage,
18 db::AstDatabaseStorage, 19 db::AstDatabaseStorage,
19 db::DefDatabaseStorage, 20 db::DefDatabaseStorage,
20 db::HirDatabaseStorage 21 db::HirDatabaseStorage
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 3532faf01..f4ca454e4 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -231,7 +231,9 @@ fn or(left: ItemOrMacro, right: ItemOrMacro) -> ItemOrMacro {
231 231
232impl CrateDefMap { 232impl CrateDefMap {
233 pub(crate) fn crate_def_map_query( 233 pub(crate) fn crate_def_map_query(
234 db: &(impl DefDatabase + AstDatabase), 234 // Note that this doesn't have `+ AstDatabase`!
235 // This gurantess that `CrateDefMap` is stable across reparses.
236 db: &impl DefDatabase,
235 krate: Crate, 237 krate: Crate,
236 ) -> Arc<CrateDefMap> { 238 ) -> Arc<CrateDefMap> {
237 let _p = profile("crate_def_map_query"); 239 let _p = profile("crate_def_map_query");
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index b74dc33b1..ef4d1ed70 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -7,7 +7,7 @@ use ra_syntax::ast;
7 7
8use crate::{ 8use crate::{
9 Function, Module, Struct, Union, Enum, Const, Static, Trait, TypeAlias, MacroDef, 9 Function, Module, Struct, Union, Enum, Const, Static, Trait, TypeAlias, MacroDef,
10 DefDatabase, HirFileId, Name, Path, AstDatabase, 10 DefDatabase, HirFileId, Name, Path,
11 KnownName, AstId, 11 KnownName, AstId,
12 nameres::{ 12 nameres::{
13 Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, 13 Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode,
@@ -19,10 +19,7 @@ use crate::{
19 either::Either, 19 either::Either,
20}; 20};
21 21
22pub(super) fn collect_defs( 22pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
23 db: &(impl DefDatabase + AstDatabase),
24 mut def_map: CrateDefMap,
25) -> CrateDefMap {
26 // populate external prelude 23 // populate external prelude
27 for dep in def_map.krate.dependencies(db) { 24 for dep in def_map.krate.dependencies(db) {
28 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate); 25 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate);
@@ -95,7 +92,7 @@ struct DefCollector<DB> {
95 92
96impl<'a, DB> DefCollector<&'a DB> 93impl<'a, DB> DefCollector<&'a DB>
97where 94where
98 DB: DefDatabase + AstDatabase, 95 DB: DefDatabase,
99{ 96{
100 fn collect(&mut self) { 97 fn collect(&mut self) {
101 let crate_graph = self.db.crate_graph(); 98 let crate_graph = self.db.crate_graph();
@@ -465,7 +462,7 @@ where
465 ModCollector { def_collector: &mut *self, file_id, module_id, raw_items: &raw_items } 462 ModCollector { def_collector: &mut *self, file_id, module_id, raw_items: &raw_items }
466 .collect(raw_items.items()); 463 .collect(raw_items.items());
467 } else { 464 } else {
468 log::error!("Too deep macro expansion: {}", macro_call_id.debug_dump(self.db)); 465 log::error!("Too deep macro expansion: {:?}", macro_call_id);
469 self.def_map.poison_macros.insert(macro_def_id); 466 self.def_map.poison_macros.insert(macro_def_id);
470 } 467 }
471 468
@@ -487,7 +484,7 @@ struct ModCollector<'a, D> {
487 484
488impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>> 485impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>>
489where 486where
490 DB: DefDatabase + AstDatabase, 487 DB: DefDatabase,
491{ 488{
492 fn collect(&mut self, items: &[raw::RawItem]) { 489 fn collect(&mut self, items: &[raw::RawItem]) {
493 for item in items { 490 for item in items {
@@ -632,7 +629,7 @@ fn is_macro_rules(path: &Path) -> bool {
632} 629}
633 630
634fn resolve_submodule( 631fn resolve_submodule(
635 db: &(impl DefDatabase + AstDatabase), 632 db: &impl DefDatabase,
636 file_id: HirFileId, 633 file_id: HirFileId,
637 name: &Name, 634 name: &Name,
638 is_root: bool, 635 is_root: bool,
@@ -675,7 +672,7 @@ mod tests {
675 use rustc_hash::FxHashSet; 672 use rustc_hash::FxHashSet;
676 673
677 fn do_collect_defs( 674 fn do_collect_defs(
678 db: &(impl DefDatabase + AstDatabase), 675 db: &impl DefDatabase,
679 def_map: CrateDefMap, 676 def_map: CrateDefMap,
680 monitor: MacroStackMonitor, 677 monitor: MacroStackMonitor,
681 ) -> CrateDefMap { 678 ) -> CrateDefMap {
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index 82b061419..cb7d30c43 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -14,6 +14,7 @@ use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}};
14 ra_db::SourceDatabaseStorage, 14 ra_db::SourceDatabaseStorage,
15 LineIndexDatabaseStorage, 15 LineIndexDatabaseStorage,
16 symbol_index::SymbolsDatabaseStorage, 16 symbol_index::SymbolsDatabaseStorage,
17 hir::db::InternDatabaseStorage,
17 hir::db::AstDatabaseStorage, 18 hir::db::AstDatabaseStorage,
18 hir::db::DefDatabaseStorage, 19 hir::db::DefDatabaseStorage,
19 hir::db::HirDatabaseStorage 20 hir::db::HirDatabaseStorage