diff options
Diffstat (limited to 'crates/ra_hir_ty/src/db.rs')
-rw-r--r-- | crates/ra_hir_ty/src/db.rs | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs new file mode 100644 index 000000000..9ce154593 --- /dev/null +++ b/crates/ra_hir_ty/src/db.rs | |||
@@ -0,0 +1,119 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use std::sync::Arc; | ||
4 | |||
5 | use hir_def::{ | ||
6 | db::DefDatabase, DefWithBodyId, GenericDefId, ImplId, LocalStructFieldId, TraitId, VariantId, | ||
7 | }; | ||
8 | use ra_arena::map::ArenaMap; | ||
9 | use ra_db::{salsa, CrateId}; | ||
10 | |||
11 | use crate::{ | ||
12 | method_resolution::CrateImplBlocks, | ||
13 | traits::{AssocTyValue, Impl}, | ||
14 | CallableDef, FnSig, GenericPredicate, ImplTy, InferenceResult, Substs, Ty, TyDefId, TypeCtor, | ||
15 | ValueTyDefId, | ||
16 | }; | ||
17 | |||
18 | #[salsa::query_group(HirDatabaseStorage)] | ||
19 | #[salsa::requires(salsa::Database)] | ||
20 | pub trait HirDatabase: DefDatabase { | ||
21 | #[salsa::invoke(crate::infer_query)] | ||
22 | fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>; | ||
23 | |||
24 | #[salsa::invoke(crate::lower::ty_query)] | ||
25 | fn ty(&self, def: TyDefId) -> Ty; | ||
26 | |||
27 | #[salsa::invoke(crate::lower::value_ty_query)] | ||
28 | fn value_ty(&self, def: ValueTyDefId) -> Ty; | ||
29 | |||
30 | #[salsa::invoke(crate::lower::impl_ty_query)] | ||
31 | fn impl_ty(&self, def: ImplId) -> ImplTy; | ||
32 | |||
33 | #[salsa::invoke(crate::lower::field_types_query)] | ||
34 | fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalStructFieldId, Ty>>; | ||
35 | |||
36 | #[salsa::invoke(crate::callable_item_sig)] | ||
37 | fn callable_item_signature(&self, def: CallableDef) -> FnSig; | ||
38 | |||
39 | #[salsa::invoke(crate::lower::generic_predicates_for_param_query)] | ||
40 | fn generic_predicates_for_param( | ||
41 | &self, | ||
42 | def: GenericDefId, | ||
43 | param_idx: u32, | ||
44 | ) -> Arc<[GenericPredicate]>; | ||
45 | |||
46 | #[salsa::invoke(crate::lower::generic_predicates_query)] | ||
47 | fn generic_predicates(&self, def: GenericDefId) -> Arc<[GenericPredicate]>; | ||
48 | |||
49 | #[salsa::invoke(crate::lower::generic_defaults_query)] | ||
50 | fn generic_defaults(&self, def: GenericDefId) -> Substs; | ||
51 | |||
52 | #[salsa::invoke(crate::method_resolution::CrateImplBlocks::impls_in_crate_query)] | ||
53 | fn impls_in_crate(&self, krate: CrateId) -> Arc<CrateImplBlocks>; | ||
54 | |||
55 | #[salsa::invoke(crate::traits::impls_for_trait_query)] | ||
56 | fn impls_for_trait(&self, krate: CrateId, trait_: TraitId) -> Arc<[ImplId]>; | ||
57 | |||
58 | /// This provides the Chalk trait solver instance. Because Chalk always | ||
59 | /// works from a specific crate, this query is keyed on the crate; and | ||
60 | /// because Chalk does its own internal caching, the solver is wrapped in a | ||
61 | /// Mutex and the query does an untracked read internally, to make sure the | ||
62 | /// cached state is thrown away when input facts change. | ||
63 | #[salsa::invoke(crate::traits::trait_solver_query)] | ||
64 | fn trait_solver(&self, krate: CrateId) -> crate::traits::TraitSolver; | ||
65 | |||
66 | // Interned IDs for Chalk integration | ||
67 | #[salsa::interned] | ||
68 | fn intern_type_ctor(&self, type_ctor: TypeCtor) -> crate::TypeCtorId; | ||
69 | #[salsa::interned] | ||
70 | fn intern_chalk_impl(&self, impl_: Impl) -> crate::traits::GlobalImplId; | ||
71 | #[salsa::interned] | ||
72 | fn intern_assoc_ty_value(&self, assoc_ty_value: AssocTyValue) -> crate::traits::AssocTyValueId; | ||
73 | |||
74 | #[salsa::invoke(crate::traits::chalk::associated_ty_data_query)] | ||
75 | fn associated_ty_data( | ||
76 | &self, | ||
77 | id: chalk_ir::TypeId, | ||
78 | ) -> Arc<chalk_rust_ir::AssociatedTyDatum<chalk_ir::family::ChalkIr>>; | ||
79 | |||
80 | #[salsa::invoke(crate::traits::chalk::trait_datum_query)] | ||
81 | fn trait_datum( | ||
82 | &self, | ||
83 | krate: CrateId, | ||
84 | trait_id: chalk_ir::TraitId, | ||
85 | ) -> Arc<chalk_rust_ir::TraitDatum<chalk_ir::family::ChalkIr>>; | ||
86 | |||
87 | #[salsa::invoke(crate::traits::chalk::struct_datum_query)] | ||
88 | fn struct_datum( | ||
89 | &self, | ||
90 | krate: CrateId, | ||
91 | struct_id: chalk_ir::StructId, | ||
92 | ) -> Arc<chalk_rust_ir::StructDatum<chalk_ir::family::ChalkIr>>; | ||
93 | |||
94 | #[salsa::invoke(crate::traits::chalk::impl_datum_query)] | ||
95 | fn impl_datum( | ||
96 | &self, | ||
97 | krate: CrateId, | ||
98 | impl_id: chalk_ir::ImplId, | ||
99 | ) -> Arc<chalk_rust_ir::ImplDatum<chalk_ir::family::ChalkIr>>; | ||
100 | |||
101 | #[salsa::invoke(crate::traits::chalk::associated_ty_value_query)] | ||
102 | fn associated_ty_value( | ||
103 | &self, | ||
104 | krate: CrateId, | ||
105 | id: chalk_rust_ir::AssociatedTyValueId, | ||
106 | ) -> Arc<chalk_rust_ir::AssociatedTyValue<chalk_ir::family::ChalkIr>>; | ||
107 | |||
108 | #[salsa::invoke(crate::traits::trait_solve_query)] | ||
109 | fn trait_solve( | ||
110 | &self, | ||
111 | krate: CrateId, | ||
112 | goal: crate::Canonical<crate::InEnvironment<crate::Obligation>>, | ||
113 | ) -> Option<crate::traits::Solution>; | ||
114 | } | ||
115 | |||
116 | #[test] | ||
117 | fn hir_database_is_object_safe() { | ||
118 | fn _assert_object_safe(_: &dyn HirDatabase) {} | ||
119 | } | ||