From 20770044631fd0c21caa12f9bc87489ea6c848ee Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 15 Jul 2020 21:47:45 +0200 Subject: Remove TypeCtor interning Our TypeCtor and Chalk's TypeName match now! --- crates/ra_hir/src/db.rs | 6 +++--- crates/ra_hir_def/src/lib.rs | 8 ++++---- crates/ra_hir_ty/src/db.rs | 4 +--- crates/ra_hir_ty/src/lib.rs | 8 +------- crates/ra_hir_ty/src/traits/chalk.rs | 12 ------------ crates/ra_hir_ty/src/traits/chalk/interner.rs | 14 +++++++++++++- crates/ra_hir_ty/src/traits/chalk/mapping.rs | 13 ++++++------- crates/ra_ide_db/src/change.rs | 1 - 8 files changed, 28 insertions(+), 38 deletions(-) diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 3a9973abf..1ad92a1f8 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -17,9 +17,9 @@ pub use hir_ty::db::{ AssociatedTyDataQuery, AssociatedTyValueQuery, CallableItemSignatureQuery, FieldTypesQuery, GenericDefaultsQuery, GenericPredicatesForParamQuery, GenericPredicatesQuery, HirDatabase, HirDatabaseStorage, ImplDatumQuery, ImplSelfTyQuery, ImplTraitQuery, InferQueryQuery, - InherentImplsInCrateQuery, InternTypeCtorQuery, InternTypeParamIdQuery, - ReturnTypeImplTraitsQuery, StructDatumQuery, TraitDatumQuery, TraitImplsInCrateQuery, - TraitImplsInDepsQuery, TraitSolveQuery, TyQuery, ValueTyQuery, + InherentImplsInCrateQuery, InternTypeParamIdQuery, ReturnTypeImplTraitsQuery, StructDatumQuery, + TraitDatumQuery, TraitImplsInCrateQuery, TraitImplsInDepsQuery, TraitSolveQuery, TyQuery, + ValueTyQuery, }; #[test] diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index b71d626c3..87000fe98 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -159,17 +159,17 @@ pub struct FunctionId(salsa::InternId); type FunctionLoc = AssocItemLoc; impl_intern!(FunctionId, FunctionLoc, intern_function, lookup_intern_function); -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct StructId(salsa::InternId); type StructLoc = ItemLoc; impl_intern!(StructId, StructLoc, intern_struct, lookup_intern_struct); -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct UnionId(salsa::InternId); pub type UnionLoc = ItemLoc; impl_intern!(UnionId, UnionLoc, intern_union, lookup_intern_union); -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct EnumId(salsa::InternId); pub type EnumLoc = ItemLoc; impl_intern!(EnumId, EnumLoc, intern_enum, lookup_intern_enum); @@ -239,7 +239,7 @@ pub enum AssocContainerId { impl_from!(ContainerId for AssocContainerId); /// A Data Type -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum AdtId { StructId(StructId), UnionId(UnionId), diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index d8a798771..608bab1b1 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs @@ -14,7 +14,7 @@ use crate::{ method_resolution::{InherentImpls, TraitImpls}, traits::chalk, Binders, CallableDef, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig, - ReturnTypeImplTraits, TraitRef, Ty, TyDefId, TypeCtor, ValueTyDefId, + ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, }; use hir_expand::name::Name; @@ -77,8 +77,6 @@ pub trait HirDatabase: DefDatabase + Upcast { // Interned IDs for Chalk integration #[salsa::interned] - fn intern_type_ctor(&self, type_ctor: TypeCtor) -> crate::TypeCtorId; - #[salsa::interned] fn intern_callable_def(&self, callable_def: CallableDef) -> crate::CallableDefId; #[salsa::interned] fn intern_type_param_id(&self, param_id: TypeParamId) -> GlobalTypeParamId; diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index c4c24a83b..9f034eca5 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -112,6 +112,7 @@ pub enum TypeCtor { /// fn foo() -> i32 { 1 } /// let bar: fn() -> i32 = foo; /// ``` + // FIXME make this a Ty variant like in Chalk FnPtr { num_args: u16, is_varargs: bool }, /// The never type `!`. @@ -139,13 +140,6 @@ pub enum TypeCtor { Closure { def: DefWithBodyId, expr: ExprId }, } -/// This exists just for Chalk, because Chalk just has a single `StructId` where -/// we have different kinds of ADTs, primitive types and special type -/// constructors like tuples and function pointers. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] -pub struct TypeCtorId(salsa::InternId); -impl_intern_key!(TypeCtorId); - /// This exists just for Chalk, because Chalk just has a single `FnDefId` where /// we have different IDs for struct and enum variant constructors. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 7f8ba2f12..1ef5baa05 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -552,18 +552,6 @@ pub(crate) fn fn_def_datum_query( Arc::new(datum) } -impl From for crate::TypeCtorId { - fn from(struct_id: AdtId) -> Self { - struct_id.0 - } -} - -impl From for AdtId { - fn from(type_ctor_id: crate::TypeCtorId) -> Self { - chalk_ir::AdtId(type_ctor_id) - } -} - impl From for crate::CallableDefId { fn from(fn_def_id: FnDefId) -> Self { InternKey::from_intern_id(fn_def_id.0) diff --git a/crates/ra_hir_ty/src/traits/chalk/interner.rs b/crates/ra_hir_ty/src/traits/chalk/interner.rs index 156b691b4..8d4c51a8f 100644 --- a/crates/ra_hir_ty/src/traits/chalk/interner.rs +++ b/crates/ra_hir_ty/src/traits/chalk/interner.rs @@ -41,7 +41,7 @@ impl chalk_ir::interner::Interner for Interner { type InternedCanonicalVarKinds = Vec>; type InternedConstraints = Vec>>; type DefId = InternId; - type InternedAdtId = crate::TypeCtorId; + type InternedAdtId = hir_def::AdtId; type Identifier = TypeAliasId; type FnAbi = (); @@ -364,6 +364,18 @@ impl chalk_ir::interner::Interner for Interner { ) -> &'a [chalk_ir::InEnvironment>] { constraints } + fn debug_closure_id( + _fn_def_id: chalk_ir::ClosureId, + _fmt: &mut fmt::Formatter<'_>, + ) -> Option { + None + } + fn debug_constraints( + _clauses: &chalk_ir::Constraints, + _fmt: &mut fmt::Formatter<'_>, + ) -> Option { + None + } } impl chalk_ir::interner::HasInterner for Interner { diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs index 796947e69..a852ce2ac 100644 --- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs +++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs @@ -316,20 +316,19 @@ impl ToChalk for TypeCtor { TypeName::Closure(closure_id.into()) } - TypeCtor::FnPtr { .. } => panic!("Trying to convert FnPtr to TypeName"), + TypeCtor::Adt(adt_id) => TypeName::Adt(chalk_ir::AdtId(adt_id)), - TypeCtor::Adt(_) => { - // FIXME no interning needed anymore - // other TypeCtors get interned and turned into a chalk StructId - let struct_id = db.intern_type_ctor(self).into(); - TypeName::Adt(struct_id) + TypeCtor::FnPtr { .. } => { + // This should not be reached, since Chalk doesn't represent + // function pointers with TypeName + unreachable!() } } } fn from_chalk(db: &dyn HirDatabase, type_name: TypeName) -> TypeCtor { match type_name { - TypeName::Adt(struct_id) => db.lookup_intern_type_ctor(struct_id.into()), + TypeName::Adt(struct_id) => TypeCtor::Adt(struct_id.0), TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)), TypeName::OpaqueType(opaque_type_id) => { TypeCtor::OpaqueType(from_chalk(db, opaque_type_id)) diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs index d40cfeb02..a1bb3043b 100644 --- a/crates/ra_ide_db/src/change.rs +++ b/crates/ra_ide_db/src/change.rs @@ -279,7 +279,6 @@ impl RootDatabase { hir::db::InternImplQuery // HirDatabase - hir::db::InternTypeCtorQuery hir::db::InternTypeParamIdQuery ]; -- cgit v1.2.3