aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/db.rs')
-rw-r--r--crates/hir_def/src/db.rs120
1 files changed, 120 insertions, 0 deletions
diff --git a/crates/hir_def/src/db.rs b/crates/hir_def/src/db.rs
new file mode 100644
index 000000000..6d694de11
--- /dev/null
+++ b/crates/hir_def/src/db.rs
@@ -0,0 +1,120 @@
1//! Defines database & queries for name resolution.
2use std::sync::Arc;
3
4use base_db::{salsa, CrateId, SourceDatabase, Upcast};
5use hir_expand::{db::AstDatabase, HirFileId};
6use syntax::SmolStr;
7
8use crate::{
9 adt::{EnumData, StructData},
10 attr::Attrs,
11 body::{scope::ExprScopes, Body, BodySourceMap},
12 data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData},
13 docs::Documentation,
14 generics::GenericParams,
15 import_map::ImportMap,
16 item_tree::ItemTree,
17 lang_item::{LangItemTarget, LangItems},
18 nameres::CrateDefMap,
19 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
20 GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
21 TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc,
22};
23
24#[salsa::query_group(InternDatabaseStorage)]
25pub trait InternDatabase: SourceDatabase {
26 #[salsa::interned]
27 fn intern_function(&self, loc: FunctionLoc) -> FunctionId;
28 #[salsa::interned]
29 fn intern_struct(&self, loc: StructLoc) -> StructId;
30 #[salsa::interned]
31 fn intern_union(&self, loc: UnionLoc) -> UnionId;
32 #[salsa::interned]
33 fn intern_enum(&self, loc: EnumLoc) -> EnumId;
34 #[salsa::interned]
35 fn intern_const(&self, loc: ConstLoc) -> ConstId;
36 #[salsa::interned]
37 fn intern_static(&self, loc: StaticLoc) -> StaticId;
38 #[salsa::interned]
39 fn intern_trait(&self, loc: TraitLoc) -> TraitId;
40 #[salsa::interned]
41 fn intern_type_alias(&self, loc: TypeAliasLoc) -> TypeAliasId;
42 #[salsa::interned]
43 fn intern_impl(&self, loc: ImplLoc) -> ImplId;
44}
45
46#[salsa::query_group(DefDatabaseStorage)]
47pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
48 #[salsa::invoke(ItemTree::item_tree_query)]
49 fn item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>;
50
51 #[salsa::invoke(crate_def_map_wait)]
52 #[salsa::transparent]
53 fn crate_def_map(&self, krate: CrateId) -> Arc<CrateDefMap>;
54
55 #[salsa::invoke(CrateDefMap::crate_def_map_query)]
56 fn crate_def_map_query(&self, krate: CrateId) -> Arc<CrateDefMap>;
57
58 #[salsa::invoke(StructData::struct_data_query)]
59 fn struct_data(&self, id: StructId) -> Arc<StructData>;
60 #[salsa::invoke(StructData::union_data_query)]
61 fn union_data(&self, id: UnionId) -> Arc<StructData>;
62
63 #[salsa::invoke(EnumData::enum_data_query)]
64 fn enum_data(&self, e: EnumId) -> Arc<EnumData>;
65
66 #[salsa::invoke(ImplData::impl_data_query)]
67 fn impl_data(&self, e: ImplId) -> Arc<ImplData>;
68
69 #[salsa::invoke(TraitData::trait_data_query)]
70 fn trait_data(&self, e: TraitId) -> Arc<TraitData>;
71
72 #[salsa::invoke(TypeAliasData::type_alias_data_query)]
73 fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>;
74
75 #[salsa::invoke(FunctionData::fn_data_query)]
76 fn function_data(&self, func: FunctionId) -> Arc<FunctionData>;
77
78 #[salsa::invoke(ConstData::const_data_query)]
79 fn const_data(&self, konst: ConstId) -> Arc<ConstData>;
80
81 #[salsa::invoke(StaticData::static_data_query)]
82 fn static_data(&self, konst: StaticId) -> Arc<StaticData>;
83
84 #[salsa::invoke(Body::body_with_source_map_query)]
85 fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
86
87 #[salsa::invoke(Body::body_query)]
88 fn body(&self, def: DefWithBodyId) -> Arc<Body>;
89
90 #[salsa::invoke(ExprScopes::expr_scopes_query)]
91 fn expr_scopes(&self, def: DefWithBodyId) -> Arc<ExprScopes>;
92
93 #[salsa::invoke(GenericParams::generic_params_query)]
94 fn generic_params(&self, def: GenericDefId) -> Arc<GenericParams>;
95
96 #[salsa::invoke(Attrs::attrs_query)]
97 fn attrs(&self, def: AttrDefId) -> Attrs;
98
99 #[salsa::invoke(LangItems::module_lang_items_query)]
100 fn module_lang_items(&self, module: ModuleId) -> Option<Arc<LangItems>>;
101
102 #[salsa::invoke(LangItems::crate_lang_items_query)]
103 fn crate_lang_items(&self, krate: CrateId) -> Arc<LangItems>;
104
105 #[salsa::invoke(LangItems::lang_item_query)]
106 fn lang_item(&self, start_crate: CrateId, item: SmolStr) -> Option<LangItemTarget>;
107
108 // FIXME(https://github.com/rust-analyzer/rust-analyzer/issues/2148#issuecomment-550519102)
109 // Remove this query completely, in favor of `Attrs::docs` method
110 #[salsa::invoke(Documentation::documentation_query)]
111 fn documentation(&self, def: AttrDefId) -> Option<Documentation>;
112
113 #[salsa::invoke(ImportMap::import_map_query)]
114 fn import_map(&self, krate: CrateId) -> Arc<ImportMap>;
115}
116
117fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
118 let _p = profile::span("crate_def_map:wait");
119 db.crate_def_map_query(krate)
120}