rust-analyzer/crates/ra_hir/src/db.rs

133 lines
4.8 KiB
Rust
Raw Normal View History

//! FIXME: write short doc here
use std::sync::Arc;
2018-11-28 00:42:26 +00:00
use ra_arena::map::ArenaMap;
2019-10-30 10:10:38 +00:00
use ra_db::salsa;
2018-11-28 00:42:26 +00:00
use crate::{
ty::{
method_resolution::CrateImplBlocks,
traits::{AssocTyValue, Impl},
CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef,
TypeCtor,
},
Crate, DefWithBody, GenericDef, ImplBlock, Trait,
};
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-11-25 12:39:12 +00:00
GenericDefId, LocalStructFieldId, VariantId,
2019-10-30 14:40:13 +00:00
};
2019-10-29 11:59:55 +00:00
pub use hir_expand::db::{
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
ParseMacroQuery,
2018-11-28 00:42:26 +00:00
};
2019-01-31 14:28:31 +00:00
#[salsa::query_group(HirDatabaseStorage)]
2019-07-05 14:45:57 +00:00
#[salsa::requires(salsa::Database)]
2019-11-23 13:30:14 +00:00
pub trait HirDatabase: DefDatabase {
2019-05-21 13:24:53 +00:00
#[salsa::invoke(crate::ty::infer_query)]
fn infer(&self, def: DefWithBody) -> Arc<InferenceResult>;
2019-01-31 14:28:31 +00:00
#[salsa::invoke(crate::ty::type_for_def)]
fn type_for_def(&self, def: TypableDef, ns: Namespace) -> Ty;
2019-01-31 14:28:31 +00:00
#[salsa::invoke(crate::ty::field_types_query)]
fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalStructFieldId, Ty>>;
2019-01-31 14:28:31 +00: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,
def: GenericDef,
param_idx: u32,
) -> Arc<[GenericPredicate]>;
#[salsa::invoke(crate::ty::generic_predicates_query)]
2019-11-25 12:39:12 +00:00
fn generic_predicates(&self, def: GenericDefId) -> Arc<[GenericPredicate]>;
2019-05-05 12:21:00 +00:00
#[salsa::invoke(crate::ty::generic_defaults_query)]
2019-05-19 13:08:16 +00:00
fn generic_defaults(&self, def: GenericDef) -> Substs;
2019-02-01 10:33:41 +00:00
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
2019-05-21 09:44:08 +00:00
#[salsa::invoke(crate::ty::traits::impls_for_trait_query)]
fn impls_for_trait(&self, krate: Crate, trait_: Trait) -> Arc<[ImplBlock]>;
/// 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 14:45:57 +00: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 19:34:23 +00:00
#[salsa::invoke(crate::ty::traits::trait_solver_query)]
2019-07-05 14:45:57 +00:00
fn trait_solver(&self, krate: Crate) -> crate::ty::traits::TraitSolver;
2019-05-05 14:04:31 +00:00
2019-10-30 06:29:55 +00:00
// Interned IDs for Chalk integration
#[salsa::interned]
2019-11-24 11:25:48 +00:00
fn intern_type_ctor(&self, type_ctor: TypeCtor) -> crate::ty::TypeCtorId;
2019-10-30 06:29:55 +00:00
#[salsa::interned]
2019-11-24 11:25:48 +00:00
fn intern_chalk_impl(&self, impl_: Impl) -> crate::ty::traits::GlobalImplId;
#[salsa::interned]
2019-11-24 11:25:48 +00:00
fn intern_assoc_ty_value(
&self,
assoc_ty_value: AssocTyValue,
) -> crate::ty::traits::AssocTyValueId;
2019-10-30 06:29:55 +00:00
#[salsa::invoke(crate::ty::traits::chalk::associated_ty_data_query)]
2019-11-16 12:21:51 +00: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,
krate: Crate,
trait_id: chalk_ir::TraitId,
2019-11-16 12:21:51 +00:00
) -> Arc<chalk_rust_ir::TraitDatum<chalk_ir::family::ChalkIr>>;
#[salsa::invoke(crate::ty::traits::chalk::struct_datum_query)]
fn struct_datum(
&self,
krate: Crate,
struct_id: chalk_ir::StructId,
2019-11-16 12:21:51 +00:00
) -> Arc<chalk_rust_ir::StructDatum<chalk_ir::family::ChalkIr>>;
#[salsa::invoke(crate::ty::traits::chalk::impl_datum_query)]
2019-11-16 12:21:51 +00:00
fn impl_datum(
&self,
krate: Crate,
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,
krate: Crate,
id: chalk_rust_ir::AssociatedTyValueId,
2019-11-16 12:21:51 +00:00
) -> Arc<chalk_rust_ir::AssociatedTyValue<chalk_ir::family::ChalkIr>>;
2019-07-09 19:34:23 +00:00
#[salsa::invoke(crate::ty::traits::trait_solve_query)]
fn trait_solve(
2019-05-05 14:04:31 +00:00
&self,
krate: Crate,
goal: crate::ty::Canonical<crate::ty::InEnvironment<crate::ty::Obligation>>,
) -> Option<crate::ty::traits::Solution>;
2019-01-31 14:28:31 +00:00
}
2019-02-03 19:15:31 +00:00
#[test]
fn hir_database_is_object_safe() {
fn _assert_object_safe(_: &dyn HirDatabase) {}
}