1 //! Defines database & queries for name resolution.
4 use base_db::{salsa, CrateId, SourceDatabase, Upcast};
5 use hir_expand::{db::AstDatabase, AstId, HirFileId};
6 use la_arena::ArenaMap;
7 use syntax::{ast, SmolStr};
10 adt::{EnumData, StructData},
12 body::{scope::ExprScopes, Body, BodySourceMap},
13 data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData},
14 generics::GenericParams,
15 import_map::ImportMap,
17 lang_item::{LangItemTarget, LangItems},
19 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
20 GenericDefId, ImplId, ImplLoc, LocalEnumVariantId, LocalFieldId, StaticId, StaticLoc, StructId,
21 StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, VariantId,
24 #[salsa::query_group(InternDatabaseStorage)]
25 pub trait InternDatabase: SourceDatabase {
27 fn intern_function(&self, loc: FunctionLoc) -> FunctionId;
29 fn intern_struct(&self, loc: StructLoc) -> StructId;
31 fn intern_union(&self, loc: UnionLoc) -> UnionId;
33 fn intern_enum(&self, loc: EnumLoc) -> EnumId;
35 fn intern_const(&self, loc: ConstLoc) -> ConstId;
37 fn intern_static(&self, loc: StaticLoc) -> StaticId;
39 fn intern_trait(&self, loc: TraitLoc) -> TraitId;
41 fn intern_type_alias(&self, loc: TypeAliasLoc) -> TypeAliasId;
43 fn intern_impl(&self, loc: ImplLoc) -> ImplId;
46 #[salsa::query_group(DefDatabaseStorage)]
47 pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
48 #[salsa::invoke(ItemTree::item_tree_query)]
49 fn item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>;
51 #[salsa::invoke(crate_def_map_wait)]
53 fn crate_def_map(&self, krate: CrateId) -> Arc<DefMap>;
55 #[salsa::invoke(DefMap::crate_def_map_query)]
56 fn crate_def_map_query(&self, krate: CrateId) -> Arc<DefMap>;
58 #[salsa::invoke(DefMap::block_def_map_query)]
59 fn block_def_map(&self, krate: CrateId, block: AstId<ast::BlockExpr>) -> Arc<DefMap>;
61 #[salsa::invoke(StructData::struct_data_query)]
62 fn struct_data(&self, id: StructId) -> Arc<StructData>;
63 #[salsa::invoke(StructData::union_data_query)]
64 fn union_data(&self, id: UnionId) -> Arc<StructData>;
66 #[salsa::invoke(EnumData::enum_data_query)]
67 fn enum_data(&self, e: EnumId) -> Arc<EnumData>;
69 #[salsa::invoke(ImplData::impl_data_query)]
70 fn impl_data(&self, e: ImplId) -> Arc<ImplData>;
72 #[salsa::invoke(TraitData::trait_data_query)]
73 fn trait_data(&self, e: TraitId) -> Arc<TraitData>;
75 #[salsa::invoke(TypeAliasData::type_alias_data_query)]
76 fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>;
78 #[salsa::invoke(FunctionData::fn_data_query)]
79 fn function_data(&self, func: FunctionId) -> Arc<FunctionData>;
81 #[salsa::invoke(ConstData::const_data_query)]
82 fn const_data(&self, konst: ConstId) -> Arc<ConstData>;
84 #[salsa::invoke(StaticData::static_data_query)]
85 fn static_data(&self, konst: StaticId) -> Arc<StaticData>;
87 #[salsa::invoke(Body::body_with_source_map_query)]
88 fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
90 #[salsa::invoke(Body::body_query)]
91 fn body(&self, def: DefWithBodyId) -> Arc<Body>;
93 #[salsa::invoke(ExprScopes::expr_scopes_query)]
94 fn expr_scopes(&self, def: DefWithBodyId) -> Arc<ExprScopes>;
96 #[salsa::invoke(GenericParams::generic_params_query)]
97 fn generic_params(&self, def: GenericDefId) -> Arc<GenericParams>;
99 #[salsa::invoke(Attrs::variants_attrs_query)]
100 fn variants_attrs(&self, def: EnumId) -> Arc<ArenaMap<LocalEnumVariantId, Attrs>>;
102 #[salsa::invoke(Attrs::fields_attrs_query)]
103 fn fields_attrs(&self, def: VariantId) -> Arc<ArenaMap<LocalFieldId, Attrs>>;
105 #[salsa::invoke(Attrs::attrs_query)]
106 fn attrs(&self, def: AttrDefId) -> Attrs;
108 #[salsa::invoke(LangItems::crate_lang_items_query)]
109 fn crate_lang_items(&self, krate: CrateId) -> Arc<LangItems>;
111 #[salsa::invoke(LangItems::lang_item_query)]
112 fn lang_item(&self, start_crate: CrateId, item: SmolStr) -> Option<LangItemTarget>;
114 #[salsa::invoke(ImportMap::import_map_query)]
115 fn import_map(&self, krate: CrateId) -> Arc<ImportMap>;
118 fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<DefMap> {
119 let _p = profile::span("crate_def_map:wait");
120 db.crate_def_map_query(krate)