mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
Remove TypeCtor interning
Our TypeCtor and Chalk's TypeName match now!
This commit is contained in:
parent
a48843a16a
commit
2077004463
@ -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]
|
||||
|
@ -159,17 +159,17 @@ pub struct FunctionId(salsa::InternId);
|
||||
type FunctionLoc = AssocItemLoc<Function>;
|
||||
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<Struct>;
|
||||
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<Union>;
|
||||
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<Enum>;
|
||||
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),
|
||||
|
@ -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<dyn DefDatabase> {
|
||||
|
||||
// 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;
|
||||
|
@ -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)]
|
||||
|
@ -552,18 +552,6 @@ pub(crate) fn fn_def_datum_query(
|
||||
Arc::new(datum)
|
||||
}
|
||||
|
||||
impl From<AdtId> for crate::TypeCtorId {
|
||||
fn from(struct_id: AdtId) -> Self {
|
||||
struct_id.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::TypeCtorId> for AdtId {
|
||||
fn from(type_ctor_id: crate::TypeCtorId) -> Self {
|
||||
chalk_ir::AdtId(type_ctor_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FnDefId> for crate::CallableDefId {
|
||||
fn from(fn_def_id: FnDefId) -> Self {
|
||||
InternKey::from_intern_id(fn_def_id.0)
|
||||
|
@ -41,7 +41,7 @@ impl chalk_ir::interner::Interner for Interner {
|
||||
type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>;
|
||||
type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>;
|
||||
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<chalk_ir::Constraint<Self>>] {
|
||||
constraints
|
||||
}
|
||||
fn debug_closure_id(
|
||||
_fn_def_id: chalk_ir::ClosureId<Self>,
|
||||
_fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
None
|
||||
}
|
||||
fn debug_constraints(
|
||||
_clauses: &chalk_ir::Constraints<Self>,
|
||||
_fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl chalk_ir::interner::HasInterner for Interner {
|
||||
|
@ -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<Interner>) -> 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))
|
||||
|
@ -279,7 +279,6 @@ impl RootDatabase {
|
||||
hir::db::InternImplQuery
|
||||
|
||||
// HirDatabase
|
||||
hir::db::InternTypeCtorQuery
|
||||
hir::db::InternTypeParamIdQuery
|
||||
];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user