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/lib.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'crates/hir_ty/src/lib.rs') 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 -- cgit v1.2.3 From 1bf6b7360c3f1d0e20dece5227979bc4d74a352f Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 13 Mar 2021 19:47:34 +0100 Subject: Use chalk_ir::PlaceholderIndex --- crates/hir_ty/src/lib.rs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'crates/hir_ty/src/lib.rs') diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index ec2010e4b..d1c018283 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -54,6 +54,7 @@ pub type ForeignDefId = chalk_ir::ForeignDefId; pub type AssocTypeId = chalk_ir::AssocTypeId; pub type FnDefId = chalk_ir::FnDefId; pub type ClosureId = chalk_ir::ClosureId; +pub type PlaceholderIndex = chalk_ir::PlaceholderIndex; #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub enum Lifetime { @@ -220,7 +221,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`, the type @@ -310,11 +311,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 +326,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) -> 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. @@ -909,13 +913,14 @@ impl Ty { 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(); @@ -1148,3 +1153,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(), + } +} -- cgit v1.2.3 From b035c314b4b0ecd2477fde216dbe7e8801f94d0d Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 13 Mar 2021 20:05:47 +0100 Subject: Use chalk_ir::OpaqueTyId --- crates/hir_ty/src/lib.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/hir_ty/src/lib.rs') diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index d1c018283..d6ff968f0 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -54,6 +54,7 @@ pub type ForeignDefId = chalk_ir::ForeignDefId; pub type AssocTypeId = chalk_ir::AssocTypeId; pub type FnDefId = chalk_ir::FnDefId; pub type ClosureId = chalk_ir::ClosureId; +pub type OpaqueTyId = chalk_ir::OpaqueTyId; pub type PlaceholderIndex = chalk_ir::PlaceholderIndex; #[derive(Clone, PartialEq, Eq, Debug, Hash)] @@ -875,8 +876,8 @@ impl Ty { pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option> { 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()) @@ -894,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() @@ -908,7 +910,7 @@ impl Ty { }) } // It always has an parameter for Future::Output type. - OpaqueTyId::AsyncBlockTypeImplTrait(..) => unreachable!(), + ImplTraitId::AsyncBlockTypeImplTrait(..) => unreachable!(), }; predicates.map(|it| it.value) @@ -1123,7 +1125,7 @@ impl TypeWalk for Vec { } #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] -pub enum OpaqueTyId { +pub enum ImplTraitId { ReturnTypeImplTrait(hir_def::FunctionId, u16), AsyncBlockTypeImplTrait(hir_def::DefWithBodyId, ExprId), } -- cgit v1.2.3