aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-03-13 18:27:09 +0000
committerFlorian Diebold <[email protected]>2021-03-13 18:27:09 +0000
commit2d69eb131f58dee1bc188b8df8d5cf0ebf9d97f2 (patch)
treeb22507ea0b79fcd5d38dcf5ae8b731467a38cc41 /crates
parentbe7a31fbd64943f71afe11b0413c99496526dddc (diff)
Use chalk_ir::ClosureId
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/db.rs6
-rw-r--r--crates/hir_ty/src/infer/expr.rs3
-rw-r--r--crates/hir_ty/src/lib.rs14
-rw-r--r--crates/hir_ty/src/traits/chalk.rs6
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs11
5 files changed, 17 insertions, 23 deletions
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<dyn DefDatabase> {
85 #[salsa::interned] 85 #[salsa::interned]
86 fn intern_impl_trait_id(&self, id: OpaqueTyId) -> InternedOpaqueTyId; 86 fn intern_impl_trait_id(&self, id: OpaqueTyId) -> InternedOpaqueTyId;
87 #[salsa::interned] 87 #[salsa::interned]
88 fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> ClosureId; 88 fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
89 89
90 #[salsa::invoke(chalk::associated_ty_data_query)] 90 #[salsa::invoke(chalk::associated_ty_data_query)]
91 fn associated_ty_data(&self, id: chalk::AssocTypeId) -> Arc<chalk::AssociatedTyDatum>; 91 fn associated_ty_data(&self, id: chalk::AssocTypeId) -> Arc<chalk::AssociatedTyDatum>;
@@ -157,8 +157,8 @@ pub struct InternedOpaqueTyId(salsa::InternId);
157impl_intern_key!(InternedOpaqueTyId); 157impl_intern_key!(InternedOpaqueTyId);
158 158
159#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 159#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
160pub struct ClosureId(salsa::InternId); 160pub struct InternedClosureId(salsa::InternId);
161impl_intern_key!(ClosureId); 161impl_intern_key!(InternedClosureId);
162 162
163/// This exists just for Chalk, because Chalk just has a single `FnDefId` where 163/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
164/// we have different IDs for struct and enum variant constructors. 164/// 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> {
264 substs: Substs(sig_tys.clone().into()), 264 substs: Substs(sig_tys.clone().into()),
265 }) 265 })
266 .intern(&Interner); 266 .intern(&Interner);
267 let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
267 let closure_ty = 268 let closure_ty =
268 TyKind::Closure(self.owner, tgt_expr, Substs::single(sig_ty)).intern(&Interner); 269 TyKind::Closure(closure_id, Substs::single(sig_ty)).intern(&Interner);
269 270
270 // Eagerly try to relate the closure type with the expected 271 // Eagerly try to relate the closure type with the expected
271 // type, otherwise we often won't have enough information to 272 // 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};
27 27
28use base_db::salsa; 28use base_db::salsa;
29use hir_def::{ 29use hir_def::{
30 builtin_type::BuiltinType, expr::ExprId, type_ref::Rawness, AssocContainerId, DefWithBodyId, 30 builtin_type::BuiltinType, expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId,
31 FunctionId, GenericDefId, HasModule, LifetimeParamId, Lookup, TraitId, TypeAliasId, 31 GenericDefId, HasModule, LifetimeParamId, Lookup, TraitId, TypeAliasId, TypeParamId,
32 TypeParamId,
33}; 32};
34use itertools::Itertools; 33use itertools::Itertools;
35 34
@@ -53,7 +52,8 @@ pub use crate::traits::chalk::Interner;
53 52
54pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>; 53pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
55pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>; 54pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
56pub(crate) type FnDefId = chalk_ir::FnDefId<Interner>; 55pub type FnDefId = chalk_ir::FnDefId<Interner>;
56pub type ClosureId = chalk_ir::ClosureId<Interner>;
57 57
58#[derive(Clone, PartialEq, Eq, Debug, Hash)] 58#[derive(Clone, PartialEq, Eq, Debug, Hash)]
59pub enum Lifetime { 59pub enum Lifetime {
@@ -195,7 +195,7 @@ pub enum TyKind {
195 /// 195 ///
196 /// The closure signature is stored in a `FnPtr` type in the first type 196 /// The closure signature is stored in a `FnPtr` type in the first type
197 /// parameter. 197 /// parameter.
198 Closure(DefWithBodyId, ExprId, Substs), 198 Closure(ClosureId, Substs),
199 199
200 /// Represents a foreign type declared in external blocks. 200 /// Represents a foreign type declared in external blocks.
201 ForeignType(ForeignDefId), 201 ForeignType(ForeignDefId),
@@ -734,9 +734,7 @@ impl Ty {
734 ty_id == ty_id2 734 ty_id == ty_id2
735 } 735 }
736 (TyKind::ForeignType(ty_id, ..), TyKind::ForeignType(ty_id2, ..)) => ty_id == ty_id2, 736 (TyKind::ForeignType(ty_id, ..), TyKind::ForeignType(ty_id2, ..)) => ty_id == ty_id2,
737 (TyKind::Closure(def, expr, _), TyKind::Closure(def2, expr2, _)) => { 737 (TyKind::Closure(id1, _), TyKind::Closure(id2, _)) => id1 == id2,
738 expr == expr2 && def == def2
739 }
740 (TyKind::Ref(mutability, ..), TyKind::Ref(mutability2, ..)) 738 (TyKind::Ref(mutability, ..), TyKind::Ref(mutability2, ..))
741 | (TyKind::Raw(mutability, ..), TyKind::Raw(mutability2, ..)) => { 739 | (TyKind::Raw(mutability, ..), TyKind::Raw(mutability2, ..)) => {
742 mutability == mutability2 740 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<crate::db::InternedOpaqueTyId> for OpaqueTyId {
716 } 716 }
717} 717}
718 718
719impl From<chalk_ir::ClosureId<Interner>> for crate::db::ClosureId { 719impl From<chalk_ir::ClosureId<Interner>> for crate::db::InternedClosureId {
720 fn from(id: chalk_ir::ClosureId<Interner>) -> Self { 720 fn from(id: chalk_ir::ClosureId<Interner>) -> Self {
721 Self::from_intern_id(id.0) 721 Self::from_intern_id(id.0)
722 } 722 }
723} 723}
724 724
725impl From<crate::db::ClosureId> for chalk_ir::ClosureId<Interner> { 725impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> {
726 fn from(id: crate::db::ClosureId) -> Self { 726 fn from(id: crate::db::InternedClosureId) -> Self {
727 chalk_ir::ClosureId(id.as_intern_id()) 727 chalk_ir::ClosureId(id.as_intern_id())
728 } 728 }
729} 729}
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 {
72 } 72 }
73 TyKind::Never => chalk_ir::TyKind::Never.intern(&Interner), 73 TyKind::Never => chalk_ir::TyKind::Never.intern(&Interner),
74 74
75 TyKind::Closure(def, expr, substs) => { 75 TyKind::Closure(closure_id, substs) => {
76 let closure_id = db.intern_closure((def, expr));
77 let substitution = substs.to_chalk(db); 76 let substitution = substs.to_chalk(db);
78 chalk_ir::TyKind::Closure(closure_id.into(), substitution).intern(&Interner) 77 chalk_ir::TyKind::Closure(closure_id, substitution).intern(&Interner)
79 } 78 }
80 79
81 TyKind::Adt(adt_id, substs) => { 80 TyKind::Adt(adt_id, substs) => {
@@ -203,11 +202,7 @@ impl ToChalk for Ty {
203 TyKind::FnDef(fn_def_id, from_chalk(db, subst)) 202 TyKind::FnDef(fn_def_id, from_chalk(db, subst))
204 } 203 }
205 204
206 chalk_ir::TyKind::Closure(id, subst) => { 205 chalk_ir::TyKind::Closure(id, subst) => TyKind::Closure(id, from_chalk(db, subst)),
207 let id: crate::db::ClosureId = id.into();
208 let (def, expr) = db.lookup_intern_closure(id);
209 TyKind::Closure(def, expr, from_chalk(db, subst))
210 }
211 206
212 chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id), 207 chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id),
213 chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME 208 chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME