2019-10-30 05:10:38 -05:00
|
|
|
//! Defines database & queries for name resolution.
|
2019-10-30 08:12:55 -05:00
|
|
|
use std::sync::Arc;
|
2019-10-30 05:10:38 -05:00
|
|
|
|
2020-08-13 09:25:38 -05:00
|
|
|
use base_db::{salsa, CrateId, SourceDatabase, Upcast};
|
2021-04-06 15:25:44 -05:00
|
|
|
use either::Either;
|
2021-01-25 12:02:05 -06:00
|
|
|
use hir_expand::{db::AstDatabase, HirFileId};
|
2021-01-14 18:11:07 -06:00
|
|
|
use la_arena::ArenaMap;
|
2021-04-06 15:25:44 -05:00
|
|
|
use syntax::{ast, AstPtr, SmolStr};
|
2019-10-30 05:10:38 -05:00
|
|
|
|
2019-10-31 08:40:36 -05:00
|
|
|
use crate::{
|
|
|
|
adt::{EnumData, StructData},
|
2021-03-19 15:23:57 -05:00
|
|
|
attr::{Attrs, AttrsWithOwner},
|
2019-11-14 08:37:22 -06:00
|
|
|
body::{scope::ExprScopes, Body, BodySourceMap},
|
2020-05-10 10:08:28 -05:00
|
|
|
data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData},
|
2019-11-20 11:33:18 -06:00
|
|
|
generics::GenericParams,
|
2020-05-20 16:51:20 -05:00
|
|
|
import_map::ImportMap,
|
2021-04-04 20:50:10 -05:00
|
|
|
intern::Interned,
|
2020-06-11 12:46:56 -05:00
|
|
|
item_tree::ItemTree,
|
2019-11-23 03:58:01 -06:00
|
|
|
lang_item::{LangItemTarget, LangItems},
|
2021-01-18 13:18:05 -06:00
|
|
|
nameres::DefMap,
|
2021-03-24 16:59:59 -05:00
|
|
|
visibility::{self, Visibility},
|
2021-01-25 12:02:05 -06:00
|
|
|
AttrDefId, BlockId, BlockLoc, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId,
|
|
|
|
FunctionLoc, GenericDefId, ImplId, ImplLoc, LocalEnumVariantId, LocalFieldId, StaticId,
|
|
|
|
StaticLoc, StructId, StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId,
|
|
|
|
UnionLoc, VariantId,
|
2019-10-31 08:40:36 -05:00
|
|
|
};
|
2019-10-30 08:12:55 -05:00
|
|
|
|
2019-10-30 05:10:38 -05:00
|
|
|
#[salsa::query_group(InternDatabaseStorage)]
|
|
|
|
pub trait InternDatabase: SourceDatabase {
|
|
|
|
#[salsa::interned]
|
2019-11-23 06:33:21 -06:00
|
|
|
fn intern_function(&self, loc: FunctionLoc) -> FunctionId;
|
2019-10-30 05:10:38 -05:00
|
|
|
#[salsa::interned]
|
2019-12-12 07:58:04 -06:00
|
|
|
fn intern_struct(&self, loc: StructLoc) -> StructId;
|
2019-11-25 08:30:50 -06:00
|
|
|
#[salsa::interned]
|
2019-12-12 08:11:57 -06:00
|
|
|
fn intern_union(&self, loc: UnionLoc) -> UnionId;
|
2019-10-30 08:12:55 -05:00
|
|
|
#[salsa::interned]
|
2019-12-12 08:11:57 -06:00
|
|
|
fn intern_enum(&self, loc: EnumLoc) -> EnumId;
|
2019-10-30 05:10:38 -05:00
|
|
|
#[salsa::interned]
|
2019-11-23 06:33:21 -06:00
|
|
|
fn intern_const(&self, loc: ConstLoc) -> ConstId;
|
2019-10-30 05:10:38 -05:00
|
|
|
#[salsa::interned]
|
2019-11-24 06:13:56 -06:00
|
|
|
fn intern_static(&self, loc: StaticLoc) -> StaticId;
|
2019-10-30 05:10:38 -05:00
|
|
|
#[salsa::interned]
|
2019-12-12 07:34:03 -06:00
|
|
|
fn intern_trait(&self, loc: TraitLoc) -> TraitId;
|
2019-10-30 05:10:38 -05:00
|
|
|
#[salsa::interned]
|
2019-11-23 06:33:21 -06:00
|
|
|
fn intern_type_alias(&self, loc: TypeAliasLoc) -> TypeAliasId;
|
2019-11-15 10:14:50 -06:00
|
|
|
#[salsa::interned]
|
2019-12-12 07:09:13 -06:00
|
|
|
fn intern_impl(&self, loc: ImplLoc) -> ImplId;
|
2021-01-25 12:02:05 -06:00
|
|
|
#[salsa::interned]
|
|
|
|
fn intern_block(&self, loc: BlockLoc) -> BlockId;
|
2019-10-30 05:10:38 -05:00
|
|
|
}
|
2019-10-30 08:12:55 -05:00
|
|
|
|
2019-11-23 05:44:43 -06:00
|
|
|
#[salsa::query_group(DefDatabaseStorage)]
|
2020-03-13 10:05:46 -05:00
|
|
|
pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
|
2021-06-03 09:11:20 -05:00
|
|
|
#[salsa::input]
|
|
|
|
fn enable_proc_attr_macros(&self) -> bool;
|
|
|
|
|
2021-03-12 19:24:26 -06:00
|
|
|
#[salsa::invoke(ItemTree::file_item_tree_query)]
|
|
|
|
fn file_item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>;
|
2020-06-11 12:46:56 -05:00
|
|
|
|
2020-03-06 17:11:52 -06:00
|
|
|
#[salsa::invoke(crate_def_map_wait)]
|
2020-03-25 12:41:46 -05:00
|
|
|
#[salsa::transparent]
|
2021-01-18 13:18:05 -06:00
|
|
|
fn crate_def_map(&self, krate: CrateId) -> Arc<DefMap>;
|
2019-10-31 10:45:10 -05:00
|
|
|
|
2021-01-18 13:18:05 -06:00
|
|
|
#[salsa::invoke(DefMap::crate_def_map_query)]
|
|
|
|
fn crate_def_map_query(&self, krate: CrateId) -> Arc<DefMap>;
|
2020-01-03 06:59:46 -06:00
|
|
|
|
2021-02-03 10:48:41 -06:00
|
|
|
/// Computes the block-level `DefMap`, returning `None` when `block` doesn't contain any inner
|
|
|
|
/// items directly.
|
|
|
|
///
|
|
|
|
/// For example:
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// fn f() { // (0)
|
|
|
|
/// { // (1)
|
|
|
|
/// fn inner() {}
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// The `block_def_map` for block 0 would return `None`, while `block_def_map` of block 1 would
|
|
|
|
/// return a `DefMap` containing `inner`.
|
2021-01-21 08:22:17 -06:00
|
|
|
#[salsa::invoke(DefMap::block_def_map_query)]
|
2021-02-01 06:32:43 -06:00
|
|
|
fn block_def_map(&self, block: BlockId) -> Option<Arc<DefMap>>;
|
2021-01-21 08:22:17 -06:00
|
|
|
|
2019-10-31 08:40:36 -05:00
|
|
|
#[salsa::invoke(StructData::struct_data_query)]
|
2019-11-25 08:30:50 -06: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 10:45:10 -05:00
|
|
|
|
2019-10-31 08:40:36 -05:00
|
|
|
#[salsa::invoke(EnumData::enum_data_query)]
|
|
|
|
fn enum_data(&self, e: EnumId) -> Arc<EnumData>;
|
2019-11-14 08:37:22 -06:00
|
|
|
|
2019-11-15 12:28:00 -06:00
|
|
|
#[salsa::invoke(ImplData::impl_data_query)]
|
|
|
|
fn impl_data(&self, e: ImplId) -> Arc<ImplData>;
|
|
|
|
|
2019-11-20 05:22:06 -06:00
|
|
|
#[salsa::invoke(TraitData::trait_data_query)]
|
|
|
|
fn trait_data(&self, e: TraitId) -> Arc<TraitData>;
|
|
|
|
|
2019-11-22 03:57:40 -06:00
|
|
|
#[salsa::invoke(TypeAliasData::type_alias_data_query)]
|
|
|
|
fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>;
|
|
|
|
|
2019-11-22 08:10:51 -06:00
|
|
|
#[salsa::invoke(FunctionData::fn_data_query)]
|
|
|
|
fn function_data(&self, func: FunctionId) -> Arc<FunctionData>;
|
|
|
|
|
2019-11-22 09:46:39 -06:00
|
|
|
#[salsa::invoke(ConstData::const_data_query)]
|
|
|
|
fn const_data(&self, konst: ConstId) -> Arc<ConstData>;
|
|
|
|
|
2020-05-10 10:08:28 -05:00
|
|
|
#[salsa::invoke(StaticData::static_data_query)]
|
|
|
|
fn static_data(&self, konst: StaticId) -> Arc<StaticData>;
|
2019-11-22 09:46:39 -06:00
|
|
|
|
2019-11-14 08:37:22 -06: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 11:33:18 -06:00
|
|
|
|
|
|
|
#[salsa::invoke(GenericParams::generic_params_query)]
|
2021-04-04 20:50:10 -05:00
|
|
|
fn generic_params(&self, def: GenericDefId) -> Interned<GenericParams>;
|
2019-11-23 02:14:10 -06:00
|
|
|
|
2021-01-04 14:56:21 -06:00
|
|
|
#[salsa::invoke(Attrs::variants_attrs_query)]
|
|
|
|
fn variants_attrs(&self, def: EnumId) -> Arc<ArenaMap<LocalEnumVariantId, Attrs>>;
|
|
|
|
|
|
|
|
#[salsa::invoke(Attrs::fields_attrs_query)]
|
|
|
|
fn fields_attrs(&self, def: VariantId) -> Arc<ArenaMap<LocalFieldId, Attrs>>;
|
|
|
|
|
2021-04-06 15:25:44 -05:00
|
|
|
#[salsa::invoke(crate::attr::variants_attrs_source_map)]
|
|
|
|
fn variants_attrs_source_map(
|
|
|
|
&self,
|
|
|
|
def: EnumId,
|
|
|
|
) -> Arc<ArenaMap<LocalEnumVariantId, AstPtr<ast::Variant>>>;
|
|
|
|
|
|
|
|
#[salsa::invoke(crate::attr::fields_attrs_source_map)]
|
|
|
|
fn fields_attrs_source_map(
|
|
|
|
&self,
|
|
|
|
def: VariantId,
|
|
|
|
) -> Arc<ArenaMap<LocalFieldId, Either<AstPtr<ast::TupleField>, AstPtr<ast::RecordField>>>>;
|
|
|
|
|
2021-03-19 15:23:57 -05:00
|
|
|
#[salsa::invoke(AttrsWithOwner::attrs_query)]
|
|
|
|
fn attrs(&self, def: AttrDefId) -> AttrsWithOwner;
|
2019-11-23 03:58:01 -06:00
|
|
|
|
|
|
|
#[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 05:43:38 -06:00
|
|
|
|
2020-05-20 16:51:20 -05:00
|
|
|
#[salsa::invoke(ImportMap::import_map_query)]
|
|
|
|
fn import_map(&self, krate: CrateId) -> Arc<ImportMap>;
|
2021-03-24 16:59:59 -05:00
|
|
|
|
|
|
|
#[salsa::invoke(visibility::field_visibilities_query)]
|
|
|
|
fn field_visibilities(&self, var: VariantId) -> Arc<ArenaMap<LocalFieldId, Visibility>>;
|
|
|
|
|
|
|
|
#[salsa::invoke(visibility::function_visibility_query)]
|
|
|
|
fn function_visibility(&self, def: FunctionId) -> Visibility;
|
2019-10-30 08:12:55 -05:00
|
|
|
}
|
2020-01-03 06:59:46 -06:00
|
|
|
|
2021-03-05 12:25:24 -06:00
|
|
|
fn crate_def_map_wait(db: &dyn DefDatabase, krate: CrateId) -> Arc<DefMap> {
|
2020-08-12 09:32:36 -05:00
|
|
|
let _p = profile::span("crate_def_map:wait");
|
2020-03-06 17:11:52 -06:00
|
|
|
db.crate_def_map_query(krate)
|
2020-01-03 06:59:46 -06:00
|
|
|
}
|