diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-13 19:08:29 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-13 19:08:29 +0000 |
commit | 17eeb2a6d2ea81b302b6707c63bf8fba489c2bdd (patch) | |
tree | a2e152f5f16dd92f4c4be011be2399998dc7eb6f | |
parent | be7a31fbd64943f71afe11b0413c99496526dddc (diff) | |
parent | b035c314b4b0ecd2477fde216dbe7e8801f94d0d (diff) |
Merge #8001
8001: More Chalk IDs r=flodiebold a=flodiebold
Co-authored-by: Florian Diebold <[email protected]>
-rw-r--r-- | crates/hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/db.rs | 16 | ||||
-rw-r--r-- | crates/hir_ty/src/display.rs | 55 | ||||
-rw-r--r-- | crates/hir_ty/src/infer.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 10 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/path.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 61 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 29 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk.rs | 13 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 61 |
10 files changed, 122 insertions, 129 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 7f8f936d3..571b89bc3 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -1384,7 +1384,7 @@ impl TypeParam { | |||
1384 | pub fn ty(self, db: &dyn HirDatabase) -> Type { | 1384 | pub fn ty(self, db: &dyn HirDatabase) -> Type { |
1385 | let resolver = self.id.parent.resolver(db.upcast()); | 1385 | let resolver = self.id.parent.resolver(db.upcast()); |
1386 | let krate = self.id.parent.module(db.upcast()).krate(); | 1386 | let krate = self.id.parent.module(db.upcast()).krate(); |
1387 | let ty = TyKind::Placeholder(self.id).intern(&Interner); | 1387 | let ty = TyKind::Placeholder(hir_ty::to_placeholder_idx(db, self.id)).intern(&Interner); |
1388 | Type::new_with_resolver_inner(db, krate, &resolver, ty) | 1388 | Type::new_with_resolver_inner(db, krate, &resolver, ty) |
1389 | } | 1389 | } |
1390 | 1390 | ||
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs index a038674cf..8a3cc0283 100644 --- a/crates/hir_ty/src/db.rs +++ b/crates/hir_ty/src/db.rs | |||
@@ -12,7 +12,7 @@ use la_arena::ArenaMap; | |||
12 | use crate::{ | 12 | use crate::{ |
13 | method_resolution::{InherentImpls, TraitImpls}, | 13 | method_resolution::{InherentImpls, TraitImpls}, |
14 | traits::chalk, | 14 | traits::chalk, |
15 | Binders, CallableDefId, FnDefId, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig, | 15 | Binders, CallableDefId, FnDefId, GenericPredicate, ImplTraitId, InferenceResult, PolyFnSig, |
16 | ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, | 16 | ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, |
17 | }; | 17 | }; |
18 | use hir_expand::name::Name; | 18 | use hir_expand::name::Name; |
@@ -81,11 +81,11 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> { | |||
81 | #[salsa::interned] | 81 | #[salsa::interned] |
82 | fn intern_callable_def(&self, callable_def: CallableDefId) -> InternedCallableDefId; | 82 | fn intern_callable_def(&self, callable_def: CallableDefId) -> InternedCallableDefId; |
83 | #[salsa::interned] | 83 | #[salsa::interned] |
84 | fn intern_type_param_id(&self, param_id: TypeParamId) -> GlobalTypeParamId; | 84 | fn intern_type_param_id(&self, param_id: TypeParamId) -> InternedTypeParamId; |
85 | #[salsa::interned] | 85 | #[salsa::interned] |
86 | fn intern_impl_trait_id(&self, id: OpaqueTyId) -> InternedOpaqueTyId; | 86 | fn intern_impl_trait_id(&self, id: ImplTraitId) -> 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>; |
@@ -149,16 +149,16 @@ fn hir_database_is_object_safe() { | |||
149 | } | 149 | } |
150 | 150 | ||
151 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 151 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
152 | pub struct GlobalTypeParamId(salsa::InternId); | 152 | pub struct InternedTypeParamId(salsa::InternId); |
153 | impl_intern_key!(GlobalTypeParamId); | 153 | impl_intern_key!(InternedTypeParamId); |
154 | 154 | ||
155 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 155 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
156 | pub struct InternedOpaqueTyId(salsa::InternId); | 156 | pub struct InternedOpaqueTyId(salsa::InternId); |
157 | impl_intern_key!(InternedOpaqueTyId); | 157 | impl_intern_key!(InternedOpaqueTyId); |
158 | 158 | ||
159 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 159 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
160 | pub struct ClosureId(salsa::InternId); | 160 | pub struct InternedClosureId(salsa::InternId); |
161 | impl_intern_key!(ClosureId); | 161 | impl_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/display.rs b/crates/hir_ty/src/display.rs index b7e85e024..e6473586b 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -11,10 +11,10 @@ use hir_def::{ | |||
11 | use hir_expand::name::Name; | 11 | use hir_expand::name::Name; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, primitive, to_assoc_type_id, | 14 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, |
15 | traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId, CallableSig, | 15 | to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId, |
16 | GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, | 16 | CallableSig, GenericPredicate, ImplTraitId, Interner, Lifetime, Obligation, OpaqueTy, |
17 | Substs, TraitRef, Ty, TyKind, | 17 | ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | pub struct HirFormatter<'a> { | 20 | pub struct HirFormatter<'a> { |
@@ -313,22 +313,26 @@ impl HirDisplay for Ty { | |||
313 | )?; | 313 | )?; |
314 | } | 314 | } |
315 | 315 | ||
316 | // FIXME: all this just to decide whether to use parentheses... | ||
316 | let datas; | 317 | let datas; |
317 | let predicates = match t.interned(&Interner) { | 318 | let predicates = match t.interned(&Interner) { |
318 | TyKind::Dyn(predicates) if predicates.len() > 1 => { | 319 | TyKind::Dyn(predicates) if predicates.len() > 1 => { |
319 | Cow::Borrowed(predicates.as_ref()) | 320 | Cow::Borrowed(predicates.as_ref()) |
320 | } | 321 | } |
321 | &TyKind::Alias(AliasTy::Opaque(OpaqueTy { | 322 | &TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, ref parameters })) => { |
322 | opaque_ty_id: OpaqueTyId::ReturnTypeImplTrait(func, idx), | 323 | let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty_id.into()); |
323 | ref parameters, | 324 | if let ImplTraitId::ReturnTypeImplTrait(func, idx) = impl_trait_id { |
324 | })) => { | 325 | datas = |
325 | datas = | 326 | f.db.return_type_impl_traits(func) |
326 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); | 327 | .expect("impl trait id without data"); |
327 | let data = (*datas) | 328 | let data = (*datas) |
328 | .as_ref() | 329 | .as_ref() |
329 | .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); | 330 | .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); |
330 | let bounds = data.subst(parameters); | 331 | let bounds = data.subst(parameters); |
331 | Cow::Owned(bounds.value) | 332 | Cow::Owned(bounds.value) |
333 | } else { | ||
334 | Cow::Borrowed(&[][..]) | ||
335 | } | ||
332 | } | 336 | } |
333 | _ => Cow::Borrowed(&[][..]), | 337 | _ => Cow::Borrowed(&[][..]), |
334 | }; | 338 | }; |
@@ -499,8 +503,9 @@ impl HirDisplay for Ty { | |||
499 | write!(f, "{}", type_alias.name)?; | 503 | write!(f, "{}", type_alias.name)?; |
500 | } | 504 | } |
501 | TyKind::OpaqueType(opaque_ty_id, parameters) => { | 505 | TyKind::OpaqueType(opaque_ty_id, parameters) => { |
502 | match opaque_ty_id { | 506 | let impl_trait_id = f.db.lookup_intern_impl_trait_id((*opaque_ty_id).into()); |
503 | &OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 507 | match impl_trait_id { |
508 | ImplTraitId::ReturnTypeImplTrait(func, idx) => { | ||
504 | let datas = | 509 | let datas = |
505 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); | 510 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); |
506 | let data = (*datas) | 511 | let data = (*datas) |
@@ -510,7 +515,7 @@ impl HirDisplay for Ty { | |||
510 | write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?; | 515 | write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?; |
511 | // FIXME: it would maybe be good to distinguish this from the alias type (when debug printing), and to show the substitution | 516 | // FIXME: it would maybe be good to distinguish this from the alias type (when debug printing), and to show the substitution |
512 | } | 517 | } |
513 | OpaqueTyId::AsyncBlockTypeImplTrait(..) => { | 518 | ImplTraitId::AsyncBlockTypeImplTrait(..) => { |
514 | write!(f, "impl Future<Output = ")?; | 519 | write!(f, "impl Future<Output = ")?; |
515 | parameters[0].hir_fmt(f)?; | 520 | parameters[0].hir_fmt(f)?; |
516 | write!(f, ">")?; | 521 | write!(f, ">")?; |
@@ -541,7 +546,8 @@ impl HirDisplay for Ty { | |||
541 | write!(f, "{{closure}}")?; | 546 | write!(f, "{{closure}}")?; |
542 | } | 547 | } |
543 | } | 548 | } |
544 | TyKind::Placeholder(id) => { | 549 | TyKind::Placeholder(idx) => { |
550 | let id = from_placeholder_idx(f.db, *idx); | ||
545 | let generics = generics(f.db.upcast(), id.parent); | 551 | let generics = generics(f.db.upcast(), id.parent); |
546 | let param_data = &generics.params.types[id.local_id]; | 552 | let param_data = &generics.params.types[id.local_id]; |
547 | match param_data.provenance { | 553 | match param_data.provenance { |
@@ -549,8 +555,8 @@ impl HirDisplay for Ty { | |||
549 | write!(f, "{}", param_data.name.clone().unwrap_or_else(Name::missing))? | 555 | write!(f, "{}", param_data.name.clone().unwrap_or_else(Name::missing))? |
550 | } | 556 | } |
551 | TypeParamProvenance::ArgumentImplTrait => { | 557 | TypeParamProvenance::ArgumentImplTrait => { |
552 | let bounds = f.db.generic_predicates_for_param(*id); | 558 | let bounds = f.db.generic_predicates_for_param(id); |
553 | let substs = Substs::type_params_for_generics(&generics); | 559 | let substs = Substs::type_params_for_generics(f.db, &generics); |
554 | write_bounds_like_dyn_trait_with_prefix( | 560 | write_bounds_like_dyn_trait_with_prefix( |
555 | "impl", | 561 | "impl", |
556 | &bounds.iter().map(|b| b.clone().subst(&substs)).collect::<Vec<_>>(), | 562 | &bounds.iter().map(|b| b.clone().subst(&substs)).collect::<Vec<_>>(), |
@@ -565,8 +571,9 @@ impl HirDisplay for Ty { | |||
565 | } | 571 | } |
566 | TyKind::Alias(AliasTy::Projection(p_ty)) => p_ty.hir_fmt(f)?, | 572 | TyKind::Alias(AliasTy::Projection(p_ty)) => p_ty.hir_fmt(f)?, |
567 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { | 573 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { |
568 | match opaque_ty.opaque_ty_id { | 574 | let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty.opaque_ty_id.into()); |
569 | OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 575 | match impl_trait_id { |
576 | ImplTraitId::ReturnTypeImplTrait(func, idx) => { | ||
570 | let datas = | 577 | let datas = |
571 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); | 578 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); |
572 | let data = (*datas) | 579 | let data = (*datas) |
@@ -575,7 +582,7 @@ impl HirDisplay for Ty { | |||
575 | let bounds = data.subst(&opaque_ty.parameters); | 582 | let bounds = data.subst(&opaque_ty.parameters); |
576 | write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?; | 583 | write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?; |
577 | } | 584 | } |
578 | OpaqueTyId::AsyncBlockTypeImplTrait(..) => { | 585 | ImplTraitId::AsyncBlockTypeImplTrait(..) => { |
579 | write!(f, "{{async block}}")?; | 586 | write!(f, "{{async block}}")?; |
580 | } | 587 | } |
581 | }; | 588 | }; |
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 9d9bf549c..4f7463422 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -454,7 +454,7 @@ impl<'a> InferenceContext<'a> { | |||
454 | } | 454 | } |
455 | TypeNs::SelfType(impl_id) => { | 455 | TypeNs::SelfType(impl_id) => { |
456 | let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); | 456 | let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); |
457 | let substs = Substs::type_params_for_generics(&generics); | 457 | let substs = Substs::type_params_for_generics(self.db, &generics); |
458 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); | 458 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); |
459 | match unresolved { | 459 | match unresolved { |
460 | None => { | 460 | None => { |
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 153f22f25..eee3e6ec5 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -21,8 +21,8 @@ use crate::{ | |||
21 | to_assoc_type_id, | 21 | to_assoc_type_id, |
22 | traits::{chalk::from_chalk, FnTrait, InEnvironment}, | 22 | traits::{chalk::from_chalk, FnTrait, InEnvironment}, |
23 | utils::{generics, variant_data, Generics}, | 23 | utils::{generics, variant_data, Generics}, |
24 | AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, OpaqueTyId, Rawness, | 24 | AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, Rawness, Scalar, Substs, |
25 | Scalar, Substs, TraitRef, Ty, TyKind, | 25 | TraitRef, Ty, TyKind, |
26 | }; | 26 | }; |
27 | 27 | ||
28 | use super::{ | 28 | use super::{ |
@@ -179,7 +179,8 @@ impl<'a> InferenceContext<'a> { | |||
179 | // Use the first type parameter as the output type of future. | 179 | // Use the first type parameter as the output type of future. |
180 | // existenail type AsyncBlockImplTrait<InnerType>: Future<Output = InnerType> | 180 | // existenail type AsyncBlockImplTrait<InnerType>: Future<Output = InnerType> |
181 | let inner_ty = self.infer_expr(*body, &Expectation::none()); | 181 | let inner_ty = self.infer_expr(*body, &Expectation::none()); |
182 | let opaque_ty_id = OpaqueTyId::AsyncBlockTypeImplTrait(self.owner, *body); | 182 | let impl_trait_id = crate::ImplTraitId::AsyncBlockTypeImplTrait(self.owner, *body); |
183 | let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into(); | ||
183 | TyKind::OpaqueType(opaque_ty_id, Substs::single(inner_ty)).intern(&Interner) | 184 | TyKind::OpaqueType(opaque_ty_id, Substs::single(inner_ty)).intern(&Interner) |
184 | } | 185 | } |
185 | Expr::Loop { body, label } => { | 186 | Expr::Loop { body, label } => { |
@@ -264,8 +265,9 @@ impl<'a> InferenceContext<'a> { | |||
264 | substs: Substs(sig_tys.clone().into()), | 265 | substs: Substs(sig_tys.clone().into()), |
265 | }) | 266 | }) |
266 | .intern(&Interner); | 267 | .intern(&Interner); |
268 | let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into(); | ||
267 | let closure_ty = | 269 | let closure_ty = |
268 | TyKind::Closure(self.owner, tgt_expr, Substs::single(sig_ty)).intern(&Interner); | 270 | TyKind::Closure(closure_id, Substs::single(sig_ty)).intern(&Interner); |
269 | 271 | ||
270 | // Eagerly try to relate the closure type with the expected | 272 | // Eagerly try to relate the closure type with the expected |
271 | // type, otherwise we often won't have enough information to | 273 | // type, otherwise we often won't have enough information to |
diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs index 392952178..c6681834c 100644 --- a/crates/hir_ty/src/infer/path.rs +++ b/crates/hir_ty/src/infer/path.rs | |||
@@ -79,7 +79,7 @@ impl<'a> InferenceContext<'a> { | |||
79 | } | 79 | } |
80 | ValueNs::ImplSelf(impl_id) => { | 80 | ValueNs::ImplSelf(impl_id) => { |
81 | let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); | 81 | let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); |
82 | let substs = Substs::type_params_for_generics(&generics); | 82 | let substs = Substs::type_params_for_generics(self.db, &generics); |
83 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); | 83 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); |
84 | if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() { | 84 | if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() { |
85 | let ty = self.db.value_ty(struct_id.into()).subst(&substs); | 85 | let ty = self.db.value_ty(struct_id.into()).subst(&substs); |
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 6b3485264..d6ff968f0 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 | ||
28 | use base_db::salsa; | 28 | use base_db::salsa; |
29 | use hir_def::{ | 29 | use 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 | }; |
34 | use itertools::Itertools; | 33 | use itertools::Itertools; |
35 | 34 | ||
@@ -53,7 +52,10 @@ pub use crate::traits::chalk::Interner; | |||
53 | 52 | ||
54 | pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>; | 53 | pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>; |
55 | pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>; | 54 | pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>; |
56 | pub(crate) type FnDefId = chalk_ir::FnDefId<Interner>; | 55 | pub type FnDefId = chalk_ir::FnDefId<Interner>; |
56 | pub type ClosureId = chalk_ir::ClosureId<Interner>; | ||
57 | pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; | ||
58 | pub type PlaceholderIndex = chalk_ir::PlaceholderIndex; | ||
57 | 59 | ||
58 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 60 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
59 | pub enum Lifetime { | 61 | pub enum Lifetime { |
@@ -195,7 +197,7 @@ pub enum TyKind { | |||
195 | /// | 197 | /// |
196 | /// The closure signature is stored in a `FnPtr` type in the first type | 198 | /// The closure signature is stored in a `FnPtr` type in the first type |
197 | /// parameter. | 199 | /// parameter. |
198 | Closure(DefWithBodyId, ExprId, Substs), | 200 | Closure(ClosureId, Substs), |
199 | 201 | ||
200 | /// Represents a foreign type declared in external blocks. | 202 | /// Represents a foreign type declared in external blocks. |
201 | ForeignType(ForeignDefId), | 203 | ForeignType(ForeignDefId), |
@@ -220,7 +222,7 @@ pub enum TyKind { | |||
220 | /// {}` when we're type-checking the body of that function. In this | 222 | /// {}` when we're type-checking the body of that function. In this |
221 | /// situation, we know this stands for *some* type, but don't know the exact | 223 | /// situation, we know this stands for *some* type, but don't know the exact |
222 | /// type. | 224 | /// type. |
223 | Placeholder(TypeParamId), | 225 | Placeholder(PlaceholderIndex), |
224 | 226 | ||
225 | /// A bound type variable. This is used in various places: when representing | 227 | /// A bound type variable. This is used in various places: when representing |
226 | /// some polymorphic type like the type of function `fn f<T>`, the type | 228 | /// some polymorphic type like the type of function `fn f<T>`, the type |
@@ -310,11 +312,14 @@ impl Substs { | |||
310 | } | 312 | } |
311 | 313 | ||
312 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). | 314 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). |
313 | pub(crate) fn type_params_for_generics(generic_params: &Generics) -> Substs { | 315 | pub(crate) fn type_params_for_generics( |
316 | db: &dyn HirDatabase, | ||
317 | generic_params: &Generics, | ||
318 | ) -> Substs { | ||
314 | Substs( | 319 | Substs( |
315 | generic_params | 320 | generic_params |
316 | .iter() | 321 | .iter() |
317 | .map(|(id, _)| TyKind::Placeholder(id).intern(&Interner)) | 322 | .map(|(id, _)| TyKind::Placeholder(to_placeholder_idx(db, id)).intern(&Interner)) |
318 | .collect(), | 323 | .collect(), |
319 | ) | 324 | ) |
320 | } | 325 | } |
@@ -322,7 +327,7 @@ impl Substs { | |||
322 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). | 327 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). |
323 | pub fn type_params(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substs { | 328 | pub fn type_params(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substs { |
324 | let params = generics(db.upcast(), def.into()); | 329 | let params = generics(db.upcast(), def.into()); |
325 | Substs::type_params_for_generics(¶ms) | 330 | Substs::type_params_for_generics(db, ¶ms) |
326 | } | 331 | } |
327 | 332 | ||
328 | /// Return Substs that replace each parameter by a bound variable. | 333 | /// Return Substs that replace each parameter by a bound variable. |
@@ -734,9 +739,7 @@ impl Ty { | |||
734 | ty_id == ty_id2 | 739 | ty_id == ty_id2 |
735 | } | 740 | } |
736 | (TyKind::ForeignType(ty_id, ..), TyKind::ForeignType(ty_id2, ..)) => ty_id == ty_id2, | 741 | (TyKind::ForeignType(ty_id, ..), TyKind::ForeignType(ty_id2, ..)) => ty_id == ty_id2, |
737 | (TyKind::Closure(def, expr, _), TyKind::Closure(def2, expr2, _)) => { | 742 | (TyKind::Closure(id1, _), TyKind::Closure(id2, _)) => id1 == id2, |
738 | expr == expr2 && def == def2 | ||
739 | } | ||
740 | (TyKind::Ref(mutability, ..), TyKind::Ref(mutability2, ..)) | 743 | (TyKind::Ref(mutability, ..), TyKind::Ref(mutability2, ..)) |
741 | | (TyKind::Raw(mutability, ..), TyKind::Raw(mutability2, ..)) => { | 744 | | (TyKind::Raw(mutability, ..), TyKind::Raw(mutability2, ..)) => { |
742 | mutability == mutability2 | 745 | mutability == mutability2 |
@@ -873,8 +876,8 @@ impl Ty { | |||
873 | pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<GenericPredicate>> { | 876 | pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<GenericPredicate>> { |
874 | match self.interned(&Interner) { | 877 | match self.interned(&Interner) { |
875 | TyKind::OpaqueType(opaque_ty_id, ..) => { | 878 | TyKind::OpaqueType(opaque_ty_id, ..) => { |
876 | match opaque_ty_id { | 879 | match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) { |
877 | OpaqueTyId::AsyncBlockTypeImplTrait(def, _expr) => { | 880 | ImplTraitId::AsyncBlockTypeImplTrait(def, _expr) => { |
878 | let krate = def.module(db.upcast()).krate(); | 881 | let krate = def.module(db.upcast()).krate(); |
879 | if let Some(future_trait) = db | 882 | if let Some(future_trait) = db |
880 | .lang_item(krate, "future_trait".into()) | 883 | .lang_item(krate, "future_trait".into()) |
@@ -892,12 +895,13 @@ impl Ty { | |||
892 | None | 895 | None |
893 | } | 896 | } |
894 | } | 897 | } |
895 | OpaqueTyId::ReturnTypeImplTrait(..) => None, | 898 | ImplTraitId::ReturnTypeImplTrait(..) => None, |
896 | } | 899 | } |
897 | } | 900 | } |
898 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { | 901 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { |
899 | let predicates = match opaque_ty.opaque_ty_id { | 902 | let predicates = match db.lookup_intern_impl_trait_id(opaque_ty.opaque_ty_id.into()) |
900 | OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 903 | { |
904 | ImplTraitId::ReturnTypeImplTrait(func, idx) => { | ||
901 | db.return_type_impl_traits(func).map(|it| { | 905 | db.return_type_impl_traits(func).map(|it| { |
902 | let data = (*it) | 906 | let data = (*it) |
903 | .as_ref() | 907 | .as_ref() |
@@ -906,18 +910,19 @@ impl Ty { | |||
906 | }) | 910 | }) |
907 | } | 911 | } |
908 | // It always has an parameter for Future::Output type. | 912 | // It always has an parameter for Future::Output type. |
909 | OpaqueTyId::AsyncBlockTypeImplTrait(..) => unreachable!(), | 913 | ImplTraitId::AsyncBlockTypeImplTrait(..) => unreachable!(), |
910 | }; | 914 | }; |
911 | 915 | ||
912 | predicates.map(|it| it.value) | 916 | predicates.map(|it| it.value) |
913 | } | 917 | } |
914 | TyKind::Placeholder(id) => { | 918 | TyKind::Placeholder(idx) => { |
919 | let id = from_placeholder_idx(db, *idx); | ||
915 | let generic_params = db.generic_params(id.parent); | 920 | let generic_params = db.generic_params(id.parent); |
916 | let param_data = &generic_params.types[id.local_id]; | 921 | let param_data = &generic_params.types[id.local_id]; |
917 | match param_data.provenance { | 922 | match param_data.provenance { |
918 | hir_def::generics::TypeParamProvenance::ArgumentImplTrait => { | 923 | hir_def::generics::TypeParamProvenance::ArgumentImplTrait => { |
919 | let predicates = db | 924 | let predicates = db |
920 | .generic_predicates_for_param(*id) | 925 | .generic_predicates_for_param(id) |
921 | .into_iter() | 926 | .into_iter() |
922 | .map(|pred| pred.value.clone()) | 927 | .map(|pred| pred.value.clone()) |
923 | .collect_vec(); | 928 | .collect_vec(); |
@@ -1120,7 +1125,7 @@ impl<T: TypeWalk> TypeWalk for Vec<T> { | |||
1120 | } | 1125 | } |
1121 | 1126 | ||
1122 | #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] | 1127 | #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] |
1123 | pub enum OpaqueTyId { | 1128 | pub enum ImplTraitId { |
1124 | ReturnTypeImplTrait(hir_def::FunctionId, u16), | 1129 | ReturnTypeImplTrait(hir_def::FunctionId, u16), |
1125 | AsyncBlockTypeImplTrait(hir_def::DefWithBodyId, ExprId), | 1130 | AsyncBlockTypeImplTrait(hir_def::DefWithBodyId, ExprId), |
1126 | } | 1131 | } |
@@ -1150,3 +1155,17 @@ pub fn to_assoc_type_id(id: TypeAliasId) -> AssocTypeId { | |||
1150 | pub fn from_assoc_type_id(id: AssocTypeId) -> TypeAliasId { | 1155 | pub fn from_assoc_type_id(id: AssocTypeId) -> TypeAliasId { |
1151 | salsa::InternKey::from_intern_id(id.0) | 1156 | salsa::InternKey::from_intern_id(id.0) |
1152 | } | 1157 | } |
1158 | |||
1159 | pub fn from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> TypeParamId { | ||
1160 | assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT); | ||
1161 | let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx)); | ||
1162 | db.lookup_intern_type_param_id(interned_id) | ||
1163 | } | ||
1164 | |||
1165 | pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeParamId) -> PlaceholderIndex { | ||
1166 | let interned_id = db.intern_type_param_id(id); | ||
1167 | PlaceholderIndex { | ||
1168 | ui: chalk_ir::UniverseIndex::ROOT, | ||
1169 | idx: salsa::InternKey::as_intern_id(&interned_id).as_usize(), | ||
1170 | } | ||
1171 | } | ||
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index b8b1400eb..e57d5970f 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -27,14 +27,14 @@ use stdx::impl_from; | |||
27 | 27 | ||
28 | use crate::{ | 28 | use crate::{ |
29 | db::HirDatabase, | 29 | db::HirDatabase, |
30 | to_assoc_type_id, | 30 | to_assoc_type_id, to_placeholder_idx, |
31 | traits::chalk::{Interner, ToChalk}, | 31 | traits::chalk::{Interner, ToChalk}, |
32 | utils::{ | 32 | utils::{ |
33 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, | 33 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, |
34 | make_mut_slice, variant_data, | 34 | make_mut_slice, variant_data, |
35 | }, | 35 | }, |
36 | AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, | 36 | AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, |
37 | OpaqueTy, OpaqueTyId, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, | 37 | ImplTraitId, OpaqueTy, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, |
38 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, | 38 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, |
39 | }; | 39 | }; |
40 | 40 | ||
@@ -228,14 +228,12 @@ impl Ty { | |||
228 | Some(GenericDefId::FunctionId(f)) => f, | 228 | Some(GenericDefId::FunctionId(f)) => f, |
229 | _ => panic!("opaque impl trait lowering in non-function"), | 229 | _ => panic!("opaque impl trait lowering in non-function"), |
230 | }; | 230 | }; |
231 | let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx); | 231 | let impl_trait_id = ImplTraitId::ReturnTypeImplTrait(func, idx); |
232 | let opaque_ty_id = ctx.db.intern_impl_trait_id(impl_trait_id).into(); | ||
232 | let generics = generics(ctx.db.upcast(), func.into()); | 233 | let generics = generics(ctx.db.upcast(), func.into()); |
233 | let parameters = Substs::bound_vars(&generics, ctx.in_binders); | 234 | let parameters = Substs::bound_vars(&generics, ctx.in_binders); |
234 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { | 235 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters })) |
235 | opaque_ty_id: impl_trait_id, | 236 | .intern(&Interner) |
236 | parameters, | ||
237 | })) | ||
238 | .intern(&Interner) | ||
239 | } | 237 | } |
240 | ImplTraitLoweringMode::Param => { | 238 | ImplTraitLoweringMode::Param => { |
241 | let idx = ctx.impl_trait_counter.get(); | 239 | let idx = ctx.impl_trait_counter.get(); |
@@ -249,7 +247,9 @@ impl Ty { | |||
249 | data.provenance == TypeParamProvenance::ArgumentImplTrait | 247 | data.provenance == TypeParamProvenance::ArgumentImplTrait |
250 | }) | 248 | }) |
251 | .nth(idx as usize) | 249 | .nth(idx as usize) |
252 | .map_or(TyKind::Unknown, |(id, _)| TyKind::Placeholder(id)); | 250 | .map_or(TyKind::Unknown, |(id, _)| { |
251 | TyKind::Placeholder(to_placeholder_idx(ctx.db, id)) | ||
252 | }); | ||
253 | param.intern(&Interner) | 253 | param.intern(&Interner) |
254 | } else { | 254 | } else { |
255 | TyKind::Unknown.intern(&Interner) | 255 | TyKind::Unknown.intern(&Interner) |
@@ -384,7 +384,9 @@ impl Ty { | |||
384 | ctx.resolver.generic_def().expect("generics in scope"), | 384 | ctx.resolver.generic_def().expect("generics in scope"), |
385 | ); | 385 | ); |
386 | match ctx.type_param_mode { | 386 | match ctx.type_param_mode { |
387 | TypeParamLoweringMode::Placeholder => TyKind::Placeholder(param_id), | 387 | TypeParamLoweringMode::Placeholder => { |
388 | TyKind::Placeholder(to_placeholder_idx(ctx.db, param_id)) | ||
389 | } | ||
388 | TypeParamLoweringMode::Variable => { | 390 | TypeParamLoweringMode::Variable => { |
389 | let idx = generics.param_idx(param_id).expect("matching generics"); | 391 | let idx = generics.param_idx(param_id).expect("matching generics"); |
390 | TyKind::BoundVar(BoundVar::new(ctx.in_binders, idx)) | 392 | TyKind::BoundVar(BoundVar::new(ctx.in_binders, idx)) |
@@ -396,7 +398,7 @@ impl Ty { | |||
396 | let generics = generics(ctx.db.upcast(), impl_id.into()); | 398 | let generics = generics(ctx.db.upcast(), impl_id.into()); |
397 | let substs = match ctx.type_param_mode { | 399 | let substs = match ctx.type_param_mode { |
398 | TypeParamLoweringMode::Placeholder => { | 400 | TypeParamLoweringMode::Placeholder => { |
399 | Substs::type_params_for_generics(&generics) | 401 | Substs::type_params_for_generics(ctx.db, &generics) |
400 | } | 402 | } |
401 | TypeParamLoweringMode::Variable => { | 403 | TypeParamLoweringMode::Variable => { |
402 | Substs::bound_vars(&generics, ctx.in_binders) | 404 | Substs::bound_vars(&generics, ctx.in_binders) |
@@ -408,7 +410,7 @@ impl Ty { | |||
408 | let generics = generics(ctx.db.upcast(), adt.into()); | 410 | let generics = generics(ctx.db.upcast(), adt.into()); |
409 | let substs = match ctx.type_param_mode { | 411 | let substs = match ctx.type_param_mode { |
410 | TypeParamLoweringMode::Placeholder => { | 412 | TypeParamLoweringMode::Placeholder => { |
411 | Substs::type_params_for_generics(&generics) | 413 | Substs::type_params_for_generics(ctx.db, &generics) |
412 | } | 414 | } |
413 | TypeParamLoweringMode::Variable => { | 415 | TypeParamLoweringMode::Variable => { |
414 | Substs::bound_vars(&generics, ctx.in_binders) | 416 | Substs::bound_vars(&generics, ctx.in_binders) |
@@ -689,8 +691,9 @@ impl GenericPredicate { | |||
689 | let generics = generics(ctx.db.upcast(), generic_def); | 691 | let generics = generics(ctx.db.upcast(), generic_def); |
690 | let param_id = | 692 | let param_id = |
691 | hir_def::TypeParamId { parent: generic_def, local_id: *param_id }; | 693 | hir_def::TypeParamId { parent: generic_def, local_id: *param_id }; |
694 | let placeholder = to_placeholder_idx(ctx.db, param_id); | ||
692 | match ctx.type_param_mode { | 695 | match ctx.type_param_mode { |
693 | TypeParamLoweringMode::Placeholder => TyKind::Placeholder(param_id), | 696 | TypeParamLoweringMode::Placeholder => TyKind::Placeholder(placeholder), |
694 | TypeParamLoweringMode::Variable => { | 697 | TypeParamLoweringMode::Variable => { |
695 | let idx = generics.param_idx(param_id).expect("matching generics"); | 698 | let idx = generics.param_idx(param_id).expect("matching generics"); |
696 | TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, idx)) | 699 | TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, idx)) |
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index bb92d8e2a..1f3e1c07a 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs | |||
@@ -177,10 +177,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
177 | } | 177 | } |
178 | 178 | ||
179 | fn opaque_ty_data(&self, id: chalk_ir::OpaqueTyId<Interner>) -> Arc<OpaqueTyDatum> { | 179 | fn opaque_ty_data(&self, id: chalk_ir::OpaqueTyId<Interner>) -> Arc<OpaqueTyDatum> { |
180 | let interned_id = crate::db::InternedOpaqueTyId::from(id); | 180 | let full_id = self.db.lookup_intern_impl_trait_id(id.into()); |
181 | let full_id = self.db.lookup_intern_impl_trait_id(interned_id); | ||
182 | let bound = match full_id { | 181 | let bound = match full_id { |
183 | crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 182 | crate::ImplTraitId::ReturnTypeImplTrait(func, idx) => { |
184 | let datas = self | 183 | let datas = self |
185 | .db | 184 | .db |
186 | .return_type_impl_traits(func) | 185 | .return_type_impl_traits(func) |
@@ -202,7 +201,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
202 | let num_vars = datas.num_binders; | 201 | let num_vars = datas.num_binders; |
203 | make_binders(bound, num_vars) | 202 | make_binders(bound, num_vars) |
204 | } | 203 | } |
205 | crate::OpaqueTyId::AsyncBlockTypeImplTrait(..) => { | 204 | crate::ImplTraitId::AsyncBlockTypeImplTrait(..) => { |
206 | if let Some((future_trait, future_output)) = self | 205 | if let Some((future_trait, future_output)) = self |
207 | .db | 206 | .db |
208 | .lang_item(self.krate, "future_trait".into()) | 207 | .lang_item(self.krate, "future_trait".into()) |
@@ -716,14 +715,14 @@ impl From<crate::db::InternedOpaqueTyId> for OpaqueTyId { | |||
716 | } | 715 | } |
717 | } | 716 | } |
718 | 717 | ||
719 | impl From<chalk_ir::ClosureId<Interner>> for crate::db::ClosureId { | 718 | impl From<chalk_ir::ClosureId<Interner>> for crate::db::InternedClosureId { |
720 | fn from(id: chalk_ir::ClosureId<Interner>) -> Self { | 719 | fn from(id: chalk_ir::ClosureId<Interner>) -> Self { |
721 | Self::from_intern_id(id.0) | 720 | Self::from_intern_id(id.0) |
722 | } | 721 | } |
723 | } | 722 | } |
724 | 723 | ||
725 | impl From<crate::db::ClosureId> for chalk_ir::ClosureId<Interner> { | 724 | impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> { |
726 | fn from(id: crate::db::ClosureId) -> Self { | 725 | fn from(id: crate::db::InternedClosureId) -> Self { |
727 | chalk_ir::ClosureId(id.as_intern_id()) | 726 | chalk_ir::ClosureId(id.as_intern_id()) |
728 | } | 727 | } |
729 | } | 728 | } |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 23ef07d77..2a66a2310 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -3,10 +3,7 @@ | |||
3 | //! Chalk (in both directions); plus some helper functions for more specialized | 3 | //! Chalk (in both directions); plus some helper functions for more specialized |
4 | //! conversions. | 4 | //! conversions. |
5 | 5 | ||
6 | use chalk_ir::{ | 6 | use chalk_ir::{cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData}; |
7 | cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex, | ||
8 | UniverseIndex, | ||
9 | }; | ||
10 | use chalk_solve::rust_ir; | 7 | use chalk_solve::rust_ir; |
11 | 8 | ||
12 | use base_db::salsa::InternKey; | 9 | use base_db::salsa::InternKey; |
@@ -18,7 +15,7 @@ use crate::{ | |||
18 | primitive::UintTy, | 15 | primitive::UintTy, |
19 | traits::{Canonical, Obligation}, | 16 | traits::{Canonical, Obligation}, |
20 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, | 17 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, |
21 | OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, | 18 | ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, |
22 | }; | 19 | }; |
23 | 20 | ||
24 | use super::interner::*; | 21 | use super::interner::*; |
@@ -44,8 +41,7 @@ impl ToChalk for Ty { | |||
44 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) | 41 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) |
45 | } | 42 | } |
46 | 43 | ||
47 | TyKind::OpaqueType(impl_trait_id, substs) => { | 44 | TyKind::OpaqueType(id, substs) => { |
48 | let id = impl_trait_id.to_chalk(db); | ||
49 | let substitution = substs.to_chalk(db); | 45 | let substitution = substs.to_chalk(db); |
50 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) | 46 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) |
51 | } | 47 | } |
@@ -72,10 +68,9 @@ impl ToChalk for Ty { | |||
72 | } | 68 | } |
73 | TyKind::Never => chalk_ir::TyKind::Never.intern(&Interner), | 69 | TyKind::Never => chalk_ir::TyKind::Never.intern(&Interner), |
74 | 70 | ||
75 | TyKind::Closure(def, expr, substs) => { | 71 | TyKind::Closure(closure_id, substs) => { |
76 | let closure_id = db.intern_closure((def, expr)); | ||
77 | let substitution = substs.to_chalk(db); | 72 | let substitution = substs.to_chalk(db); |
78 | chalk_ir::TyKind::Closure(closure_id.into(), substitution).intern(&Interner) | 73 | chalk_ir::TyKind::Closure(closure_id, substitution).intern(&Interner) |
79 | } | 74 | } |
80 | 75 | ||
81 | TyKind::Adt(adt_id, substs) => { | 76 | TyKind::Adt(adt_id, substs) => { |
@@ -92,14 +87,7 @@ impl ToChalk for Ty { | |||
92 | .cast(&Interner) | 87 | .cast(&Interner) |
93 | .intern(&Interner) | 88 | .intern(&Interner) |
94 | } | 89 | } |
95 | TyKind::Placeholder(id) => { | 90 | TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner), |
96 | let interned_id = db.intern_type_param_id(id); | ||
97 | PlaceholderIndex { | ||
98 | ui: UniverseIndex::ROOT, | ||
99 | idx: interned_id.as_intern_id().as_usize(), | ||
100 | } | ||
101 | .to_ty::<Interner>(&Interner) | ||
102 | } | ||
103 | TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), | 91 | TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), |
104 | TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), | 92 | TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), |
105 | TyKind::Dyn(predicates) => { | 93 | TyKind::Dyn(predicates) => { |
@@ -114,7 +102,7 @@ impl ToChalk for Ty { | |||
114 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) | 102 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) |
115 | } | 103 | } |
116 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { | 104 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { |
117 | let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); | 105 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
118 | let substitution = opaque_ty.parameters.to_chalk(db); | 106 | let substitution = opaque_ty.parameters.to_chalk(db); |
119 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { | 107 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { |
120 | opaque_ty_id, | 108 | opaque_ty_id, |
@@ -129,22 +117,16 @@ impl ToChalk for Ty { | |||
129 | match chalk.data(&Interner).kind.clone() { | 117 | match chalk.data(&Interner).kind.clone() { |
130 | chalk_ir::TyKind::Error => TyKind::Unknown, | 118 | chalk_ir::TyKind::Error => TyKind::Unknown, |
131 | chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(Substs::single(from_chalk(db, ty))), | 119 | chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(Substs::single(from_chalk(db, ty))), |
132 | chalk_ir::TyKind::Placeholder(idx) => { | 120 | chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx), |
133 | assert_eq!(idx.ui, UniverseIndex::ROOT); | ||
134 | let interned_id = crate::db::GlobalTypeParamId::from_intern_id( | ||
135 | crate::salsa::InternId::from(idx.idx), | ||
136 | ); | ||
137 | TyKind::Placeholder(db.lookup_intern_type_param_id(interned_id)) | ||
138 | } | ||
139 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { | 121 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { |
140 | let associated_ty = proj.associated_ty_id; | 122 | let associated_ty = proj.associated_ty_id; |
141 | let parameters = from_chalk(db, proj.substitution); | 123 | let parameters = from_chalk(db, proj.substitution); |
142 | TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) | 124 | TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) |
143 | } | 125 | } |
144 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { | 126 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { |
145 | let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); | 127 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
146 | let parameters = from_chalk(db, opaque_ty.substitution); | 128 | let parameters = from_chalk(db, opaque_ty.substitution); |
147 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters })) | 129 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters })) |
148 | } | 130 | } |
149 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { | 131 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
150 | num_binders, | 132 | num_binders, |
@@ -182,7 +164,7 @@ impl ToChalk for Ty { | |||
182 | } | 164 | } |
183 | 165 | ||
184 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { | 166 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { |
185 | TyKind::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst)) | 167 | TyKind::OpaqueType(opaque_type_id, from_chalk(db, subst)) |
186 | } | 168 | } |
187 | 169 | ||
188 | chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar), | 170 | chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar), |
@@ -203,11 +185,7 @@ impl ToChalk for Ty { | |||
203 | TyKind::FnDef(fn_def_id, from_chalk(db, subst)) | 185 | TyKind::FnDef(fn_def_id, from_chalk(db, subst)) |
204 | } | 186 | } |
205 | 187 | ||
206 | chalk_ir::TyKind::Closure(id, subst) => { | 188 | 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 | 189 | ||
212 | chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id), | 190 | chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id), |
213 | chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME | 191 | chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME |
@@ -289,21 +267,6 @@ impl ToChalk for hir_def::TraitId { | |||
289 | } | 267 | } |
290 | } | 268 | } |
291 | 269 | ||
292 | impl ToChalk for OpaqueTyId { | ||
293 | type Chalk = chalk_ir::OpaqueTyId<Interner>; | ||
294 | |||
295 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::OpaqueTyId<Interner> { | ||
296 | db.intern_impl_trait_id(self).into() | ||
297 | } | ||
298 | |||
299 | fn from_chalk( | ||
300 | db: &dyn HirDatabase, | ||
301 | opaque_ty_id: chalk_ir::OpaqueTyId<Interner>, | ||
302 | ) -> OpaqueTyId { | ||
303 | db.lookup_intern_impl_trait_id(opaque_ty_id.into()) | ||
304 | } | ||
305 | } | ||
306 | |||
307 | impl ToChalk for hir_def::ImplId { | 270 | impl ToChalk for hir_def::ImplId { |
308 | type Chalk = ImplId; | 271 | type Chalk = ImplId; |
309 | 272 | ||