2019-06-01 02:57:44 -05:00
|
|
|
use std::sync::Arc;
|
2018-11-27 18:42:26 -06:00
|
|
|
|
2019-06-01 02:57:44 -05:00
|
|
|
use parking_lot::Mutex;
|
2019-05-13 17:42:59 -05:00
|
|
|
use ra_syntax::{SyntaxNode, TreeArc, SmolStr, ast};
|
2019-03-26 05:09:39 -05:00
|
|
|
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-06-18 12:07:35 -05:00
|
|
|
Function, FnData, ExprScopes, TypeAlias,
|
2019-01-25 05:21:14 -06:00
|
|
|
Struct, Enum, StructField,
|
2019-06-18 12:07:35 -05:00
|
|
|
Const, ConstData, Static,
|
2019-04-20 05:34:36 -05:00
|
|
|
DefWithBody, Trait,
|
|
|
|
ids,
|
2019-03-16 09:17:50 -05:00
|
|
|
nameres::{Namespace, ImportSourceMap, RawItems, CrateDefMap},
|
2019-05-19 08:08:16 -05:00
|
|
|
ty::{InferenceResult, Ty, method_resolution::CrateImplBlocks, TypableDef, CallableDef, FnSig, TypeCtor, GenericPredicate, Substs},
|
2019-01-25 03:41:23 -06:00
|
|
|
adt::{StructData, EnumData},
|
2019-04-20 05:34:36 -05:00
|
|
|
impl_block::{ModuleImplBlocks, ImplSourceMap, ImplBlock},
|
2019-01-24 06:28:50 -06:00
|
|
|
generics::{GenericParams, GenericDef},
|
2019-04-20 05:34:36 -05:00
|
|
|
traits::TraitData,
|
2019-05-12 10:53:44 -05:00
|
|
|
lang_item::{LangItems, LangItemTarget}, type_alias::TypeAliasData,
|
2018-11-27 18:42:26 -06:00
|
|
|
};
|
|
|
|
|
2019-06-01 13:17:57 -05:00
|
|
|
// This database has access to source code, so queries here are not really
|
|
|
|
// incremental.
|
|
|
|
#[salsa::query_group(AstDatabaseStorage)]
|
|
|
|
pub trait AstDatabase: SourceDatabase {
|
2019-04-09 14:51:22 -05:00
|
|
|
#[salsa::interned]
|
|
|
|
fn intern_macro(&self, macro_call: MacroCallLoc) -> ids::MacroCallId;
|
2019-06-01 13:17:57 -05:00
|
|
|
|
|
|
|
#[salsa::invoke(crate::source_id::AstIdMap::ast_id_map_query)]
|
|
|
|
fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>;
|
|
|
|
#[salsa::transparent]
|
|
|
|
#[salsa::invoke(crate::source_id::AstIdMap::file_item_query)]
|
|
|
|
fn ast_id_to_node(&self, file_id: HirFileId, ast_id: ErasedFileAstId) -> TreeArc<SyntaxNode>;
|
2019-06-02 12:15:10 -05:00
|
|
|
#[salsa::transparent]
|
2019-06-01 13:17:57 -05:00
|
|
|
#[salsa::invoke(crate::ids::HirFileId::parse_or_expand_query)]
|
|
|
|
fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>;
|
2019-06-02 12:15:10 -05:00
|
|
|
#[salsa::invoke(crate::ids::HirFileId::parse_macro_query)]
|
|
|
|
fn parse_macro(&self, macro_file: ids::MacroFile) -> Option<TreeArc<SyntaxNode>>;
|
2019-06-01 13:17:57 -05:00
|
|
|
|
|
|
|
#[salsa::invoke(crate::ids::macro_def_query)]
|
|
|
|
fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>;
|
|
|
|
|
|
|
|
#[salsa::invoke(crate::ids::macro_arg_query)]
|
|
|
|
fn macro_arg(&self, macro_call: ids::MacroCallId) -> Option<Arc<tt::Subtree>>;
|
|
|
|
|
|
|
|
#[salsa::invoke(crate::ids::macro_expand_query)]
|
|
|
|
fn macro_expand(&self, macro_call: ids::MacroCallId) -> Result<Arc<tt::Subtree>, String>;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This database uses `AstDatabase` internally,
|
|
|
|
#[salsa::query_group(DefDatabaseStorage)]
|
|
|
|
#[salsa::requires(AstDatabase)]
|
|
|
|
pub trait DefDatabase: SourceDatabase {
|
2019-04-09 14:51:22 -05:00
|
|
|
#[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-04-20 05:34:36 -05:00
|
|
|
// Interned IDs for Chalk integration
|
|
|
|
#[salsa::interned]
|
|
|
|
fn intern_type_ctor(&self, type_ctor: TypeCtor) -> ids::TypeCtorId;
|
|
|
|
#[salsa::interned]
|
|
|
|
fn intern_impl_block(&self, impl_block: ImplBlock) -> ids::GlobalImplId;
|
|
|
|
|
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>;
|
|
|
|
|
2019-03-31 13:02:16 -05:00
|
|
|
#[salsa::invoke(crate::traits::TraitItemsIndex::trait_items_index)]
|
|
|
|
fn trait_items_index(&self, module: Module) -> crate::traits::TraitItemsIndex;
|
|
|
|
|
2019-03-13 08:38:02 -05:00
|
|
|
#[salsa::invoke(RawItems::raw_items_query)]
|
2019-03-26 05:09:39 -05:00
|
|
|
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)]
|
2019-03-26 05:09:39 -05:00
|
|
|
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)]
|
2019-01-23 14:14:13 -06:00
|
|
|
fn impls_in_module(&self, module: Module) -> Arc<ModuleImplBlocks>;
|
2019-01-17 05:11:00 -06:00
|
|
|
|
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-12 14:27:35 -06:00
|
|
|
|
2019-06-18 12:07:35 -05:00
|
|
|
#[salsa::invoke(crate::FnData::fn_data_query)]
|
|
|
|
fn fn_data(&self, func: Function) -> Arc<FnData>;
|
2019-02-24 10:25:41 -06:00
|
|
|
|
2019-05-12 10:53:44 -05:00
|
|
|
#[salsa::invoke(crate::type_alias::type_alias_data_query)]
|
|
|
|
fn type_alias_data(&self, typ: TypeAlias) -> Arc<TypeAliasData>;
|
2019-02-25 01:27:47 -06:00
|
|
|
|
2019-06-18 12:07:35 -05:00
|
|
|
#[salsa::invoke(crate::ConstData::const_data_query)]
|
|
|
|
fn const_data(&self, konst: Const) -> Arc<ConstData>;
|
2019-02-25 02:21:01 -06:00
|
|
|
|
2019-06-18 12:07:35 -05:00
|
|
|
#[salsa::invoke(crate::ConstData::static_data_query)]
|
|
|
|
fn static_data(&self, konst: Static) -> Arc<ConstData>;
|
2019-04-14 17:03:54 -05:00
|
|
|
|
|
|
|
#[salsa::invoke(crate::lang_item::LangItems::lang_items_query)]
|
|
|
|
fn lang_items(&self, krate: Crate) -> Arc<LangItems>;
|
2019-04-18 13:34:10 -05:00
|
|
|
|
|
|
|
#[salsa::invoke(crate::lang_item::LangItems::lang_item_query)]
|
|
|
|
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-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)]
|
2019-03-30 06:17:31 -05:00
|
|
|
fn infer(&self, def: DefWithBody) -> Arc<InferenceResult>;
|
2019-01-31 08:28:31 -06:00
|
|
|
|
|
|
|
#[salsa::invoke(crate::ty::type_for_def)]
|
2019-02-17 10:29:51 -06:00
|
|
|
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;
|
|
|
|
|
2019-03-16 11:29:55 -05:00
|
|
|
#[salsa::invoke(crate::ty::callable_item_sig)]
|
|
|
|
fn callable_item_signature(&self, def: CallableDef) -> FnSig;
|
|
|
|
|
2019-05-05 07:21:00 -05:00
|
|
|
#[salsa::invoke(crate::ty::generic_predicates)]
|
|
|
|
fn generic_predicates(&self, def: GenericDef) -> Arc<[GenericPredicate]>;
|
|
|
|
|
2019-05-19 08:08:16 -05:00
|
|
|
#[salsa::invoke(crate::ty::generic_defaults)]
|
|
|
|
fn generic_defaults(&self, def: GenericDef) -> Substs;
|
|
|
|
|
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>;
|
2019-03-24 11:37:27 -05:00
|
|
|
|
2019-05-21 04:44:08 -05:00
|
|
|
#[salsa::invoke(crate::ty::traits::impls_for_trait_query)]
|
2019-04-20 05:34:36 -05:00
|
|
|
fn impls_for_trait(&self, krate: Crate, trait_: Trait) -> Arc<[ImplBlock]>;
|
|
|
|
|
2019-05-01 10:13:33 -05:00
|
|
|
/// 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
|
|
|
|
/// Mutex and the query is marked volatile, to make sure the cached state is
|
|
|
|
/// thrown away when input facts change.
|
2019-05-21 04:44:08 -05:00
|
|
|
#[salsa::invoke(crate::ty::traits::solver_query)]
|
2019-04-20 05:34:36 -05:00
|
|
|
#[salsa::volatile]
|
2019-05-01 10:13:33 -05:00
|
|
|
fn solver(&self, krate: Crate) -> Arc<Mutex<crate::ty::traits::Solver>>;
|
2019-05-05 09:04:31 -05:00
|
|
|
|
2019-05-21 04:44:08 -05:00
|
|
|
#[salsa::invoke(crate::ty::traits::implements_query)]
|
2019-05-05 09:04:31 -05:00
|
|
|
fn implements(
|
|
|
|
&self,
|
|
|
|
krate: Crate,
|
|
|
|
goal: crate::ty::Canonical<crate::ty::TraitRef>,
|
|
|
|
) -> Option<crate::ty::traits::Solution>;
|
2019-05-12 10:53:44 -05:00
|
|
|
|
2019-06-16 05:04:08 -05:00
|
|
|
#[salsa::invoke(crate::ty::traits::normalize_query)]
|
2019-05-12 10:53:44 -05:00
|
|
|
fn normalize(
|
|
|
|
&self,
|
|
|
|
krate: Crate,
|
2019-06-16 05:04:08 -05:00
|
|
|
goal: crate::ty::Canonical<crate::ty::ProjectionPredicate>,
|
2019-05-12 10:53:44 -05:00
|
|
|
) -> 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) {}
|
|
|
|
}
|