mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 01:38:13 +00:00
Merge #8001
8001: More Chalk IDs r=flodiebold a=flodiebold Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
commit
17eeb2a6d2
10 changed files with 122 additions and 129 deletions
|
@ -1384,7 +1384,7 @@ impl TypeParam {
|
|||
pub fn ty(self, db: &dyn HirDatabase) -> Type {
|
||||
let resolver = self.id.parent.resolver(db.upcast());
|
||||
let krate = self.id.parent.module(db.upcast()).krate();
|
||||
let ty = TyKind::Placeholder(self.id).intern(&Interner);
|
||||
let ty = TyKind::Placeholder(hir_ty::to_placeholder_idx(db, self.id)).intern(&Interner);
|
||||
Type::new_with_resolver_inner(db, krate, &resolver, ty)
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use la_arena::ArenaMap;
|
|||
use crate::{
|
||||
method_resolution::{InherentImpls, TraitImpls},
|
||||
traits::chalk,
|
||||
Binders, CallableDefId, FnDefId, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig,
|
||||
Binders, CallableDefId, FnDefId, GenericPredicate, ImplTraitId, InferenceResult, PolyFnSig,
|
||||
ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId,
|
||||
};
|
||||
use hir_expand::name::Name;
|
||||
|
@ -81,11 +81,11 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
|||
#[salsa::interned]
|
||||
fn intern_callable_def(&self, callable_def: CallableDefId) -> InternedCallableDefId;
|
||||
#[salsa::interned]
|
||||
fn intern_type_param_id(&self, param_id: TypeParamId) -> GlobalTypeParamId;
|
||||
fn intern_type_param_id(&self, param_id: TypeParamId) -> InternedTypeParamId;
|
||||
#[salsa::interned]
|
||||
fn intern_impl_trait_id(&self, id: OpaqueTyId) -> InternedOpaqueTyId;
|
||||
fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId;
|
||||
#[salsa::interned]
|
||||
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> ClosureId;
|
||||
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
|
||||
|
||||
#[salsa::invoke(chalk::associated_ty_data_query)]
|
||||
fn associated_ty_data(&self, id: chalk::AssocTypeId) -> Arc<chalk::AssociatedTyDatum>;
|
||||
|
@ -149,16 +149,16 @@ fn hir_database_is_object_safe() {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct GlobalTypeParamId(salsa::InternId);
|
||||
impl_intern_key!(GlobalTypeParamId);
|
||||
pub struct InternedTypeParamId(salsa::InternId);
|
||||
impl_intern_key!(InternedTypeParamId);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct InternedOpaqueTyId(salsa::InternId);
|
||||
impl_intern_key!(InternedOpaqueTyId);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct ClosureId(salsa::InternId);
|
||||
impl_intern_key!(ClosureId);
|
||||
pub struct InternedClosureId(salsa::InternId);
|
||||
impl_intern_key!(InternedClosureId);
|
||||
|
||||
/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
|
||||
/// we have different IDs for struct and enum variant constructors.
|
||||
|
|
|
@ -11,10 +11,10 @@ use hir_def::{
|
|||
use hir_expand::name::Name;
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase, from_assoc_type_id, from_foreign_def_id, primitive, to_assoc_type_id,
|
||||
traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId, CallableSig,
|
||||
GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar,
|
||||
Substs, TraitRef, Ty, TyKind,
|
||||
db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive,
|
||||
to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId,
|
||||
CallableSig, GenericPredicate, ImplTraitId, Interner, Lifetime, Obligation, OpaqueTy,
|
||||
ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind,
|
||||
};
|
||||
|
||||
pub struct HirFormatter<'a> {
|
||||
|
@ -313,22 +313,26 @@ impl HirDisplay for Ty {
|
|||
)?;
|
||||
}
|
||||
|
||||
// FIXME: all this just to decide whether to use parentheses...
|
||||
let datas;
|
||||
let predicates = match t.interned(&Interner) {
|
||||
TyKind::Dyn(predicates) if predicates.len() > 1 => {
|
||||
Cow::Borrowed(predicates.as_ref())
|
||||
}
|
||||
&TyKind::Alias(AliasTy::Opaque(OpaqueTy {
|
||||
opaque_ty_id: OpaqueTyId::ReturnTypeImplTrait(func, idx),
|
||||
ref parameters,
|
||||
})) => {
|
||||
&TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, ref parameters })) => {
|
||||
let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty_id.into());
|
||||
if let ImplTraitId::ReturnTypeImplTrait(func, idx) = impl_trait_id {
|
||||
datas =
|
||||
f.db.return_type_impl_traits(func).expect("impl trait id without data");
|
||||
f.db.return_type_impl_traits(func)
|
||||
.expect("impl trait id without data");
|
||||
let data = (*datas)
|
||||
.as_ref()
|
||||
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
|
||||
let bounds = data.subst(parameters);
|
||||
Cow::Owned(bounds.value)
|
||||
} else {
|
||||
Cow::Borrowed(&[][..])
|
||||
}
|
||||
}
|
||||
_ => Cow::Borrowed(&[][..]),
|
||||
};
|
||||
|
@ -499,8 +503,9 @@ impl HirDisplay for Ty {
|
|||
write!(f, "{}", type_alias.name)?;
|
||||
}
|
||||
TyKind::OpaqueType(opaque_ty_id, parameters) => {
|
||||
match opaque_ty_id {
|
||||
&OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
|
||||
let impl_trait_id = f.db.lookup_intern_impl_trait_id((*opaque_ty_id).into());
|
||||
match impl_trait_id {
|
||||
ImplTraitId::ReturnTypeImplTrait(func, idx) => {
|
||||
let datas =
|
||||
f.db.return_type_impl_traits(func).expect("impl trait id without data");
|
||||
let data = (*datas)
|
||||
|
@ -510,7 +515,7 @@ impl HirDisplay for Ty {
|
|||
write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?;
|
||||
// FIXME: it would maybe be good to distinguish this from the alias type (when debug printing), and to show the substitution
|
||||
}
|
||||
OpaqueTyId::AsyncBlockTypeImplTrait(..) => {
|
||||
ImplTraitId::AsyncBlockTypeImplTrait(..) => {
|
||||
write!(f, "impl Future<Output = ")?;
|
||||
parameters[0].hir_fmt(f)?;
|
||||
write!(f, ">")?;
|
||||
|
@ -541,7 +546,8 @@ impl HirDisplay for Ty {
|
|||
write!(f, "{{closure}}")?;
|
||||
}
|
||||
}
|
||||
TyKind::Placeholder(id) => {
|
||||
TyKind::Placeholder(idx) => {
|
||||
let id = from_placeholder_idx(f.db, *idx);
|
||||
let generics = generics(f.db.upcast(), id.parent);
|
||||
let param_data = &generics.params.types[id.local_id];
|
||||
match param_data.provenance {
|
||||
|
@ -549,8 +555,8 @@ impl HirDisplay for Ty {
|
|||
write!(f, "{}", param_data.name.clone().unwrap_or_else(Name::missing))?
|
||||
}
|
||||
TypeParamProvenance::ArgumentImplTrait => {
|
||||
let bounds = f.db.generic_predicates_for_param(*id);
|
||||
let substs = Substs::type_params_for_generics(&generics);
|
||||
let bounds = f.db.generic_predicates_for_param(id);
|
||||
let substs = Substs::type_params_for_generics(f.db, &generics);
|
||||
write_bounds_like_dyn_trait_with_prefix(
|
||||
"impl",
|
||||
&bounds.iter().map(|b| b.clone().subst(&substs)).collect::<Vec<_>>(),
|
||||
|
@ -565,8 +571,9 @@ impl HirDisplay for Ty {
|
|||
}
|
||||
TyKind::Alias(AliasTy::Projection(p_ty)) => p_ty.hir_fmt(f)?,
|
||||
TyKind::Alias(AliasTy::Opaque(opaque_ty)) => {
|
||||
match opaque_ty.opaque_ty_id {
|
||||
OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
|
||||
let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty.opaque_ty_id.into());
|
||||
match impl_trait_id {
|
||||
ImplTraitId::ReturnTypeImplTrait(func, idx) => {
|
||||
let datas =
|
||||
f.db.return_type_impl_traits(func).expect("impl trait id without data");
|
||||
let data = (*datas)
|
||||
|
@ -575,7 +582,7 @@ impl HirDisplay for Ty {
|
|||
let bounds = data.subst(&opaque_ty.parameters);
|
||||
write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?;
|
||||
}
|
||||
OpaqueTyId::AsyncBlockTypeImplTrait(..) => {
|
||||
ImplTraitId::AsyncBlockTypeImplTrait(..) => {
|
||||
write!(f, "{{async block}}")?;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -454,7 +454,7 @@ impl<'a> InferenceContext<'a> {
|
|||
}
|
||||
TypeNs::SelfType(impl_id) => {
|
||||
let generics = crate::utils::generics(self.db.upcast(), impl_id.into());
|
||||
let substs = Substs::type_params_for_generics(&generics);
|
||||
let substs = Substs::type_params_for_generics(self.db, &generics);
|
||||
let ty = self.db.impl_self_ty(impl_id).subst(&substs);
|
||||
match unresolved {
|
||||
None => {
|
||||
|
|
|
@ -21,8 +21,8 @@ use crate::{
|
|||
to_assoc_type_id,
|
||||
traits::{chalk::from_chalk, FnTrait, InEnvironment},
|
||||
utils::{generics, variant_data, Generics},
|
||||
AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, OpaqueTyId, Rawness,
|
||||
Scalar, Substs, TraitRef, Ty, TyKind,
|
||||
AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, Rawness, Scalar, Substs,
|
||||
TraitRef, Ty, TyKind,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
@ -179,7 +179,8 @@ impl<'a> InferenceContext<'a> {
|
|||
// Use the first type parameter as the output type of future.
|
||||
// existenail type AsyncBlockImplTrait<InnerType>: Future<Output = InnerType>
|
||||
let inner_ty = self.infer_expr(*body, &Expectation::none());
|
||||
let opaque_ty_id = OpaqueTyId::AsyncBlockTypeImplTrait(self.owner, *body);
|
||||
let impl_trait_id = crate::ImplTraitId::AsyncBlockTypeImplTrait(self.owner, *body);
|
||||
let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into();
|
||||
TyKind::OpaqueType(opaque_ty_id, Substs::single(inner_ty)).intern(&Interner)
|
||||
}
|
||||
Expr::Loop { body, label } => {
|
||||
|
@ -264,8 +265,9 @@ impl<'a> InferenceContext<'a> {
|
|||
substs: Substs(sig_tys.clone().into()),
|
||||
})
|
||||
.intern(&Interner);
|
||||
let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
|
||||
let closure_ty =
|
||||
TyKind::Closure(self.owner, tgt_expr, Substs::single(sig_ty)).intern(&Interner);
|
||||
TyKind::Closure(closure_id, Substs::single(sig_ty)).intern(&Interner);
|
||||
|
||||
// Eagerly try to relate the closure type with the expected
|
||||
// type, otherwise we often won't have enough information to
|
||||
|
|
|
@ -79,7 +79,7 @@ impl<'a> InferenceContext<'a> {
|
|||
}
|
||||
ValueNs::ImplSelf(impl_id) => {
|
||||
let generics = crate::utils::generics(self.db.upcast(), impl_id.into());
|
||||
let substs = Substs::type_params_for_generics(&generics);
|
||||
let substs = Substs::type_params_for_generics(self.db, &generics);
|
||||
let ty = self.db.impl_self_ty(impl_id).subst(&substs);
|
||||
if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() {
|
||||
let ty = self.db.value_ty(struct_id.into()).subst(&substs);
|
||||
|
|
|
@ -27,9 +27,8 @@ use std::{iter, mem, ops::Deref, sync::Arc};
|
|||
|
||||
use base_db::salsa;
|
||||
use hir_def::{
|
||||
builtin_type::BuiltinType, expr::ExprId, type_ref::Rawness, AssocContainerId, DefWithBodyId,
|
||||
FunctionId, GenericDefId, HasModule, LifetimeParamId, Lookup, TraitId, TypeAliasId,
|
||||
TypeParamId,
|
||||
builtin_type::BuiltinType, expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId,
|
||||
GenericDefId, HasModule, LifetimeParamId, Lookup, TraitId, TypeAliasId, TypeParamId,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
|
||||
|
@ -53,7 +52,10 @@ pub use crate::traits::chalk::Interner;
|
|||
|
||||
pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
|
||||
pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
|
||||
pub(crate) type FnDefId = chalk_ir::FnDefId<Interner>;
|
||||
pub type FnDefId = chalk_ir::FnDefId<Interner>;
|
||||
pub type ClosureId = chalk_ir::ClosureId<Interner>;
|
||||
pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
|
||||
pub type PlaceholderIndex = chalk_ir::PlaceholderIndex;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum Lifetime {
|
||||
|
@ -195,7 +197,7 @@ pub enum TyKind {
|
|||
///
|
||||
/// The closure signature is stored in a `FnPtr` type in the first type
|
||||
/// parameter.
|
||||
Closure(DefWithBodyId, ExprId, Substs),
|
||||
Closure(ClosureId, Substs),
|
||||
|
||||
/// Represents a foreign type declared in external blocks.
|
||||
ForeignType(ForeignDefId),
|
||||
|
@ -220,7 +222,7 @@ pub enum TyKind {
|
|||
/// {}` when we're type-checking the body of that function. In this
|
||||
/// situation, we know this stands for *some* type, but don't know the exact
|
||||
/// type.
|
||||
Placeholder(TypeParamId),
|
||||
Placeholder(PlaceholderIndex),
|
||||
|
||||
/// A bound type variable. This is used in various places: when representing
|
||||
/// some polymorphic type like the type of function `fn f<T>`, the type
|
||||
|
@ -310,11 +312,14 @@ impl Substs {
|
|||
}
|
||||
|
||||
/// Return Substs that replace each parameter by itself (i.e. `Ty::Param`).
|
||||
pub(crate) fn type_params_for_generics(generic_params: &Generics) -> Substs {
|
||||
pub(crate) fn type_params_for_generics(
|
||||
db: &dyn HirDatabase,
|
||||
generic_params: &Generics,
|
||||
) -> Substs {
|
||||
Substs(
|
||||
generic_params
|
||||
.iter()
|
||||
.map(|(id, _)| TyKind::Placeholder(id).intern(&Interner))
|
||||
.map(|(id, _)| TyKind::Placeholder(to_placeholder_idx(db, id)).intern(&Interner))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
@ -322,7 +327,7 @@ impl Substs {
|
|||
/// Return Substs that replace each parameter by itself (i.e. `Ty::Param`).
|
||||
pub fn type_params(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substs {
|
||||
let params = generics(db.upcast(), def.into());
|
||||
Substs::type_params_for_generics(¶ms)
|
||||
Substs::type_params_for_generics(db, ¶ms)
|
||||
}
|
||||
|
||||
/// Return Substs that replace each parameter by a bound variable.
|
||||
|
@ -734,9 +739,7 @@ impl Ty {
|
|||
ty_id == ty_id2
|
||||
}
|
||||
(TyKind::ForeignType(ty_id, ..), TyKind::ForeignType(ty_id2, ..)) => ty_id == ty_id2,
|
||||
(TyKind::Closure(def, expr, _), TyKind::Closure(def2, expr2, _)) => {
|
||||
expr == expr2 && def == def2
|
||||
}
|
||||
(TyKind::Closure(id1, _), TyKind::Closure(id2, _)) => id1 == id2,
|
||||
(TyKind::Ref(mutability, ..), TyKind::Ref(mutability2, ..))
|
||||
| (TyKind::Raw(mutability, ..), TyKind::Raw(mutability2, ..)) => {
|
||||
mutability == mutability2
|
||||
|
@ -873,8 +876,8 @@ impl Ty {
|
|||
pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<GenericPredicate>> {
|
||||
match self.interned(&Interner) {
|
||||
TyKind::OpaqueType(opaque_ty_id, ..) => {
|
||||
match opaque_ty_id {
|
||||
OpaqueTyId::AsyncBlockTypeImplTrait(def, _expr) => {
|
||||
match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) {
|
||||
ImplTraitId::AsyncBlockTypeImplTrait(def, _expr) => {
|
||||
let krate = def.module(db.upcast()).krate();
|
||||
if let Some(future_trait) = db
|
||||
.lang_item(krate, "future_trait".into())
|
||||
|
@ -892,12 +895,13 @@ impl Ty {
|
|||
None
|
||||
}
|
||||
}
|
||||
OpaqueTyId::ReturnTypeImplTrait(..) => None,
|
||||
ImplTraitId::ReturnTypeImplTrait(..) => None,
|
||||
}
|
||||
}
|
||||
TyKind::Alias(AliasTy::Opaque(opaque_ty)) => {
|
||||
let predicates = match opaque_ty.opaque_ty_id {
|
||||
OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
|
||||
let predicates = match db.lookup_intern_impl_trait_id(opaque_ty.opaque_ty_id.into())
|
||||
{
|
||||
ImplTraitId::ReturnTypeImplTrait(func, idx) => {
|
||||
db.return_type_impl_traits(func).map(|it| {
|
||||
let data = (*it)
|
||||
.as_ref()
|
||||
|
@ -906,18 +910,19 @@ impl Ty {
|
|||
})
|
||||
}
|
||||
// It always has an parameter for Future::Output type.
|
||||
OpaqueTyId::AsyncBlockTypeImplTrait(..) => unreachable!(),
|
||||
ImplTraitId::AsyncBlockTypeImplTrait(..) => unreachable!(),
|
||||
};
|
||||
|
||||
predicates.map(|it| it.value)
|
||||
}
|
||||
TyKind::Placeholder(id) => {
|
||||
TyKind::Placeholder(idx) => {
|
||||
let id = from_placeholder_idx(db, *idx);
|
||||
let generic_params = db.generic_params(id.parent);
|
||||
let param_data = &generic_params.types[id.local_id];
|
||||
match param_data.provenance {
|
||||
hir_def::generics::TypeParamProvenance::ArgumentImplTrait => {
|
||||
let predicates = db
|
||||
.generic_predicates_for_param(*id)
|
||||
.generic_predicates_for_param(id)
|
||||
.into_iter()
|
||||
.map(|pred| pred.value.clone())
|
||||
.collect_vec();
|
||||
|
@ -1120,7 +1125,7 @@ impl<T: TypeWalk> TypeWalk for Vec<T> {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum OpaqueTyId {
|
||||
pub enum ImplTraitId {
|
||||
ReturnTypeImplTrait(hir_def::FunctionId, u16),
|
||||
AsyncBlockTypeImplTrait(hir_def::DefWithBodyId, ExprId),
|
||||
}
|
||||
|
@ -1150,3 +1155,17 @@ pub fn to_assoc_type_id(id: TypeAliasId) -> AssocTypeId {
|
|||
pub fn from_assoc_type_id(id: AssocTypeId) -> TypeAliasId {
|
||||
salsa::InternKey::from_intern_id(id.0)
|
||||
}
|
||||
|
||||
pub fn from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> TypeParamId {
|
||||
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
|
||||
let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
|
||||
db.lookup_intern_type_param_id(interned_id)
|
||||
}
|
||||
|
||||
pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeParamId) -> PlaceholderIndex {
|
||||
let interned_id = db.intern_type_param_id(id);
|
||||
PlaceholderIndex {
|
||||
ui: chalk_ir::UniverseIndex::ROOT,
|
||||
idx: salsa::InternKey::as_intern_id(&interned_id).as_usize(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,14 +27,14 @@ use stdx::impl_from;
|
|||
|
||||
use crate::{
|
||||
db::HirDatabase,
|
||||
to_assoc_type_id,
|
||||
to_assoc_type_id, to_placeholder_idx,
|
||||
traits::chalk::{Interner, ToChalk},
|
||||
utils::{
|
||||
all_super_trait_refs, associated_type_by_name_including_super_traits, generics,
|
||||
make_mut_slice, variant_data,
|
||||
},
|
||||
AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate,
|
||||
OpaqueTy, OpaqueTyId, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait,
|
||||
ImplTraitId, OpaqueTy, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait,
|
||||
ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk,
|
||||
};
|
||||
|
||||
|
@ -228,13 +228,11 @@ impl Ty {
|
|||
Some(GenericDefId::FunctionId(f)) => f,
|
||||
_ => panic!("opaque impl trait lowering in non-function"),
|
||||
};
|
||||
let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx);
|
||||
let impl_trait_id = ImplTraitId::ReturnTypeImplTrait(func, idx);
|
||||
let opaque_ty_id = ctx.db.intern_impl_trait_id(impl_trait_id).into();
|
||||
let generics = generics(ctx.db.upcast(), func.into());
|
||||
let parameters = Substs::bound_vars(&generics, ctx.in_binders);
|
||||
TyKind::Alias(AliasTy::Opaque(OpaqueTy {
|
||||
opaque_ty_id: impl_trait_id,
|
||||
parameters,
|
||||
}))
|
||||
TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters }))
|
||||
.intern(&Interner)
|
||||
}
|
||||
ImplTraitLoweringMode::Param => {
|
||||
|
@ -249,7 +247,9 @@ impl Ty {
|
|||
data.provenance == TypeParamProvenance::ArgumentImplTrait
|
||||
})
|
||||
.nth(idx as usize)
|
||||
.map_or(TyKind::Unknown, |(id, _)| TyKind::Placeholder(id));
|
||||
.map_or(TyKind::Unknown, |(id, _)| {
|
||||
TyKind::Placeholder(to_placeholder_idx(ctx.db, id))
|
||||
});
|
||||
param.intern(&Interner)
|
||||
} else {
|
||||
TyKind::Unknown.intern(&Interner)
|
||||
|
@ -384,7 +384,9 @@ impl Ty {
|
|||
ctx.resolver.generic_def().expect("generics in scope"),
|
||||
);
|
||||
match ctx.type_param_mode {
|
||||
TypeParamLoweringMode::Placeholder => TyKind::Placeholder(param_id),
|
||||
TypeParamLoweringMode::Placeholder => {
|
||||
TyKind::Placeholder(to_placeholder_idx(ctx.db, param_id))
|
||||
}
|
||||
TypeParamLoweringMode::Variable => {
|
||||
let idx = generics.param_idx(param_id).expect("matching generics");
|
||||
TyKind::BoundVar(BoundVar::new(ctx.in_binders, idx))
|
||||
|
@ -396,7 +398,7 @@ impl Ty {
|
|||
let generics = generics(ctx.db.upcast(), impl_id.into());
|
||||
let substs = match ctx.type_param_mode {
|
||||
TypeParamLoweringMode::Placeholder => {
|
||||
Substs::type_params_for_generics(&generics)
|
||||
Substs::type_params_for_generics(ctx.db, &generics)
|
||||
}
|
||||
TypeParamLoweringMode::Variable => {
|
||||
Substs::bound_vars(&generics, ctx.in_binders)
|
||||
|
@ -408,7 +410,7 @@ impl Ty {
|
|||
let generics = generics(ctx.db.upcast(), adt.into());
|
||||
let substs = match ctx.type_param_mode {
|
||||
TypeParamLoweringMode::Placeholder => {
|
||||
Substs::type_params_for_generics(&generics)
|
||||
Substs::type_params_for_generics(ctx.db, &generics)
|
||||
}
|
||||
TypeParamLoweringMode::Variable => {
|
||||
Substs::bound_vars(&generics, ctx.in_binders)
|
||||
|
@ -689,8 +691,9 @@ impl GenericPredicate {
|
|||
let generics = generics(ctx.db.upcast(), generic_def);
|
||||
let param_id =
|
||||
hir_def::TypeParamId { parent: generic_def, local_id: *param_id };
|
||||
let placeholder = to_placeholder_idx(ctx.db, param_id);
|
||||
match ctx.type_param_mode {
|
||||
TypeParamLoweringMode::Placeholder => TyKind::Placeholder(param_id),
|
||||
TypeParamLoweringMode::Placeholder => TyKind::Placeholder(placeholder),
|
||||
TypeParamLoweringMode::Variable => {
|
||||
let idx = generics.param_idx(param_id).expect("matching generics");
|
||||
TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, idx))
|
||||
|
|
|
@ -177,10 +177,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
|||
}
|
||||
|
||||
fn opaque_ty_data(&self, id: chalk_ir::OpaqueTyId<Interner>) -> Arc<OpaqueTyDatum> {
|
||||
let interned_id = crate::db::InternedOpaqueTyId::from(id);
|
||||
let full_id = self.db.lookup_intern_impl_trait_id(interned_id);
|
||||
let full_id = self.db.lookup_intern_impl_trait_id(id.into());
|
||||
let bound = match full_id {
|
||||
crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
|
||||
crate::ImplTraitId::ReturnTypeImplTrait(func, idx) => {
|
||||
let datas = self
|
||||
.db
|
||||
.return_type_impl_traits(func)
|
||||
|
@ -202,7 +201,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
|||
let num_vars = datas.num_binders;
|
||||
make_binders(bound, num_vars)
|
||||
}
|
||||
crate::OpaqueTyId::AsyncBlockTypeImplTrait(..) => {
|
||||
crate::ImplTraitId::AsyncBlockTypeImplTrait(..) => {
|
||||
if let Some((future_trait, future_output)) = self
|
||||
.db
|
||||
.lang_item(self.krate, "future_trait".into())
|
||||
|
@ -716,14 +715,14 @@ impl From<crate::db::InternedOpaqueTyId> for OpaqueTyId {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<chalk_ir::ClosureId<Interner>> for crate::db::ClosureId {
|
||||
impl From<chalk_ir::ClosureId<Interner>> for crate::db::InternedClosureId {
|
||||
fn from(id: chalk_ir::ClosureId<Interner>) -> Self {
|
||||
Self::from_intern_id(id.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::db::ClosureId> for chalk_ir::ClosureId<Interner> {
|
||||
fn from(id: crate::db::ClosureId) -> Self {
|
||||
impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> {
|
||||
fn from(id: crate::db::InternedClosureId) -> Self {
|
||||
chalk_ir::ClosureId(id.as_intern_id())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@
|
|||
//! Chalk (in both directions); plus some helper functions for more specialized
|
||||
//! conversions.
|
||||
|
||||
use chalk_ir::{
|
||||
cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex,
|
||||
UniverseIndex,
|
||||
};
|
||||
use chalk_ir::{cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData};
|
||||
use chalk_solve::rust_ir;
|
||||
|
||||
use base_db::salsa::InternKey;
|
||||
|
@ -18,7 +15,7 @@ use crate::{
|
|||
primitive::UintTy,
|
||||
traits::{Canonical, Obligation},
|
||||
AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy,
|
||||
OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty,
|
||||
ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty,
|
||||
};
|
||||
|
||||
use super::interner::*;
|
||||
|
@ -44,8 +41,7 @@ impl ToChalk for Ty {
|
|||
chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner)
|
||||
}
|
||||
|
||||
TyKind::OpaqueType(impl_trait_id, substs) => {
|
||||
let id = impl_trait_id.to_chalk(db);
|
||||
TyKind::OpaqueType(id, substs) => {
|
||||
let substitution = substs.to_chalk(db);
|
||||
chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner)
|
||||
}
|
||||
|
@ -72,10 +68,9 @@ impl ToChalk for Ty {
|
|||
}
|
||||
TyKind::Never => chalk_ir::TyKind::Never.intern(&Interner),
|
||||
|
||||
TyKind::Closure(def, expr, substs) => {
|
||||
let closure_id = db.intern_closure((def, expr));
|
||||
TyKind::Closure(closure_id, substs) => {
|
||||
let substitution = substs.to_chalk(db);
|
||||
chalk_ir::TyKind::Closure(closure_id.into(), substitution).intern(&Interner)
|
||||
chalk_ir::TyKind::Closure(closure_id, substitution).intern(&Interner)
|
||||
}
|
||||
|
||||
TyKind::Adt(adt_id, substs) => {
|
||||
|
@ -92,14 +87,7 @@ impl ToChalk for Ty {
|
|||
.cast(&Interner)
|
||||
.intern(&Interner)
|
||||
}
|
||||
TyKind::Placeholder(id) => {
|
||||
let interned_id = db.intern_type_param_id(id);
|
||||
PlaceholderIndex {
|
||||
ui: UniverseIndex::ROOT,
|
||||
idx: interned_id.as_intern_id().as_usize(),
|
||||
}
|
||||
.to_ty::<Interner>(&Interner)
|
||||
}
|
||||
TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner),
|
||||
TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner),
|
||||
TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"),
|
||||
TyKind::Dyn(predicates) => {
|
||||
|
@ -114,7 +102,7 @@ impl ToChalk for Ty {
|
|||
chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner)
|
||||
}
|
||||
TyKind::Alias(AliasTy::Opaque(opaque_ty)) => {
|
||||
let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db);
|
||||
let opaque_ty_id = opaque_ty.opaque_ty_id;
|
||||
let substitution = opaque_ty.parameters.to_chalk(db);
|
||||
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy {
|
||||
opaque_ty_id,
|
||||
|
@ -129,22 +117,16 @@ impl ToChalk for Ty {
|
|||
match chalk.data(&Interner).kind.clone() {
|
||||
chalk_ir::TyKind::Error => TyKind::Unknown,
|
||||
chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(Substs::single(from_chalk(db, ty))),
|
||||
chalk_ir::TyKind::Placeholder(idx) => {
|
||||
assert_eq!(idx.ui, UniverseIndex::ROOT);
|
||||
let interned_id = crate::db::GlobalTypeParamId::from_intern_id(
|
||||
crate::salsa::InternId::from(idx.idx),
|
||||
);
|
||||
TyKind::Placeholder(db.lookup_intern_type_param_id(interned_id))
|
||||
}
|
||||
chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx),
|
||||
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
|
||||
let associated_ty = proj.associated_ty_id;
|
||||
let parameters = from_chalk(db, proj.substitution);
|
||||
TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters }))
|
||||
}
|
||||
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => {
|
||||
let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id);
|
||||
let opaque_ty_id = opaque_ty.opaque_ty_id;
|
||||
let parameters = from_chalk(db, opaque_ty.substitution);
|
||||
TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters }))
|
||||
TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters }))
|
||||
}
|
||||
chalk_ir::TyKind::Function(chalk_ir::FnPointer {
|
||||
num_binders,
|
||||
|
@ -182,7 +164,7 @@ impl ToChalk for Ty {
|
|||
}
|
||||
|
||||
chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => {
|
||||
TyKind::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst))
|
||||
TyKind::OpaqueType(opaque_type_id, from_chalk(db, subst))
|
||||
}
|
||||
|
||||
chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar),
|
||||
|
@ -203,11 +185,7 @@ impl ToChalk for Ty {
|
|||
TyKind::FnDef(fn_def_id, from_chalk(db, subst))
|
||||
}
|
||||
|
||||
chalk_ir::TyKind::Closure(id, subst) => {
|
||||
let id: crate::db::ClosureId = id.into();
|
||||
let (def, expr) = db.lookup_intern_closure(id);
|
||||
TyKind::Closure(def, expr, from_chalk(db, subst))
|
||||
}
|
||||
chalk_ir::TyKind::Closure(id, subst) => TyKind::Closure(id, from_chalk(db, subst)),
|
||||
|
||||
chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id),
|
||||
chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME
|
||||
|
@ -289,21 +267,6 @@ impl ToChalk for hir_def::TraitId {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToChalk for OpaqueTyId {
|
||||
type Chalk = chalk_ir::OpaqueTyId<Interner>;
|
||||
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::OpaqueTyId<Interner> {
|
||||
db.intern_impl_trait_id(self).into()
|
||||
}
|
||||
|
||||
fn from_chalk(
|
||||
db: &dyn HirDatabase,
|
||||
opaque_ty_id: chalk_ir::OpaqueTyId<Interner>,
|
||||
) -> OpaqueTyId {
|
||||
db.lookup_intern_impl_trait_id(opaque_ty_id.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToChalk for hir_def::ImplId {
|
||||
type Chalk = ImplId;
|
||||
|
||||
|
|
Loading…
Reference in a new issue