diff options
Diffstat (limited to 'crates/ra_hir_ty/src/db.rs')
-rw-r--r-- | crates/ra_hir_ty/src/db.rs | 116 |
1 files changed, 116 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..aa2659c4b --- /dev/null +++ b/crates/ra_hir_ty/src/db.rs | |||
@@ -0,0 +1,116 @@ | |||
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, 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::field_types_query)] | ||
31 | fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalStructFieldId, Ty>>; | ||
32 | |||
33 | #[salsa::invoke(crate::callable_item_sig)] | ||
34 | fn callable_item_signature(&self, def: CallableDef) -> FnSig; | ||
35 | |||
36 | #[salsa::invoke(crate::lower::generic_predicates_for_param_query)] | ||
37 | fn generic_predicates_for_param( | ||
38 | &self, | ||
39 | def: GenericDefId, | ||
40 | param_idx: u32, | ||
41 | ) -> Arc<[GenericPredicate]>; | ||
42 | |||
43 | #[salsa::invoke(crate::lower::generic_predicates_query)] | ||
44 | fn generic_predicates(&self, def: GenericDefId) -> Arc<[GenericPredicate]>; | ||
45 | |||
46 | #[salsa::invoke(crate::lower::generic_defaults_query)] | ||
47 | fn generic_defaults(&self, def: GenericDefId) -> Substs; | ||
48 | |||
49 | #[salsa::invoke(crate::method_resolution::CrateImplBlocks::impls_in_crate_query)] | ||
50 | fn impls_in_crate(&self, krate: CrateId) -> Arc<CrateImplBlocks>; | ||
51 | |||
52 | #[salsa::invoke(crate::traits::impls_for_trait_query)] | ||
53 | fn impls_for_trait(&self, krate: CrateId, trait_: TraitId) -> Arc<[ImplId]>; | ||
54 | |||
55 | /// This provides the Chalk trait solver instance. Because Chalk always | ||
56 | /// works from a specific crate, this query is keyed on the crate; and | ||
57 | /// because Chalk does its own internal caching, the solver is wrapped in a | ||
58 | /// Mutex and the query does an untracked read internally, to make sure the | ||
59 | /// cached state is thrown away when input facts change. | ||
60 | #[salsa::invoke(crate::traits::trait_solver_query)] | ||
61 | fn trait_solver(&self, krate: CrateId) -> crate::traits::TraitSolver; | ||
62 | |||
63 | // Interned IDs for Chalk integration | ||
64 | #[salsa::interned] | ||
65 | fn intern_type_ctor(&self, type_ctor: TypeCtor) -> crate::TypeCtorId; | ||
66 | #[salsa::interned] | ||
67 | fn intern_chalk_impl(&self, impl_: Impl) -> crate::traits::GlobalImplId; | ||
68 | #[salsa::interned] | ||
69 | fn intern_assoc_ty_value(&self, assoc_ty_value: AssocTyValue) -> crate::traits::AssocTyValueId; | ||
70 | |||
71 | #[salsa::invoke(crate::traits::chalk::associated_ty_data_query)] | ||
72 | fn associated_ty_data( | ||
73 | &self, | ||
74 | id: chalk_ir::TypeId, | ||
75 | ) -> Arc<chalk_rust_ir::AssociatedTyDatum<chalk_ir::family::ChalkIr>>; | ||
76 | |||
77 | #[salsa::invoke(crate::traits::chalk::trait_datum_query)] | ||
78 | fn trait_datum( | ||
79 | &self, | ||
80 | krate: CrateId, | ||
81 | trait_id: chalk_ir::TraitId, | ||
82 | ) -> Arc<chalk_rust_ir::TraitDatum<chalk_ir::family::ChalkIr>>; | ||
83 | |||
84 | #[salsa::invoke(crate::traits::chalk::struct_datum_query)] | ||
85 | fn struct_datum( | ||
86 | &self, | ||
87 | krate: CrateId, | ||
88 | struct_id: chalk_ir::StructId, | ||
89 | ) -> Arc<chalk_rust_ir::StructDatum<chalk_ir::family::ChalkIr>>; | ||
90 | |||
91 | #[salsa::invoke(crate::traits::chalk::impl_datum_query)] | ||
92 | fn impl_datum( | ||
93 | &self, | ||
94 | krate: CrateId, | ||
95 | impl_id: chalk_ir::ImplId, | ||
96 | ) -> Arc<chalk_rust_ir::ImplDatum<chalk_ir::family::ChalkIr>>; | ||
97 | |||
98 | #[salsa::invoke(crate::traits::chalk::associated_ty_value_query)] | ||
99 | fn associated_ty_value( | ||
100 | &self, | ||
101 | krate: CrateId, | ||
102 | id: chalk_rust_ir::AssociatedTyValueId, | ||
103 | ) -> Arc<chalk_rust_ir::AssociatedTyValue<chalk_ir::family::ChalkIr>>; | ||
104 | |||
105 | #[salsa::invoke(crate::traits::trait_solve_query)] | ||
106 | fn trait_solve( | ||
107 | &self, | ||
108 | krate: CrateId, | ||
109 | goal: crate::Canonical<crate::InEnvironment<crate::Obligation>>, | ||
110 | ) -> Option<crate::traits::Solution>; | ||
111 | } | ||
112 | |||
113 | #[test] | ||
114 | fn hir_database_is_object_safe() { | ||
115 | fn _assert_object_safe(_: &dyn HirDatabase) {} | ||
116 | } | ||