diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 174 | ||||
-rw-r--r-- | crates/ra_hir/src/mock.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 4 |
5 files changed, 78 insertions, 114 deletions
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index 415848f09..87d2e98e9 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml | |||
@@ -8,7 +8,6 @@ authors = ["Aleksey Kladov <[email protected]>"] | |||
8 | arrayvec = "0.4.10" | 8 | arrayvec = "0.4.10" |
9 | log = "0.4.5" | 9 | log = "0.4.5" |
10 | relative-path = "0.4.0" | 10 | relative-path = "0.4.0" |
11 | salsa = "0.9.2" | ||
12 | rustc-hash = "1.0" | 11 | rustc-hash = "1.0" |
13 | parking_lot = "0.7.0" | 12 | parking_lot = "0.7.0" |
14 | ena = "0.11" | 13 | ena = "0.11" |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 0a0994f5f..b42f10071 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_syntax::{SyntaxNode, TreeArc, SourceFile}; | 3 | use ra_syntax::{SyntaxNode, TreeArc, SourceFile}; |
4 | use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase}; | 4 | use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, salsa}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | DefLoc, DefId, MacroCallLoc, MacroCallId, Name, HirFileId, | 7 | DefLoc, DefId, MacroCallLoc, MacroCallId, Name, HirFileId, |
@@ -16,111 +16,77 @@ use crate::{ | |||
16 | impl_block::ModuleImplBlocks, | 16 | impl_block::ModuleImplBlocks, |
17 | }; | 17 | }; |
18 | 18 | ||
19 | salsa::query_group! { | 19 | #[salsa::query_group] |
20 | 20 | pub trait HirDatabase: | |
21 | pub trait HirDatabase: SyntaxDatabase | 21 | SyntaxDatabase |
22 | + AsRef<LocationIntener<DefLoc, DefId>> | 22 | + AsRef<LocationIntener<DefLoc, DefId>> |
23 | + AsRef<LocationIntener<MacroCallLoc, MacroCallId>> | 23 | + AsRef<LocationIntener<MacroCallLoc, MacroCallId>> |
24 | { | 24 | { |
25 | fn hir_source_file(file_id: HirFileId) -> TreeArc<SourceFile> { | 25 | #[salsa::invoke(HirFileId::hir_source_file)] |
26 | type HirSourceFileQuery; | 26 | fn hir_source_file(&self, file_id: HirFileId) -> TreeArc<SourceFile>; |
27 | use fn HirFileId::hir_source_file; | 27 | |
28 | } | 28 | #[salsa::invoke(crate::macros::expand_macro_invocation)] |
29 | 29 | fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option<Arc<MacroExpansion>>; | |
30 | fn expand_macro_invocation(invoc: MacroCallId) -> Option<Arc<MacroExpansion>> { | 30 | |
31 | type ExpandMacroCallQuery; | 31 | #[salsa::invoke(query_definitions::fn_scopes)] |
32 | use fn crate::macros::expand_macro_invocation; | 32 | fn fn_scopes(&self, def_id: DefId) -> Arc<FnScopes>; |
33 | } | 33 | |
34 | 34 | #[salsa::invoke(crate::adt::StructData::struct_data_query)] | |
35 | fn fn_scopes(def_id: DefId) -> Arc<FnScopes> { | 35 | fn struct_data(&self, def_id: DefId) -> Arc<StructData>; |
36 | type FnScopesQuery; | 36 | |
37 | use fn query_definitions::fn_scopes; | 37 | #[salsa::invoke(crate::adt::EnumData::enum_data_query)] |
38 | } | 38 | fn enum_data(&self, def_id: DefId) -> Arc<EnumData>; |
39 | 39 | ||
40 | fn struct_data(def_id: DefId) -> Arc<StructData> { | 40 | #[salsa::invoke(crate::adt::EnumVariantData::enum_variant_data_query)] |
41 | type StructDataQuery; | 41 | fn enum_variant_data(&self, def_id: DefId) -> Arc<EnumVariantData>; |
42 | use fn crate::adt::StructData::struct_data_query; | 42 | |
43 | } | 43 | #[salsa::invoke(crate::ty::infer)] |
44 | 44 | fn infer(&self, def_id: DefId) -> Arc<InferenceResult>; | |
45 | fn enum_data(def_id: DefId) -> Arc<EnumData> { | 45 | |
46 | type EnumDataQuery; | 46 | #[salsa::invoke(crate::ty::type_for_def)] |
47 | use fn crate::adt::EnumData::enum_data_query; | 47 | fn type_for_def(&self, def_id: DefId) -> Ty; |
48 | } | 48 | |
49 | 49 | #[salsa::invoke(crate::ty::type_for_field)] | |
50 | fn enum_variant_data(def_id: DefId) -> Arc<EnumVariantData> { | 50 | fn type_for_field(&self, def_id: DefId, field: Name) -> Option<Ty>; |
51 | type EnumVariantDataQuery; | 51 | |
52 | use fn crate::adt::EnumVariantData::enum_variant_data_query; | 52 | #[salsa::invoke(query_definitions::file_items)] |
53 | } | 53 | fn file_items(&self, file_id: HirFileId) -> Arc<SourceFileItems>; |
54 | 54 | ||
55 | fn infer(def_id: DefId) -> Arc<InferenceResult> { | 55 | #[salsa::invoke(query_definitions::file_item)] |
56 | type InferQuery; | 56 | fn file_item(&self, source_item_id: SourceItemId) -> TreeArc<SyntaxNode>; |
57 | use fn crate::ty::infer; | 57 | |
58 | } | 58 | #[salsa::invoke(crate::module_tree::Submodule::submodules_query)] |
59 | 59 | fn submodules(&self, source: SourceItemId) -> Arc<Vec<crate::module_tree::Submodule>>; | |
60 | fn type_for_def(def_id: DefId) -> Ty { | 60 | |
61 | type TypeForDefQuery; | 61 | #[salsa::invoke(query_definitions::input_module_items)] |
62 | use fn crate::ty::type_for_def; | 62 | fn input_module_items( |
63 | } | 63 | &self, |
64 | 64 | source_root_id: SourceRootId, | |
65 | fn type_for_field(def_id: DefId, field: Name) -> Option<Ty> { | 65 | module_id: ModuleId, |
66 | type TypeForFieldQuery; | 66 | ) -> Arc<InputModuleItems>; |
67 | use fn crate::ty::type_for_field; | 67 | |
68 | } | 68 | #[salsa::invoke(query_definitions::item_map)] |
69 | 69 | fn item_map(&self, source_root_id: SourceRootId) -> Arc<ItemMap>; | |
70 | fn file_items(file_id: HirFileId) -> Arc<SourceFileItems> { | 70 | |
71 | type SourceFileItemsQuery; | 71 | #[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)] |
72 | use fn query_definitions::file_items; | 72 | fn module_tree(&self, source_root_id: SourceRootId) -> Arc<ModuleTree>; |
73 | } | 73 | |
74 | 74 | #[salsa::invoke(crate::impl_block::impls_in_module)] | |
75 | fn file_item(source_item_id: SourceItemId) -> TreeArc<SyntaxNode> { | 75 | fn impls_in_module( |
76 | type FileItemQuery; | 76 | &self, |
77 | use fn query_definitions::file_item; | 77 | source_root_id: SourceRootId, |
78 | } | 78 | module_id: ModuleId, |
79 | 79 | ) -> Arc<ModuleImplBlocks>; | |
80 | fn submodules(source: SourceItemId) -> Arc<Vec<crate::module_tree::Submodule>> { | 80 | |
81 | type SubmodulesQuery; | 81 | #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] |
82 | use fn crate::module_tree::Submodule::submodules_query; | 82 | fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>; |
83 | } | 83 | |
84 | 84 | #[salsa::invoke(crate::expr::body_hir)] | |
85 | fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<InputModuleItems> { | 85 | fn body_hir(&self, def_id: DefId) -> Arc<crate::expr::Body>; |
86 | type InputModuleItemsQuery; | 86 | |
87 | use fn query_definitions::input_module_items; | 87 | #[salsa::invoke(crate::expr::body_syntax_mapping)] |
88 | } | 88 | fn body_syntax_mapping(&self, def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping>; |
89 | |||
90 | fn item_map(source_root_id: SourceRootId) -> Arc<ItemMap> { | ||
91 | type ItemMapQuery; | ||
92 | use fn query_definitions::item_map; | ||
93 | } | ||
94 | |||
95 | fn module_tree(source_root_id: SourceRootId) -> Arc<ModuleTree> { | ||
96 | type ModuleTreeQuery; | ||
97 | use fn crate::module_tree::ModuleTree::module_tree_query; | ||
98 | } | ||
99 | |||
100 | fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<ModuleImplBlocks> { | ||
101 | type ImplsInModuleQuery; | ||
102 | use fn crate::impl_block::impls_in_module; | ||
103 | } | ||
104 | |||
105 | fn impls_in_crate(krate: Crate) -> Arc<CrateImplBlocks> { | ||
106 | type ImplsInCrateQuery; | ||
107 | use fn crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query; | ||
108 | } | ||
109 | |||
110 | fn body_hir(def_id: DefId) -> Arc<crate::expr::Body> { | ||
111 | type BodyHirQuery; | ||
112 | use fn crate::expr::body_hir; | ||
113 | } | ||
114 | |||
115 | fn body_syntax_mapping(def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping> { | ||
116 | type BodySyntaxMappingQuery; | ||
117 | use fn crate::expr::body_syntax_mapping; | ||
118 | } | ||
119 | |||
120 | fn fn_signature(def_id: DefId) -> Arc<FnSignature> { | ||
121 | type FnSignatureQuery; | ||
122 | use fn crate::FnSignature::fn_signature_query; | ||
123 | } | ||
124 | } | ||
125 | 89 | ||
90 | #[salsa::invoke(crate::FnSignature::fn_signature_query)] | ||
91 | fn fn_signature(&self, def_id: DefId) -> Arc<FnSignature>; | ||
126 | } | 92 | } |
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 9371c5a0d..a83a5c6cc 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs | |||
@@ -1,8 +1,10 @@ | |||
1 | use std::{sync::Arc, panic}; | 1 | use std::{sync::Arc, panic}; |
2 | 2 | ||
3 | use parking_lot::Mutex; | 3 | use parking_lot::Mutex; |
4 | use salsa::{self, Database}; | 4 | use ra_db::{ |
5 | use ra_db::{LocationIntener, BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId}; | 5 | LocationIntener, BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, |
6 | salsa::{self, Database}, | ||
7 | }; | ||
6 | use relative_path::RelativePathBuf; | 8 | use relative_path::RelativePathBuf; |
7 | use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; | 9 | use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; |
8 | 10 | ||
@@ -220,10 +222,10 @@ salsa::database_storage! { | |||
220 | } | 222 | } |
221 | impl db::HirDatabase { | 223 | impl db::HirDatabase { |
222 | fn hir_source_file() for db::HirSourceFileQuery; | 224 | fn hir_source_file() for db::HirSourceFileQuery; |
223 | fn expand_macro_invocation() for db::ExpandMacroCallQuery; | 225 | fn expand_macro_invocation() for db::ExpandMacroInvocationQuery; |
224 | fn module_tree() for db::ModuleTreeQuery; | 226 | fn module_tree() for db::ModuleTreeQuery; |
225 | fn fn_scopes() for db::FnScopesQuery; | 227 | fn fn_scopes() for db::FnScopesQuery; |
226 | fn file_items() for db::SourceFileItemsQuery; | 228 | fn file_items() for db::FileItemsQuery; |
227 | fn file_item() for db::FileItemQuery; | 229 | fn file_item() for db::FileItemQuery; |
228 | fn input_module_items() for db::InputModuleItemsQuery; | 230 | fn input_module_items() for db::InputModuleItemsQuery; |
229 | fn item_map() for db::ItemMapQuery; | 231 | fn item_map() for db::ItemMapQuery; |
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 9a0474045..0ec11ec12 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use salsa::Database; | 3 | use ra_db::{FilesDatabase, CrateGraph, SourceRootId, salsa::Database}; |
4 | use ra_db::{FilesDatabase, CrateGraph, SourceRootId}; | ||
5 | use relative_path::RelativePath; | 4 | use relative_path::RelativePath; |
6 | use test_utils::assert_eq_text; | 5 | use test_utils::assert_eq_text; |
7 | 6 | ||
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index affd63a85..a430cbe88 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -3,9 +3,7 @@ use std::fmt::Write; | |||
3 | use std::path::{PathBuf, Path}; | 3 | use std::path::{PathBuf, Path}; |
4 | use std::fs; | 4 | use std::fs; |
5 | 5 | ||
6 | use salsa::Database; | 6 | use ra_db::{SyntaxDatabase, salsa::Database}; |
7 | |||
8 | use ra_db::SyntaxDatabase; | ||
9 | use ra_syntax::ast::{self, AstNode}; | 7 | use ra_syntax::ast::{self, AstNode}; |
10 | use test_utils::{project_dir, assert_eq_text, read_text}; | 8 | use test_utils::{project_dir, assert_eq_text, read_text}; |
11 | 9 | ||