rust/crates/ra_hir/src/db.rs

130 lines
4.8 KiB
Rust
Raw Normal View History

//! FIXME: write short doc here
use std::sync::Arc;
2018-11-27 18:42:26 -06:00
2019-11-27 07:02:33 -06:00
use hir_def::{DefWithBodyId, GenericDefId, ImplId, LocalStructFieldId, TraitId, VariantId};
use ra_arena::map::ArenaMap;
2019-11-26 06:27:33 -06:00
use ra_db::{salsa, CrateId};
2018-11-27 18:42:26 -06:00
2019-11-27 07:02:33 -06:00
use crate::ty::{
method_resolution::CrateImplBlocks,
traits::{AssocTyValue, Impl},
CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, Ty, TyDefId, TypeCtor,
ValueTyDefId,
};
2019-11-26 13:26:47 -06:00
pub use hir_def::db::{
BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery,
DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery,
FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage,
LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery,
StaticDataQuery, StructDataQuery, TraitDataQuery, TypeAliasDataQuery,
2019-10-30 09:40:13 -05:00
};
2019-10-29 06:59:55 -05:00
pub use hir_expand::db::{
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
ParseMacroQuery,
2018-11-27 18:42:26 -06:00
};
2019-01-31 08:28:31 -06:00
#[salsa::query_group(HirDatabaseStorage)]
2019-07-05 09:45:57 -05:00
#[salsa::requires(salsa::Database)]
2019-11-23 07:30:14 -06:00
pub trait HirDatabase: DefDatabase {
2019-05-21 08:24:53 -05:00
#[salsa::invoke(crate::ty::infer_query)]
2019-11-27 07:02:33 -06:00
fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
2019-01-31 08:28:31 -06:00
2019-11-26 12:04:24 -06:00
#[salsa::invoke(crate::ty::ty_query)]
fn ty(&self, def: TyDefId) -> Ty;
#[salsa::invoke(crate::ty::value_ty_query)]
fn value_ty(&self, def: ValueTyDefId) -> Ty;
2019-01-31 08:28:31 -06:00
#[salsa::invoke(crate::ty::field_types_query)]
fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalStructFieldId, Ty>>;
2019-01-31 08:28:31 -06:00
#[salsa::invoke(crate::ty::callable_item_sig)]
fn callable_item_signature(&self, def: CallableDef) -> FnSig;
#[salsa::invoke(crate::ty::generic_predicates_for_param_query)]
fn generic_predicates_for_param(
&self,
2019-11-25 06:41:53 -06:00
def: GenericDefId,
param_idx: u32,
) -> Arc<[GenericPredicate]>;
#[salsa::invoke(crate::ty::generic_predicates_query)]
2019-11-25 06:39:12 -06:00
fn generic_predicates(&self, def: GenericDefId) -> Arc<[GenericPredicate]>;
2019-05-05 07:21:00 -05:00
#[salsa::invoke(crate::ty::generic_defaults_query)]
2019-11-25 06:41:53 -06:00
fn generic_defaults(&self, def: GenericDefId) -> Substs;
2019-05-19 08:08:16 -05:00
2019-02-01 04:33:41 -06:00
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
2019-11-26 06:27:33 -06:00
fn impls_in_crate(&self, krate: CrateId) -> Arc<CrateImplBlocks>;
2019-05-21 04:44:08 -05:00
#[salsa::invoke(crate::ty::traits::impls_for_trait_query)]
2019-11-27 03:02:54 -06:00
fn impls_for_trait(&self, krate: CrateId, trait_: TraitId) -> Arc<[ImplId]>;
/// This provides the Chalk trait solver instance. Because Chalk always
/// works from a specific crate, this query is keyed on the crate; and
/// because Chalk does its own internal caching, the solver is wrapped in a
2019-07-05 09:45:57 -05:00
/// Mutex and the query does an untracked read internally, to make sure the
/// cached state is thrown away when input facts change.
2019-07-09 14:34:23 -05:00
#[salsa::invoke(crate::ty::traits::trait_solver_query)]
2019-11-27 00:42:55 -06:00
fn trait_solver(&self, krate: CrateId) -> crate::ty::traits::TraitSolver;
2019-05-05 09:04:31 -05:00
2019-10-30 01:29:55 -05:00
// Interned IDs for Chalk integration
#[salsa::interned]
2019-11-24 05:25:48 -06:00
fn intern_type_ctor(&self, type_ctor: TypeCtor) -> crate::ty::TypeCtorId;
2019-10-30 01:29:55 -05:00
#[salsa::interned]
2019-11-24 05:25:48 -06:00
fn intern_chalk_impl(&self, impl_: Impl) -> crate::ty::traits::GlobalImplId;
#[salsa::interned]
2019-11-24 05:25:48 -06:00
fn intern_assoc_ty_value(
&self,
assoc_ty_value: AssocTyValue,
) -> crate::ty::traits::AssocTyValueId;
2019-10-30 01:29:55 -05:00
#[salsa::invoke(crate::ty::traits::chalk::associated_ty_data_query)]
2019-11-16 06:21:51 -06:00
fn associated_ty_data(
&self,
id: chalk_ir::TypeId,
) -> Arc<chalk_rust_ir::AssociatedTyDatum<chalk_ir::family::ChalkIr>>;
#[salsa::invoke(crate::ty::traits::chalk::trait_datum_query)]
fn trait_datum(
&self,
2019-11-27 00:42:55 -06:00
krate: CrateId,
trait_id: chalk_ir::TraitId,
2019-11-16 06:21:51 -06:00
) -> Arc<chalk_rust_ir::TraitDatum<chalk_ir::family::ChalkIr>>;
#[salsa::invoke(crate::ty::traits::chalk::struct_datum_query)]
fn struct_datum(
&self,
2019-11-27 00:42:55 -06:00
krate: CrateId,
struct_id: chalk_ir::StructId,
2019-11-16 06:21:51 -06:00
) -> Arc<chalk_rust_ir::StructDatum<chalk_ir::family::ChalkIr>>;
#[salsa::invoke(crate::ty::traits::chalk::impl_datum_query)]
2019-11-16 06:21:51 -06:00
fn impl_datum(
&self,
2019-11-27 00:42:55 -06:00
krate: CrateId,
2019-11-16 06:21:51 -06:00
impl_id: chalk_ir::ImplId,
) -> Arc<chalk_rust_ir::ImplDatum<chalk_ir::family::ChalkIr>>;
#[salsa::invoke(crate::ty::traits::chalk::associated_ty_value_query)]
fn associated_ty_value(
&self,
2019-11-27 00:42:55 -06:00
krate: CrateId,
id: chalk_rust_ir::AssociatedTyValueId,
2019-11-16 06:21:51 -06:00
) -> Arc<chalk_rust_ir::AssociatedTyValue<chalk_ir::family::ChalkIr>>;
2019-07-09 14:34:23 -05:00
#[salsa::invoke(crate::ty::traits::trait_solve_query)]
fn trait_solve(
2019-05-05 09:04:31 -05:00
&self,
2019-11-27 00:42:55 -06:00
krate: CrateId,
goal: crate::ty::Canonical<crate::ty::InEnvironment<crate::ty::Obligation>>,
) -> Option<crate::ty::traits::Solution>;
2019-01-31 08:28:31 -06:00
}
2019-02-03 13:15:31 -06:00
#[test]
fn hir_database_is_object_safe() {
fn _assert_object_safe(_: &dyn HirDatabase) {}
}