rust/crates/ra_hir_ty/src/db.rs

145 lines
5.3 KiB
Rust
Raw Normal View History

2019-11-27 08:46:02 -06:00
//! FIXME: write short doc here
use std::sync::Arc;
use hir_def::{
2020-04-25 07:23:34 -05:00
db::DefDatabase, DefWithBodyId, GenericDefId, ImplId, LocalFieldId, TraitId, TypeParamId,
2020-02-07 08:13:15 -06:00
VariantId,
2019-11-27 08:46:02 -06:00
};
use ra_arena::map::ArenaMap;
use ra_db::{impl_intern_key, salsa, CrateId, Upcast};
use ra_prof::profile;
2019-11-27 08:46:02 -06:00
use crate::{
method_resolution::{CrateImplDefs, TyFingerprint},
traits::{chalk, AssocTyValue, Impl},
2020-02-07 08:13:15 -06:00
Binders, CallableDef, GenericPredicate, InferenceResult, PolyFnSig, Substs, TraitRef, Ty,
TyDefId, TypeCtor, ValueTyDefId,
2019-11-27 08:46:02 -06:00
};
use hir_expand::name::Name;
2019-11-27 08:46:02 -06:00
#[salsa::query_group(HirDatabaseStorage)]
#[salsa::requires(salsa::Database)]
pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
2020-03-06 17:11:52 -06:00
#[salsa::invoke(infer_wait)]
2020-03-25 12:41:46 -05:00
#[salsa::transparent]
2019-11-27 08:46:02 -06:00
fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
2020-03-06 17:11:52 -06:00
#[salsa::invoke(crate::infer::infer_query)]
fn infer_query(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::lower::ty_query)]
2019-11-30 05:48:51 -06:00
#[salsa::cycle(crate::lower::ty_recover)]
fn ty(&self, def: TyDefId) -> Binders<Ty>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::lower::value_ty_query)]
fn value_ty(&self, def: ValueTyDefId) -> Binders<Ty>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::lower::impl_self_ty_query)]
#[salsa::cycle(crate::lower::impl_self_ty_recover)]
fn impl_self_ty(&self, def: ImplId) -> Binders<Ty>;
#[salsa::invoke(crate::lower::impl_trait_query)]
2020-01-31 09:52:43 -06:00
fn impl_trait(&self, def: ImplId) -> Option<Binders<TraitRef>>;
2019-11-27 13:12:09 -06:00
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::lower::field_types_query)]
2020-04-25 07:23:34 -05:00
fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalFieldId, Binders<Ty>>>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::callable_item_sig)]
fn callable_item_signature(&self, def: CallableDef) -> PolyFnSig;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::lower::generic_predicates_for_param_query)]
#[salsa::cycle(crate::lower::generic_predicates_for_param_recover)]
2019-11-27 08:46:02 -06:00
fn generic_predicates_for_param(
&self,
2020-01-31 09:52:43 -06:00
param_id: TypeParamId,
2020-02-02 10:11:54 -06:00
) -> Arc<[Binders<GenericPredicate>]>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::lower::generic_predicates_query)]
2020-02-02 10:11:54 -06:00
fn generic_predicates(&self, def: GenericDefId) -> Arc<[Binders<GenericPredicate>]>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::lower::generic_defaults_query)]
fn generic_defaults(&self, def: GenericDefId) -> Substs;
2020-02-29 14:24:40 -06:00
#[salsa::invoke(crate::method_resolution::CrateImplDefs::impls_in_crate_query)]
fn impls_in_crate(&self, krate: CrateId) -> Arc<CrateImplDefs>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::traits::impls_for_trait_query)]
fn impls_for_trait(
&self,
krate: CrateId,
trait_: TraitId,
self_ty_fp: Option<TyFingerprint>,
) -> Arc<[ImplId]>;
2019-11-27 08:46:02 -06:00
// Interned IDs for Chalk integration
#[salsa::interned]
fn intern_type_ctor(&self, type_ctor: TypeCtor) -> crate::TypeCtorId;
#[salsa::interned]
fn intern_callable_def(&self, callable_def: CallableDef) -> crate::CallableDefId;
#[salsa::interned]
2020-01-31 09:52:43 -06:00
fn intern_type_param_id(&self, param_id: TypeParamId) -> GlobalTypeParamId;
#[salsa::interned]
2019-11-27 08:46:02 -06:00
fn intern_chalk_impl(&self, impl_: Impl) -> crate::traits::GlobalImplId;
#[salsa::interned]
fn intern_assoc_ty_value(&self, assoc_ty_value: AssocTyValue) -> crate::traits::AssocTyValueId;
#[salsa::invoke(chalk::associated_ty_data_query)]
fn associated_ty_data(&self, id: chalk::AssocTypeId) -> Arc<chalk::AssociatedTyDatum>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(chalk::trait_datum_query)]
fn trait_datum(&self, krate: CrateId, trait_id: chalk::TraitId) -> Arc<chalk::TraitDatum>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(chalk::struct_datum_query)]
fn struct_datum(&self, krate: CrateId, struct_id: chalk::AdtId) -> Arc<chalk::StructDatum>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::traits::chalk::impl_datum_query)]
fn impl_datum(&self, krate: CrateId, impl_id: chalk::ImplId) -> Arc<chalk::ImplDatum>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::traits::chalk::fn_def_datum_query)]
fn fn_def_datum(&self, krate: CrateId, fn_def_id: chalk::FnDefId) -> Arc<chalk::FnDefDatum>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::traits::chalk::associated_ty_value_query)]
fn associated_ty_value(
&self,
krate: CrateId,
id: chalk::AssociatedTyValueId,
) -> Arc<chalk::AssociatedTyValue>;
2019-11-27 08:46:02 -06:00
#[salsa::invoke(crate::traits::trait_solve_query)]
fn trait_solve(
&self,
krate: CrateId,
goal: crate::Canonical<crate::InEnvironment<crate::Obligation>>,
) -> Option<crate::traits::Solution>;
#[salsa::invoke(crate::traits::chalk::program_clauses_for_chalk_env_query)]
fn program_clauses_for_chalk_env(
&self,
krate: CrateId,
env: chalk_ir::Environment<chalk::Interner>,
) -> chalk_ir::ProgramClauses<chalk::Interner>;
2019-11-27 08:46:02 -06:00
}
2020-03-06 17:11:52 -06:00
fn infer_wait(db: &impl HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
let _p = profile("infer:wait").detail(|| match def {
DefWithBodyId::FunctionId(it) => db.function_data(it).name.to_string(),
DefWithBodyId::StaticId(it) => {
db.static_data(it).name.clone().unwrap_or_else(Name::missing).to_string()
}
DefWithBodyId::ConstId(it) => {
db.const_data(it).name.clone().unwrap_or_else(Name::missing).to_string()
}
});
2020-03-06 17:11:52 -06:00
db.infer_query(def)
}
2019-11-27 08:46:02 -06:00
#[test]
fn hir_database_is_object_safe() {
fn _assert_object_safe(_: &dyn HirDatabase) {}
}
2020-01-31 09:52:43 -06:00
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GlobalTypeParamId(salsa::InternId);
impl_intern_key!(GlobalTypeParamId);