rust/crates/ra_hir/src/db.rs

211 lines
8.0 KiB
Rust
Raw Normal View History

//! FIXME: write short doc here
use std::sync::Arc;
2018-11-27 18:42:26 -06:00
use ra_db::{salsa, SourceDatabase};
use ra_syntax::{ast, SmolStr};
2018-11-27 18:42:26 -06:00
use crate::{
adt::{EnumData, StructData},
debug::HirDebugDatabase,
generics::{GenericDef, GenericParams},
ids,
impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks},
lang_item::{LangItemTarget, LangItems},
nameres::{CrateDefMap, ImportSourceMap, Namespace, RawItems},
traits::TraitData,
ty::{
2019-09-09 15:10:58 -05:00
method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate,
InferenceResult, Substs, Ty, TypableDef, TypeCtor,
},
type_alias::TypeAliasData,
Const, ConstData, Crate, DefWithBody, Enum, ExprScopes, FnData, Function, HirFileId, Module,
Static, Struct, StructField, Trait, TypeAlias,
};
pub use hir_def::db::{
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
ParseMacroQuery,
2018-11-27 18:42:26 -06:00
};
/// We store all interned things in the single QueryGroup.
///
/// This is done mainly to allow both "volatile" `AstDatabase` and "stable"
/// `DefDatabase` to access macros, without adding hard dependencies between the
/// two.
#[salsa::query_group(InternDatabaseStorage)]
pub trait InternDatabase: SourceDatabase {
#[salsa::interned]
fn intern_function(&self, loc: ids::ItemLoc<ast::FnDef>) -> ids::FunctionId;
#[salsa::interned]
fn intern_struct(&self, loc: ids::ItemLoc<ast::StructDef>) -> ids::StructId;
#[salsa::interned]
fn intern_enum(&self, loc: ids::ItemLoc<ast::EnumDef>) -> ids::EnumId;
#[salsa::interned]
fn intern_const(&self, loc: ids::ItemLoc<ast::ConstDef>) -> ids::ConstId;
#[salsa::interned]
fn intern_static(&self, loc: ids::ItemLoc<ast::StaticDef>) -> ids::StaticId;
#[salsa::interned]
fn intern_trait(&self, loc: ids::ItemLoc<ast::TraitDef>) -> ids::TraitId;
#[salsa::interned]
fn intern_type_alias(&self, loc: ids::ItemLoc<ast::TypeAliasDef>) -> ids::TypeAliasId;
2019-06-01 13:17:57 -05:00
// Interned IDs for Chalk integration
#[salsa::interned]
fn intern_type_ctor(&self, type_ctor: TypeCtor) -> ids::TypeCtorId;
#[salsa::interned]
2019-09-09 15:10:58 -05:00
fn intern_impl(&self, impl_: Impl) -> ids::GlobalImplId;
}
2019-06-01 13:17:57 -05:00
// This database uses `AstDatabase` internally,
#[salsa::query_group(DefDatabaseStorage)]
#[salsa::requires(AstDatabase)]
pub trait DefDatabase: InternDatabase + HirDebugDatabase + AstDatabase {
2019-01-17 05:11:00 -06:00
#[salsa::invoke(crate::adt::StructData::struct_data_query)]
2019-01-24 09:56:38 -06:00
fn struct_data(&self, s: Struct) -> Arc<StructData>;
2019-01-17 05:11:00 -06:00
#[salsa::invoke(crate::adt::EnumData::enum_data_query)]
2019-01-24 09:56:38 -06:00
fn enum_data(&self, e: Enum) -> Arc<EnumData>;
2019-01-17 05:11:00 -06:00
2019-03-24 11:36:15 -05:00
#[salsa::invoke(crate::traits::TraitData::trait_data_query)]
fn trait_data(&self, t: Trait) -> Arc<TraitData>;
#[salsa::invoke(crate::traits::TraitItemsIndex::trait_items_index)]
fn trait_items_index(&self, module: Module) -> crate::traits::TraitItemsIndex;
2019-03-14 05:14:54 -05:00
#[salsa::invoke(RawItems::raw_items_with_source_map_query)]
fn raw_items_with_source_map(
&self,
file_id: HirFileId,
) -> (Arc<RawItems>, Arc<ImportSourceMap>);
2019-03-14 05:14:54 -05:00
2019-06-30 08:35:40 -05:00
#[salsa::invoke(RawItems::raw_items_query)]
fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;
2019-03-13 08:38:02 -05:00
#[salsa::invoke(CrateDefMap::crate_def_map_query)]
fn crate_def_map(&self, krate: Crate) -> Arc<CrateDefMap>;
2019-01-17 05:11:00 -06:00
2019-10-16 05:26:02 -05:00
#[salsa::invoke(ModuleImplBlocks::impls_in_module_with_source_map_query)]
2019-02-01 04:33:41 -06:00
fn impls_in_module_with_source_map(
&self,
module: Module,
) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>);
2019-01-17 05:11:00 -06:00
2019-10-16 05:26:02 -05:00
#[salsa::invoke(ModuleImplBlocks::impls_in_module_query)]
2019-06-30 08:35:40 -05:00
fn impls_in_module(&self, module: Module) -> Arc<ModuleImplBlocks>;
2019-01-19 11:58:04 -06:00
#[salsa::invoke(crate::generics::GenericParams::generic_params_query)]
2019-01-24 06:28:50 -06:00
fn generic_params(&self, def: GenericDef) -> Arc<GenericParams>;
2019-10-16 05:26:02 -05:00
#[salsa::invoke(FnData::fn_data_query)]
2019-06-18 12:07:35 -05:00
fn fn_data(&self, func: Function) -> Arc<FnData>;
2019-02-24 10:25:41 -06:00
2019-10-16 05:26:02 -05:00
#[salsa::invoke(TypeAliasData::type_alias_data_query)]
fn type_alias_data(&self, typ: TypeAlias) -> Arc<TypeAliasData>;
2019-02-25 01:27:47 -06:00
2019-10-16 05:26:02 -05:00
#[salsa::invoke(ConstData::const_data_query)]
2019-06-18 12:07:35 -05:00
fn const_data(&self, konst: Const) -> Arc<ConstData>;
2019-02-25 02:21:01 -06:00
2019-10-16 05:26:02 -05:00
#[salsa::invoke(ConstData::static_data_query)]
2019-06-18 12:07:35 -05:00
fn static_data(&self, konst: Static) -> Arc<ConstData>;
2019-04-14 17:03:54 -05:00
2019-10-16 05:26:02 -05:00
#[salsa::invoke(LangItems::module_lang_items_query)]
fn module_lang_items(&self, module: Module) -> Option<Arc<LangItems>>;
2019-10-16 05:26:02 -05:00
#[salsa::invoke(LangItems::crate_lang_items_query)]
fn crate_lang_items(&self, krate: Crate) -> Arc<LangItems>;
2019-04-18 13:34:10 -05:00
2019-10-16 05:26:02 -05:00
#[salsa::invoke(LangItems::lang_item_query)]
2019-04-18 13:34:10 -05:00
fn lang_item(&self, start_crate: Crate, item: SmolStr) -> Option<LangItemTarget>;
2019-06-08 06:36:39 -05:00
2019-06-11 10:14:27 -05:00
#[salsa::invoke(crate::code_model::docs::documentation_query)]
fn documentation(&self, def: crate::DocDef) -> Option<crate::Documentation>;
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-06-01 13:17:57 -05:00
pub trait HirDatabase: DefDatabase + AstDatabase {
2019-02-01 04:33:41 -06:00
#[salsa::invoke(ExprScopes::expr_scopes_query)]
2019-03-30 05:50:00 -05:00
fn expr_scopes(&self, def: DefWithBody) -> Arc<ExprScopes>;
2019-01-31 08:28:31 -06:00
2019-05-21 08:24:53 -05:00
#[salsa::invoke(crate::ty::infer_query)]
fn infer(&self, def: DefWithBody) -> Arc<InferenceResult>;
2019-01-31 08:28:31 -06:00
#[salsa::invoke(crate::ty::type_for_def)]
fn type_for_def(&self, def: TypableDef, ns: Namespace) -> Ty;
2019-01-31 08:28:31 -06:00
#[salsa::invoke(crate::ty::type_for_field)]
fn type_for_field(&self, field: StructField) -> Ty;
#[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-05-05 07:21:00 -05:00
fn generic_predicates(&self, def: GenericDef) -> Arc<[GenericPredicate]>;
#[salsa::invoke(crate::ty::generic_defaults_query)]
2019-05-19 08:08:16 -05:00
fn generic_defaults(&self, def: GenericDef) -> Substs;
2019-09-03 01:40:34 -05:00
#[salsa::invoke(crate::expr::body_with_source_map_query)]
2019-03-02 07:18:40 -06:00
fn body_with_source_map(
&self,
2019-03-30 05:50:00 -05:00
def: DefWithBody,
2019-03-02 07:18:40 -06:00
) -> (Arc<crate::expr::Body>, Arc<crate::expr::BodySourceMap>);
2019-01-31 08:28:31 -06:00
2019-09-03 01:40:34 -05:00
#[salsa::invoke(crate::expr::body_hir_query)]
2019-03-30 05:50:00 -05:00
fn body_hir(&self, def: DefWithBody) -> Arc<crate::expr::Body>;
2019-02-01 04:33:41 -06:00
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
2019-05-21 04:44:08 -05: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 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-07-05 09:45:57 -05:00
fn trait_solver(&self, krate: Crate) -> crate::ty::traits::TraitSolver;
2019-05-05 09:04:31 -05:00
#[salsa::invoke(crate::ty::traits::chalk::associated_ty_data_query)]
fn associated_ty_data(&self, id: chalk_ir::TypeId) -> Arc<chalk_rust_ir::AssociatedTyDatum>;
#[salsa::invoke(crate::ty::traits::chalk::trait_datum_query)]
fn trait_datum(
&self,
krate: Crate,
trait_id: chalk_ir::TraitId,
) -> Arc<chalk_rust_ir::TraitDatum>;
#[salsa::invoke(crate::ty::traits::chalk::struct_datum_query)]
fn struct_datum(
&self,
krate: Crate,
struct_id: chalk_ir::StructId,
) -> Arc<chalk_rust_ir::StructDatum>;
#[salsa::invoke(crate::ty::traits::chalk::impl_datum_query)]
fn impl_datum(&self, krate: Crate, impl_id: chalk_ir::ImplId) -> Arc<chalk_rust_ir::ImplDatum>;
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,
krate: Crate,
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) {}
}