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