aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-06-02 10:32:26 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-06-02 10:32:26 +0100
commit82cf27b5fc91a4125315d28b8a3c86e5fa7be26d (patch)
treec6f5e240d385fd33f25a70d20b8244a721202264 /crates/ra_hir
parent8256dfdd713451cbe54ee61a176b79f1d1bab589 (diff)
parent5af9e475f4acce54f8383ed22febc412cf2541d0 (diff)
Merge #1362
1362: Introduce AST database r=matklad a=matklad The idea here is to separate fragile bits which look into the syntax directly from robust bits which are safe across reparses. This uses the new `salsa::requires` featue Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/adt.rs16
-rw-r--r--crates/ra_hir/src/code_model.rs70
-rw-r--r--crates/ra_hir/src/db.rs50
-rw-r--r--crates/ra_hir/src/generics.rs4
-rw-r--r--crates/ra_hir/src/ids.rs31
-rw-r--r--crates/ra_hir/src/impl_block.rs17
-rw-r--r--crates/ra_hir/src/lang_item.rs13
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/mock.rs7
-rw-r--r--crates/ra_hir/src/nameres.rs13
-rw-r--r--crates/ra_hir/src/nameres/collector.rs15
-rw-r--r--crates/ra_hir/src/nameres/raw.rs9
-rw-r--r--crates/ra_hir/src/source_id.rs8
-rw-r--r--crates/ra_hir/src/traits.rs10
-rw-r--r--crates/ra_hir/src/type_alias.rs7
15 files changed, 177 insertions, 95 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 5e5905f15..45a12dd4d 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -10,7 +10,7 @@ use ra_syntax::{
10}; 10};
11 11
12use crate::{ 12use crate::{
13 Name, AsName, Struct, Union, Enum, EnumVariant, Crate, 13 Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase,
14 HirDatabase, HirFileId, StructField, FieldSource, 14 HirDatabase, HirFileId, StructField, FieldSource,
15 type_ref::TypeRef, DefDatabase, 15 type_ref::TypeRef, DefDatabase,
16}; 16};
@@ -55,7 +55,10 @@ impl StructData {
55 StructData { name, variant_data } 55 StructData { name, variant_data }
56 } 56 }
57 57
58 pub(crate) fn struct_data_query(db: &impl DefDatabase, struct_: Struct) -> Arc<StructData> { 58 pub(crate) fn struct_data_query(
59 db: &(impl DefDatabase + AstDatabase),
60 struct_: Struct,
61 ) -> Arc<StructData> {
59 let (_, struct_def) = struct_.source(db); 62 let (_, struct_def) = struct_.source(db);
60 Arc::new(StructData::new(&*struct_def)) 63 Arc::new(StructData::new(&*struct_def))
61 } 64 }
@@ -68,7 +71,7 @@ fn variants(enum_def: &ast::EnumDef) -> impl Iterator<Item = &ast::EnumVariant>
68impl EnumVariant { 71impl EnumVariant {
69 pub(crate) fn source_impl( 72 pub(crate) fn source_impl(
70 &self, 73 &self,
71 db: &impl DefDatabase, 74 db: &(impl DefDatabase + AstDatabase),
72 ) -> (HirFileId, TreeArc<ast::EnumVariant>) { 75 ) -> (HirFileId, TreeArc<ast::EnumVariant>) {
73 let (file_id, enum_def) = self.parent.source(db); 76 let (file_id, enum_def) = self.parent.source(db);
74 let var = variants(&*enum_def) 77 let var = variants(&*enum_def)
@@ -91,7 +94,7 @@ pub struct EnumData {
91} 94}
92 95
93impl EnumData { 96impl EnumData {
94 pub(crate) fn enum_data_query(db: &impl DefDatabase, e: Enum) -> Arc<EnumData> { 97 pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> {
95 let (_file_id, enum_def) = e.source(db); 98 let (_file_id, enum_def) = e.source(db);
96 let name = enum_def.name().map(|n| n.as_name()); 99 let name = enum_def.name().map(|n| n.as_name());
97 let variants = variants(&*enum_def) 100 let variants = variants(&*enum_def)
@@ -198,7 +201,10 @@ impl VariantDef {
198} 201}
199 202
200impl StructField { 203impl StructField {
201 pub(crate) fn source_impl(&self, db: &impl DefDatabase) -> (HirFileId, FieldSource) { 204 pub(crate) fn source_impl(
205 &self,
206 db: &(impl DefDatabase + AstDatabase),
207 ) -> (HirFileId, FieldSource) {
202 let var_data = self.parent.variant_data(db); 208 let var_data = self.parent.variant_data(db);
203 let fields = var_data.fields().unwrap(); 209 let fields = var_data.fields().unwrap();
204 let ss; 210 let ss;
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index e3c765674..9c02b3995 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -5,7 +5,7 @@ use ra_syntax::{ast::{self, NameOwner, TypeAscriptionOwner}, TreeArc};
5 5
6use crate::{ 6use crate::{
7 Name, AsName, AstId, Ty, HirFileId, Either, KnownName, 7 Name, AsName, AstId, Ty, HirFileId, Either, KnownName,
8 HirDatabase, DefDatabase, 8 HirDatabase, DefDatabase, AstDatabase,
9 type_ref::TypeRef, 9 type_ref::TypeRef,
10 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, 10 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId},
11 expr::{Body, BodySourceMap, validation::ExprValidator}, 11 expr::{Body, BodySourceMap, validation::ExprValidator},
@@ -147,7 +147,7 @@ pub enum ModuleSource {
147 147
148impl ModuleSource { 148impl ModuleSource {
149 pub(crate) fn new( 149 pub(crate) fn new(
150 db: &impl DefDatabase, 150 db: &(impl DefDatabase + AstDatabase),
151 file_id: Option<FileId>, 151 file_id: Option<FileId>,
152 decl_id: Option<AstId<ast::Module>>, 152 decl_id: Option<AstId<ast::Module>>,
153 ) -> ModuleSource { 153 ) -> ModuleSource {
@@ -168,7 +168,7 @@ impl ModuleSource {
168 168
169impl Module { 169impl Module {
170 /// Name of this module. 170 /// Name of this module.
171 pub fn name(self, db: &impl HirDatabase) -> Option<Name> { 171 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
172 let def_map = db.crate_def_map(self.krate); 172 let def_map = db.crate_def_map(self.krate);
173 let parent = def_map[self.module_id].parent?; 173 let parent = def_map[self.module_id].parent?;
174 def_map[parent].children.iter().find_map(|(name, module_id)| { 174 def_map[parent].children.iter().find_map(|(name, module_id)| {
@@ -181,7 +181,10 @@ impl Module {
181 } 181 }
182 182
183 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. 183 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
184 pub fn definition_source(self, db: &impl DefDatabase) -> (HirFileId, ModuleSource) { 184 pub fn definition_source(
185 self,
186 db: &(impl DefDatabase + AstDatabase),
187 ) -> (HirFileId, ModuleSource) {
185 let def_map = db.crate_def_map(self.krate); 188 let def_map = db.crate_def_map(self.krate);
186 let decl_id = def_map[self.module_id].declaration; 189 let decl_id = def_map[self.module_id].declaration;
187 let file_id = def_map[self.module_id].definition; 190 let file_id = def_map[self.module_id].definition;
@@ -340,7 +343,7 @@ impl StructField {
340 self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() 343 self.parent.variant_data(db).fields().unwrap()[self.id].name.clone()
341 } 344 }
342 345
343 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, FieldSource) { 346 pub fn source(&self, db: &(impl DefDatabase + AstDatabase)) -> (HirFileId, FieldSource) {
344 self.source_impl(db) 347 self.source_impl(db)
345 } 348 }
346 349
@@ -368,7 +371,10 @@ pub struct Struct {
368} 371}
369 372
370impl Struct { 373impl Struct {
371 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StructDef>) { 374 pub fn source(
375 self,
376 db: &(impl DefDatabase + AstDatabase),
377 ) -> (HirFileId, TreeArc<ast::StructDef>) {
372 self.id.source(db) 378 self.id.source(db)
373 } 379 }
374 380
@@ -376,7 +382,7 @@ impl Struct {
376 self.id.module(db) 382 self.id.module(db)
377 } 383 }
378 384
379 pub fn name(self, db: &impl HirDatabase) -> Option<Name> { 385 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
380 db.struct_data(self).name.clone() 386 db.struct_data(self).name.clone()
381 } 387 }
382 388
@@ -432,11 +438,14 @@ pub struct Union {
432} 438}
433 439
434impl Union { 440impl Union {
435 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StructDef>) { 441 pub fn source(
442 self,
443 db: &(impl DefDatabase + AstDatabase),
444 ) -> (HirFileId, TreeArc<ast::StructDef>) {
436 self.id.source(db) 445 self.id.source(db)
437 } 446 }
438 447
439 pub fn name(self, db: &impl HirDatabase) -> Option<Name> { 448 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
440 db.struct_data(Struct { id: self.id }).name.clone() 449 db.struct_data(Struct { id: self.id }).name.clone()
441 } 450 }
442 451
@@ -468,7 +477,10 @@ pub struct Enum {
468} 477}
469 478
470impl Enum { 479impl Enum {
471 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) { 480 pub fn source(
481 self,
482 db: &(impl DefDatabase + AstDatabase),
483 ) -> (HirFileId, TreeArc<ast::EnumDef>) {
472 self.id.source(db) 484 self.id.source(db)
473 } 485 }
474 486
@@ -476,7 +488,7 @@ impl Enum {
476 self.id.module(db) 488 self.id.module(db)
477 } 489 }
478 490
479 pub fn name(self, db: &impl HirDatabase) -> Option<Name> { 491 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
480 db.enum_data(self).name.clone() 492 db.enum_data(self).name.clone()
481 } 493 }
482 494
@@ -521,7 +533,10 @@ pub struct EnumVariant {
521} 533}
522 534
523impl EnumVariant { 535impl EnumVariant {
524 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::EnumVariant>) { 536 pub fn source(
537 &self,
538 db: &(impl DefDatabase + AstDatabase),
539 ) -> (HirFileId, TreeArc<ast::EnumVariant>) {
525 self.source_impl(db) 540 self.source_impl(db)
526 } 541 }
527 pub fn module(&self, db: &impl HirDatabase) -> Module { 542 pub fn module(&self, db: &impl HirDatabase) -> Module {
@@ -610,7 +625,10 @@ pub struct FnSignature {
610} 625}
611 626
612impl FnSignature { 627impl FnSignature {
613 pub(crate) fn fn_signature_query(db: &impl DefDatabase, func: Function) -> Arc<FnSignature> { 628 pub(crate) fn fn_signature_query(
629 db: &(impl DefDatabase + AstDatabase),
630 func: Function,
631 ) -> Arc<FnSignature> {
614 let (_, node) = func.source(db); 632 let (_, node) = func.source(db);
615 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); 633 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
616 let mut params = Vec::new(); 634 let mut params = Vec::new();
@@ -668,7 +686,7 @@ impl FnSignature {
668} 686}
669 687
670impl Function { 688impl Function {
671 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::FnDef>) { 689 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> (HirFileId, TreeArc<ast::FnDef>) {
672 self.id.source(db) 690 self.id.source(db)
673 } 691 }
674 692
@@ -752,7 +770,10 @@ pub struct Const {
752} 770}
753 771
754impl Const { 772impl Const {
755 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { 773 pub fn source(
774 self,
775 db: &(impl DefDatabase + AstDatabase),
776 ) -> (HirFileId, TreeArc<ast::ConstDef>) {
756 self.id.source(db) 777 self.id.source(db)
757 } 778 }
758 779
@@ -809,7 +830,7 @@ impl ConstSignature {
809 } 830 }
810 831
811 pub(crate) fn const_signature_query( 832 pub(crate) fn const_signature_query(
812 db: &impl DefDatabase, 833 db: &(impl DefDatabase + AstDatabase),
813 konst: Const, 834 konst: Const,
814 ) -> Arc<ConstSignature> { 835 ) -> Arc<ConstSignature> {
815 let (_, node) = konst.source(db); 836 let (_, node) = konst.source(db);
@@ -817,7 +838,7 @@ impl ConstSignature {
817 } 838 }
818 839
819 pub(crate) fn static_signature_query( 840 pub(crate) fn static_signature_query(
820 db: &impl DefDatabase, 841 db: &(impl DefDatabase + AstDatabase),
821 konst: Static, 842 konst: Static,
822 ) -> Arc<ConstSignature> { 843 ) -> Arc<ConstSignature> {
823 let (_, node) = konst.source(db); 844 let (_, node) = konst.source(db);
@@ -838,7 +859,10 @@ pub struct Static {
838} 859}
839 860
840impl Static { 861impl Static {
841 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { 862 pub fn source(
863 self,
864 db: &(impl DefDatabase + AstDatabase),
865 ) -> (HirFileId, TreeArc<ast::StaticDef>) {
842 self.id.source(db) 866 self.id.source(db)
843 } 867 }
844 868
@@ -873,7 +897,10 @@ pub struct Trait {
873} 897}
874 898
875impl Trait { 899impl Trait {
876 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) { 900 pub fn source(
901 self,
902 db: &(impl DefDatabase + AstDatabase),
903 ) -> (HirFileId, TreeArc<ast::TraitDef>) {
877 self.id.source(db) 904 self.id.source(db)
878 } 905 }
879 906
@@ -922,7 +949,10 @@ pub struct TypeAlias {
922} 949}
923 950
924impl TypeAlias { 951impl TypeAlias {
925 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TypeAliasDef>) { 952 pub fn source(
953 self,
954 db: &(impl DefDatabase + AstDatabase),
955 ) -> (HirFileId, TreeArc<ast::TypeAliasDef>) {
926 self.id.source(db) 956 self.id.source(db)
927 } 957 }
928 958
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index e8b4f0ddc..872103219 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -21,10 +21,35 @@ use crate::{
21 lang_item::{LangItems, LangItemTarget}, 21 lang_item::{LangItems, LangItemTarget},
22}; 22};
23 23
24#[salsa::query_group(DefDatabaseStorage)] 24// This database has access to source code, so queries here are not really
25pub trait DefDatabase: SourceDatabase { 25// incremental.
26#[salsa::query_group(AstDatabaseStorage)]
27pub trait AstDatabase: SourceDatabase {
26 #[salsa::interned] 28 #[salsa::interned]
27 fn intern_macro(&self, macro_call: MacroCallLoc) -> ids::MacroCallId; 29 fn intern_macro(&self, macro_call: MacroCallLoc) -> ids::MacroCallId;
30
31 #[salsa::invoke(crate::source_id::AstIdMap::ast_id_map_query)]
32 fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>;
33 #[salsa::transparent]
34 #[salsa::invoke(crate::source_id::AstIdMap::file_item_query)]
35 fn ast_id_to_node(&self, file_id: HirFileId, ast_id: ErasedFileAstId) -> TreeArc<SyntaxNode>;
36 #[salsa::invoke(crate::ids::HirFileId::parse_or_expand_query)]
37 fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>;
38
39 #[salsa::invoke(crate::ids::macro_def_query)]
40 fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>;
41
42 #[salsa::invoke(crate::ids::macro_arg_query)]
43 fn macro_arg(&self, macro_call: ids::MacroCallId) -> Option<Arc<tt::Subtree>>;
44
45 #[salsa::invoke(crate::ids::macro_expand_query)]
46 fn macro_expand(&self, macro_call: ids::MacroCallId) -> Result<Arc<tt::Subtree>, String>;
47}
48
49// This database uses `AstDatabase` internally,
50#[salsa::query_group(DefDatabaseStorage)]
51#[salsa::requires(AstDatabase)]
52pub trait DefDatabase: SourceDatabase {
28 #[salsa::interned] 53 #[salsa::interned]
29 fn intern_function(&self, loc: ids::ItemLoc<ast::FnDef>) -> ids::FunctionId; 54 fn intern_function(&self, loc: ids::ItemLoc<ast::FnDef>) -> ids::FunctionId;
30 #[salsa::interned] 55 #[salsa::interned]
@@ -46,18 +71,6 @@ pub trait DefDatabase: SourceDatabase {
46 #[salsa::interned] 71 #[salsa::interned]
47 fn intern_impl_block(&self, impl_block: ImplBlock) -> ids::GlobalImplId; 72 fn intern_impl_block(&self, impl_block: ImplBlock) -> ids::GlobalImplId;
48 73
49 #[salsa::invoke(crate::ids::macro_def_query)]
50 fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>;
51
52 #[salsa::invoke(crate::ids::macro_arg_query)]
53 fn macro_arg(&self, macro_call: ids::MacroCallId) -> Option<Arc<tt::Subtree>>;
54
55 #[salsa::invoke(crate::ids::macro_expand_query)]
56 fn macro_expand(&self, macro_call: ids::MacroCallId) -> Result<Arc<tt::Subtree>, String>;
57
58 #[salsa::invoke(crate::ids::HirFileId::parse_or_expand_query)]
59 fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>;
60
61 #[salsa::invoke(crate::adt::StructData::struct_data_query)] 74 #[salsa::invoke(crate::adt::StructData::struct_data_query)]
62 fn struct_data(&self, s: Struct) -> Arc<StructData>; 75 fn struct_data(&self, s: Struct) -> Arc<StructData>;
63 76
@@ -70,13 +83,6 @@ pub trait DefDatabase: SourceDatabase {
70 #[salsa::invoke(crate::traits::TraitItemsIndex::trait_items_index)] 83 #[salsa::invoke(crate::traits::TraitItemsIndex::trait_items_index)]
71 fn trait_items_index(&self, module: Module) -> crate::traits::TraitItemsIndex; 84 fn trait_items_index(&self, module: Module) -> crate::traits::TraitItemsIndex;
72 85
73 #[salsa::invoke(crate::source_id::AstIdMap::ast_id_map_query)]
74 fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>;
75
76 #[salsa::invoke(crate::source_id::AstIdMap::file_item_query)]
77 #[salsa::transparent]
78 fn ast_id_to_node(&self, file_id: HirFileId, ast_id: ErasedFileAstId) -> TreeArc<SyntaxNode>;
79
80 #[salsa::invoke(RawItems::raw_items_query)] 86 #[salsa::invoke(RawItems::raw_items_query)]
81 fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>; 87 fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;
82 88
@@ -121,7 +127,7 @@ pub trait DefDatabase: SourceDatabase {
121} 127}
122 128
123#[salsa::query_group(HirDatabaseStorage)] 129#[salsa::query_group(HirDatabaseStorage)]
124pub trait HirDatabase: DefDatabase { 130pub trait HirDatabase: DefDatabase + AstDatabase {
125 #[salsa::invoke(ExprScopes::expr_scopes_query)] 131 #[salsa::invoke(ExprScopes::expr_scopes_query)]
126 fn expr_scopes(&self, def: DefWithBody) -> Arc<ExprScopes>; 132 fn expr_scopes(&self, def: DefWithBody) -> Arc<ExprScopes>;
127 133
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 8effbbe35..b6c5e18d3 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -8,7 +8,7 @@ use std::sync::Arc;
8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultTypeParamOwner}; 8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultTypeParamOwner};
9 9
10use crate::{ 10use crate::{
11 db::{ HirDatabase, DefDatabase}, 11 db::{HirDatabase, DefDatabase, AstDatabase},
12 Name, AsName, Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, Container, path::Path, type_ref::TypeRef, AdtDef 12 Name, AsName, Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, Container, path::Path, type_ref::TypeRef, AdtDef
13}; 13};
14 14
@@ -52,7 +52,7 @@ impl_froms!(GenericDef: Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlo
52 52
53impl GenericParams { 53impl GenericParams {
54 pub(crate) fn generic_params_query( 54 pub(crate) fn generic_params_query(
55 db: &impl DefDatabase, 55 db: &(impl DefDatabase + AstDatabase),
56 def: GenericDef, 56 def: GenericDef,
57 ) -> Arc<GenericParams> { 57 ) -> Arc<GenericParams> {
58 let mut generics = GenericParams::default(); 58 let mut generics = GenericParams::default();
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 06b6888f4..79e32e579 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, 12 Module, DefDatabase, AstId, FileAstId, AstDatabase,
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 DefDatabase) -> FileId { 40 pub fn original_file(self, db: &impl AstDatabase) -> 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) => {
@@ -58,7 +58,7 @@ impl HirFileId {
58 } 58 }
59 59
60 pub(crate) fn parse_or_expand_query( 60 pub(crate) fn parse_or_expand_query(
61 db: &impl DefDatabase, 61 db: &impl AstDatabase,
62 file_id: HirFileId, 62 file_id: HirFileId,
63 ) -> Option<TreeArc<SyntaxNode>> { 63 ) -> Option<TreeArc<SyntaxNode>> {
64 db.check_canceled(); 64 db.check_canceled();
@@ -120,7 +120,7 @@ impl From<FileId> for HirFileId {
120#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 120#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
121pub struct MacroDefId(pub(crate) AstId<ast::MacroCall>); 121pub struct MacroDefId(pub(crate) AstId<ast::MacroCall>);
122 122
123pub(crate) fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> { 123pub(crate) fn macro_def_query(db: &impl AstDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> {
124 let macro_call = id.0.to_node(db); 124 let macro_call = id.0.to_node(db);
125 let arg = macro_call.token_tree()?; 125 let arg = macro_call.token_tree()?;
126 let (tt, _) = mbe::ast_to_token_tree(arg).or_else(|| { 126 let (tt, _) = mbe::ast_to_token_tree(arg).or_else(|| {
@@ -134,7 +134,7 @@ pub(crate) fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<A
134 Some(Arc::new(rules)) 134 Some(Arc::new(rules))
135} 135}
136 136
137pub(crate) fn macro_arg_query(db: &impl DefDatabase, id: MacroCallId) -> Option<Arc<tt::Subtree>> { 137pub(crate) fn macro_arg_query(db: &impl AstDatabase, id: MacroCallId) -> Option<Arc<tt::Subtree>> {
138 let loc = id.loc(db); 138 let loc = id.loc(db);
139 let macro_call = loc.ast_id.to_node(db); 139 let macro_call = loc.ast_id.to_node(db);
140 let arg = macro_call.token_tree()?; 140 let arg = macro_call.token_tree()?;
@@ -143,7 +143,7 @@ pub(crate) fn macro_arg_query(db: &impl DefDatabase, id: MacroCallId) -> Option<
143} 143}
144 144
145pub(crate) fn macro_expand_query( 145pub(crate) fn macro_expand_query(
146 db: &impl DefDatabase, 146 db: &impl AstDatabase,
147 id: MacroCallId, 147 id: MacroCallId,
148) -> Result<Arc<tt::Subtree>, String> { 148) -> Result<Arc<tt::Subtree>, String> {
149 let loc = id.loc(db); 149 let loc = id.loc(db);
@@ -185,7 +185,7 @@ pub struct MacroCallLoc {
185} 185}
186 186
187impl MacroCallId { 187impl MacroCallId {
188 pub(crate) fn loc(self, db: &impl DefDatabase) -> MacroCallLoc { 188 pub(crate) fn loc(self, db: &impl AstDatabase) -> MacroCallLoc {
189 db.lookup_intern_macro(self) 189 db.lookup_intern_macro(self)
190 } 190 }
191 191
@@ -196,7 +196,7 @@ impl MacroCallId {
196} 196}
197 197
198impl MacroCallLoc { 198impl MacroCallLoc {
199 pub(crate) fn id(self, db: &impl DefDatabase) -> MacroCallId { 199 pub(crate) fn id(self, db: &impl AstDatabase) -> MacroCallId {
200 db.intern_macro(self) 200 db.intern_macro(self)
201 } 201 }
202} 202}
@@ -233,7 +233,7 @@ pub(crate) struct LocationCtx<DB> {
233 file_id: HirFileId, 233 file_id: HirFileId,
234} 234}
235 235
236impl<'a, DB: DefDatabase> LocationCtx<&'a DB> { 236impl<'a, DB: DefDatabase + AstDatabase> LocationCtx<&'a DB> {
237 pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> { 237 pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> {
238 LocationCtx { db, module, file_id } 238 LocationCtx { db, module, file_id }
239 } 239 }
@@ -250,16 +250,19 @@ pub(crate) trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
250 fn intern(db: &impl DefDatabase, loc: ItemLoc<N>) -> Self; 250 fn intern(db: &impl DefDatabase, loc: ItemLoc<N>) -> Self;
251 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<N>; 251 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<N>;
252 252
253 fn from_ast(ctx: LocationCtx<&impl DefDatabase>, ast: &N) -> Self { 253 fn from_ast(ctx: LocationCtx<&(impl AstDatabase + DefDatabase)>, ast: &N) -> Self {
254 let items = ctx.db.ast_id_map(ctx.file_id); 254 let items = ctx.db.ast_id_map(ctx.file_id);
255 let item_id = items.ast_id(ast); 255 let item_id = items.ast_id(ast);
256 Self::from_ast_id(ctx, item_id) 256 Self::from_ast_id(ctx, item_id)
257 } 257 }
258 fn from_ast_id(ctx: LocationCtx<&impl DefDatabase>, ast_id: FileAstId<N>) -> Self { 258 fn from_ast_id(
259 ctx: LocationCtx<&(impl AstDatabase + DefDatabase)>,
260 ast_id: FileAstId<N>,
261 ) -> Self {
259 let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) }; 262 let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) };
260 Self::intern(ctx.db, loc) 263 Self::intern(ctx.db, loc)
261 } 264 }
262 fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<N>) { 265 fn source(self, db: &(impl AstDatabase + DefDatabase)) -> (HirFileId, TreeArc<N>) {
263 let loc = self.lookup_intern(db); 266 let loc = self.lookup_intern(db);
264 let ast = loc.ast_id.to_node(db); 267 let ast = loc.ast_id.to_node(db);
265 (loc.ast_id.file_id(), ast) 268 (loc.ast_id.file_id(), ast)
@@ -356,7 +359,7 @@ impl AstItemDef<ast::TypeAliasDef> for TypeAliasId {
356} 359}
357 360
358impl MacroCallId { 361impl MacroCallId {
359 pub fn debug_dump(&self, db: &impl DefDatabase) -> String { 362 pub fn debug_dump(&self, db: &impl AstDatabase) -> String {
360 let loc = self.clone().loc(db); 363 let loc = self.clone().loc(db);
361 let node = loc.ast_id.to_node(db); 364 let node = loc.ast_id.to_node(db);
362 let syntax_str = node.syntax().text().chunks().collect::<Vec<_>>().join(" "); 365 let syntax_str = node.syntax().text().chunks().collect::<Vec<_>>().join(" ");
@@ -367,7 +370,7 @@ impl MacroCallId {
367 let macro_rules = db.macro_def(loc.def); 370 let macro_rules = db.macro_def(loc.def);
368 371
369 format!( 372 format!(
370 "macro call [file: {:#?}] : {}\nhas rules: {}", 373 "macro call [file: {:?}] : {}\nhas rules: {}",
371 db.file_relative_path(original), 374 db.file_relative_path(original),
372 syntax_str, 375 syntax_str,
373 macro_rules.is_some() 376 macro_rules.is_some()
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index 072670444..ba90e67e9 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -8,7 +8,7 @@ use ra_syntax::{
8}; 8};
9 9
10use crate::{ 10use crate::{
11 Const, TypeAlias, Function, HirFileId, 11 Const, TypeAlias, Function, HirFileId, AstDatabase,
12 HirDatabase, DefDatabase, TraitRef, 12 HirDatabase, DefDatabase, TraitRef,
13 type_ref::TypeRef, 13 type_ref::TypeRef,
14 ids::LocationCtx, 14 ids::LocationCtx,
@@ -58,7 +58,10 @@ impl ImplBlock {
58 } 58 }
59 59
60 /// Returns the syntax of the impl block 60 /// Returns the syntax of the impl block
61 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) { 61 pub fn source(
62 &self,
63 db: &(impl DefDatabase + AstDatabase),
64 ) -> (HirFileId, TreeArc<ast::ImplBlock>) {
62 let source_map = db.impls_in_module_with_source_map(self.module).1; 65 let source_map = db.impls_in_module_with_source_map(self.module).1;
63 let (file_id, source) = self.module.definition_source(db); 66 let (file_id, source) = self.module.definition_source(db);
64 (file_id, source_map.get(&source, self.impl_id)) 67 (file_id, source_map.get(&source, self.impl_id))
@@ -117,7 +120,7 @@ pub struct ImplData {
117 120
118impl ImplData { 121impl ImplData {
119 pub(crate) fn from_ast( 122 pub(crate) fn from_ast(
120 db: &impl DefDatabase, 123 db: &(impl DefDatabase + AstDatabase),
121 file_id: HirFileId, 124 file_id: HirFileId,
122 module: Module, 125 module: Module,
123 node: &ast::ImplBlock, 126 node: &ast::ImplBlock,
@@ -187,7 +190,11 @@ pub struct ModuleImplBlocks {
187} 190}
188 191
189impl ModuleImplBlocks { 192impl ModuleImplBlocks {
190 fn collect(db: &impl DefDatabase, module: Module, source_map: &mut ImplSourceMap) -> Self { 193 fn collect(
194 db: &(impl DefDatabase + AstDatabase),
195 module: Module,
196 source_map: &mut ImplSourceMap,
197 ) -> Self {
191 let mut m = ModuleImplBlocks { 198 let mut m = ModuleImplBlocks {
192 module, 199 module,
193 impls: Arena::default(), 200 impls: Arena::default(),
@@ -218,7 +225,7 @@ impl ModuleImplBlocks {
218} 225}
219 226
220pub(crate) fn impls_in_module_with_source_map_query( 227pub(crate) fn impls_in_module_with_source_map_query(
221 db: &impl DefDatabase, 228 db: &(impl DefDatabase + AstDatabase),
222 module: Module, 229 module: Module,
223) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) { 230) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) {
224 let mut source_map = ImplSourceMap::default(); 231 let mut source_map = ImplSourceMap::default();
diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs
index 5f3f91cba..4cacaeba4 100644
--- a/crates/ra_hir/src/lang_item.rs
+++ b/crates/ra_hir/src/lang_item.rs
@@ -4,7 +4,7 @@ use rustc_hash::FxHashMap;
4use ra_syntax::{SmolStr, ast::AttrsOwner}; 4use ra_syntax::{SmolStr, ast::AttrsOwner};
5 5
6use crate::{ 6use crate::{
7 Crate, DefDatabase, Enum, Function, HirDatabase, ImplBlock, Module, Static, Struct, Trait 7 Crate, DefDatabase, Enum, Function, HirDatabase, ImplBlock, Module, Static, Struct, Trait, AstDatabase,
8}; 8};
9 9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -41,7 +41,10 @@ impl LangItems {
41 } 41 }
42 42
43 /// Salsa query. This will look for lang items in a specific crate. 43 /// Salsa query. This will look for lang items in a specific crate.
44 pub(crate) fn lang_items_query(db: &impl DefDatabase, krate: Crate) -> Arc<LangItems> { 44 pub(crate) fn lang_items_query(
45 db: &(impl DefDatabase + AstDatabase),
46 krate: Crate,
47 ) -> Arc<LangItems> {
45 let mut lang_items = LangItems { items: FxHashMap::default() }; 48 let mut lang_items = LangItems { items: FxHashMap::default() };
46 49
47 if let Some(module) = krate.root_module(db) { 50 if let Some(module) = krate.root_module(db) {
@@ -74,7 +77,11 @@ impl LangItems {
74 } 77 }
75 } 78 }
76 79
77 fn collect_lang_items_recursive(&mut self, db: &impl DefDatabase, module: &Module) { 80 fn collect_lang_items_recursive(
81 &mut self,
82 db: &(impl DefDatabase + AstDatabase),
83 module: &Module,
84 ) {
78 // Look for impl targets 85 // Look for impl targets
79 let (impl_blocks, source_map) = db.impls_in_module_with_source_map(module.clone()); 86 let (impl_blocks, source_map) = db.impls_in_module_with_source_map(module.clone());
80 let source = module.definition_source(db).1; 87 let source = module.definition_source(db).1;
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 3e00eea26..f2a31795d 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -48,7 +48,7 @@ mod code_model;
48mod marks; 48mod marks;
49 49
50use crate::{ 50use crate::{
51 db::{HirDatabase, DefDatabase}, 51 db::{AstDatabase, DefDatabase, HirDatabase},
52 name::{AsName, KnownName}, 52 name::{AsName, KnownName},
53 source_id::{FileAstId, AstId}, 53 source_id::{FileAstId, AstId},
54 resolve::Resolver, 54 resolve::Resolver,
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index b84cb7503..5d38ac76c 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -13,7 +13,12 @@ use crate::{db, diagnostics::DiagnosticSink};
13 13
14pub const WORKSPACE: SourceRootId = SourceRootId(0); 14pub const WORKSPACE: SourceRootId = SourceRootId(0);
15 15
16#[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage, db::DefDatabaseStorage)] 16#[salsa::database(
17 ra_db::SourceDatabaseStorage,
18 db::AstDatabaseStorage,
19 db::DefDatabaseStorage,
20 db::HirDatabaseStorage
21)]
17#[derive(Debug)] 22#[derive(Debug)]
18pub struct MockDatabase { 23pub struct MockDatabase {
19 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, 24 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 6b1160aa7..d649aa820 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -65,7 +65,7 @@ use ra_prof::profile;
65use once_cell::sync::Lazy; 65use once_cell::sync::Lazy;
66 66
67use crate::{ 67use crate::{
68 ModuleDef, Name, Crate, Module, MacroDef, AsName, BuiltinType, 68 ModuleDef, Name, Crate, Module, MacroDef, AsName, BuiltinType, AstDatabase,
69 DefDatabase, Path, PathKind, HirFileId, Trait, 69 DefDatabase, Path, PathKind, HirFileId, Trait,
70 ids::MacroDefId, 70 ids::MacroDefId,
71 diagnostics::DiagnosticSink, 71 diagnostics::DiagnosticSink,
@@ -232,7 +232,10 @@ fn or(left: ItemOrMacro, right: ItemOrMacro) -> ItemOrMacro {
232} 232}
233 233
234impl CrateDefMap { 234impl CrateDefMap {
235 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: Crate) -> Arc<CrateDefMap> { 235 pub(crate) fn crate_def_map_query(
236 db: &(impl DefDatabase + AstDatabase),
237 krate: Crate,
238 ) -> Arc<CrateDefMap> {
236 db.check_canceled(); 239 db.check_canceled();
237 let _p = profile("crate_def_map_query"); 240 let _p = profile("crate_def_map_query");
238 let def_map = { 241 let def_map = {
@@ -278,7 +281,7 @@ impl CrateDefMap {
278 281
279 pub(crate) fn add_diagnostics( 282 pub(crate) fn add_diagnostics(
280 &self, 283 &self,
281 db: &impl DefDatabase, 284 db: &(impl DefDatabase + AstDatabase),
282 module: CrateModuleId, 285 module: CrateModuleId,
283 sink: &mut DiagnosticSink, 286 sink: &mut DiagnosticSink,
284 ) { 287 ) {
@@ -534,7 +537,7 @@ mod diagnostics {
534 use ra_syntax::{AstPtr, ast}; 537 use ra_syntax::{AstPtr, ast};
535 538
536 use crate::{ 539 use crate::{
537 AstId, DefDatabase, 540 AstId, DefDatabase, AstDatabase,
538 nameres::CrateModuleId, 541 nameres::CrateModuleId,
539 diagnostics::{DiagnosticSink, UnresolvedModule} 542 diagnostics::{DiagnosticSink, UnresolvedModule}
540}; 543};
@@ -551,7 +554,7 @@ mod diagnostics {
551 impl DefDiagnostic { 554 impl DefDiagnostic {
552 pub(super) fn add_to( 555 pub(super) fn add_to(
553 &self, 556 &self,
554 db: &impl DefDatabase, 557 db: &(impl DefDatabase + AstDatabase),
555 target_module: CrateModuleId, 558 target_module: CrateModuleId,
556 sink: &mut DiagnosticSink, 559 sink: &mut DiagnosticSink,
557 ) { 560 ) {
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index af8ac064c..693c3fe8e 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -8,7 +8,7 @@ use ra_syntax::ast;
8 8
9use crate::{ 9use crate::{
10 Function, Module, Struct, Union, Enum, Const, Static, Trait, TypeAlias, MacroDef, 10 Function, Module, Struct, Union, Enum, Const, Static, Trait, TypeAlias, MacroDef,
11 DefDatabase, HirFileId, Name, Path, 11 DefDatabase, HirFileId, Name, Path, AstDatabase,
12 KnownName, 12 KnownName,
13 nameres::{ 13 nameres::{
14 Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, 14 Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode,
@@ -20,7 +20,10 @@ use crate::{
20 AstId, 20 AstId,
21}; 21};
22 22
23pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { 23pub(super) fn collect_defs(
24 db: &(impl DefDatabase + AstDatabase),
25 mut def_map: CrateDefMap,
26) -> CrateDefMap {
24 // populate external prelude 27 // populate external prelude
25 for dep in def_map.krate.dependencies(db) { 28 for dep in def_map.krate.dependencies(db) {
26 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate); 29 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate);
@@ -93,7 +96,7 @@ struct DefCollector<DB> {
93 96
94impl<'a, DB> DefCollector<&'a DB> 97impl<'a, DB> DefCollector<&'a DB>
95where 98where
96 DB: DefDatabase, 99 DB: DefDatabase + AstDatabase,
97{ 100{
98 fn collect(&mut self) { 101 fn collect(&mut self) {
99 let crate_graph = self.db.crate_graph(); 102 let crate_graph = self.db.crate_graph();
@@ -470,7 +473,7 @@ struct ModCollector<'a, D> {
470 473
471impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>> 474impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>>
472where 475where
473 DB: DefDatabase, 476 DB: DefDatabase + AstDatabase,
474{ 477{
475 fn collect(&mut self, items: &[raw::RawItem]) { 478 fn collect(&mut self, items: &[raw::RawItem]) {
476 for item in items { 479 for item in items {
@@ -615,7 +618,7 @@ fn is_macro_rules(path: &Path) -> bool {
615} 618}
616 619
617fn resolve_submodule( 620fn resolve_submodule(
618 db: &impl DefDatabase, 621 db: &(impl DefDatabase + AstDatabase),
619 file_id: HirFileId, 622 file_id: HirFileId,
620 name: &Name, 623 name: &Name,
621 is_root: bool, 624 is_root: bool,
@@ -658,7 +661,7 @@ mod tests {
658 use rustc_hash::FxHashSet; 661 use rustc_hash::FxHashSet;
659 662
660 fn do_collect_defs( 663 fn do_collect_defs(
661 db: &impl DefDatabase, 664 db: &(impl DefDatabase + AstDatabase),
662 def_map: CrateDefMap, 665 def_map: CrateDefMap,
663 monitor: MacroStackMonitor, 666 monitor: MacroStackMonitor,
664 ) -> CrateDefMap { 667 ) -> CrateDefMap {
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index 1b4dcbb7a..21935dbb9 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -7,7 +7,7 @@ use ra_syntax::{
7 ast::{self, NameOwner, AttrsOwner}, 7 ast::{self, NameOwner, AttrsOwner},
8}; 8};
9 9
10use crate::{DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, AstIdMap, FileAstId, Either}; 10use crate::{DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, AstIdMap, FileAstId, Either, AstDatabase};
11 11
12/// `RawItems` is a set of top-level items in a file (except for impls). 12/// `RawItems` is a set of top-level items in a file (except for impls).
13/// 13///
@@ -56,12 +56,15 @@ impl ImportSourceMap {
56} 56}
57 57
58impl RawItems { 58impl RawItems {
59 pub(crate) fn raw_items_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc<RawItems> { 59 pub(crate) fn raw_items_query(
60 db: &(impl DefDatabase + AstDatabase),
61 file_id: HirFileId,
62 ) -> Arc<RawItems> {
60 db.raw_items_with_source_map(file_id).0 63 db.raw_items_with_source_map(file_id).0
61 } 64 }
62 65
63 pub(crate) fn raw_items_with_source_map_query( 66 pub(crate) fn raw_items_with_source_map_query(
64 db: &impl DefDatabase, 67 db: &(impl DefDatabase + AstDatabase),
65 file_id: HirFileId, 68 file_id: HirFileId,
66 ) -> (Arc<RawItems>, Arc<ImportSourceMap>) { 69 ) -> (Arc<RawItems>, Arc<ImportSourceMap>) {
67 let mut collector = RawItemsCollector { 70 let mut collector = RawItemsCollector {
diff --git a/crates/ra_hir/src/source_id.rs b/crates/ra_hir/src/source_id.rs
index 13f548eaf..986269e00 100644
--- a/crates/ra_hir/src/source_id.rs
+++ b/crates/ra_hir/src/source_id.rs
@@ -3,7 +3,7 @@ use std::{marker::PhantomData, sync::Arc, hash::{Hash, Hasher}};
3use ra_arena::{Arena, RawId, impl_arena_id}; 3use ra_arena::{Arena, RawId, impl_arena_id};
4use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, AstNode, ast}; 4use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, AstNode, ast};
5 5
6use crate::{HirFileId, DefDatabase}; 6use crate::{HirFileId, AstDatabase};
7 7
8/// `AstId` points to an AST node in any file. 8/// `AstId` points to an AST node in any file.
9/// 9///
@@ -38,7 +38,7 @@ impl<N: AstNode> AstId<N> {
38 self.file_id 38 self.file_id
39 } 39 }
40 40
41 pub(crate) fn to_node(&self, db: &impl DefDatabase) -> TreeArc<N> { 41 pub(crate) fn to_node(&self, db: &impl AstDatabase) -> TreeArc<N> {
42 let syntax_node = db.ast_id_to_node(self.file_id, self.file_ast_id.raw); 42 let syntax_node = db.ast_id_to_node(self.file_id, self.file_ast_id.raw);
43 N::cast(&syntax_node).unwrap().to_owned() 43 N::cast(&syntax_node).unwrap().to_owned()
44 } 44 }
@@ -87,7 +87,7 @@ pub struct AstIdMap {
87} 87}
88 88
89impl AstIdMap { 89impl AstIdMap {
90 pub(crate) fn ast_id_map_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc<AstIdMap> { 90 pub(crate) fn ast_id_map_query(db: &impl AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
91 let map = if let Some(node) = db.parse_or_expand(file_id) { 91 let map = if let Some(node) = db.parse_or_expand(file_id) {
92 AstIdMap::from_source(&*node) 92 AstIdMap::from_source(&*node)
93 } else { 93 } else {
@@ -97,7 +97,7 @@ impl AstIdMap {
97 } 97 }
98 98
99 pub(crate) fn file_item_query( 99 pub(crate) fn file_item_query(
100 db: &impl DefDatabase, 100 db: &impl AstDatabase,
101 file_id: HirFileId, 101 file_id: HirFileId,
102 ast_id: ErasedFileAstId, 102 ast_id: ErasedFileAstId,
103 ) -> TreeArc<SyntaxNode> { 103 ) -> TreeArc<SyntaxNode> {
diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs
index dfe883fa4..2a7c2b791 100644
--- a/crates/ra_hir/src/traits.rs
+++ b/crates/ra_hir/src/traits.rs
@@ -5,7 +5,10 @@ use rustc_hash::FxHashMap;
5 5
6use ra_syntax::ast::{self, NameOwner}; 6use ra_syntax::ast::{self, NameOwner};
7 7
8use crate::{Function, Const, TypeAlias, Name, DefDatabase, Trait, ids::LocationCtx, name::AsName, Module}; 8use crate::{
9 Function, Const, TypeAlias, Name, DefDatabase, Trait, AstDatabase, Module,
10 ids::LocationCtx, name::AsName,
11};
9 12
10#[derive(Debug, Clone, PartialEq, Eq)] 13#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct TraitData { 14pub struct TraitData {
@@ -15,7 +18,10 @@ pub struct TraitData {
15} 18}
16 19
17impl TraitData { 20impl TraitData {
18 pub(crate) fn trait_data_query(db: &impl DefDatabase, tr: Trait) -> Arc<TraitData> { 21 pub(crate) fn trait_data_query(
22 db: &(impl DefDatabase + AstDatabase),
23 tr: Trait,
24 ) -> Arc<TraitData> {
19 let (file_id, node) = tr.source(db); 25 let (file_id, node) = tr.source(db);
20 let name = node.name().map(|n| n.as_name()); 26 let name = node.name().map(|n| n.as_name());
21 let module = tr.module(db); 27 let module = tr.module(db);
diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs
index e35adcb2f..970468e3c 100644
--- a/crates/ra_hir/src/type_alias.rs
+++ b/crates/ra_hir/src/type_alias.rs
@@ -2,9 +2,12 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use crate::{TypeAlias, db::DefDatabase, type_ref::TypeRef}; 5use crate::{TypeAlias, DefDatabase, AstDatabase, type_ref::TypeRef};
6 6
7pub(crate) fn type_alias_ref_query(db: &impl DefDatabase, typ: TypeAlias) -> Arc<TypeRef> { 7pub(crate) fn type_alias_ref_query(
8 db: &(impl DefDatabase + AstDatabase),
9 typ: TypeAlias,
10) -> Arc<TypeRef> {
8 let (_, node) = typ.source(db); 11 let (_, node) = typ.source(db);
9 Arc::new(TypeRef::from_ast_opt(node.type_ref())) 12 Arc::new(TypeRef::from_ast_opt(node.type_ref()))
10} 13}