2019-11-27 08:46:02 -06:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
2020-08-13 09:25:38 -05:00
|
|
|
use base_db::{impl_intern_key, salsa, CrateId, Upcast};
|
2019-11-27 08:46:02 -06:00
|
|
|
use hir_def::{
|
2021-01-01 03:06:42 -06:00
|
|
|
db::DefDatabase, expr::ExprId, ConstParamId, DefWithBodyId, FunctionId, GenericDefId, ImplId,
|
|
|
|
LocalFieldId, TypeParamId, VariantId,
|
2019-11-27 08:46:02 -06:00
|
|
|
};
|
2021-01-14 18:11:07 -06:00
|
|
|
use la_arena::ArenaMap;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
|
|
|
use crate::{
|
2020-07-01 10:15:20 -05:00
|
|
|
method_resolution::{InherentImpls, TraitImpls},
|
2020-07-12 08:26:02 -05:00
|
|
|
traits::chalk,
|
2021-03-21 11:40:14 -05:00
|
|
|
Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, PolyFnSig,
|
|
|
|
QuantifiedWhereClause, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId,
|
2019-11-27 08:46:02 -06:00
|
|
|
};
|
2020-03-06 10:23:08 -06:00
|
|
|
use hir_expand::name::Name;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
|
|
|
#[salsa::query_group(HirDatabaseStorage)]
|
2020-03-13 10:05:46 -05:00
|
|
|
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>;
|
2020-01-03 10:02:08 -06:00
|
|
|
|
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)]
|
2020-01-25 16:38:33 -06:00
|
|
|
fn ty(&self, def: TyDefId) -> Binders<Ty>;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
|
|
|
#[salsa::invoke(crate::lower::value_ty_query)]
|
2020-01-25 16:38:33 -06:00
|
|
|
fn value_ty(&self, def: ValueTyDefId) -> Binders<Ty>;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
2019-11-30 05:35:37 -06:00
|
|
|
#[salsa::invoke(crate::lower::impl_self_ty_query)]
|
|
|
|
#[salsa::cycle(crate::lower::impl_self_ty_recover)]
|
2020-01-25 16:38:33 -06:00
|
|
|
fn impl_self_ty(&self, def: ImplId) -> Binders<Ty>;
|
2019-11-30 05:35:37 -06:00
|
|
|
|
2021-01-01 03:06:42 -06:00
|
|
|
#[salsa::invoke(crate::lower::const_param_ty_query)]
|
|
|
|
fn const_param_ty(&self, def: ConstParamId) -> Ty;
|
|
|
|
|
2019-11-30 05:35:37 -06:00
|
|
|
#[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)]
|
2020-07-16 06:15:00 -05:00
|
|
|
fn callable_item_signature(&self, def: CallableDefId) -> PolyFnSig;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
2020-03-04 16:00:44 -06:00
|
|
|
#[salsa::invoke(crate::lower::return_type_impl_traits)]
|
|
|
|
fn return_type_impl_traits(
|
|
|
|
&self,
|
|
|
|
def: FunctionId,
|
|
|
|
) -> Option<Arc<Binders<ReturnTypeImplTraits>>>;
|
|
|
|
|
2019-11-27 08:46:02 -06:00
|
|
|
#[salsa::invoke(crate::lower::generic_predicates_for_param_query)]
|
2019-11-30 05:39:21 -06:00
|
|
|
#[salsa::cycle(crate::lower::generic_predicates_for_param_recover)]
|
2021-03-21 11:40:14 -05:00
|
|
|
fn generic_predicates_for_param(
|
|
|
|
&self,
|
|
|
|
param_id: TypeParamId,
|
|
|
|
) -> Arc<[Binders<QuantifiedWhereClause>]>;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
|
|
|
#[salsa::invoke(crate::lower::generic_predicates_query)]
|
2021-03-21 11:40:14 -05:00
|
|
|
fn generic_predicates(&self, def: GenericDefId) -> Arc<[Binders<QuantifiedWhereClause>]>;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
2021-03-13 13:38:11 -06:00
|
|
|
#[salsa::invoke(crate::lower::trait_environment_query)]
|
|
|
|
fn trait_environment(&self, def: GenericDefId) -> Arc<crate::TraitEnvironment>;
|
|
|
|
|
2019-11-27 08:46:02 -06:00
|
|
|
#[salsa::invoke(crate::lower::generic_defaults_query)]
|
2020-06-26 09:36:59 -05:00
|
|
|
fn generic_defaults(&self, def: GenericDefId) -> Arc<[Binders<Ty>]>;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
2020-07-01 10:15:20 -05:00
|
|
|
#[salsa::invoke(InherentImpls::inherent_impls_in_crate_query)]
|
|
|
|
fn inherent_impls_in_crate(&self, krate: CrateId) -> Arc<InherentImpls>;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
2020-07-01 10:15:20 -05:00
|
|
|
#[salsa::invoke(TraitImpls::trait_impls_in_crate_query)]
|
|
|
|
fn trait_impls_in_crate(&self, krate: CrateId) -> Arc<TraitImpls>;
|
|
|
|
|
|
|
|
#[salsa::invoke(TraitImpls::trait_impls_in_deps_query)]
|
|
|
|
fn trait_impls_in_deps(&self, krate: CrateId) -> Arc<TraitImpls>;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
|
|
|
// Interned IDs for Chalk integration
|
|
|
|
#[salsa::interned]
|
2020-07-16 06:15:00 -05:00
|
|
|
fn intern_callable_def(&self, callable_def: CallableDefId) -> InternedCallableDefId;
|
2020-05-22 11:15:53 -05:00
|
|
|
#[salsa::interned]
|
2021-03-13 12:47:34 -06:00
|
|
|
fn intern_type_param_id(&self, param_id: TypeParamId) -> InternedTypeParamId;
|
2020-01-31 09:52:43 -06:00
|
|
|
#[salsa::interned]
|
2021-03-13 13:05:47 -06:00
|
|
|
fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId;
|
2020-03-04 16:00:44 -06:00
|
|
|
#[salsa::interned]
|
2021-03-13 12:27:09 -06:00
|
|
|
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
2019-12-21 07:29:33 -06:00
|
|
|
#[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
|
|
|
|
2019-12-21 07:29:33 -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
|
|
|
|
2019-12-21 07:29:33 -06:00
|
|
|
#[salsa::invoke(chalk::struct_datum_query)]
|
2020-05-22 10:50:58 -05:00
|
|
|
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)]
|
2019-12-21 07:29:33 -06:00
|
|
|
fn impl_datum(&self, krate: CrateId, impl_id: chalk::ImplId) -> Arc<chalk::ImplDatum>;
|
2019-11-27 08:46:02 -06:00
|
|
|
|
2020-05-22 11:15:53 -05:00
|
|
|
#[salsa::invoke(crate::traits::chalk::fn_def_datum_query)]
|
2021-03-13 10:55:50 -06:00
|
|
|
fn fn_def_datum(&self, krate: CrateId, fn_def_id: FnDefId) -> Arc<chalk::FnDefDatum>;
|
2020-11-20 11:00:34 -06:00
|
|
|
|
|
|
|
#[salsa::invoke(crate::traits::chalk::fn_def_variance_query)]
|
2021-03-13 10:55:50 -06:00
|
|
|
fn fn_def_variance(&self, krate: CrateId, fn_def_id: FnDefId) -> chalk::Variances;
|
2020-11-20 11:00:34 -06:00
|
|
|
|
|
|
|
#[salsa::invoke(crate::traits::chalk::adt_variance_query)]
|
|
|
|
fn adt_variance(&self, krate: CrateId, adt_id: chalk::AdtId) -> chalk::Variances;
|
2020-05-22 11:15:53 -05:00
|
|
|
|
2019-11-27 08:46:02 -06:00
|
|
|
#[salsa::invoke(crate::traits::chalk::associated_ty_value_query)]
|
|
|
|
fn associated_ty_value(
|
|
|
|
&self,
|
|
|
|
krate: CrateId,
|
2019-12-21 07:29:33 -06:00
|
|
|
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,
|
2021-03-20 05:23:59 -05:00
|
|
|
goal: crate::Canonical<crate::InEnvironment<crate::DomainGoal>>,
|
2019-11-27 08:46:02 -06:00
|
|
|
) -> Option<crate::traits::Solution>;
|
2020-04-18 06:36:35 -05:00
|
|
|
|
|
|
|
#[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
|
|
|
}
|
|
|
|
|
2021-03-05 12:25:24 -06:00
|
|
|
fn infer_wait(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
|
2020-08-12 09:32:36 -05:00
|
|
|
let _p = profile::span("infer:wait").detail(|| match def {
|
2020-03-06 10:23:08 -06:00
|
|
|
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)
|
2020-01-03 10:02:08 -06:00
|
|
|
}
|
|
|
|
|
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)]
|
2021-03-13 12:47:34 -06:00
|
|
|
pub struct InternedTypeParamId(salsa::InternId);
|
|
|
|
impl_intern_key!(InternedTypeParamId);
|
2020-03-04 16:00:44 -06:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
|
|
pub struct InternedOpaqueTyId(salsa::InternId);
|
|
|
|
impl_intern_key!(InternedOpaqueTyId);
|
2020-07-12 08:26:02 -05:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
2021-03-13 12:27:09 -06:00
|
|
|
pub struct InternedClosureId(salsa::InternId);
|
|
|
|
impl_intern_key!(InternedClosureId);
|
2020-07-16 06:13:17 -05:00
|
|
|
|
|
|
|
/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
|
|
|
|
/// we have different IDs for struct and enum variant constructors.
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
|
|
|
pub struct InternedCallableDefId(salsa::InternId);
|
|
|
|
impl_intern_key!(InternedCallableDefId);
|