Use chalk_ir::ClosureId

This commit is contained in:
Florian Diebold 2021-03-13 19:27:09 +01:00
parent be7a31fbd6
commit 2d69eb131f
5 changed files with 17 additions and 23 deletions

View file

@ -85,7 +85,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
#[salsa::interned]
fn intern_impl_trait_id(&self, id: OpaqueTyId) -> 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>;
@ -157,8 +157,8 @@ 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.

View file

@ -264,8 +264,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

View file

@ -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,8 @@ 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>;
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub enum Lifetime {
@ -195,7 +195,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),
@ -734,9 +734,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

View file

@ -716,14 +716,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())
}
}

View file

@ -72,10 +72,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) => {
@ -203,11 +202,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