aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/adt.rs19
-rw-r--r--crates/ra_hir/src/code_model_api.rs83
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs7
-rw-r--r--crates/ra_hir/src/code_model_impl/konst.rs6
-rw-r--r--crates/ra_hir/src/code_model_impl/krate.rs9
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs15
-rw-r--r--crates/ra_hir/src/db.rs6
-rw-r--r--crates/ra_hir/src/generics.rs4
-rw-r--r--crates/ra_hir/src/ids.rs28
-rw-r--r--crates/ra_hir/src/impl_block.rs29
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/mock.rs6
-rw-r--r--crates/ra_hir/src/nameres.rs15
-rw-r--r--crates/ra_hir/src/nameres/collector.rs13
-rw-r--r--crates/ra_hir/src/nameres/raw.rs9
-rw-r--r--crates/ra_hir/src/type_alias.rs7
16 files changed, 104 insertions, 154 deletions
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::{
12use crate::{ 12use crate::{
13 Name, AsName, Struct, Enum, EnumVariant, Crate, 13 Name, AsName, Struct, Enum, EnumVariant, Crate,
14 HirDatabase, HirFileId, StructField, FieldSource, 14 HirDatabase, HirFileId, StructField, FieldSource,
15 type_ref::TypeRef, PersistentHirDatabase, 15 type_ref::TypeRef, DefDatabase,
16}; 16};
17 17
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -33,7 +33,7 @@ impl AdtDef {
33} 33}
34 34
35impl Struct { 35impl Struct {
36 pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc<VariantData> { 36 pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> {
37 db.struct_data((*self).into()).variant_data.clone() 37 db.struct_data((*self).into()).variant_data.clone()
38 } 38 }
39} 39}
@@ -52,10 +52,7 @@ impl StructData {
52 StructData { name, variant_data } 52 StructData { name, variant_data }
53 } 53 }
54 54
55 pub(crate) fn struct_data_query( 55 pub(crate) fn struct_data_query(db: &impl DefDatabase, struct_: Struct) -> Arc<StructData> {
56 db: &impl PersistentHirDatabase,
57 struct_: Struct,
58 ) -> Arc<StructData> {
59 let (_, struct_def) = struct_.source(db); 56 let (_, struct_def) = struct_.source(db);
60 Arc::new(StructData::new(&*struct_def)) 57 Arc::new(StructData::new(&*struct_def))
61 } 58 }
@@ -68,7 +65,7 @@ fn variants(enum_def: &ast::EnumDef) -> impl Iterator<Item = &ast::EnumVariant>
68impl EnumVariant { 65impl EnumVariant {
69 pub(crate) fn source_impl( 66 pub(crate) fn source_impl(
70 &self, 67 &self,
71 db: &impl PersistentHirDatabase, 68 db: &impl DefDatabase,
72 ) -> (HirFileId, TreeArc<ast::EnumVariant>) { 69 ) -> (HirFileId, TreeArc<ast::EnumVariant>) {
73 let (file_id, enum_def) = self.parent.source(db); 70 let (file_id, enum_def) = self.parent.source(db);
74 let var = variants(&*enum_def) 71 let var = variants(&*enum_def)
@@ -79,7 +76,7 @@ impl EnumVariant {
79 .to_owned(); 76 .to_owned();
80 (file_id, var) 77 (file_id, var)
81 } 78 }
82 pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc<VariantData> { 79 pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> {
83 db.enum_data(self.parent).variants[self.id].variant_data.clone() 80 db.enum_data(self.parent).variants[self.id].variant_data.clone()
84 } 81 }
85} 82}
@@ -91,7 +88,7 @@ pub struct EnumData {
91} 88}
92 89
93impl EnumData { 90impl EnumData {
94 pub(crate) fn enum_data_query(db: &impl PersistentHirDatabase, e: Enum) -> Arc<EnumData> { 91 pub(crate) fn enum_data_query(db: &impl DefDatabase, e: Enum) -> Arc<EnumData> {
95 let (_file_id, enum_def) = e.source(db); 92 let (_file_id, enum_def) = e.source(db);
96 let name = enum_def.name().map(|n| n.as_name()); 93 let name = enum_def.name().map(|n| n.as_name());
97 let variants = variants(&*enum_def) 94 let variants = variants(&*enum_def)
@@ -189,7 +186,7 @@ impl VariantDef {
189 VariantDef::EnumVariant(it) => it.field(db, name), 186 VariantDef::EnumVariant(it) => it.field(db, name),
190 } 187 }
191 } 188 }
192 pub(crate) fn variant_data(self, db: &impl PersistentHirDatabase) -> Arc<VariantData> { 189 pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
193 match self { 190 match self {
194 VariantDef::Struct(it) => it.variant_data(db), 191 VariantDef::Struct(it) => it.variant_data(db),
195 VariantDef::EnumVariant(it) => it.variant_data(db), 192 VariantDef::EnumVariant(it) => it.variant_data(db),
@@ -198,7 +195,7 @@ impl VariantDef {
198} 195}
199 196
200impl StructField { 197impl StructField {
201 pub(crate) fn source_impl(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { 198 pub(crate) fn source_impl(&self, db: &impl DefDatabase) -> (HirFileId, FieldSource) {
202 let var_data = self.parent.variant_data(db); 199 let var_data = self.parent.variant_data(db);
203 let fields = var_data.fields().unwrap(); 200 let fields = var_data.fields().unwrap();
204 let ss; 201 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};
6 6
7use crate::{ 7use crate::{
8 Name, ScopesWithSourceMap, Ty, HirFileId, 8 Name, ScopesWithSourceMap, Ty, HirFileId,
9 HirDatabase, PersistentHirDatabase, 9 HirDatabase, DefDatabase,
10 type_ref::TypeRef, 10 type_ref::TypeRef,
11 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, 11 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId},
12 expr::{Body, BodySourceMap}, 12 expr::{Body, BodySourceMap},
@@ -38,24 +38,21 @@ impl Crate {
38 self.crate_id 38 self.crate_id
39 } 39 }
40 40
41 pub fn dependencies(&self, db: &impl PersistentHirDatabase) -> Vec<CrateDependency> { 41 pub fn dependencies(&self, db: &impl DefDatabase) -> Vec<CrateDependency> {
42 self.dependencies_impl(db) 42 self.dependencies_impl(db)
43 } 43 }
44 44
45 pub fn root_module(&self, db: &impl PersistentHirDatabase) -> Option<Module> { 45 pub fn root_module(&self, db: &impl DefDatabase) -> Option<Module> {
46 self.root_module_impl(db) 46 self.root_module_impl(db)
47 } 47 }
48 48
49 pub fn edition(&self, db: &impl PersistentHirDatabase) -> Edition { 49 pub fn edition(&self, db: &impl DefDatabase) -> Edition {
50 let crate_graph = db.crate_graph(); 50 let crate_graph = db.crate_graph();
51 crate_graph.edition(self.crate_id) 51 crate_graph.edition(self.crate_id)
52 } 52 }
53 53
54 // FIXME: should this be in source_binder? 54 // FIXME: should this be in source_binder?
55 pub fn source_root_crates( 55 pub fn source_root_crates(db: &impl DefDatabase, source_root: SourceRootId) -> Vec<Crate> {
56 db: &impl PersistentHirDatabase,
57 source_root: SourceRootId,
58 ) -> Vec<Crate> {
59 let crate_ids = db.source_root_crates(source_root); 56 let crate_ids = db.source_root_crates(source_root);
60 crate_ids.iter().map(|&crate_id| Crate { crate_id }).collect() 57 crate_ids.iter().map(|&crate_id| Crate { crate_id }).collect()
61 } 58 }
@@ -111,7 +108,7 @@ impl Module {
111 } 108 }
112 109
113 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. 110 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
114 pub fn definition_source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, ModuleSource) { 111 pub fn definition_source(&self, db: &impl DefDatabase) -> (HirFileId, ModuleSource) {
115 self.definition_source_impl(db) 112 self.definition_source_impl(db)
116 } 113 }
117 114
@@ -134,14 +131,14 @@ impl Module {
134 } 131 }
135 132
136 /// Returns the crate this module is part of. 133 /// Returns the crate this module is part of.
137 pub fn krate(&self, _db: &impl PersistentHirDatabase) -> Option<Crate> { 134 pub fn krate(&self, _db: &impl DefDatabase) -> Option<Crate> {
138 Some(self.krate) 135 Some(self.krate)
139 } 136 }
140 137
141 /// Topmost parent of this module. Every module has a `crate_root`, but some 138 /// Topmost parent of this module. Every module has a `crate_root`, but some
142 /// might be missing `krate`. This can happen if a module's file is not included 139 /// might be missing `krate`. This can happen if a module's file is not included
143 /// in the module tree of any target in `Cargo.toml`. 140 /// in the module tree of any target in `Cargo.toml`.
144 pub fn crate_root(&self, db: &impl PersistentHirDatabase) -> Module { 141 pub fn crate_root(&self, db: &impl DefDatabase) -> Module {
145 self.crate_root_impl(db) 142 self.crate_root_impl(db)
146 } 143 }
147 144
@@ -151,12 +148,12 @@ impl Module {
151 } 148 }
152 149
153 /// Iterates over all child modules. 150 /// Iterates over all child modules.
154 pub fn children(&self, db: &impl PersistentHirDatabase) -> impl Iterator<Item = Module> { 151 pub fn children(&self, db: &impl DefDatabase) -> impl Iterator<Item = Module> {
155 self.children_impl(db) 152 self.children_impl(db)
156 } 153 }
157 154
158 /// Finds a parent module. 155 /// Finds a parent module.
159 pub fn parent(&self, db: &impl PersistentHirDatabase) -> Option<Module> { 156 pub fn parent(&self, db: &impl DefDatabase) -> Option<Module> {
160 self.parent_impl(db) 157 self.parent_impl(db)
161 } 158 }
162 159
@@ -229,7 +226,7 @@ impl StructField {
229 self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() 226 self.parent.variant_data(db).fields().unwrap()[self.id].name.clone()
230 } 227 }
231 228
232 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { 229 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, FieldSource) {
233 self.source_impl(db) 230 self.source_impl(db)
234 } 231 }
235 232
@@ -257,7 +254,7 @@ pub struct Struct {
257} 254}
258 255
259impl Struct { 256impl Struct {
260 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StructDef>) { 257 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StructDef>) {
261 self.id.source(db) 258 self.id.source(db)
262 } 259 }
263 260
@@ -289,7 +286,7 @@ impl Struct {
289 .map(|(id, _)| StructField { parent: (*self).into(), id }) 286 .map(|(id, _)| StructField { parent: (*self).into(), id })
290 } 287 }
291 288
292 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 289 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
293 db.generic_params((*self).into()) 290 db.generic_params((*self).into())
294 } 291 }
295 292
@@ -325,7 +322,7 @@ pub struct Enum {
325} 322}
326 323
327impl Enum { 324impl Enum {
328 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) { 325 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) {
329 self.id.source(db) 326 self.id.source(db)
330 } 327 }
331 328
@@ -337,7 +334,7 @@ impl Enum {
337 db.enum_data(*self).name.clone() 334 db.enum_data(*self).name.clone()
338 } 335 }
339 336
340 pub fn variants(&self, db: &impl PersistentHirDatabase) -> Vec<EnumVariant> { 337 pub fn variants(&self, db: &impl DefDatabase) -> Vec<EnumVariant> {
341 db.enum_data(*self) 338 db.enum_data(*self)
342 .variants 339 .variants
343 .iter() 340 .iter()
@@ -345,7 +342,7 @@ impl Enum {
345 .collect() 342 .collect()
346 } 343 }
347 344
348 pub fn variant(&self, db: &impl PersistentHirDatabase, name: &Name) -> Option<EnumVariant> { 345 pub fn variant(&self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> {
349 db.enum_data(*self) 346 db.enum_data(*self)
350 .variants 347 .variants
351 .iter() 348 .iter()
@@ -353,7 +350,7 @@ impl Enum {
353 .map(|(id, _)| EnumVariant { parent: *self, id }) 350 .map(|(id, _)| EnumVariant { parent: *self, id })
354 } 351 }
355 352
356 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 353 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
357 db.generic_params((*self).into()) 354 db.generic_params((*self).into())
358 } 355 }
359 356
@@ -386,20 +383,17 @@ pub struct EnumVariant {
386} 383}
387 384
388impl EnumVariant { 385impl EnumVariant {
389 pub fn source( 386 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::EnumVariant>) {
390 &self,
391 db: &impl PersistentHirDatabase,
392 ) -> (HirFileId, TreeArc<ast::EnumVariant>) {
393 self.source_impl(db) 387 self.source_impl(db)
394 } 388 }
395 pub fn module(&self, db: &impl HirDatabase) -> Module { 389 pub fn module(&self, db: &impl HirDatabase) -> Module {
396 self.parent.module(db) 390 self.parent.module(db)
397 } 391 }
398 pub fn parent_enum(&self, _db: &impl PersistentHirDatabase) -> Enum { 392 pub fn parent_enum(&self, _db: &impl DefDatabase) -> Enum {
399 self.parent 393 self.parent
400 } 394 }
401 395
402 pub fn name(&self, db: &impl PersistentHirDatabase) -> Option<Name> { 396 pub fn name(&self, db: &impl DefDatabase) -> Option<Name> {
403 db.enum_data(self.parent).variants[self.id].name.clone() 397 db.enum_data(self.parent).variants[self.id].name.clone()
404 } 398 }
405 399
@@ -465,11 +459,11 @@ impl FnSignature {
465} 459}
466 460
467impl Function { 461impl Function {
468 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::FnDef>) { 462 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::FnDef>) {
469 self.id.source(db) 463 self.id.source(db)
470 } 464 }
471 465
472 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { 466 pub fn module(&self, db: &impl DefDatabase) -> Module {
473 self.id.module(db) 467 self.id.module(db)
474 } 468 }
475 469
@@ -503,12 +497,12 @@ impl Function {
503 db.infer(*self) 497 db.infer(*self)
504 } 498 }
505 499
506 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 500 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
507 db.generic_params((*self).into()) 501 db.generic_params((*self).into())
508 } 502 }
509 503
510 /// The containing impl block, if this is a method. 504 /// The containing impl block, if this is a method.
511 pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { 505 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> {
512 let module_impls = db.impls_in_module(self.module(db)); 506 let module_impls = db.impls_in_module(self.module(db));
513 ImplBlock::containing(module_impls, (*self).into()) 507 ImplBlock::containing(module_impls, (*self).into())
514 } 508 }
@@ -540,11 +534,11 @@ pub struct Const {
540} 534}
541 535
542impl Const { 536impl Const {
543 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { 537 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
544 self.id.source(db) 538 self.id.source(db)
545 } 539 }
546 540
547 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { 541 pub fn module(&self, db: &impl DefDatabase) -> Module {
548 self.id.module(db) 542 self.id.module(db)
549 } 543 }
550 544
@@ -553,7 +547,7 @@ impl Const {
553 } 547 }
554 548
555 /// The containing impl block, if this is a method. 549 /// The containing impl block, if this is a method.
556 pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { 550 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> {
557 let module_impls = db.impls_in_module(self.module(db)); 551 let module_impls = db.impls_in_module(self.module(db));
558 ImplBlock::containing(module_impls, (*self).into()) 552 ImplBlock::containing(module_impls, (*self).into())
559 } 553 }
@@ -599,11 +593,11 @@ pub struct Static {
599} 593}
600 594
601impl Static { 595impl Static {
602 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { 596 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
603 self.id.source(db) 597 self.id.source(db)
604 } 598 }
605 599
606 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { 600 pub fn module(&self, db: &impl DefDatabase) -> Module {
607 self.id.module(db) 601 self.id.module(db)
608 } 602 }
609 603
@@ -630,15 +624,15 @@ pub struct Trait {
630} 624}
631 625
632impl Trait { 626impl Trait {
633 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) { 627 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) {
634 self.id.source(db) 628 self.id.source(db)
635 } 629 }
636 630
637 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { 631 pub fn module(&self, db: &impl DefDatabase) -> Module {
638 self.id.module(db) 632 self.id.module(db)
639 } 633 }
640 634
641 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 635 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
642 db.generic_params((*self).into()) 636 db.generic_params((*self).into())
643 } 637 }
644} 638}
@@ -655,28 +649,25 @@ pub struct TypeAlias {
655} 649}
656 650
657impl TypeAlias { 651impl TypeAlias {
658 pub fn source( 652 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TypeAliasDef>) {
659 &self,
660 db: &impl PersistentHirDatabase,
661 ) -> (HirFileId, TreeArc<ast::TypeAliasDef>) {
662 self.id.source(db) 653 self.id.source(db)
663 } 654 }
664 655
665 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 656 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
666 db.generic_params((*self).into()) 657 db.generic_params((*self).into())
667 } 658 }
668 659
669 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { 660 pub fn module(&self, db: &impl DefDatabase) -> Module {
670 self.id.module(db) 661 self.id.module(db)
671 } 662 }
672 663
673 /// The containing impl block, if this is a method. 664 /// The containing impl block, if this is a method.
674 pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { 665 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> {
675 let module_impls = db.impls_in_module(self.module(db)); 666 let module_impls = db.impls_in_module(self.module(db));
676 ImplBlock::containing(module_impls, (*self).into()) 667 ImplBlock::containing(module_impls, (*self).into())
677 } 668 }
678 669
679 pub fn type_ref(self, db: &impl PersistentHirDatabase) -> Arc<TypeRef> { 670 pub fn type_ref(self, db: &impl DefDatabase) -> Arc<TypeRef> {
680 db.type_alias_ref(self) 671 db.type_alias_ref(self)
681 } 672 }
682 673
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};
5use crate::{ 5use crate::{
6 Name, AsName, Function, FnSignature, 6 Name, AsName, Function, FnSignature,
7 type_ref::{TypeRef, Mutability}, 7 type_ref::{TypeRef, Mutability},
8 PersistentHirDatabase, 8 DefDatabase,
9}; 9};
10 10
11impl FnSignature { 11impl FnSignature {
12 pub(crate) fn fn_signature_query( 12 pub(crate) fn fn_signature_query(db: &impl DefDatabase, func: Function) -> Arc<FnSignature> {
13 db: &impl PersistentHirDatabase,
14 func: Function,
15 ) -> Arc<FnSignature> {
16 let (_, node) = func.source(db); 13 let (_, node) = func.source(db);
17 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); 14 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
18 let mut params = Vec::new(); 15 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};
5use crate::{ 5use crate::{
6 Name, AsName, Const, ConstSignature, Static, 6 Name, AsName, Const, ConstSignature, Static,
7 type_ref::{TypeRef}, 7 type_ref::{TypeRef},
8 PersistentHirDatabase, 8 DefDatabase,
9}; 9};
10 10
11fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> { 11fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> {
@@ -17,7 +17,7 @@ fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<Cons
17 17
18impl ConstSignature { 18impl ConstSignature {
19 pub(crate) fn const_signature_query( 19 pub(crate) fn const_signature_query(
20 db: &impl PersistentHirDatabase, 20 db: &impl DefDatabase,
21 konst: Const, 21 konst: Const,
22 ) -> Arc<ConstSignature> { 22 ) -> Arc<ConstSignature> {
23 let (_, node) = konst.source(db); 23 let (_, node) = konst.source(db);
@@ -25,7 +25,7 @@ impl ConstSignature {
25 } 25 }
26 26
27 pub(crate) fn static_signature_query( 27 pub(crate) fn static_signature_query(
28 db: &impl PersistentHirDatabase, 28 db: &impl DefDatabase,
29 konst: Static, 29 konst: Static,
30 ) -> Arc<ConstSignature> { 30 ) -> Arc<ConstSignature> {
31 let (_, node) = konst.source(db); 31 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 @@
1use crate::{ 1use crate::{
2 Crate, CrateDependency, AsName, Module, PersistentHirDatabase, 2 Crate, CrateDependency, AsName, Module, DefDatabase,
3}; 3};
4 4
5impl Crate { 5impl Crate {
6 pub(crate) fn dependencies_impl( 6 pub(crate) fn dependencies_impl(&self, db: &impl DefDatabase) -> Vec<CrateDependency> {
7 &self,
8 db: &impl PersistentHirDatabase,
9 ) -> Vec<CrateDependency> {
10 let crate_graph = db.crate_graph(); 7 let crate_graph = db.crate_graph();
11 crate_graph 8 crate_graph
12 .dependencies(self.crate_id) 9 .dependencies(self.crate_id)
@@ -17,7 +14,7 @@ impl Crate {
17 }) 14 })
18 .collect() 15 .collect()
19 } 16 }
20 pub(crate) fn root_module_impl(&self, db: &impl PersistentHirDatabase) -> Option<Module> { 17 pub(crate) fn root_module_impl(&self, db: &impl DefDatabase) -> Option<Module> {
21 let module_id = db.crate_def_map(*self).root(); 18 let module_id = db.crate_def_map(*self).root();
22 let module = Module { krate: *self, module_id }; 19 let module = Module { krate: *self, module_id };
23 Some(module) 20 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};
4use crate::{ 4use crate::{
5 Module, ModuleSource, Problem, Name, 5 Module, ModuleSource, Problem, Name,
6 nameres::{CrateModuleId, ImportId}, 6 nameres::{CrateModuleId, ImportId},
7 HirDatabase, PersistentHirDatabase, 7 HirDatabase, DefDatabase,
8 HirFileId, SourceItemId, 8 HirFileId, SourceItemId,
9}; 9};
10 10
11impl ModuleSource { 11impl ModuleSource {
12 pub(crate) fn new( 12 pub(crate) fn new(
13 db: &impl PersistentHirDatabase, 13 db: &impl DefDatabase,
14 file_id: Option<FileId>, 14 file_id: Option<FileId>,
15 decl_id: Option<SourceItemId>, 15 decl_id: Option<SourceItemId>,
16 ) -> ModuleSource { 16 ) -> ModuleSource {
@@ -49,7 +49,7 @@ impl Module {
49 49
50 pub(crate) fn definition_source_impl( 50 pub(crate) fn definition_source_impl(
51 &self, 51 &self,
52 db: &impl PersistentHirDatabase, 52 db: &impl DefDatabase,
53 ) -> (HirFileId, ModuleSource) { 53 ) -> (HirFileId, ModuleSource) {
54 let def_map = db.crate_def_map(self.krate); 54 let def_map = db.crate_def_map(self.krate);
55 let decl_id = def_map[self.module_id].declaration; 55 let decl_id = def_map[self.module_id].declaration;
@@ -80,7 +80,7 @@ impl Module {
80 source_map.get(&source, import) 80 source_map.get(&source, import)
81 } 81 }
82 82
83 pub(crate) fn crate_root_impl(&self, db: &impl PersistentHirDatabase) -> Module { 83 pub(crate) fn crate_root_impl(&self, db: &impl DefDatabase) -> Module {
84 let def_map = db.crate_def_map(self.krate); 84 let def_map = db.crate_def_map(self.krate);
85 self.with_module_id(def_map.root()) 85 self.with_module_id(def_map.root())
86 } 86 }
@@ -93,10 +93,7 @@ impl Module {
93 } 93 }
94 94
95 /// Iterates over all child modules. 95 /// Iterates over all child modules.
96 pub(crate) fn children_impl( 96 pub(crate) fn children_impl(&self, db: &impl DefDatabase) -> impl Iterator<Item = Module> {
97 &self,
98 db: &impl PersistentHirDatabase,
99 ) -> impl Iterator<Item = Module> {
100 let def_map = db.crate_def_map(self.krate); 97 let def_map = db.crate_def_map(self.krate);
101 let children = def_map[self.module_id] 98 let children = def_map[self.module_id]
102 .children 99 .children
@@ -106,7 +103,7 @@ impl Module {
106 children.into_iter() 103 children.into_iter()
107 } 104 }
108 105
109 pub(crate) fn parent_impl(&self, db: &impl PersistentHirDatabase) -> Option<Module> { 106 pub(crate) fn parent_impl(&self, db: &impl DefDatabase) -> Option<Module> {
110 let def_map = db.crate_def_map(self.krate); 107 let def_map = db.crate_def_map(self.krate);
111 let parent_id = def_map[self.module_id].parent?; 108 let parent_id = def_map[self.module_id].parent?;
112 Some(self.with_module_id(parent_id)) 109 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::{
16 type_ref::TypeRef, 16 type_ref::TypeRef,
17}; 17};
18 18
19#[salsa::query_group(PersistentHirDatabaseStorage)] 19#[salsa::query_group(DefDatabaseStorage)]
20pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> { 20pub trait DefDatabase: SourceDatabase + AsRef<HirInterner> {
21 #[salsa::invoke(HirFileId::hir_parse)] 21 #[salsa::invoke(HirFileId::hir_parse)]
22 fn hir_parse(&self, file_id: HirFileId) -> TreeArc<SourceFile>; 22 fn hir_parse(&self, file_id: HirFileId) -> TreeArc<SourceFile>;
23 23
@@ -71,7 +71,7 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> {
71} 71}
72 72
73#[salsa::query_group(HirDatabaseStorage)] 73#[salsa::query_group(HirDatabaseStorage)]
74pub trait HirDatabase: PersistentHirDatabase { 74pub trait HirDatabase: DefDatabase {
75 #[salsa::invoke(ExprScopes::expr_scopes_query)] 75 #[salsa::invoke(ExprScopes::expr_scopes_query)]
76 fn expr_scopes(&self, func: Function) -> Arc<ExprScopes>; 76 fn expr_scopes(&self, func: Function) -> Arc<ExprScopes>;
77 77
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;
8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner}; 8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner};
9 9
10use crate::{ 10use crate::{
11 db::PersistentHirDatabase, 11 db::DefDatabase,
12 Name, AsName, Function, Struct, Enum, Trait, TypeAlias, ImplBlock 12 Name, AsName, Function, Struct, Enum, Trait, TypeAlias, ImplBlock
13}; 13};
14 14
@@ -40,7 +40,7 @@ impl_froms!(GenericDef: Function, Struct, Enum, Trait, TypeAlias, ImplBlock);
40 40
41impl GenericParams { 41impl GenericParams {
42 pub(crate) fn generic_params_query( 42 pub(crate) fn generic_params_query(
43 db: &impl PersistentHirDatabase, 43 db: &impl DefDatabase,
44 def: GenericDef, 44 def: GenericDef,
45 ) -> Arc<GenericParams> { 45 ) -> Arc<GenericParams> {
46 let mut generics = GenericParams::default(); 46 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};
10 10
11use crate::{ 11use crate::{
12 Module, 12 Module,
13 PersistentHirDatabase, 13 DefDatabase,
14}; 14};
15 15
16#[derive(Debug, Default)] 16#[derive(Debug, Default)]
@@ -63,7 +63,7 @@ pub struct HirFileId(HirFileIdRepr);
63impl HirFileId { 63impl HirFileId {
64 /// For macro-expansion files, returns the file original source file the 64 /// For macro-expansion files, returns the file original source file the
65 /// expansion originated from. 65 /// expansion originated from.
66 pub fn original_file(self, db: &impl PersistentHirDatabase) -> FileId { 66 pub fn original_file(self, db: &impl DefDatabase) -> FileId {
67 match self.0 { 67 match self.0 {
68 HirFileIdRepr::File(file_id) => file_id, 68 HirFileIdRepr::File(file_id) => file_id,
69 HirFileIdRepr::Macro(macro_call_id) => { 69 HirFileIdRepr::Macro(macro_call_id) => {
@@ -83,10 +83,7 @@ impl HirFileId {
83 } 83 }
84 } 84 }
85 85
86 pub(crate) fn hir_parse( 86 pub(crate) fn hir_parse(db: &impl DefDatabase, file_id: HirFileId) -> TreeArc<SourceFile> {
87 db: &impl PersistentHirDatabase,
88 file_id: HirFileId,
89 ) -> TreeArc<SourceFile> {
90 match file_id.0 { 87 match file_id.0 {
91 HirFileIdRepr::File(file_id) => db.parse(file_id), 88 HirFileIdRepr::File(file_id) => db.parse(file_id),
92 HirFileIdRepr::Macro(macro_call_id) => { 89 HirFileIdRepr::Macro(macro_call_id) => {
@@ -97,10 +94,7 @@ impl HirFileId {
97 } 94 }
98} 95}
99 96
100fn parse_macro( 97fn parse_macro(db: &impl DefDatabase, macro_call_id: MacroCallId) -> Option<TreeArc<SourceFile>> {
101 db: &impl PersistentHirDatabase,
102 macro_call_id: MacroCallId,
103) -> Option<TreeArc<SourceFile>> {
104 let loc = macro_call_id.loc(db); 98 let loc = macro_call_id.loc(db);
105 let syntax = db.file_item(loc.source_item_id); 99 let syntax = db.file_item(loc.source_item_id);
106 let macro_call = ast::MacroCall::cast(&syntax).unwrap(); 100 let macro_call = ast::MacroCall::cast(&syntax).unwrap();
@@ -190,7 +184,7 @@ pub(crate) struct LocationCtx<DB> {
190 file_id: HirFileId, 184 file_id: HirFileId,
191} 185}
192 186
193impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> { 187impl<'a, DB: DefDatabase> LocationCtx<&'a DB> {
194 pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> { 188 pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> {
195 LocationCtx { db, module, file_id } 189 LocationCtx { db, module, file_id }
196 } 190 }
@@ -205,13 +199,13 @@ impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> {
205 199
206pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { 200pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone {
207 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<N>, Self>; 201 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<N>, Self>;
208 fn from_ast(ctx: LocationCtx<&impl PersistentHirDatabase>, ast: &N) -> Self { 202 fn from_ast(ctx: LocationCtx<&impl DefDatabase>, ast: &N) -> Self {
209 let items = ctx.db.file_items(ctx.file_id); 203 let items = ctx.db.file_items(ctx.file_id);
210 let item_id = items.id_of(ctx.file_id, ast.syntax()); 204 let item_id = items.id_of(ctx.file_id, ast.syntax());
211 Self::from_source_item_id_unchecked(ctx, item_id) 205 Self::from_source_item_id_unchecked(ctx, item_id)
212 } 206 }
213 fn from_source_item_id_unchecked( 207 fn from_source_item_id_unchecked(
214 ctx: LocationCtx<&impl PersistentHirDatabase>, 208 ctx: LocationCtx<&impl DefDatabase>,
215 item_id: SourceFileItemId, 209 item_id: SourceFileItemId,
216 ) -> Self { 210 ) -> Self {
217 let raw = SourceItemId { file_id: ctx.file_id, item_id }; 211 let raw = SourceItemId { file_id: ctx.file_id, item_id };
@@ -219,7 +213,7 @@ pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone {
219 213
220 Self::interner(ctx.db.as_ref()).loc2id(&loc) 214 Self::interner(ctx.db.as_ref()).loc2id(&loc)
221 } 215 }
222 fn source(self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<N>) { 216 fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<N>) {
223 let int = Self::interner(db.as_ref()); 217 let int = Self::interner(db.as_ref());
224 let loc = int.id2loc(self); 218 let loc = int.id2loc(self);
225 let syntax = db.file_item(loc.raw); 219 let syntax = db.file_item(loc.raw);
@@ -227,7 +221,7 @@ pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone {
227 N::cast(&syntax).unwrap_or_else(|| panic!("invalid ItemLoc: {:?}", loc.raw)).to_owned(); 221 N::cast(&syntax).unwrap_or_else(|| panic!("invalid ItemLoc: {:?}", loc.raw)).to_owned();
228 (loc.raw.file_id, ast) 222 (loc.raw.file_id, ast)
229 } 223 }
230 fn module(self, db: &impl PersistentHirDatabase) -> Module { 224 fn module(self, db: &impl DefDatabase) -> Module {
231 let int = Self::interner(db.as_ref()); 225 let int = Self::interner(db.as_ref());
232 let loc = int.id2loc(self); 226 let loc = int.id2loc(self);
233 loc.module 227 loc.module
@@ -324,7 +318,7 @@ pub struct SourceFileItems {
324 318
325impl SourceFileItems { 319impl SourceFileItems {
326 pub(crate) fn file_items_query( 320 pub(crate) fn file_items_query(
327 db: &impl PersistentHirDatabase, 321 db: &impl DefDatabase,
328 file_id: HirFileId, 322 file_id: HirFileId,
329 ) -> Arc<SourceFileItems> { 323 ) -> Arc<SourceFileItems> {
330 let source_file = db.hir_parse(file_id); 324 let source_file = db.hir_parse(file_id);
@@ -332,7 +326,7 @@ impl SourceFileItems {
332 } 326 }
333 327
334 pub(crate) fn file_item_query( 328 pub(crate) fn file_item_query(
335 db: &impl PersistentHirDatabase, 329 db: &impl DefDatabase,
336 source_item_id: SourceItemId, 330 source_item_id: SourceItemId,
337 ) -> TreeArc<SyntaxNode> { 331 ) -> TreeArc<SyntaxNode> {
338 let source_file = db.hir_parse(source_item_id.file_id); 332 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::{
9 9
10use crate::{ 10use crate::{
11 Const, TypeAlias, Function, HirFileId, 11 Const, TypeAlias, Function, HirFileId,
12 HirDatabase, PersistentHirDatabase, 12 HirDatabase, DefDatabase,
13 ModuleDef, Trait, Resolution, 13 ModuleDef, Trait, Resolution,
14 type_ref::TypeRef, 14 type_ref::TypeRef,
15 ids::LocationCtx, 15 ids::LocationCtx,
@@ -59,7 +59,7 @@ impl ImplBlock {
59 } 59 }
60 60
61 /// Returns the syntax of the impl block 61 /// Returns the syntax of the impl block
62 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) { 62 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) {
63 let source_map = db.impls_in_module_source_map(self.module); 63 let source_map = db.impls_in_module_source_map(self.module);
64 let (file_id, source) = self.module.definition_source(db); 64 let (file_id, source) = self.module.definition_source(db);
65 (file_id, source_map.get(&source, self.impl_id)) 65 (file_id, source_map.get(&source, self.impl_id))
@@ -73,11 +73,11 @@ impl ImplBlock {
73 self.module 73 self.module
74 } 74 }
75 75
76 pub fn target_trait_ref(&self, db: &impl PersistentHirDatabase) -> Option<TypeRef> { 76 pub fn target_trait_ref(&self, db: &impl DefDatabase) -> Option<TypeRef> {
77 db.impls_in_module(self.module).impls[self.impl_id].target_trait().cloned() 77 db.impls_in_module(self.module).impls[self.impl_id].target_trait().cloned()
78 } 78 }
79 79
80 pub fn target_type(&self, db: &impl PersistentHirDatabase) -> TypeRef { 80 pub fn target_type(&self, db: &impl DefDatabase) -> TypeRef {
81 db.impls_in_module(self.module).impls[self.impl_id].target_type().clone() 81 db.impls_in_module(self.module).impls[self.impl_id].target_type().clone()
82 } 82 }
83 83
@@ -97,11 +97,11 @@ impl ImplBlock {
97 None 97 None
98 } 98 }
99 99
100 pub fn items(&self, db: &impl PersistentHirDatabase) -> Vec<ImplItem> { 100 pub fn items(&self, db: &impl DefDatabase) -> Vec<ImplItem> {
101 db.impls_in_module(self.module).impls[self.impl_id].items().to_vec() 101 db.impls_in_module(self.module).impls[self.impl_id].items().to_vec()
102 } 102 }
103 103
104 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 104 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
105 db.generic_params((*self).into()) 105 db.generic_params((*self).into())
106 } 106 }
107 107
@@ -124,7 +124,7 @@ pub struct ImplData {
124 124
125impl ImplData { 125impl ImplData {
126 pub(crate) fn from_ast( 126 pub(crate) fn from_ast(
127 db: &impl PersistentHirDatabase, 127 db: &impl DefDatabase,
128 file_id: HirFileId, 128 file_id: HirFileId,
129 module: Module, 129 module: Module,
130 node: &ast::ImplBlock, 130 node: &ast::ImplBlock,
@@ -193,11 +193,7 @@ pub struct ModuleImplBlocks {
193} 193}
194 194
195impl ModuleImplBlocks { 195impl ModuleImplBlocks {
196 fn collect( 196 fn collect(db: &impl DefDatabase, module: Module, source_map: &mut ImplSourceMap) -> Self {
197 db: &impl PersistentHirDatabase,
198 module: Module,
199 source_map: &mut ImplSourceMap,
200 ) -> Self {
201 let mut m = ModuleImplBlocks { 197 let mut m = ModuleImplBlocks {
202 module, 198 module,
203 impls: Arena::default(), 199 impls: Arena::default(),
@@ -228,7 +224,7 @@ impl ModuleImplBlocks {
228} 224}
229 225
230pub(crate) fn impls_in_module_with_source_map_query( 226pub(crate) fn impls_in_module_with_source_map_query(
231 db: &impl PersistentHirDatabase, 227 db: &impl DefDatabase,
232 module: Module, 228 module: Module,
233) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) { 229) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) {
234 let mut source_map = ImplSourceMap::default(); 230 let mut source_map = ImplSourceMap::default();
@@ -238,15 +234,12 @@ pub(crate) fn impls_in_module_with_source_map_query(
238 (Arc::new(result), Arc::new(source_map)) 234 (Arc::new(result), Arc::new(source_map))
239} 235}
240 236
241pub(crate) fn impls_in_module( 237pub(crate) fn impls_in_module(db: &impl DefDatabase, module: Module) -> Arc<ModuleImplBlocks> {
242 db: &impl PersistentHirDatabase,
243 module: Module,
244) -> Arc<ModuleImplBlocks> {
245 db.impls_in_module_with_source_map(module).0 238 db.impls_in_module_with_source_map(module).0
246} 239}
247 240
248pub(crate) fn impls_in_module_source_map_query( 241pub(crate) fn impls_in_module_source_map_query(
249 db: &impl PersistentHirDatabase, 242 db: &impl DefDatabase,
250 module: Module, 243 module: Module,
251) -> Arc<ImplSourceMap> { 244) -> Arc<ImplSourceMap> {
252 db.impls_in_module_with_source_map(module).1 245 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;
43mod marks; 43mod marks;
44 44
45use crate::{ 45use crate::{
46 db::{HirDatabase, PersistentHirDatabase}, 46 db::{HirDatabase, DefDatabase},
47 name::{AsName, KnownName}, 47 name::{AsName, KnownName},
48 ids::{SourceItemId, SourceFileItems}, 48 ids::{SourceItemId, SourceFileItems},
49}; 49};
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};
13 13
14pub const WORKSPACE: SourceRootId = SourceRootId(0); 14pub const WORKSPACE: SourceRootId = SourceRootId(0);
15 15
16#[salsa::database( 16#[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage, db::DefDatabaseStorage)]
17 ra_db::SourceDatabaseStorage,
18 db::HirDatabaseStorage,
19 db::PersistentHirDatabaseStorage
20)]
21#[derive(Debug)] 17#[derive(Debug)]
22pub struct MockDatabase { 18pub struct MockDatabase {
23 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, 19 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
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;
62 62
63use crate::{ 63use crate::{
64 ModuleDef, Name, Crate, Module, Problem, 64 ModuleDef, Name, Crate, Module, Problem,
65 PersistentHirDatabase, Path, PathKind, HirFileId, 65 DefDatabase, Path, PathKind, HirFileId,
66 ids::{SourceItemId, SourceFileItemId, MacroCallId}, 66 ids::{SourceItemId, SourceFileItemId, MacroCallId},
67}; 67};
68 68
@@ -196,10 +196,7 @@ enum ReachedFixedPoint {
196} 196}
197 197
198impl CrateDefMap { 198impl CrateDefMap {
199 pub(crate) fn crate_def_map_query( 199 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: Crate) -> Arc<CrateDefMap> {
200 db: &impl PersistentHirDatabase,
201 krate: Crate,
202 ) -> Arc<CrateDefMap> {
203 let start = std::time::Instant::now(); 200 let start = std::time::Instant::now();
204 let def_map = { 201 let def_map = {
205 let edition = krate.edition(db); 202 let edition = krate.edition(db);
@@ -268,7 +265,7 @@ impl CrateDefMap {
268 265
269 pub(crate) fn resolve_path( 266 pub(crate) fn resolve_path(
270 &self, 267 &self,
271 db: &impl PersistentHirDatabase, 268 db: &impl DefDatabase,
272 original_module: CrateModuleId, 269 original_module: CrateModuleId,
273 path: &Path, 270 path: &Path,
274 ) -> (PerNs<ModuleDef>, Option<usize>) { 271 ) -> (PerNs<ModuleDef>, Option<usize>) {
@@ -280,7 +277,7 @@ impl CrateDefMap {
280 // the result. 277 // the result.
281 fn resolve_path_fp( 278 fn resolve_path_fp(
282 &self, 279 &self,
283 db: &impl PersistentHirDatabase, 280 db: &impl DefDatabase,
284 mode: ResolveMode, 281 mode: ResolveMode,
285 original_module: CrateModuleId, 282 original_module: CrateModuleId,
286 path: &Path, 283 path: &Path,
@@ -422,7 +419,7 @@ impl CrateDefMap {
422 419
423 pub(crate) fn resolve_name_in_module( 420 pub(crate) fn resolve_name_in_module(
424 &self, 421 &self,
425 db: &impl PersistentHirDatabase, 422 db: &impl DefDatabase,
426 module: CrateModuleId, 423 module: CrateModuleId,
427 name: &Name, 424 name: &Name,
428 ) -> PerNs<ModuleDef> { 425 ) -> PerNs<ModuleDef> {
@@ -442,7 +439,7 @@ impl CrateDefMap {
442 self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)) 439 self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it))
443 } 440 }
444 441
445 fn resolve_in_prelude(&self, db: &impl PersistentHirDatabase, name: &Name) -> PerNs<ModuleDef> { 442 fn resolve_in_prelude(&self, db: &impl DefDatabase, name: &Name) -> PerNs<ModuleDef> {
446 if let Some(prelude) = self.prelude { 443 if let Some(prelude) = self.prelude {
447 let resolution = if prelude.krate == self.krate { 444 let resolution = if prelude.krate == self.krate {
448 self[prelude.module_id].scope.items.get(name).cloned() 445 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;
6 6
7use crate::{ 7use crate::{
8 Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias, 8 Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias,
9 PersistentHirDatabase, HirFileId, Name, Path, Problem, Crate, 9 DefDatabase, HirFileId, Name, Path, Problem, Crate,
10 KnownName, 10 KnownName,
11 nameres::{Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, raw}, 11 nameres::{Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, raw},
12 ids::{AstItemDef, LocationCtx, MacroCallLoc, SourceItemId, MacroCallId}, 12 ids::{AstItemDef, LocationCtx, MacroCallLoc, SourceItemId, MacroCallId},
@@ -14,10 +14,7 @@ use crate::{
14 14
15use super::{CrateDefMap, CrateModuleId, ModuleData, CrateMacroId}; 15use super::{CrateDefMap, CrateModuleId, ModuleData, CrateMacroId};
16 16
17pub(super) fn collect_defs( 17pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
18 db: &impl PersistentHirDatabase,
19 mut def_map: CrateDefMap,
20) -> CrateDefMap {
21 // populate external prelude 18 // populate external prelude
22 for dep in def_map.krate.dependencies(db) { 19 for dep in def_map.krate.dependencies(db) {
23 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate); 20 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate);
@@ -57,7 +54,7 @@ struct DefCollector<DB> {
57 54
58impl<'a, DB> DefCollector<&'a DB> 55impl<'a, DB> DefCollector<&'a DB>
59where 56where
60 DB: PersistentHirDatabase, 57 DB: DefDatabase,
61{ 58{
62 fn collect(&mut self) { 59 fn collect(&mut self) {
63 let crate_graph = self.db.crate_graph(); 60 let crate_graph = self.db.crate_graph();
@@ -370,7 +367,7 @@ struct ModCollector<'a, D> {
370 367
371impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>> 368impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>>
372where 369where
373 DB: PersistentHirDatabase, 370 DB: DefDatabase,
374{ 371{
375 fn collect(&mut self, items: &[raw::RawItem]) { 372 fn collect(&mut self, items: &[raw::RawItem]) {
376 for item in items { 373 for item in items {
@@ -523,7 +520,7 @@ fn is_macro_rules(path: &Path) -> bool {
523} 520}
524 521
525fn resolve_submodule( 522fn resolve_submodule(
526 db: &impl PersistentHirDatabase, 523 db: &impl DefDatabase,
527 file_id: HirFileId, 524 file_id: HirFileId,
528 name: &Name, 525 name: &Name,
529 is_root: bool, 526 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::{
12}; 12};
13 13
14use crate::{ 14use crate::{
15 PersistentHirDatabase, Name, AsName, Path, HirFileId, ModuleSource, 15 DefDatabase, Name, AsName, Path, HirFileId, ModuleSource,
16 ids::{SourceFileItemId, SourceFileItems}, 16 ids::{SourceFileItemId, SourceFileItems},
17}; 17};
18 18
@@ -47,15 +47,12 @@ impl ImportSourceMap {
47} 47}
48 48
49impl RawItems { 49impl RawItems {
50 pub(crate) fn raw_items_query( 50 pub(crate) fn raw_items_query(db: &impl DefDatabase, file_id: FileId) -> Arc<RawItems> {
51 db: &impl PersistentHirDatabase,
52 file_id: FileId,
53 ) -> Arc<RawItems> {
54 db.raw_items_with_source_map(file_id).0 51 db.raw_items_with_source_map(file_id).0
55 } 52 }
56 53
57 pub(crate) fn raw_items_with_source_map_query( 54 pub(crate) fn raw_items_with_source_map_query(
58 db: &impl PersistentHirDatabase, 55 db: &impl DefDatabase,
59 file_id: FileId, 56 file_id: FileId,
60 ) -> (Arc<RawItems>, Arc<ImportSourceMap>) { 57 ) -> (Arc<RawItems>, Arc<ImportSourceMap>) {
61 let mut collector = RawItemsCollector { 58 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 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use crate::{TypeAlias, db::PersistentHirDatabase, type_ref::TypeRef}; 5use crate::{TypeAlias, db::DefDatabase, type_ref::TypeRef};
6 6
7pub(crate) fn type_alias_ref_query( 7pub(crate) fn type_alias_ref_query(db: &impl DefDatabase, typ: TypeAlias) -> Arc<TypeRef> {
8 db: &impl PersistentHirDatabase,
9 typ: TypeAlias,
10) -> Arc<TypeRef> {
11 let (_, node) = typ.source(db); 8 let (_, node) = typ.source(db);
12 Arc::new(TypeRef::from_ast_opt(node.type_ref())) 9 Arc::new(TypeRef::from_ast_opt(node.type_ref()))
13} 10}