From 2d69eb131f58dee1bc188b8df8d5cf0ebf9d97f2 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 13 Mar 2021 19:27:09 +0100 Subject: Use chalk_ir::ClosureId --- crates/hir_ty/src/db.rs | 6 +++--- crates/hir_ty/src/infer/expr.rs | 3 ++- crates/hir_ty/src/lib.rs | 14 ++++++-------- crates/hir_ty/src/traits/chalk.rs | 6 +++--- crates/hir_ty/src/traits/chalk/mapping.rs | 11 +++-------- 5 files changed, 17 insertions(+), 23 deletions(-) (limited to 'crates') diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs index a038674cf..1b59616ba 100644 --- a/crates/hir_ty/src/db.rs +++ b/crates/hir_ty/src/db.rs @@ -85,7 +85,7 @@ pub trait HirDatabase: DefDatabase + Upcast { #[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; @@ -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. diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 153f22f25..2e21d796c 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -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 diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 6b3485264..ec2010e4b 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -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; pub type AssocTypeId = chalk_ir::AssocTypeId; -pub(crate) type FnDefId = chalk_ir::FnDefId; +pub type FnDefId = chalk_ir::FnDefId; +pub type ClosureId = chalk_ir::ClosureId; #[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 diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index bb92d8e2a..e7217bc11 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -716,14 +716,14 @@ impl From for OpaqueTyId { } } -impl From> for crate::db::ClosureId { +impl From> for crate::db::InternedClosureId { fn from(id: chalk_ir::ClosureId) -> Self { Self::from_intern_id(id.0) } } -impl From for chalk_ir::ClosureId { - fn from(id: crate::db::ClosureId) -> Self { +impl From for chalk_ir::ClosureId { + fn from(id: crate::db::InternedClosureId) -> Self { chalk_ir::ClosureId(id.as_intern_id()) } } diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 23ef07d77..56a30363b 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -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 -- cgit v1.2.3