diff options
25 files changed, 149 insertions, 216 deletions
diff --git a/Cargo.lock b/Cargo.lock index 3c78346c1..1b5de271e 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -369,11 +369,6 @@ dependencies = [ | |||
369 | ] | 369 | ] |
370 | 370 | ||
371 | [[package]] | 371 | [[package]] |
372 | name = "fnv" | ||
373 | version = "1.0.6" | ||
374 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
375 | |||
376 | [[package]] | ||
377 | name = "fs_extra" | 372 | name = "fs_extra" |
378 | version = "1.1.0" | 373 | version = "1.1.0" |
379 | source = "registry+https://github.com/rust-lang/crates.io-index" | 374 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -873,8 +868,6 @@ dependencies = [ | |||
873 | "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", | 868 | "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", |
874 | "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", | 869 | "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", |
875 | "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", | 870 | "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", |
876 | "rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||
877 | "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", | ||
878 | ] | 871 | ] |
879 | 872 | ||
880 | [[package]] | 873 | [[package]] |
@@ -1352,17 +1345,6 @@ dependencies = [ | |||
1352 | ] | 1345 | ] |
1353 | 1346 | ||
1354 | [[package]] | 1347 | [[package]] |
1355 | name = "rusty-fork" | ||
1356 | version = "0.2.1" | ||
1357 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1358 | dependencies = [ | ||
1359 | "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1360 | "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1361 | "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1362 | "wait-timeout 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1363 | ] | ||
1364 | |||
1365 | [[package]] | ||
1366 | name = "ryu" | 1348 | name = "ryu" |
1367 | version = "0.2.7" | 1349 | version = "0.2.7" |
1368 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1350 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1812,14 +1794,6 @@ version = "0.1.5" | |||
1812 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1794 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1813 | 1795 | ||
1814 | [[package]] | 1796 | [[package]] |
1815 | name = "wait-timeout" | ||
1816 | version = "0.1.5" | ||
1817 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1818 | dependencies = [ | ||
1819 | "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1820 | ] | ||
1821 | |||
1822 | [[package]] | ||
1823 | name = "walkdir" | 1797 | name = "walkdir" |
1824 | version = "2.2.7" | 1798 | version = "2.2.7" |
1825 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1799 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1930,7 +1904,6 @@ dependencies = [ | |||
1930 | "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" | 1904 | "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" |
1931 | "checksum filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a2df5c1a8c4be27e7707789dc42ae65976e60b394afd293d1419ab915833e646" | 1905 | "checksum filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a2df5c1a8c4be27e7707789dc42ae65976e60b394afd293d1419ab915833e646" |
1932 | "checksum flexi_logger 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4a7878fc9e06c948c6f9cddf571758e0c44786a509e646a094ef13ade3b1aab7" | 1906 | "checksum flexi_logger 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4a7878fc9e06c948c6f9cddf571758e0c44786a509e646a094ef13ade3b1aab7" |
1933 | "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" | ||
1934 | "checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" | 1907 | "checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" |
1935 | "checksum fsevent 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "c4bbbf71584aeed076100b5665ac14e3d85eeb31fdbb45fbd41ef9a682b5ec05" | 1908 | "checksum fsevent 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "c4bbbf71584aeed076100b5665ac14e3d85eeb31fdbb45fbd41ef9a682b5ec05" |
1936 | "checksum fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a772d36c338d07a032d5375a36f15f9a7043bf0cb8ce7cee658e037c6032874" | 1909 | "checksum fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a772d36c338d07a032d5375a36f15f9a7043bf0cb8ce7cee658e037c6032874" |
@@ -2015,7 +1988,6 @@ dependencies = [ | |||
2015 | "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" | 1988 | "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" |
2016 | "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" | 1989 | "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" |
2017 | "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" | 1990 | "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" |
2018 | "checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c" | ||
2019 | "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" | 1991 | "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" |
2020 | "checksum salsa 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cad0e2348e2f80725b2980914a08a00267136c3ecf720896d3f7f08eef51e08f" | 1992 | "checksum salsa 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cad0e2348e2f80725b2980914a08a00267136c3ecf720896d3f7f08eef51e08f" |
2021 | "checksum salsa-macros 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c79744109df21b80aef1367669b0a9e4985bc966e76bf0e9321b222ec0b9fbb" | 1993 | "checksum salsa-macros 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c79744109df21b80aef1367669b0a9e4985bc966e76bf0e9321b222ec0b9fbb" |
@@ -2069,7 +2041,6 @@ dependencies = [ | |||
2069 | "checksum uuid 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0238db0c5b605dd1cf51de0f21766f97fba2645897024461d6a00c036819a768" | 2041 | "checksum uuid 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0238db0c5b605dd1cf51de0f21766f97fba2645897024461d6a00c036819a768" |
2070 | "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" | 2042 | "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" |
2071 | "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" | 2043 | "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" |
2072 | "checksum wait-timeout 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "b9f3bf741a801531993db6478b95682117471f76916f5e690dd8d45395b09349" | ||
2073 | "checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" | 2044 | "checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" |
2074 | "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" | 2045 | "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" |
2075 | "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" | 2046 | "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" |
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index deb9f95d7..3bbcdb0b8 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs | |||
@@ -16,11 +16,7 @@ use vfs_filter::IncludeRustFiles; | |||
16 | 16 | ||
17 | type Result<T> = std::result::Result<T, failure::Error>; | 17 | type Result<T> = std::result::Result<T, failure::Error>; |
18 | 18 | ||
19 | #[salsa::database( | 19 | #[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage, db::DefDatabaseStorage)] |
20 | ra_db::SourceDatabaseStorage, | ||
21 | db::HirDatabaseStorage, | ||
22 | db::PersistentHirDatabaseStorage | ||
23 | )] | ||
24 | #[derive(Debug)] | 20 | #[derive(Debug)] |
25 | pub struct BatchDatabase { | 21 | pub struct BatchDatabase { |
26 | runtime: salsa::Runtime<BatchDatabase>, | 22 | runtime: salsa::Runtime<BatchDatabase>, |
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::{ | |||
12 | use crate::{ | 12 | use 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 | ||
35 | impl Struct { | 35 | impl 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> | |||
68 | impl EnumVariant { | 65 | impl 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 | ||
93 | impl EnumData { | 90 | impl 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 | ||
200 | impl StructField { | 197 | impl 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..45fa4cd11 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 | ||
7 | use crate::{ | 7 | use 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 | } |
@@ -101,7 +98,6 @@ pub enum ModuleSource { | |||
101 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] | 98 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] |
102 | pub enum Problem { | 99 | pub enum Problem { |
103 | UnresolvedModule { candidate: RelativePathBuf }, | 100 | UnresolvedModule { candidate: RelativePathBuf }, |
104 | NotDirOwner { move_to: RelativePathBuf, candidate: RelativePathBuf }, | ||
105 | } | 101 | } |
106 | 102 | ||
107 | impl Module { | 103 | impl Module { |
@@ -111,7 +107,7 @@ impl Module { | |||
111 | } | 107 | } |
112 | 108 | ||
113 | /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. | 109 | /// 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) { | 110 | pub fn definition_source(&self, db: &impl DefDatabase) -> (HirFileId, ModuleSource) { |
115 | self.definition_source_impl(db) | 111 | self.definition_source_impl(db) |
116 | } | 112 | } |
117 | 113 | ||
@@ -134,14 +130,14 @@ impl Module { | |||
134 | } | 130 | } |
135 | 131 | ||
136 | /// Returns the crate this module is part of. | 132 | /// Returns the crate this module is part of. |
137 | pub fn krate(&self, _db: &impl PersistentHirDatabase) -> Option<Crate> { | 133 | pub fn krate(&self, _db: &impl DefDatabase) -> Option<Crate> { |
138 | Some(self.krate) | 134 | Some(self.krate) |
139 | } | 135 | } |
140 | 136 | ||
141 | /// Topmost parent of this module. Every module has a `crate_root`, but some | 137 | /// 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 | 138 | /// 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`. | 139 | /// in the module tree of any target in `Cargo.toml`. |
144 | pub fn crate_root(&self, db: &impl PersistentHirDatabase) -> Module { | 140 | pub fn crate_root(&self, db: &impl DefDatabase) -> Module { |
145 | self.crate_root_impl(db) | 141 | self.crate_root_impl(db) |
146 | } | 142 | } |
147 | 143 | ||
@@ -151,12 +147,12 @@ impl Module { | |||
151 | } | 147 | } |
152 | 148 | ||
153 | /// Iterates over all child modules. | 149 | /// Iterates over all child modules. |
154 | pub fn children(&self, db: &impl PersistentHirDatabase) -> impl Iterator<Item = Module> { | 150 | pub fn children(&self, db: &impl DefDatabase) -> impl Iterator<Item = Module> { |
155 | self.children_impl(db) | 151 | self.children_impl(db) |
156 | } | 152 | } |
157 | 153 | ||
158 | /// Finds a parent module. | 154 | /// Finds a parent module. |
159 | pub fn parent(&self, db: &impl PersistentHirDatabase) -> Option<Module> { | 155 | pub fn parent(&self, db: &impl DefDatabase) -> Option<Module> { |
160 | self.parent_impl(db) | 156 | self.parent_impl(db) |
161 | } | 157 | } |
162 | 158 | ||
@@ -229,7 +225,7 @@ impl StructField { | |||
229 | self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() | 225 | self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() |
230 | } | 226 | } |
231 | 227 | ||
232 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { | 228 | pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, FieldSource) { |
233 | self.source_impl(db) | 229 | self.source_impl(db) |
234 | } | 230 | } |
235 | 231 | ||
@@ -257,7 +253,7 @@ pub struct Struct { | |||
257 | } | 253 | } |
258 | 254 | ||
259 | impl Struct { | 255 | impl Struct { |
260 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StructDef>) { | 256 | pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StructDef>) { |
261 | self.id.source(db) | 257 | self.id.source(db) |
262 | } | 258 | } |
263 | 259 | ||
@@ -289,7 +285,7 @@ impl Struct { | |||
289 | .map(|(id, _)| StructField { parent: (*self).into(), id }) | 285 | .map(|(id, _)| StructField { parent: (*self).into(), id }) |
290 | } | 286 | } |
291 | 287 | ||
292 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { | 288 | pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> { |
293 | db.generic_params((*self).into()) | 289 | db.generic_params((*self).into()) |
294 | } | 290 | } |
295 | 291 | ||
@@ -325,7 +321,7 @@ pub struct Enum { | |||
325 | } | 321 | } |
326 | 322 | ||
327 | impl Enum { | 323 | impl Enum { |
328 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) { | 324 | pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) { |
329 | self.id.source(db) | 325 | self.id.source(db) |
330 | } | 326 | } |
331 | 327 | ||
@@ -337,7 +333,7 @@ impl Enum { | |||
337 | db.enum_data(*self).name.clone() | 333 | db.enum_data(*self).name.clone() |
338 | } | 334 | } |
339 | 335 | ||
340 | pub fn variants(&self, db: &impl PersistentHirDatabase) -> Vec<EnumVariant> { | 336 | pub fn variants(&self, db: &impl DefDatabase) -> Vec<EnumVariant> { |
341 | db.enum_data(*self) | 337 | db.enum_data(*self) |
342 | .variants | 338 | .variants |
343 | .iter() | 339 | .iter() |
@@ -345,7 +341,7 @@ impl Enum { | |||
345 | .collect() | 341 | .collect() |
346 | } | 342 | } |
347 | 343 | ||
348 | pub fn variant(&self, db: &impl PersistentHirDatabase, name: &Name) -> Option<EnumVariant> { | 344 | pub fn variant(&self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> { |
349 | db.enum_data(*self) | 345 | db.enum_data(*self) |
350 | .variants | 346 | .variants |
351 | .iter() | 347 | .iter() |
@@ -353,7 +349,7 @@ impl Enum { | |||
353 | .map(|(id, _)| EnumVariant { parent: *self, id }) | 349 | .map(|(id, _)| EnumVariant { parent: *self, id }) |
354 | } | 350 | } |
355 | 351 | ||
356 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { | 352 | pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> { |
357 | db.generic_params((*self).into()) | 353 | db.generic_params((*self).into()) |
358 | } | 354 | } |
359 | 355 | ||
@@ -386,20 +382,17 @@ pub struct EnumVariant { | |||
386 | } | 382 | } |
387 | 383 | ||
388 | impl EnumVariant { | 384 | impl EnumVariant { |
389 | pub fn source( | 385 | 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) | 386 | self.source_impl(db) |
394 | } | 387 | } |
395 | pub fn module(&self, db: &impl HirDatabase) -> Module { | 388 | pub fn module(&self, db: &impl HirDatabase) -> Module { |
396 | self.parent.module(db) | 389 | self.parent.module(db) |
397 | } | 390 | } |
398 | pub fn parent_enum(&self, _db: &impl PersistentHirDatabase) -> Enum { | 391 | pub fn parent_enum(&self, _db: &impl DefDatabase) -> Enum { |
399 | self.parent | 392 | self.parent |
400 | } | 393 | } |
401 | 394 | ||
402 | pub fn name(&self, db: &impl PersistentHirDatabase) -> Option<Name> { | 395 | pub fn name(&self, db: &impl DefDatabase) -> Option<Name> { |
403 | db.enum_data(self.parent).variants[self.id].name.clone() | 396 | db.enum_data(self.parent).variants[self.id].name.clone() |
404 | } | 397 | } |
405 | 398 | ||
@@ -465,11 +458,11 @@ impl FnSignature { | |||
465 | } | 458 | } |
466 | 459 | ||
467 | impl Function { | 460 | impl Function { |
468 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::FnDef>) { | 461 | pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::FnDef>) { |
469 | self.id.source(db) | 462 | self.id.source(db) |
470 | } | 463 | } |
471 | 464 | ||
472 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { | 465 | pub fn module(&self, db: &impl DefDatabase) -> Module { |
473 | self.id.module(db) | 466 | self.id.module(db) |
474 | } | 467 | } |
475 | 468 | ||
@@ -503,12 +496,12 @@ impl Function { | |||
503 | db.infer(*self) | 496 | db.infer(*self) |
504 | } | 497 | } |
505 | 498 | ||
506 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { | 499 | pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> { |
507 | db.generic_params((*self).into()) | 500 | db.generic_params((*self).into()) |
508 | } | 501 | } |
509 | 502 | ||
510 | /// The containing impl block, if this is a method. | 503 | /// The containing impl block, if this is a method. |
511 | pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { | 504 | pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> { |
512 | let module_impls = db.impls_in_module(self.module(db)); | 505 | let module_impls = db.impls_in_module(self.module(db)); |
513 | ImplBlock::containing(module_impls, (*self).into()) | 506 | ImplBlock::containing(module_impls, (*self).into()) |
514 | } | 507 | } |
@@ -540,11 +533,11 @@ pub struct Const { | |||
540 | } | 533 | } |
541 | 534 | ||
542 | impl Const { | 535 | impl Const { |
543 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { | 536 | pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { |
544 | self.id.source(db) | 537 | self.id.source(db) |
545 | } | 538 | } |
546 | 539 | ||
547 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { | 540 | pub fn module(&self, db: &impl DefDatabase) -> Module { |
548 | self.id.module(db) | 541 | self.id.module(db) |
549 | } | 542 | } |
550 | 543 | ||
@@ -553,7 +546,7 @@ impl Const { | |||
553 | } | 546 | } |
554 | 547 | ||
555 | /// The containing impl block, if this is a method. | 548 | /// The containing impl block, if this is a method. |
556 | pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { | 549 | pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> { |
557 | let module_impls = db.impls_in_module(self.module(db)); | 550 | let module_impls = db.impls_in_module(self.module(db)); |
558 | ImplBlock::containing(module_impls, (*self).into()) | 551 | ImplBlock::containing(module_impls, (*self).into()) |
559 | } | 552 | } |
@@ -599,11 +592,11 @@ pub struct Static { | |||
599 | } | 592 | } |
600 | 593 | ||
601 | impl Static { | 594 | impl Static { |
602 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { | 595 | pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { |
603 | self.id.source(db) | 596 | self.id.source(db) |
604 | } | 597 | } |
605 | 598 | ||
606 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { | 599 | pub fn module(&self, db: &impl DefDatabase) -> Module { |
607 | self.id.module(db) | 600 | self.id.module(db) |
608 | } | 601 | } |
609 | 602 | ||
@@ -630,15 +623,15 @@ pub struct Trait { | |||
630 | } | 623 | } |
631 | 624 | ||
632 | impl Trait { | 625 | impl Trait { |
633 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) { | 626 | pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) { |
634 | self.id.source(db) | 627 | self.id.source(db) |
635 | } | 628 | } |
636 | 629 | ||
637 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { | 630 | pub fn module(&self, db: &impl DefDatabase) -> Module { |
638 | self.id.module(db) | 631 | self.id.module(db) |
639 | } | 632 | } |
640 | 633 | ||
641 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { | 634 | pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> { |
642 | db.generic_params((*self).into()) | 635 | db.generic_params((*self).into()) |
643 | } | 636 | } |
644 | } | 637 | } |
@@ -655,28 +648,25 @@ pub struct TypeAlias { | |||
655 | } | 648 | } |
656 | 649 | ||
657 | impl TypeAlias { | 650 | impl TypeAlias { |
658 | pub fn source( | 651 | 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) | 652 | self.id.source(db) |
663 | } | 653 | } |
664 | 654 | ||
665 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { | 655 | pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> { |
666 | db.generic_params((*self).into()) | 656 | db.generic_params((*self).into()) |
667 | } | 657 | } |
668 | 658 | ||
669 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { | 659 | pub fn module(&self, db: &impl DefDatabase) -> Module { |
670 | self.id.module(db) | 660 | self.id.module(db) |
671 | } | 661 | } |
672 | 662 | ||
673 | /// The containing impl block, if this is a method. | 663 | /// The containing impl block, if this is a method. |
674 | pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { | 664 | pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> { |
675 | let module_impls = db.impls_in_module(self.module(db)); | 665 | let module_impls = db.impls_in_module(self.module(db)); |
676 | ImplBlock::containing(module_impls, (*self).into()) | 666 | ImplBlock::containing(module_impls, (*self).into()) |
677 | } | 667 | } |
678 | 668 | ||
679 | pub fn type_ref(self, db: &impl PersistentHirDatabase) -> Arc<TypeRef> { | 669 | pub fn type_ref(self, db: &impl DefDatabase) -> Arc<TypeRef> { |
680 | db.type_alias_ref(self) | 670 | db.type_alias_ref(self) |
681 | } | 671 | } |
682 | 672 | ||
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}; | |||
5 | use crate::{ | 5 | use 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 | ||
11 | impl FnSignature { | 11 | impl 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}; | |||
5 | use crate::{ | 5 | use 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 | ||
11 | fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> { | 11 | fn 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 | ||
18 | impl ConstSignature { | 18 | impl 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 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | Crate, CrateDependency, AsName, Module, PersistentHirDatabase, | 2 | Crate, CrateDependency, AsName, Module, DefDatabase, |
3 | }; | 3 | }; |
4 | 4 | ||
5 | impl Crate { | 5 | impl 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}; | |||
4 | use crate::{ | 4 | use 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 | ||
11 | impl ModuleSource { | 11 | impl 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)] |
20 | pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> { | 20 | pub 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)] |
74 | pub trait HirDatabase: PersistentHirDatabase { | 74 | pub 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; | |||
8 | use ra_syntax::ast::{self, NameOwner, TypeParamsOwner}; | 8 | use ra_syntax::ast::{self, NameOwner, TypeParamsOwner}; |
9 | 9 | ||
10 | use crate::{ | 10 | use 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 | ||
41 | impl GenericParams { | 41 | impl 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 | ||
11 | use crate::{ | 11 | use 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); | |||
63 | impl HirFileId { | 63 | impl 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 | ||
100 | fn parse_macro( | 97 | fn 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 | ||
193 | impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> { | 187 | impl<'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 | ||
206 | pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { | 200 | pub(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 | ||
325 | impl SourceFileItems { | 319 | impl 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 | ||
10 | use crate::{ | 10 | use 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 | ||
125 | impl ImplData { | 125 | impl 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 | ||
195 | impl ModuleImplBlocks { | 195 | impl 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 | ||
230 | pub(crate) fn impls_in_module_with_source_map_query( | 226 | pub(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 | ||
241 | pub(crate) fn impls_in_module( | 237 | pub(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 | ||
248 | pub(crate) fn impls_in_module_source_map_query( | 241 | pub(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; | |||
43 | mod marks; | 43 | mod marks; |
44 | 44 | ||
45 | use crate::{ | 45 | use 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 | ||
14 | pub const WORKSPACE: SourceRootId = SourceRootId(0); | 14 | pub 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)] |
22 | pub struct MockDatabase { | 18 | pub 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 | ||
63 | use crate::{ | 63 | use 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 | ||
198 | impl CrateDefMap { | 198 | impl 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 | ||
7 | use crate::{ | 7 | use 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 | ||
15 | use super::{CrateDefMap, CrateModuleId, ModuleData, CrateMacroId}; | 15 | use super::{CrateDefMap, CrateModuleId, ModuleData, CrateMacroId}; |
16 | 16 | ||
17 | pub(super) fn collect_defs( | 17 | pub(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 | ||
58 | impl<'a, DB> DefCollector<&'a DB> | 55 | impl<'a, DB> DefCollector<&'a DB> |
59 | where | 56 | where |
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 | ||
371 | impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>> | 368 | impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>> |
372 | where | 369 | where |
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 | ||
525 | fn resolve_submodule( | 522 | fn 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 | ||
14 | use crate::{ | 14 | use 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 | ||
49 | impl RawItems { | 49 | impl 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/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 132ee0ca2..cff7e7481 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -407,7 +407,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
407 | 407 | ||
408 | let substs = | 408 | let substs = |
409 | Ty::substs_from_path_segment(self.db, &self.resolver, segment, typable); | 409 | Ty::substs_from_path_segment(self.db, &self.resolver, segment, typable); |
410 | self.db.type_for_def(typable, Namespace::Types).apply_substs(substs) | 410 | self.db.type_for_def(typable, Namespace::Types).subst(&substs) |
411 | } | 411 | } |
412 | Resolution::LocalBinding(_) => { | 412 | Resolution::LocalBinding(_) => { |
413 | // can't have a local binding in an associated item path | 413 | // can't have a local binding in an associated item path |
@@ -466,7 +466,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
466 | let typable: Option<TypableDef> = def.into(); | 466 | let typable: Option<TypableDef> = def.into(); |
467 | let typable = typable?; | 467 | let typable = typable?; |
468 | let substs = Ty::substs_from_path(self.db, &self.resolver, path, typable); | 468 | let substs = Ty::substs_from_path(self.db, &self.resolver, path, typable); |
469 | let ty = self.db.type_for_def(typable, Namespace::Values).apply_substs(substs); | 469 | let ty = self.db.type_for_def(typable, Namespace::Values).subst(&substs); |
470 | let ty = self.insert_type_vars(ty); | 470 | let ty = self.insert_type_vars(ty); |
471 | Some(ty) | 471 | Some(ty) |
472 | } | 472 | } |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 0f2172ddf..5d8ad4aa7 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -1792,6 +1792,29 @@ fn test<R>(query_response: Canonical<QueryResponse<R>>) { | |||
1792 | } | 1792 | } |
1793 | 1793 | ||
1794 | #[test] | 1794 | #[test] |
1795 | fn bug_1030() { | ||
1796 | assert_snapshot_matches!(infer(r#" | ||
1797 | struct HashSet<T, H>; | ||
1798 | struct FxHasher; | ||
1799 | type FxHashSet<T> = HashSet<T, FxHasher>; | ||
1800 | |||
1801 | impl<T, H> HashSet<T, H> { | ||
1802 | fn default() -> HashSet<T, H> {} | ||
1803 | } | ||
1804 | |||
1805 | pub fn main_loop() { | ||
1806 | FxHashSet::default(); | ||
1807 | } | ||
1808 | "#), | ||
1809 | @r###" | ||
1810 | [144; 146) '{}': () | ||
1811 | [169; 198) '{ ...t(); }': () | ||
1812 | [175; 193) 'FxHash...efault': fn default<{unknown}, {unknown}>() -> HashSet<T, H> | ||
1813 | [175; 195) 'FxHash...ault()': HashSet<{unknown}, {unknown}>"### | ||
1814 | ); | ||
1815 | } | ||
1816 | |||
1817 | #[test] | ||
1795 | fn cross_crate_associated_method_call() { | 1818 | fn cross_crate_associated_method_call() { |
1796 | let (mut db, pos) = MockDatabase::with_position( | 1819 | let (mut db, pos) = MockDatabase::with_position( |
1797 | r#" | 1820 | r#" |
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 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use crate::{TypeAlias, db::PersistentHirDatabase, type_ref::TypeRef}; | 5 | use crate::{TypeAlias, db::DefDatabase, type_ref::TypeRef}; |
6 | 6 | ||
7 | pub(crate) fn type_alias_ref_query( | 7 | pub(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 | } |
diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml index 97c8bab18..c64226801 100644 --- a/crates/ra_ide_api/Cargo.toml +++ b/crates/ra_ide_api/Cargo.toml | |||
@@ -30,7 +30,12 @@ ra_assists = { path = "../ra_assists" } | |||
30 | 30 | ||
31 | [dev-dependencies] | 31 | [dev-dependencies] |
32 | insta = "0.7.0" | 32 | insta = "0.7.0" |
33 | proptest = "0.9.0" | 33 | |
34 | [dev-dependencies.proptest] | ||
35 | version = "0.9.0" | ||
36 | # Disable `fork` feature to allow compiling on webassembly | ||
37 | default-features = false | ||
38 | features = ["std", "bit-set", "break-dead-code"] | ||
34 | 39 | ||
35 | [features] | 40 | [features] |
36 | jemalloc = [ "jemallocator", "jemalloc-ctl" ] | 41 | jemalloc = [ "jemallocator", "jemalloc-ctl" ] |
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index 00f4bdfd2..ea4255d35 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs | |||
@@ -15,7 +15,7 @@ use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}}; | |||
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 | hir::db::DefDatabaseStorage |
19 | )] | 19 | )] |
20 | #[derive(Debug)] | 20 | #[derive(Debug)] |
21 | pub(crate) struct RootDatabase { | 21 | pub(crate) struct RootDatabase { |
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index aabb614b9..b9dc424c6 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -157,27 +157,6 @@ fn check_module( | |||
157 | fix: Some(fix), | 157 | fix: Some(fix), |
158 | } | 158 | } |
159 | } | 159 | } |
160 | Problem::NotDirOwner { move_to, candidate } => { | ||
161 | let move_file = FileSystemEdit::MoveFile { | ||
162 | src: file_id, | ||
163 | dst_source_root: source_root, | ||
164 | dst_path: move_to.clone(), | ||
165 | }; | ||
166 | let create_file = | ||
167 | FileSystemEdit::CreateFile { source_root, path: move_to.join(candidate) }; | ||
168 | let fix = SourceChange { | ||
169 | label: "move file and create module".to_string(), | ||
170 | source_file_edits: Vec::new(), | ||
171 | file_system_edits: vec![move_file, create_file], | ||
172 | cursor_position: None, | ||
173 | }; | ||
174 | Diagnostic { | ||
175 | range: name_node.range(), | ||
176 | message: "can't declare module at this location".to_string(), | ||
177 | severity: Severity::Error, | ||
178 | fix: Some(fix), | ||
179 | } | ||
180 | } | ||
181 | }; | 160 | }; |
182 | acc.push(diag) | 161 | acc.push(diag) |
183 | } | 162 | } |
diff --git a/crates/ra_ide_api_light/Cargo.toml b/crates/ra_ide_api_light/Cargo.toml index a30833dc3..4e69f5325 100644 --- a/crates/ra_ide_api_light/Cargo.toml +++ b/crates/ra_ide_api_light/Cargo.toml | |||
@@ -17,5 +17,10 @@ ra_fmt = { path = "../ra_fmt" } | |||
17 | 17 | ||
18 | [dev-dependencies] | 18 | [dev-dependencies] |
19 | test_utils = { path = "../test_utils" } | 19 | test_utils = { path = "../test_utils" } |
20 | proptest = "0.9.0" | ||
21 | insta = "0.7.0" | 20 | insta = "0.7.0" |
21 | |||
22 | [dev-dependencies.proptest] | ||
23 | version = "0.9.0" | ||
24 | # Disable `fork` feature to allow compiling on webassembly | ||
25 | default-features = false | ||
26 | features = ["std", "bit-set", "break-dead-code"] | ||
diff --git a/crates/ra_text_edit/Cargo.toml b/crates/ra_text_edit/Cargo.toml index 5769940df..b40026004 100644 --- a/crates/ra_text_edit/Cargo.toml +++ b/crates/ra_text_edit/Cargo.toml | |||
@@ -7,7 +7,12 @@ publish = false | |||
7 | 7 | ||
8 | [dependencies] | 8 | [dependencies] |
9 | text_unit = "0.1.6" | 9 | text_unit = "0.1.6" |
10 | proptest = "0.9.0" | 10 | |
11 | [dependencies.proptest] | ||
12 | version = "0.9.0" | ||
13 | # Disable `fork` feature to allow compiling on webassembly | ||
14 | default-features = false | ||
15 | features = ["std", "bit-set", "break-dead-code"] | ||
11 | 16 | ||
12 | [dev-dependencies] | 17 | [dev-dependencies] |
13 | test_utils = { path = "../test_utils" } | 18 | test_utils = { path = "../test_utils" } |