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

122 lines
4.6 KiB
Rust
Raw Normal View History

2019-10-30 10:10:38 +00:00
//! Defines database & queries for name resolution.
2019-10-30 13:12:55 +00:00
use std::sync::Arc;
2019-10-30 10:10:38 +00:00
use hir_expand::{db::AstDatabase, HirFileId};
use ra_db::{salsa, CrateId, SourceDatabase, Upcast};
use ra_prof::profile;
2019-12-12 14:11:57 +00:00
use ra_syntax::SmolStr;
2019-10-30 10:10:38 +00:00
2019-10-31 13:40:36 +00:00
use crate::{
adt::{EnumData, StructData},
2019-11-23 08:14:10 +00:00
attr::Attrs,
2019-11-14 14:37:22 +00:00
body::{scope::ExprScopes, Body, BodySourceMap},
2020-05-10 15:08:28 +00:00
data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData},
2019-11-23 11:43:38 +00:00
docs::Documentation,
2019-11-20 17:33:18 +00:00
generics::GenericParams,
2020-05-20 21:51:20 +00:00
import_map::ImportMap,
2020-06-11 17:46:56 +00:00
item_tree::ItemTree,
2019-11-23 09:58:01 +00:00
lang_item::{LangItemTarget, LangItems},
2020-06-15 17:16:43 +00:00
nameres::CrateDefMap,
2019-12-12 14:11:57 +00:00
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc,
2019-10-31 13:40:36 +00:00
};
2019-10-30 13:12:55 +00:00
2019-10-30 10:10:38 +00:00
#[salsa::query_group(InternDatabaseStorage)]
pub trait InternDatabase: SourceDatabase {
#[salsa::interned]
2019-11-23 12:33:21 +00:00
fn intern_function(&self, loc: FunctionLoc) -> FunctionId;
2019-10-30 10:10:38 +00:00
#[salsa::interned]
2019-12-12 13:58:04 +00:00
fn intern_struct(&self, loc: StructLoc) -> StructId;
2019-11-25 14:30:50 +00:00
#[salsa::interned]
2019-12-12 14:11:57 +00:00
fn intern_union(&self, loc: UnionLoc) -> UnionId;
2019-10-30 13:12:55 +00:00
#[salsa::interned]
2019-12-12 14:11:57 +00:00
fn intern_enum(&self, loc: EnumLoc) -> EnumId;
2019-10-30 10:10:38 +00:00
#[salsa::interned]
2019-11-23 12:33:21 +00:00
fn intern_const(&self, loc: ConstLoc) -> ConstId;
2019-10-30 10:10:38 +00:00
#[salsa::interned]
2019-11-24 12:13:56 +00:00
fn intern_static(&self, loc: StaticLoc) -> StaticId;
2019-10-30 10:10:38 +00:00
#[salsa::interned]
2019-12-12 13:34:03 +00:00
fn intern_trait(&self, loc: TraitLoc) -> TraitId;
2019-10-30 10:10:38 +00:00
#[salsa::interned]
2019-11-23 12:33:21 +00:00
fn intern_type_alias(&self, loc: TypeAliasLoc) -> TypeAliasId;
2019-11-15 16:14:50 +00:00
#[salsa::interned]
2019-12-12 13:09:13 +00:00
fn intern_impl(&self, loc: ImplLoc) -> ImplId;
2019-10-30 10:10:38 +00:00
}
2019-10-30 13:12:55 +00:00
2019-11-23 11:44:43 +00:00
#[salsa::query_group(DefDatabaseStorage)]
pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
2020-06-11 17:46:56 +00:00
#[salsa::invoke(ItemTree::item_tree_query)]
fn item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>;
2020-03-06 23:11:52 +00:00
#[salsa::invoke(crate_def_map_wait)]
2020-03-25 17:41:46 +00:00
#[salsa::transparent]
2019-10-31 15:45:10 +00:00
fn crate_def_map(&self, krate: CrateId) -> Arc<CrateDefMap>;
2020-03-06 23:11:52 +00:00
#[salsa::invoke(CrateDefMap::crate_def_map_query)]
fn crate_def_map_query(&self, krate: CrateId) -> Arc<CrateDefMap>;
2019-10-31 13:40:36 +00:00
#[salsa::invoke(StructData::struct_data_query)]
2019-11-25 14:30:50 +00:00
fn struct_data(&self, id: StructId) -> Arc<StructData>;
#[salsa::invoke(StructData::union_data_query)]
fn union_data(&self, id: UnionId) -> Arc<StructData>;
2019-10-31 15:45:10 +00:00
2019-10-31 13:40:36 +00:00
#[salsa::invoke(EnumData::enum_data_query)]
fn enum_data(&self, e: EnumId) -> Arc<EnumData>;
2019-11-14 14:37:22 +00:00
2019-11-15 18:28:00 +00:00
#[salsa::invoke(ImplData::impl_data_query)]
fn impl_data(&self, e: ImplId) -> Arc<ImplData>;
2019-11-20 11:22:06 +00:00
#[salsa::invoke(TraitData::trait_data_query)]
fn trait_data(&self, e: TraitId) -> Arc<TraitData>;
2019-11-22 09:57:40 +00:00
#[salsa::invoke(TypeAliasData::type_alias_data_query)]
fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>;
2019-11-22 14:10:51 +00:00
#[salsa::invoke(FunctionData::fn_data_query)]
fn function_data(&self, func: FunctionId) -> Arc<FunctionData>;
2019-11-22 15:46:39 +00:00
#[salsa::invoke(ConstData::const_data_query)]
fn const_data(&self, konst: ConstId) -> Arc<ConstData>;
2020-05-10 15:08:28 +00:00
#[salsa::invoke(StaticData::static_data_query)]
fn static_data(&self, konst: StaticId) -> Arc<StaticData>;
2019-11-22 15:46:39 +00:00
2019-11-14 14:37:22 +00:00
#[salsa::invoke(Body::body_with_source_map_query)]
fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
#[salsa::invoke(Body::body_query)]
fn body(&self, def: DefWithBodyId) -> Arc<Body>;
#[salsa::invoke(ExprScopes::expr_scopes_query)]
fn expr_scopes(&self, def: DefWithBodyId) -> Arc<ExprScopes>;
2019-11-20 17:33:18 +00:00
#[salsa::invoke(GenericParams::generic_params_query)]
fn generic_params(&self, def: GenericDefId) -> Arc<GenericParams>;
2019-11-23 08:14:10 +00:00
#[salsa::invoke(Attrs::attrs_query)]
fn attrs(&self, def: AttrDefId) -> Attrs;
2019-11-23 09:58:01 +00:00
#[salsa::invoke(LangItems::module_lang_items_query)]
fn module_lang_items(&self, module: ModuleId) -> Option<Arc<LangItems>>;
#[salsa::invoke(LangItems::crate_lang_items_query)]
fn crate_lang_items(&self, krate: CrateId) -> Arc<LangItems>;
#[salsa::invoke(LangItems::lang_item_query)]
fn lang_item(&self, start_crate: CrateId, item: SmolStr) -> Option<LangItemTarget>;
2019-11-23 11:43:38 +00:00
// FIXME(https://github.com/rust-analyzer/rust-analyzer/issues/2148#issuecomment-550519102)
// Remove this query completely, in favor of `Attrs::docs` method
#[salsa::invoke(Documentation::documentation_query)]
fn documentation(&self, def: AttrDefId) -> Option<Documentation>;
2020-05-20 21:51:20 +00:00
#[salsa::invoke(ImportMap::import_map_query)]
fn import_map(&self, krate: CrateId) -> Arc<ImportMap>;
2019-10-30 13:12:55 +00:00
}
2020-03-06 23:11:52 +00:00
fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
let _p = profile("crate_def_map:wait");
db.crate_def_map_query(krate)
}