aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/db.rs')
-rw-r--r--crates/ra_hir/src/db.rs174
1 files changed, 70 insertions, 104 deletions
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 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_syntax::{SyntaxNode, TreeArc, SourceFile}; 3use ra_syntax::{SyntaxNode, TreeArc, SourceFile};
4use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase}; 4use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, salsa};
5 5
6use crate::{ 6use 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
19salsa::query_group! { 19#[salsa::query_group]
20 20pub trait HirDatabase:
21pub 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}