rust/crates/ra_hir/src/db.rs

142 lines
5.5 KiB
Rust
Raw Normal View History

2018-11-27 18:42:26 -06:00
use std::sync::Arc;
2019-04-09 14:51:22 -05:00
use ra_syntax::{SyntaxNode, TreeArc, SourceFile, ast};
use ra_db::{SourceDatabase, salsa};
2018-11-27 18:42:26 -06:00
use crate::{
2019-04-09 14:51:22 -05:00
HirFileId, MacroDefId, AstIdMap, ErasedFileAstId, Crate, Module, MacroCallLoc,
2019-02-24 14:36:49 -06:00
Function, FnSignature, ExprScopes, TypeAlias,
2019-01-25 05:21:14 -06:00
Struct, Enum, StructField,
2019-02-25 02:21:01 -06:00
Const, ConstSignature, Static,
2019-03-30 05:50:00 -05:00
DefWithBody,
2019-03-16 09:17:50 -05:00
nameres::{Namespace, ImportSourceMap, RawItems, CrateDefMap},
ty::{InferenceResult, Ty, method_resolution::CrateImplBlocks, TypableDef, CallableDef, FnSig},
2019-01-25 03:41:23 -06:00
adt::{StructData, EnumData},
impl_block::{ModuleImplBlocks, ImplSourceMap},
2019-01-24 06:28:50 -06:00
generics::{GenericParams, GenericDef},
2019-02-24 14:36:49 -06:00
type_ref::TypeRef,
2019-04-09 14:51:22 -05:00
traits::TraitData, Trait, ty::TraitRef,
ids
2018-11-27 18:42:26 -06:00
};
#[salsa::query_group(DefDatabaseStorage)]
2019-04-09 14:51:22 -05:00
pub trait DefDatabase: SourceDatabase {
#[salsa::interned]
fn intern_macro(&self, macro_call: MacroCallLoc) -> ids::MacroCallId;
#[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-03-26 06:13:17 -05:00
#[salsa::invoke(crate::ids::macro_def_query)]
fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>;
2019-03-26 10:57:57 -05:00
#[salsa::invoke(HirFileId::hir_parse_query)]
2019-01-26 02:51:36 -06:00
fn hir_parse(&self, file_id: HirFileId) -> TreeArc<SourceFile>;
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-26 11:00:11 -05:00
#[salsa::invoke(crate::source_id::AstIdMap::ast_id_map_query)]
fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>;
2019-01-17 05:11:00 -06:00
2019-03-26 11:00:11 -05:00
#[salsa::invoke(crate::source_id::AstIdMap::file_item_query)]
fn ast_id_to_node(&self, file_id: HirFileId, ast_id: ErasedFileAstId) -> TreeArc<SyntaxNode>;
2019-02-01 04:33:41 -06:00
2019-03-13 08:38:02 -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
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-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
#[salsa::invoke(crate::impl_block::impls_in_module)]
fn impls_in_module(&self, module: Module) -> Arc<ModuleImplBlocks>;
2019-01-17 05:11:00 -06:00
#[salsa::invoke(crate::impl_block::impls_in_module_source_map_query)]
fn impls_in_module_source_map(&self, module: Module) -> Arc<ImplSourceMap>;
2019-02-01 04:33:41 -06:00
#[salsa::invoke(crate::impl_block::impls_in_module_with_source_map_query)]
fn impls_in_module_with_source_map(
&self,
module: Module,
) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>);
2019-01-17 05:11:00 -06:00
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-01-17 05:11:00 -06:00
#[salsa::invoke(crate::FnSignature::fn_signature_query)]
2019-01-24 06:28:50 -06:00
fn fn_signature(&self, func: Function) -> Arc<FnSignature>;
2019-02-24 10:25:41 -06:00
#[salsa::invoke(crate::type_alias::type_alias_ref_query)]
2019-02-24 14:36:49 -06:00
fn type_alias_ref(&self, typ: TypeAlias) -> Arc<TypeRef>;
2019-02-25 01:27:47 -06:00
#[salsa::invoke(crate::ConstSignature::const_signature_query)]
fn const_signature(&self, konst: Const) -> Arc<ConstSignature>;
2019-02-25 02:21:01 -06:00
#[salsa::invoke(crate::ConstSignature::static_signature_query)]
fn static_signature(&self, konst: Static) -> Arc<ConstSignature>;
2018-11-27 18:42:26 -06:00
}
2019-01-31 08:28:31 -06:00
#[salsa::query_group(HirDatabaseStorage)]
pub trait HirDatabase: DefDatabase {
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
#[salsa::invoke(crate::ty::infer)]
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;
2019-03-02 07:18:40 -06:00
#[salsa::invoke(crate::expr::body_with_source_map_query)]
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-03-02 07:18:40 -06: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>;
#[salsa::invoke(crate::ty::traits::implements)]
fn implements(&self, trait_ref: TraitRef) -> 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) {}
}