aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcsmoe <[email protected]>2019-02-01 10:33:41 +0000
committercsmoe <[email protected]>2019-02-01 14:05:24 +0000
commit4dffdcf14abe0c79f9d7a9702be77958be1f75b1 (patch)
tree3904cb714292f3e1abe5081e4e516eea1b2568fa
parent12433a78871610edfccc82442846615872747e06 (diff)
split HirDatabase api
-rw-r--r--crates/ra_hir/src/adt.rs19
-rw-r--r--crates/ra_hir/src/code_model_api.rs51
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs7
-rw-r--r--crates/ra_hir/src/code_model_impl/krate.rs10
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs16
-rw-r--r--crates/ra_hir/src/db.rs29
-rw-r--r--crates/ra_hir/src/expr.rs4
-rw-r--r--crates/ra_hir/src/expr/scope.rs2
-rw-r--r--crates/ra_hir/src/generics.rs4
-rw-r--r--crates/ra_hir/src/ids.rs14
-rw-r--r--crates/ra_hir/src/impl_block.rs20
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/macros.rs4
-rw-r--r--crates/ra_hir/src/mock.rs6
-rw-r--r--crates/ra_hir/src/module_tree.rs22
-rw-r--r--crates/ra_hir/src/nameres.rs13
-rw-r--r--crates/ra_hir/src/nameres/lower.rs14
-rw-r--r--crates/ra_hir/src/nameres/tests.rs2
-rw-r--r--crates/ra_hir/src/query_definitions.rs9
-rw-r--r--crates/ra_hir/src/ty.rs2
-rw-r--r--crates/ra_ide_api/src/db.rs3
21 files changed, 147 insertions, 106 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 22bbad964..c549e2126 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, 15 type_ref::TypeRef, PersistentHirDatabase,
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 HirDatabase) -> Arc<VariantData> { 36 pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> 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,7 +52,10 @@ impl StructData {
52 StructData { name, variant_data } 52 StructData { name, variant_data }
53 } 53 }
54 54
55 pub(crate) fn struct_data_query(db: &impl HirDatabase, struct_: Struct) -> Arc<StructData> { 55 pub(crate) fn struct_data_query(
56 db: &impl PersistentHirDatabase,
57 struct_: Struct,
58 ) -> Arc<StructData> {
56 let (_, struct_def) = struct_.source(db); 59 let (_, struct_def) = struct_.source(db);
57 Arc::new(StructData::new(&*struct_def)) 60 Arc::new(StructData::new(&*struct_def))
58 } 61 }
@@ -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 HirDatabase, 74 db: &impl PersistentHirDatabase,
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)
@@ -79,7 +82,7 @@ impl EnumVariant {
79 .to_owned(); 82 .to_owned();
80 (file_id, var) 83 (file_id, var)
81 } 84 }
82 pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Arc<VariantData> { 85 pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc<VariantData> {
83 db.enum_data(self.parent).variants[self.id] 86 db.enum_data(self.parent).variants[self.id]
84 .variant_data 87 .variant_data
85 .clone() 88 .clone()
@@ -93,7 +96,7 @@ pub struct EnumData {
93} 96}
94 97
95impl EnumData { 98impl EnumData {
96 pub(crate) fn enum_data_query(db: &impl HirDatabase, e: Enum) -> Arc<EnumData> { 99 pub(crate) fn enum_data_query(db: &impl PersistentHirDatabase, e: Enum) -> Arc<EnumData> {
97 let (_file_id, enum_def) = e.source(db); 100 let (_file_id, enum_def) = e.source(db);
98 let name = enum_def.name().map(|n| n.as_name()); 101 let name = enum_def.name().map(|n| n.as_name());
99 let variants = variants(&*enum_def) 102 let variants = variants(&*enum_def)
@@ -191,7 +194,7 @@ impl VariantDef {
191 VariantDef::EnumVariant(it) => it.field(db, name), 194 VariantDef::EnumVariant(it) => it.field(db, name),
192 } 195 }
193 } 196 }
194 pub(crate) fn variant_data(self, db: &impl HirDatabase) -> Arc<VariantData> { 197 pub(crate) fn variant_data(self, db: &impl PersistentHirDatabase) -> Arc<VariantData> {
195 match self { 198 match self {
196 VariantDef::Struct(it) => it.variant_data(db), 199 VariantDef::Struct(it) => it.variant_data(db),
197 VariantDef::EnumVariant(it) => it.variant_data(db), 200 VariantDef::EnumVariant(it) => it.variant_data(db),
@@ -200,7 +203,7 @@ impl VariantDef {
200} 203}
201 204
202impl StructField { 205impl StructField {
203 pub(crate) fn source_impl(&self, db: &impl HirDatabase) -> (HirFileId, FieldSource) { 206 pub(crate) fn source_impl(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) {
204 let var_data = self.parent.variant_data(db); 207 let var_data = self.parent.variant_data(db);
205 let fields = var_data.fields().unwrap(); 208 let fields = var_data.fields().unwrap();
206 let ss; 209 let ss;
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 9405aa8ad..71123a698 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -8,7 +8,7 @@ use crate::{
8 Name, Path, PerNs, ScopesWithSyntaxMapping, Ty, HirFileId, 8 Name, Path, PerNs, ScopesWithSyntaxMapping, Ty, HirFileId,
9 type_ref::TypeRef, 9 type_ref::TypeRef,
10 nameres::{ModuleScope, lower::ImportId}, 10 nameres::{ModuleScope, lower::ImportId},
11 db::HirDatabase, 11 HirDatabase, PersistentHirDatabase,
12 expr::BodySyntaxMapping, 12 expr::BodySyntaxMapping,
13 ty::{InferenceResult}, 13 ty::{InferenceResult},
14 adt::{EnumVariantId, StructFieldId, VariantDef}, 14 adt::{EnumVariantId, StructFieldId, VariantDef},
@@ -37,10 +37,10 @@ impl Crate {
37 pub fn crate_id(&self) -> CrateId { 37 pub fn crate_id(&self) -> CrateId {
38 self.crate_id 38 self.crate_id
39 } 39 }
40 pub fn dependencies(&self, db: &impl HirDatabase) -> Vec<CrateDependency> { 40 pub fn dependencies(&self, db: &impl PersistentHirDatabase) -> Vec<CrateDependency> {
41 self.dependencies_impl(db) 41 self.dependencies_impl(db)
42 } 42 }
43 pub fn root_module(&self, db: &impl HirDatabase) -> Option<Module> { 43 pub fn root_module(&self, db: &impl PersistentHirDatabase) -> Option<Module> {
44 self.root_module_impl(db) 44 self.root_module_impl(db)
45 } 45 }
46} 46}
@@ -105,7 +105,7 @@ impl Module {
105 } 105 }
106 106
107 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. 107 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
108 pub fn definition_source(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) { 108 pub fn definition_source(&self, db: &impl PersistentHirDatabase) -> (FileId, ModuleSource) {
109 self.definition_source_impl(db) 109 self.definition_source_impl(db)
110 } 110 }
111 111
@@ -140,7 +140,7 @@ impl Module {
140 /// Topmost parent of this module. Every module has a `crate_root`, but some 140 /// Topmost parent of this module. Every module has a `crate_root`, but some
141 /// might be missing `krate`. This can happen if a module's file is not included 141 /// might be missing `krate`. This can happen if a module's file is not included
142 /// in the module tree of any target in Cargo.toml. 142 /// in the module tree of any target in Cargo.toml.
143 pub fn crate_root(&self, db: &impl HirDatabase) -> Module { 143 pub fn crate_root(&self, db: &impl PersistentHirDatabase) -> Module {
144 self.crate_root_impl(db) 144 self.crate_root_impl(db)
145 } 145 }
146 146
@@ -150,12 +150,12 @@ impl Module {
150 } 150 }
151 151
152 /// Iterates over all child modules. 152 /// Iterates over all child modules.
153 pub fn children(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> { 153 pub fn children(&self, db: &impl PersistentHirDatabase) -> impl Iterator<Item = Module> {
154 self.children_impl(db) 154 self.children_impl(db)
155 } 155 }
156 156
157 /// Finds a parent module. 157 /// Finds a parent module.
158 pub fn parent(&self, db: &impl HirDatabase) -> Option<Module> { 158 pub fn parent(&self, db: &impl PersistentHirDatabase) -> Option<Module> {
159 self.parent_impl(db) 159 self.parent_impl(db)
160 } 160 }
161 161
@@ -174,7 +174,7 @@ impl Module {
174 db.item_map(self.krate)[self.module_id].clone() 174 db.item_map(self.krate)[self.module_id].clone()
175 } 175 }
176 176
177 pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<ModuleDef> { 177 pub fn resolve_path(&self, db: &impl PersistentHirDatabase, path: &Path) -> PerNs<ModuleDef> {
178 db.item_map(self.krate).resolve_path(db, *self, path) 178 db.item_map(self.krate).resolve_path(db, *self, path)
179 } 179 }
180 180
@@ -209,7 +209,7 @@ impl StructField {
209 .clone() 209 .clone()
210 } 210 }
211 211
212 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, FieldSource) { 212 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) {
213 self.source_impl(db) 213 self.source_impl(db)
214 } 214 }
215 215
@@ -237,7 +237,7 @@ pub struct Struct {
237} 237}
238 238
239impl Struct { 239impl Struct {
240 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::StructDef>) { 240 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StructDef>) {
241 self.id.source(db) 241 self.id.source(db)
242 } 242 }
243 243
@@ -275,7 +275,7 @@ impl Struct {
275 }) 275 })
276 } 276 }
277 277
278 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { 278 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
279 db.generic_params((*self).into()) 279 db.generic_params((*self).into())
280 } 280 }
281 281
@@ -296,7 +296,7 @@ pub struct Enum {
296} 296}
297 297
298impl Enum { 298impl Enum {
299 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) { 299 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) {
300 self.id.source(db) 300 self.id.source(db)
301 } 301 }
302 302
@@ -316,7 +316,7 @@ impl Enum {
316 .collect() 316 .collect()
317 } 317 }
318 318
319 pub fn variant(&self, db: &impl HirDatabase, name: &Name) -> Option<EnumVariant> { 319 pub fn variant(&self, db: &impl PersistentHirDatabase, name: &Name) -> Option<EnumVariant> {
320 db.enum_data(*self) 320 db.enum_data(*self)
321 .variants 321 .variants
322 .iter() 322 .iter()
@@ -324,7 +324,7 @@ impl Enum {
324 .map(|(id, _)| EnumVariant { parent: *self, id }) 324 .map(|(id, _)| EnumVariant { parent: *self, id })
325 } 325 }
326 326
327 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { 327 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
328 db.generic_params((*self).into()) 328 db.generic_params((*self).into())
329 } 329 }
330 330
@@ -346,13 +346,16 @@ pub struct EnumVariant {
346} 346}
347 347
348impl EnumVariant { 348impl EnumVariant {
349 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumVariant>) { 349 pub fn source(
350 &self,
351 db: &impl PersistentHirDatabase,
352 ) -> (HirFileId, TreeArc<ast::EnumVariant>) {
350 self.source_impl(db) 353 self.source_impl(db)
351 } 354 }
352 pub fn module(&self, db: &impl HirDatabase) -> Module { 355 pub fn module(&self, db: &impl HirDatabase) -> Module {
353 self.parent.module(db) 356 self.parent.module(db)
354 } 357 }
355 pub fn parent_enum(&self, _db: &impl HirDatabase) -> Enum { 358 pub fn parent_enum(&self, _db: &impl PersistentHirDatabase) -> Enum {
356 self.parent 359 self.parent
357 } 360 }
358 361
@@ -430,7 +433,7 @@ impl FnSignature {
430} 433}
431 434
432impl Function { 435impl Function {
433 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::FnDef>) { 436 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::FnDef>) {
434 self.id.source(db) 437 self.id.source(db)
435 } 438 }
436 439
@@ -463,7 +466,7 @@ impl Function {
463 db.infer(*self) 466 db.infer(*self)
464 } 467 }
465 468
466 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { 469 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
467 db.generic_params((*self).into()) 470 db.generic_params((*self).into())
468 } 471 }
469} 472}
@@ -480,7 +483,7 @@ pub struct Const {
480} 483}
481 484
482impl Const { 485impl Const {
483 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { 486 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
484 self.id.source(db) 487 self.id.source(db)
485 } 488 }
486} 489}
@@ -497,7 +500,7 @@ pub struct Static {
497} 500}
498 501
499impl Static { 502impl Static {
500 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { 503 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
501 self.id.source(db) 504 self.id.source(db)
502 } 505 }
503} 506}
@@ -514,11 +517,11 @@ pub struct Trait {
514} 517}
515 518
516impl Trait { 519impl Trait {
517 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) { 520 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) {
518 self.id.source(db) 521 self.id.source(db)
519 } 522 }
520 523
521 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { 524 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
522 db.generic_params((*self).into()) 525 db.generic_params((*self).into())
523 } 526 }
524} 527}
@@ -535,11 +538,11 @@ pub struct Type {
535} 538}
536 539
537impl Type { 540impl Type {
538 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) { 541 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) {
539 self.id.source(db) 542 self.id.source(db)
540 } 543 }
541 544
542 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { 545 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
543 db.generic_params((*self).into()) 546 db.generic_params((*self).into())
544 } 547 }
545} 548}
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index 422643996..5b0b31b1d 100644
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ b/crates/ra_hir/src/code_model_impl/function.rs
@@ -5,7 +5,7 @@ use ra_syntax::ast::{self, NameOwner};
5use crate::{ 5use crate::{
6 HirDatabase, Name, AsName, Function, FnSignature, 6 HirDatabase, Name, AsName, Function, FnSignature,
7 type_ref::{TypeRef, Mutability}, 7 type_ref::{TypeRef, Mutability},
8 expr::Body, 8 expr::Body, PersistentHirDatabase,
9 impl_block::ImplBlock, 9 impl_block::ImplBlock,
10}; 10};
11 11
@@ -22,7 +22,10 @@ impl Function {
22} 22}
23 23
24impl FnSignature { 24impl FnSignature {
25 pub(crate) fn fn_signature_query(db: &impl HirDatabase, func: Function) -> Arc<FnSignature> { 25 pub(crate) fn fn_signature_query(
26 db: &impl PersistentHirDatabase,
27 func: Function,
28 ) -> Arc<FnSignature> {
26 let (_, node) = func.source(db); 29 let (_, node) = func.source(db);
27 let name = node 30 let name = node
28 .name() 31 .name()
diff --git a/crates/ra_hir/src/code_model_impl/krate.rs b/crates/ra_hir/src/code_model_impl/krate.rs
index 86f29d959..1517434b8 100644
--- a/crates/ra_hir/src/code_model_impl/krate.rs
+++ b/crates/ra_hir/src/code_model_impl/krate.rs
@@ -1,10 +1,12 @@
1use crate::{ 1use crate::{
2 Crate, CrateDependency, AsName, Module, 2 Crate, CrateDependency, AsName, Module, PersistentHirDatabase,
3 db::HirDatabase,
4}; 3};
5 4
6impl Crate { 5impl Crate {
7 pub(crate) fn dependencies_impl(&self, db: &impl HirDatabase) -> Vec<CrateDependency> { 6 pub(crate) fn dependencies_impl(
7 &self,
8 db: &impl PersistentHirDatabase,
9 ) -> Vec<CrateDependency> {
8 let crate_graph = db.crate_graph(); 10 let crate_graph = db.crate_graph();
9 crate_graph 11 crate_graph
10 .dependencies(self.crate_id) 12 .dependencies(self.crate_id)
@@ -17,7 +19,7 @@ impl Crate {
17 }) 19 })
18 .collect() 20 .collect()
19 } 21 }
20 pub(crate) fn root_module_impl(&self, db: &impl HirDatabase) -> Option<Module> { 22 pub(crate) fn root_module_impl(&self, db: &impl PersistentHirDatabase) -> Option<Module> {
21 let module_tree = db.module_tree(*self); 23 let module_tree = db.module_tree(*self);
22 let module_id = module_tree.modules().next()?; 24 let module_id = module_tree.modules().next()?;
23 25
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 4a3901b8b..f487b8532 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -7,7 +7,7 @@ use crate::{
7 module_tree::ModuleId, 7 module_tree::ModuleId,
8 impl_block::ImplId, 8 impl_block::ImplId,
9 nameres::{lower::ImportId}, 9 nameres::{lower::ImportId},
10 db::HirDatabase, 10 HirDatabase, PersistentHirDatabase,
11}; 11};
12 12
13impl Module { 13impl Module {
@@ -24,7 +24,10 @@ impl Module {
24 Some(link.name(&module_tree).clone()) 24 Some(link.name(&module_tree).clone())
25 } 25 }
26 26
27 pub(crate) fn definition_source_impl(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) { 27 pub(crate) fn definition_source_impl(
28 &self,
29 db: &impl PersistentHirDatabase,
30 ) -> (FileId, ModuleSource) {
28 let module_tree = db.module_tree(self.krate); 31 let module_tree = db.module_tree(self.krate);
29 let file_id = self.module_id.file_id(&module_tree); 32 let file_id = self.module_id.file_id(&module_tree);
30 let decl_id = self.module_id.decl_id(&module_tree); 33 let decl_id = self.module_id.decl_id(&module_tree);
@@ -67,7 +70,7 @@ impl Module {
67 source_map.get(&source, impl_id) 70 source_map.get(&source, impl_id)
68 } 71 }
69 72
70 pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Module { 73 pub(crate) fn crate_root_impl(&self, db: &impl PersistentHirDatabase) -> Module {
71 let module_tree = db.module_tree(self.krate); 74 let module_tree = db.module_tree(self.krate);
72 let module_id = self.module_id.crate_root(&module_tree); 75 let module_id = self.module_id.crate_root(&module_tree);
73 self.with_module_id(module_id) 76 self.with_module_id(module_id)
@@ -81,7 +84,10 @@ impl Module {
81 } 84 }
82 85
83 /// Iterates over all child modules. 86 /// Iterates over all child modules.
84 pub(crate) fn children_impl(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> { 87 pub(crate) fn children_impl(
88 &self,
89 db: &impl PersistentHirDatabase,
90 ) -> impl Iterator<Item = Module> {
85 let module_tree = db.module_tree(self.krate); 91 let module_tree = db.module_tree(self.krate);
86 let children = self 92 let children = self
87 .module_id 93 .module_id
@@ -91,7 +97,7 @@ impl Module {
91 children.into_iter() 97 children.into_iter()
92 } 98 }
93 99
94 pub(crate) fn parent_impl(&self, db: &impl HirDatabase) -> Option<Module> { 100 pub(crate) fn parent_impl(&self, db: &impl PersistentHirDatabase) -> Option<Module> {
95 let module_tree = db.module_tree(self.krate); 101 let module_tree = db.module_tree(self.krate);
96 let parent_id = self.module_id.parent(&module_tree)?; 102 let parent_id = self.module_id.parent(&module_tree)?;
97 Some(self.with_module_id(parent_id)) 103 Some(self.with_module_id(parent_id))
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 7183b1630..6b21fe744 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -27,9 +27,6 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> {
27 #[salsa::invoke(crate::macros::expand_macro_invocation)] 27 #[salsa::invoke(crate::macros::expand_macro_invocation)]
28 fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option<Arc<MacroExpansion>>; 28 fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option<Arc<MacroExpansion>>;
29 29
30 #[salsa::invoke(ExprScopes::expr_scopes_query)]
31 fn expr_scopes(&self, func: Function) -> Arc<ExprScopes>;
32
33 #[salsa::invoke(crate::adt::StructData::struct_data_query)] 30 #[salsa::invoke(crate::adt::StructData::struct_data_query)]
34 fn struct_data(&self, s: Struct) -> Arc<StructData>; 31 fn struct_data(&self, s: Struct) -> Arc<StructData>;
35 32
@@ -39,6 +36,9 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> {
39 #[salsa::invoke(query_definitions::file_items)] 36 #[salsa::invoke(query_definitions::file_items)]
40 fn file_items(&self, file_id: HirFileId) -> Arc<SourceFileItems>; 37 fn file_items(&self, file_id: HirFileId) -> Arc<SourceFileItems>;
41 38
39 #[salsa::invoke(query_definitions::file_item)]
40 fn file_item(&self, source_item_id: SourceItemId) -> TreeArc<SyntaxNode>;
41
42 #[salsa::invoke(crate::module_tree::Submodule::submodules_query)] 42 #[salsa::invoke(crate::module_tree::Submodule::submodules_query)]
43 fn submodules( 43 fn submodules(
44 &self, 44 &self,
@@ -61,20 +61,17 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> {
61 #[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)] 61 #[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)]
62 fn module_tree(&self, krate: Crate) -> Arc<ModuleTree>; 62 fn module_tree(&self, krate: Crate) -> Arc<ModuleTree>;
63 63
64 #[salsa::invoke(crate::impl_block::impls_in_module_with_source_map_query)]
65 fn impls_in_module_with_source_map(
66 &self,
67 module: Module,
68 ) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>);
69
70 #[salsa::invoke(crate::impl_block::impls_in_module)] 64 #[salsa::invoke(crate::impl_block::impls_in_module)]
71 fn impls_in_module(&self, module: Module) -> Arc<ModuleImplBlocks>; 65 fn impls_in_module(&self, module: Module) -> Arc<ModuleImplBlocks>;
72 66
73 #[salsa::invoke(crate::impl_block::impls_in_module_source_map_query)] 67 #[salsa::invoke(crate::impl_block::impls_in_module_source_map_query)]
74 fn impls_in_module_source_map(&self, module: Module) -> Arc<ImplSourceMap>; 68 fn impls_in_module_source_map(&self, module: Module) -> Arc<ImplSourceMap>;
75 69
76 #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] 70 #[salsa::invoke(crate::impl_block::impls_in_module_with_source_map_query)]
77 fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>; 71 fn impls_in_module_with_source_map(
72 &self,
73 module: Module,
74 ) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>);
78 75
79 #[salsa::invoke(crate::generics::GenericParams::generic_params_query)] 76 #[salsa::invoke(crate::generics::GenericParams::generic_params_query)]
80 fn generic_params(&self, def: GenericDef) -> Arc<GenericParams>; 77 fn generic_params(&self, def: GenericDef) -> Arc<GenericParams>;
@@ -85,11 +82,8 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> {
85 82
86#[salsa::query_group(HirDatabaseStorage)] 83#[salsa::query_group(HirDatabaseStorage)]
87pub trait HirDatabase: PersistentHirDatabase { 84pub trait HirDatabase: PersistentHirDatabase {
88 #[salsa::invoke(query_definitions::fn_scopes)] 85 #[salsa::invoke(ExprScopes::expr_scopes_query)]
89 fn fn_scopes(&self, func: Function) -> Arc<FnScopes>; 86 fn expr_scopes(&self, func: Function) -> Arc<ExprScopes>;
90
91 #[salsa::invoke(query_definitions::file_item)]
92 fn file_item(&self, source_item_id: SourceItemId) -> TreeArc<SyntaxNode>;
93 87
94 #[salsa::invoke(crate::ty::infer)] 88 #[salsa::invoke(crate::ty::infer)]
95 fn infer(&self, func: Function) -> Arc<InferenceResult>; 89 fn infer(&self, func: Function) -> Arc<InferenceResult>;
@@ -105,4 +99,7 @@ pub trait HirDatabase: PersistentHirDatabase {
105 99
106 #[salsa::invoke(crate::expr::body_syntax_mapping)] 100 #[salsa::invoke(crate::expr::body_syntax_mapping)]
107 fn body_syntax_mapping(&self, func: Function) -> Arc<crate::expr::BodySyntaxMapping>; 101 fn body_syntax_mapping(&self, func: Function) -> Arc<crate::expr::BodySyntaxMapping>;
102
103 #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
104 fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
108} 105}
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 37aa24677..f4a950418 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -10,8 +10,8 @@ use ra_syntax::{
10}; 10};
11 11
12use crate::{ 12use crate::{
13 Path, Name, HirDatabase, Function, 13 Path, Name, Function,
14 name::AsName, 14 name::AsName, HirDatabase,
15 type_ref::{Mutability, TypeRef}, 15 type_ref::{Mutability, TypeRef},
16}; 16};
17use crate::ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy}; 17use crate::ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy};
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index f8b5ba581..b7971088d 100644
--- a/crates/ra_hir/src/expr/scope.rs
+++ b/crates/ra_hir/src/expr/scope.rs
@@ -12,7 +12,7 @@ use ra_arena::{Arena, RawId, impl_arena_id};
12use crate::{ 12use crate::{
13 Name, AsName, Function, 13 Name, AsName, Function,
14 expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping}, 14 expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping},
15 db::HirDatabase, 15 HirDatabase,
16}; 16};
17 17
18#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 18#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 64c20a462..b0bd735bd 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -7,7 +7,7 @@ use std::sync::Arc;
7 7
8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner}; 8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner};
9 9
10use crate::{db::HirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type}; 10use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type};
11 11
12/// Data about a generic parameter (to a function, struct, impl, ...). 12/// Data about a generic parameter (to a function, struct, impl, ...).
13#[derive(Clone, PartialEq, Eq, Debug)] 13#[derive(Clone, PartialEq, Eq, Debug)]
@@ -34,7 +34,7 @@ impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type);
34 34
35impl GenericParams { 35impl GenericParams {
36 pub(crate) fn generic_params_query( 36 pub(crate) fn generic_params_query(
37 db: &impl HirDatabase, 37 db: &impl PersistentHirDatabase,
38 def: GenericDef, 38 def: GenericDef,
39 ) -> Arc<GenericParams> { 39 ) -> Arc<GenericParams> {
40 let mut generics = GenericParams::default(); 40 let mut generics = GenericParams::default();
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 0e4dc6261..95678bf70 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -10,6 +10,7 @@ use ra_arena::{Arena, RawId, ArenaId, impl_arena_id};
10use crate::{ 10use crate::{
11 HirDatabase, 11 HirDatabase,
12 Module, 12 Module,
13 PersistentHirDatabase,
13}; 14};
14 15
15#[derive(Debug, Default)] 16#[derive(Debug, Default)]
@@ -62,7 +63,7 @@ pub struct HirFileId(HirFileIdRepr);
62impl HirFileId { 63impl HirFileId {
63 /// For macro-expansion files, returns the file original source file the 64 /// For macro-expansion files, returns the file original source file the
64 /// expansionoriginated from. 65 /// expansionoriginated from.
65 pub fn original_file(self, db: &impl HirDatabase) -> FileId { 66 pub fn original_file(self, db: &impl PersistentHirDatabase) -> FileId {
66 match self.0 { 67 match self.0 {
67 HirFileIdRepr::File(file_id) => file_id, 68 HirFileIdRepr::File(file_id) => file_id,
68 HirFileIdRepr::Macro(macro_call_id) => { 69 HirFileIdRepr::Macro(macro_call_id) => {
@@ -86,7 +87,10 @@ impl HirFileId {
86 } 87 }
87 } 88 }
88 89
89 pub(crate) fn hir_parse(db: &impl HirDatabase, file_id: HirFileId) -> TreeArc<SourceFile> { 90 pub(crate) fn hir_parse(
91 db: &impl PersistentHirDatabase,
92 file_id: HirFileId,
93 ) -> TreeArc<SourceFile> {
90 match file_id.0 { 94 match file_id.0 {
91 HirFileIdRepr::File(file_id) => db.parse(file_id), 95 HirFileIdRepr::File(file_id) => db.parse(file_id),
92 HirFileIdRepr::Macro(m) => { 96 HirFileIdRepr::Macro(m) => {
@@ -180,7 +184,7 @@ pub(crate) struct LocationCtx<DB> {
180 file_id: HirFileId, 184 file_id: HirFileId,
181} 185}
182 186
183impl<'a, DB: HirDatabase> LocationCtx<&'a DB> { 187impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> {
184 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> {
185 LocationCtx { 189 LocationCtx {
186 db, 190 db,
@@ -199,7 +203,7 @@ impl<'a, DB: HirDatabase> LocationCtx<&'a DB> {
199 203
200pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { 204pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone {
201 fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<N>, Self>; 205 fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<N>, Self>;
202 fn from_ast(ctx: LocationCtx<&impl HirDatabase>, ast: &N) -> Self { 206 fn from_ast(ctx: LocationCtx<&impl PersistentHirDatabase>, ast: &N) -> Self {
203 let items = ctx.db.file_items(ctx.file_id); 207 let items = ctx.db.file_items(ctx.file_id);
204 let raw = SourceItemId { 208 let raw = SourceItemId {
205 file_id: ctx.file_id, 209 file_id: ctx.file_id,
@@ -213,7 +217,7 @@ pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone {
213 217
214 Self::interner(ctx.db.as_ref()).loc2id(&loc) 218 Self::interner(ctx.db.as_ref()).loc2id(&loc)
215 } 219 }
216 fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc<N>) { 220 fn source(self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<N>) {
217 let int = Self::interner(db.as_ref()); 221 let int = Self::interner(db.as_ref());
218 let loc = int.id2loc(self); 222 let loc = int.id2loc(self);
219 let syntax = db.file_item(loc.raw); 223 let syntax = db.file_item(loc.raw);
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index 5fc26324a..36d72b103 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -9,7 +9,7 @@ ast::{self, AstNode}};
9use crate::{ 9use crate::{
10 Const, Type, 10 Const, Type,
11 Function, HirFileId, 11 Function, HirFileId,
12 db::HirDatabase, 12 PersistentHirDatabase,
13 type_ref::TypeRef, 13 type_ref::TypeRef,
14 ids::LocationCtx, 14 ids::LocationCtx,
15}; 15};
@@ -91,7 +91,7 @@ pub struct ImplData {
91 91
92impl ImplData { 92impl ImplData {
93 pub(crate) fn from_ast( 93 pub(crate) fn from_ast(
94 db: &impl HirDatabase, 94 db: &impl PersistentHirDatabase,
95 file_id: HirFileId, 95 file_id: HirFileId,
96 module: Module, 96 module: Module,
97 node: &ast::ImplBlock, 97 node: &ast::ImplBlock,
@@ -174,7 +174,12 @@ impl ModuleImplBlocks {
174 } 174 }
175 } 175 }
176 176
177 fn collect(&mut self, db: &impl HirDatabase, module: Module, source_map: &mut ImplSourceMap) { 177 fn collect(
178 &mut self,
179 db: &impl PersistentHirDatabase,
180 module: Module,
181 source_map: &mut ImplSourceMap,
182 ) {
178 let (file_id, module_source) = module.definition_source(db); 183 let (file_id, module_source) = module.definition_source(db);
179 let file_id: HirFileId = file_id.into(); 184 let file_id: HirFileId = file_id.into();
180 let node = match &module_source { 185 let node = match &module_source {
@@ -198,7 +203,7 @@ impl ModuleImplBlocks {
198} 203}
199 204
200pub(crate) fn impls_in_module_with_source_map_query( 205pub(crate) fn impls_in_module_with_source_map_query(
201 db: &impl HirDatabase, 206 db: &impl PersistentHirDatabase,
202 module: Module, 207 module: Module,
203) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) { 208) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) {
204 let mut source_map = ImplSourceMap::default(); 209 let mut source_map = ImplSourceMap::default();
@@ -209,12 +214,15 @@ pub(crate) fn impls_in_module_with_source_map_query(
209 (Arc::new(result), Arc::new(source_map)) 214 (Arc::new(result), Arc::new(source_map))
210} 215}
211 216
212pub(crate) fn impls_in_module(db: &impl HirDatabase, module: Module) -> Arc<ModuleImplBlocks> { 217pub(crate) fn impls_in_module(
218 db: &impl PersistentHirDatabase,
219 module: Module,
220) -> Arc<ModuleImplBlocks> {
213 db.impls_in_module_with_source_map(module).0 221 db.impls_in_module_with_source_map(module).0
214} 222}
215 223
216pub(crate) fn impls_in_module_source_map_query( 224pub(crate) fn impls_in_module_source_map_query(
217 db: &impl HirDatabase, 225 db: &impl PersistentHirDatabase,
218 module: Module, 226 module: Module,
219) -> Arc<ImplSourceMap> { 227) -> Arc<ImplSourceMap> {
220 db.impls_in_module_with_source_map(module).1 228 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 0b9ee63bf..905c53c7d 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -44,7 +44,7 @@ mod code_model_impl;
44mod marks; 44mod marks;
45 45
46use crate::{ 46use crate::{
47 db::HirDatabase, 47 db::{HirDatabase, PersistentHirDatabase},
48 name::{AsName, KnownName}, 48 name::{AsName, KnownName},
49 ids::{SourceItemId, SourceFileItems}, 49 ids::{SourceItemId, SourceFileItems},
50}; 50};
diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs
index cf7220875..cb8a9312e 100644
--- a/crates/ra_hir/src/macros.rs
+++ b/crates/ra_hir/src/macros.rs
@@ -14,7 +14,7 @@ use ra_syntax::{
14 ast::{self, NameOwner}, 14 ast::{self, NameOwner},
15}; 15};
16 16
17use crate::{HirDatabase, MacroCallId}; 17use crate::{MacroCallId, PersistentHirDatabase};
18 18
19// Hard-coded defs for now :-( 19// Hard-coded defs for now :-(
20#[derive(Debug, Clone, PartialEq, Eq, Hash)] 20#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -157,7 +157,7 @@ impl MacroExpansion {
157} 157}
158 158
159pub(crate) fn expand_macro_invocation( 159pub(crate) fn expand_macro_invocation(
160 db: &impl HirDatabase, 160 db: &impl PersistentHirDatabase,
161 invoc: MacroCallId, 161 invoc: MacroCallId,
162) -> Option<Arc<MacroExpansion>> { 162) -> Option<Arc<MacroExpansion>> {
163 let loc = invoc.loc(db); 163 let loc = invoc.loc(db);
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 7da15eca0..17bdd48c6 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -11,7 +11,11 @@ use crate::{db, HirInterner};
11 11
12pub const WORKSPACE: SourceRootId = SourceRootId(0); 12pub const WORKSPACE: SourceRootId = SourceRootId(0);
13 13
14#[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage)] 14#[salsa::database(
15 ra_db::SourceDatabaseStorage,
16 db::HirDatabaseStorage,
17 db::PersistentHirDatabaseStorage
18)]
15#[derive(Debug)] 19#[derive(Debug)]
16pub(crate) struct MockDatabase { 20pub(crate) struct MockDatabase {
17 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, 21 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs
index 1f327eeb2..a1aa3d8ce 100644
--- a/crates/ra_hir/src/module_tree.rs
+++ b/crates/ra_hir/src/module_tree.rs
@@ -13,13 +13,14 @@ use test_utils::tested_by;
13 13
14use crate::{ 14use crate::{
15 Name, AsName, HirDatabase, SourceItemId, HirFileId, Problem, SourceFileItems, ModuleSource, 15 Name, AsName, HirDatabase, SourceItemId, HirFileId, Problem, SourceFileItems, ModuleSource,
16 PersistentHirDatabase,
16 Crate, 17 Crate,
17 ids::SourceFileItemId, 18 ids::SourceFileItemId,
18}; 19};
19 20
20impl ModuleSource { 21impl ModuleSource {
21 pub(crate) fn new( 22 pub(crate) fn new(
22 db: &impl HirDatabase, 23 db: &impl PersistentHirDatabase,
23 file_id: HirFileId, 24 file_id: HirFileId,
24 decl_id: Option<SourceFileItemId>, 25 decl_id: Option<SourceFileItemId>,
25 ) -> ModuleSource { 26 ) -> ModuleSource {
@@ -47,7 +48,7 @@ pub struct Submodule {
47 48
48impl Submodule { 49impl Submodule {
49 pub(crate) fn submodules_query( 50 pub(crate) fn submodules_query(
50 db: &impl HirDatabase, 51 db: &impl PersistentHirDatabase,
51 file_id: HirFileId, 52 file_id: HirFileId,
52 decl_id: Option<SourceFileItemId>, 53 decl_id: Option<SourceFileItemId>,
53 ) -> Arc<Vec<Submodule>> { 54 ) -> Arc<Vec<Submodule>> {
@@ -133,7 +134,10 @@ struct LinkData {
133} 134}
134 135
135impl ModuleTree { 136impl ModuleTree {
136 pub(crate) fn module_tree_query(db: &impl HirDatabase, krate: Crate) -> Arc<ModuleTree> { 137 pub(crate) fn module_tree_query(
138 db: &impl PersistentHirDatabase,
139 krate: Crate,
140 ) -> Arc<ModuleTree> {
137 db.check_canceled(); 141 db.check_canceled();
138 let mut res = ModuleTree::default(); 142 let mut res = ModuleTree::default();
139 res.init_crate(db, krate); 143 res.init_crate(db, krate);
@@ -156,7 +160,7 @@ impl ModuleTree {
156 Some(res) 160 Some(res)
157 } 161 }
158 162
159 fn init_crate(&mut self, db: &impl HirDatabase, krate: Crate) { 163 fn init_crate(&mut self, db: &impl PersistentHirDatabase, krate: Crate) {
160 let crate_graph = db.crate_graph(); 164 let crate_graph = db.crate_graph();
161 let file_id = crate_graph.crate_root(krate.crate_id); 165 let file_id = crate_graph.crate_root(krate.crate_id);
162 let source_root_id = db.file_source_root(file_id); 166 let source_root_id = db.file_source_root(file_id);
@@ -167,7 +171,7 @@ impl ModuleTree {
167 171
168 fn init_subtree( 172 fn init_subtree(
169 &mut self, 173 &mut self,
170 db: &impl HirDatabase, 174 db: &impl PersistentHirDatabase,
171 source_root: &SourceRoot, 175 source_root: &SourceRoot,
172 parent: Option<LinkId>, 176 parent: Option<LinkId>,
173 file_id: HirFileId, 177 file_id: HirFileId,
@@ -287,14 +291,18 @@ impl LinkId {
287 pub(crate) fn name(self, tree: &ModuleTree) -> &Name { 291 pub(crate) fn name(self, tree: &ModuleTree) -> &Name {
288 &tree.links[self].name 292 &tree.links[self].name
289 } 293 }
290 pub(crate) fn source(self, tree: &ModuleTree, db: &impl HirDatabase) -> TreeArc<ast::Module> { 294 pub(crate) fn source(
295 self,
296 tree: &ModuleTree,
297 db: &impl PersistentHirDatabase,
298 ) -> TreeArc<ast::Module> {
291 let syntax_node = db.file_item(tree.links[self].source); 299 let syntax_node = db.file_item(tree.links[self].source);
292 ast::Module::cast(&syntax_node).unwrap().to_owned() 300 ast::Module::cast(&syntax_node).unwrap().to_owned()
293 } 301 }
294} 302}
295 303
296fn resolve_submodule( 304fn resolve_submodule(
297 db: &impl HirDatabase, 305 db: &impl PersistentHirDatabase,
298 file_id: HirFileId, 306 file_id: HirFileId,
299 name: &Name, 307 name: &Name,
300 is_root: bool, 308 is_root: bool,
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 4573a72ba..f8627acbe 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -24,9 +24,8 @@ use rustc_hash::{FxHashMap, FxHashSet};
24 24
25use crate::{ 25use crate::{
26 Module, ModuleDef, 26 Module, ModuleDef,
27 Path, PathKind, 27 Path, PathKind, Crate,
28 HirDatabase, Crate, 28 Name, PersistentHirDatabase,
29 Name,
30 module_tree::{ModuleId, ModuleTree}, 29 module_tree::{ModuleId, ModuleTree},
31 nameres::lower::{ImportId, LoweredModule, ImportData}, 30 nameres::lower::{ImportId, LoweredModule, ImportData},
32}; 31};
@@ -166,7 +165,7 @@ struct Resolver<'a, DB> {
166 165
167impl<'a, DB> Resolver<'a, DB> 166impl<'a, DB> Resolver<'a, DB>
168where 167where
169 DB: HirDatabase, 168 DB: PersistentHirDatabase,
170{ 169{
171 fn new( 170 fn new(
172 db: &'a DB, 171 db: &'a DB,
@@ -330,7 +329,7 @@ enum ReachedFixedPoint {
330} 329}
331 330
332impl ItemMap { 331impl ItemMap {
333 pub(crate) fn item_map_query(db: &impl HirDatabase, krate: Crate) -> Arc<ItemMap> { 332 pub(crate) fn item_map_query(db: &impl PersistentHirDatabase, krate: Crate) -> Arc<ItemMap> {
334 let start = time::Instant::now(); 333 let start = time::Instant::now();
335 let module_tree = db.module_tree(krate); 334 let module_tree = db.module_tree(krate);
336 let input = module_tree 335 let input = module_tree
@@ -352,7 +351,7 @@ impl ItemMap {
352 351
353 pub(crate) fn resolve_path( 352 pub(crate) fn resolve_path(
354 &self, 353 &self,
355 db: &impl HirDatabase, 354 db: &impl PersistentHirDatabase,
356 original_module: Module, 355 original_module: Module,
357 path: &Path, 356 path: &Path,
358 ) -> PerNs<ModuleDef> { 357 ) -> PerNs<ModuleDef> {
@@ -363,7 +362,7 @@ impl ItemMap {
363 // the result. 362 // the result.
364 fn resolve_path_fp( 363 fn resolve_path_fp(
365 &self, 364 &self,
366 db: &impl HirDatabase, 365 db: &impl PersistentHirDatabase,
367 original_module: Module, 366 original_module: Module,
368 path: &Path, 367 path: &Path,
369 ) -> (PerNs<ModuleDef>, ReachedFixedPoint) { 368 ) -> (PerNs<ModuleDef>, ReachedFixedPoint) {
diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs
index 8df11a5f4..9a45fa61c 100644
--- a/crates/ra_hir/src/nameres/lower.rs
+++ b/crates/ra_hir/src/nameres/lower.rs
@@ -8,10 +8,10 @@ use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
8use rustc_hash::FxHashMap; 8use rustc_hash::FxHashMap;
9 9
10use crate::{ 10use crate::{
11 SourceItemId, Path, ModuleSource, HirDatabase, Name, 11 SourceItemId, Path, ModuleSource, Name,
12 HirFileId, MacroCallLoc, AsName, PerNs, Function, 12 HirFileId, MacroCallLoc, AsName, PerNs, Function,
13 ModuleDef, Module, Struct, Enum, Const, Static, Trait, Type, 13 ModuleDef, Module, Struct, Enum, Const, Static, Trait, Type,
14 ids::LocationCtx, 14 ids::LocationCtx, PersistentHirDatabase,
15}; 15};
16 16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -58,21 +58,21 @@ impl ImportSourceMap {
58 58
59impl LoweredModule { 59impl LoweredModule {
60 pub(crate) fn lower_module_module_query( 60 pub(crate) fn lower_module_module_query(
61 db: &impl HirDatabase, 61 db: &impl PersistentHirDatabase,
62 module: Module, 62 module: Module,
63 ) -> Arc<LoweredModule> { 63 ) -> Arc<LoweredModule> {
64 db.lower_module(module).0 64 db.lower_module(module).0
65 } 65 }
66 66
67 pub(crate) fn lower_module_source_map_query( 67 pub(crate) fn lower_module_source_map_query(
68 db: &impl HirDatabase, 68 db: &impl PersistentHirDatabase,
69 module: Module, 69 module: Module,
70 ) -> Arc<ImportSourceMap> { 70 ) -> Arc<ImportSourceMap> {
71 db.lower_module(module).1 71 db.lower_module(module).1
72 } 72 }
73 73
74 pub(crate) fn lower_module_query( 74 pub(crate) fn lower_module_query(
75 db: &impl HirDatabase, 75 db: &impl PersistentHirDatabase,
76 module: Module, 76 module: Module,
77 ) -> (Arc<LoweredModule>, Arc<ImportSourceMap>) { 77 ) -> (Arc<LoweredModule>, Arc<ImportSourceMap>) {
78 let (file_id, source) = module.definition_source(db); 78 let (file_id, source) = module.definition_source(db);
@@ -105,7 +105,7 @@ impl LoweredModule {
105 fn fill( 105 fn fill(
106 &mut self, 106 &mut self,
107 source_map: &mut ImportSourceMap, 107 source_map: &mut ImportSourceMap,
108 db: &impl HirDatabase, 108 db: &impl PersistentHirDatabase,
109 module: Module, 109 module: Module,
110 file_id: HirFileId, 110 file_id: HirFileId,
111 items: &mut Iterator<Item = ast::ItemOrMacro>, 111 items: &mut Iterator<Item = ast::ItemOrMacro>,
@@ -137,7 +137,7 @@ impl LoweredModule {
137 fn add_def_id( 137 fn add_def_id(
138 &mut self, 138 &mut self,
139 source_map: &mut ImportSourceMap, 139 source_map: &mut ImportSourceMap,
140 db: &impl HirDatabase, 140 db: &impl PersistentHirDatabase,
141 module: Module, 141 module: Module,
142 file_id: HirFileId, 142 file_id: HirFileId,
143 item: &ast::ModuleItem, 143 item: &ast::ModuleItem,
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index 9c5ca097e..1ce7bd146 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -6,7 +6,7 @@ use test_utils::{assert_eq_text, covers};
6 6
7use crate::{ 7use crate::{
8 ItemMap, Resolution, 8 ItemMap, Resolution,
9 db::HirDatabase, 9 PersistentHirDatabase,
10 mock::MockDatabase, 10 mock::MockDatabase,
11 module_tree::ModuleId, 11 module_tree::ModuleId,
12}; 12};
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index 734a98282..b4d8da1e6 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -6,17 +6,20 @@ use ra_syntax::{
6 6
7use crate::{ 7use crate::{
8 SourceFileItems, SourceItemId, HirFileId, 8 SourceFileItems, SourceItemId, HirFileId,
9 db::HirDatabase, 9 PersistentHirDatabase,
10}; 10};
11 11
12pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { 12pub(super) fn file_items(
13 db: &impl PersistentHirDatabase,
14 file_id: HirFileId,
15) -> Arc<SourceFileItems> {
13 let source_file = db.hir_parse(file_id); 16 let source_file = db.hir_parse(file_id);
14 let res = SourceFileItems::new(file_id, &source_file); 17 let res = SourceFileItems::new(file_id, &source_file);
15 Arc::new(res) 18 Arc::new(res)
16} 19}
17 20
18pub(super) fn file_item( 21pub(super) fn file_item(
19 db: &impl HirDatabase, 22 db: &impl PersistentHirDatabase,
20 source_item_id: SourceItemId, 23 source_item_id: SourceItemId,
21) -> TreeArc<SyntaxNode> { 24) -> TreeArc<SyntaxNode> {
22 let source_file = db.hir_parse(source_item_id.file_id); 25 let source_file = db.hir_parse(source_item_id.file_id);
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 60c231e82..d3e31981a 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -35,7 +35,7 @@ use test_utils::tested_by;
35use crate::{ 35use crate::{
36 Module, Function, Struct, StructField, Enum, EnumVariant, Path, Name, ImplBlock, 36 Module, Function, Struct, StructField, Enum, EnumVariant, Path, Name, ImplBlock,
37 FnSignature, ExprScopes, ModuleDef, AdtDef, 37 FnSignature, ExprScopes, ModuleDef, AdtDef,
38 db::HirDatabase, 38 HirDatabase,
39 type_ref::{TypeRef, Mutability}, 39 type_ref::{TypeRef, Mutability},
40 name::KnownName, 40 name::KnownName,
41 expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat}, 41 expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat},
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index 6850811d7..3a9089c22 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -14,7 +14,8 @@ 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::HirDatabaseStorage 17 hir::db::HirDatabaseStorage,
18 hir::db::PersistentHirDatabaseStorage
18)] 19)]
19#[derive(Debug)] 20#[derive(Debug)]
20pub(crate) struct RootDatabase { 21pub(crate) struct RootDatabase {