From bca51e35190e47688ccf252c367a7951d36dadad Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 30 Oct 2020 18:57:16 +0100 Subject: Upgrade Chalk to 0.36 Quite a few changes, because Chalk got rid of the `ApplicationTy` nesting. --- crates/hir_ty/Cargo.toml | 6 +- crates/hir_ty/src/traits/chalk.rs | 21 +- crates/hir_ty/src/traits/chalk/interner.rs | 7 - crates/hir_ty/src/traits/chalk/mapping.rs | 356 +++++++++++++---------------- crates/hir_ty/src/traits/chalk/tls.rs | 108 +-------- 5 files changed, 179 insertions(+), 319 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml index 367a1b98d..3b822d223 100644 --- a/crates/hir_ty/Cargo.toml +++ b/crates/hir_ty/Cargo.toml @@ -17,9 +17,9 @@ ena = "0.14.0" log = "0.4.8" rustc-hash = "1.1.0" scoped-tls = "1" -chalk-solve = { version = "0.34", default-features = false } -chalk-ir = "0.34" -chalk-recursive = "0.34" +chalk-solve = { version = "0.36", default-features = false } +chalk-ir = "0.36" +chalk-recursive = "0.36" stdx = { path = "../stdx", version = "0.0.0" } hir_def = { path = "../hir_def", version = "0.0.0" } diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index cbe5cd7dd..a6c247f87 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use log::debug; -use chalk_ir::{fold::shift::Shift, CanonicalVarKinds, GenericArg, TypeName}; +use chalk_ir::{fold::shift::Shift, CanonicalVarKinds, GenericArg}; use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; use base_db::{salsa::InternKey, CrateId}; @@ -81,7 +81,10 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone()); - fn binder_kind(ty: &Ty, binders: &CanonicalVarKinds) -> Option { + fn binder_kind( + ty: &Ty, + binders: &CanonicalVarKinds, + ) -> Option { if let Ty::Bound(bv) = ty { let binders = binders.as_slice(&Interner); if bv.debruijn == DebruijnIndex::INNERMOST { @@ -95,8 +98,8 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { let self_ty_fp = TyFingerprint::for_impl(&ty); let fps: &[TyFingerprint] = match binder_kind(&ty, binders) { - Some(chalk_ir::TyKind::Integer) => &ALL_INT_FPS, - Some(chalk_ir::TyKind::Float) => &ALL_FLOAT_FPS, + Some(chalk_ir::TyVariableKind::Integer) => &ALL_INT_FPS, + Some(chalk_ir::TyVariableKind::Float) => &ALL_FLOAT_FPS, _ => self_ty_fp.as_ref().map(std::slice::from_ref).unwrap_or(&[]), }; @@ -129,12 +132,8 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { debug!("impls_for_trait returned {} impls", result.len()); result } - fn impl_provided_for( - &self, - auto_trait_id: TraitId, - application_ty: &chalk_ir::ApplicationTy, - ) -> bool { - debug!("impl_provided_for {:?}, {:?}", auto_trait_id, application_ty); + fn impl_provided_for(&self, auto_trait_id: TraitId, kind: &chalk_ir::TyKind) -> bool { + debug!("impl_provided_for {:?}, {:?}", auto_trait_id, kind); false // FIXME } fn associated_ty_value(&self, id: AssociatedTyValueId) -> Arc { @@ -466,7 +465,7 @@ pub(crate) fn struct_datum_query( struct_id: AdtId, ) -> Arc { debug!("struct_datum {:?}", struct_id); - let type_ctor: TypeCtor = from_chalk(db, TypeName::Adt(struct_id)); + let type_ctor = TypeCtor::Adt(from_chalk(db, struct_id)); debug!("struct {:?} = {:?}", struct_id, type_ctor); let num_params = type_ctor.num_ty_params(db); let upstream = type_ctor.krate(db) != Some(krate); diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index f9304b7d0..f65873872 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs @@ -122,13 +122,6 @@ impl chalk_ir::interner::Interner for Interner { tls::with_current_program(|prog| Some(prog?.debug_program_clause_implication(pci, fmt))) } - fn debug_application_ty( - application_ty: &chalk_ir::ApplicationTy, - fmt: &mut fmt::Formatter<'_>, - ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_application_ty(application_ty, fmt))) - } - fn debug_substitution( substitution: &chalk_ir::Substitution, fmt: &mut fmt::Formatter<'_>, diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index dd7affcec..58c337b40 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -5,7 +5,7 @@ use chalk_ir::{ cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex, Scalar, - TypeName, UniverseIndex, + UniverseIndex, }; use chalk_solve::rust_ir; @@ -32,7 +32,7 @@ impl ToChalk for Ty { TypeCtor::Array => array_to_chalk(db, apply_ty.parameters), TypeCtor::FnPtr { num_args: _, is_varargs } => { let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner); - chalk_ir::TyData::Function(chalk_ir::FnPointer { + chalk_ir::TyKind::Function(chalk_ir::FnPointer { num_binders: 0, sig: chalk_ir::FnSig { abi: (), @@ -43,10 +43,68 @@ impl ToChalk for Ty { }) .intern(&Interner) } - _ => { - let name = apply_ty.ctor.to_chalk(db); + TypeCtor::AssociatedType(type_alias) => { + let assoc_type = TypeAliasAsAssocType(type_alias); + let assoc_type_id = assoc_type.to_chalk(db); let substitution = apply_ty.parameters.to_chalk(db); - chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner) + chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) + } + + TypeCtor::OpaqueType(impl_trait_id) => { + let id = impl_trait_id.to_chalk(db); + let substitution = apply_ty.parameters.to_chalk(db); + chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) + } + + TypeCtor::ForeignType(type_alias) => { + let foreign_type = TypeAliasAsForeignType(type_alias); + let foreign_type_id = foreign_type.to_chalk(db); + chalk_ir::TyKind::Foreign(foreign_type_id).intern(&Interner) + } + + TypeCtor::Bool => chalk_ir::TyKind::Scalar(Scalar::Bool).intern(&Interner), + TypeCtor::Char => chalk_ir::TyKind::Scalar(Scalar::Char).intern(&Interner), + TypeCtor::Int(int_ty) => { + chalk_ir::TyKind::Scalar(int_ty_to_chalk(int_ty)).intern(&Interner) + } + TypeCtor::Float(FloatTy { bitness: FloatBitness::X32 }) => { + chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F32)) + .intern(&Interner) + } + TypeCtor::Float(FloatTy { bitness: FloatBitness::X64 }) => { + chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F64)) + .intern(&Interner) + } + + TypeCtor::Tuple { cardinality } => { + let substitution = apply_ty.parameters.to_chalk(db); + chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) + } + TypeCtor::RawPtr(mutability) => { + let ty = apply_ty.parameters[0].clone().to_chalk(db); + chalk_ir::TyKind::Raw(mutability.to_chalk(db), ty).intern(&Interner) + } + TypeCtor::Slice => { + chalk_ir::TyKind::Slice(apply_ty.parameters[0].clone().to_chalk(db)) + .intern(&Interner) + } + TypeCtor::Str => chalk_ir::TyKind::Str.intern(&Interner), + TypeCtor::FnDef(callable_def) => { + let id = callable_def.to_chalk(db); + let substitution = apply_ty.parameters.to_chalk(db); + chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner) + } + TypeCtor::Never => chalk_ir::TyKind::Never.intern(&Interner), + + TypeCtor::Closure { def, expr } => { + let closure_id = db.intern_closure((def, expr)); + let substitution = apply_ty.parameters.to_chalk(db); + chalk_ir::TyKind::Closure(closure_id.into(), substitution).intern(&Interner) + } + + TypeCtor::Adt(adt_id) => { + let substitution = apply_ty.parameters.to_chalk(db); + chalk_ir::TyKind::Adt(chalk_ir::AdtId(adt_id), substitution).intern(&Interner) } }, Ty::Projection(proj_ty) => { @@ -67,7 +125,7 @@ impl ToChalk for Ty { } .to_ty::(&Interner) } - Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx).intern(&Interner), + Ty::Bound(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), Ty::Dyn(predicates) => { let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( @@ -78,55 +136,45 @@ impl ToChalk for Ty { bounds: make_binders(where_clauses, 1), lifetime: LifetimeData::Static.intern(&Interner), }; - chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) + chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) } Ty::Opaque(opaque_ty) => { let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); let substitution = opaque_ty.parameters.to_chalk(db); - chalk_ir::TyData::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { + chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { opaque_ty_id, substitution, })) .intern(&Interner) } - Ty::Unknown => { - let substitution = chalk_ir::Substitution::empty(&Interner); - let name = TypeName::Error; - chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner) - } + Ty::Unknown => chalk_ir::TyKind::Error.intern(&Interner), } } fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty) -> Self { - match chalk.data(&Interner).clone() { - chalk_ir::TyData::Apply(apply_ty) => match apply_ty.name { - TypeName::Error => Ty::Unknown, - TypeName::Ref(m) => ref_from_chalk(db, m, apply_ty.substitution), - TypeName::Array => array_from_chalk(db, apply_ty.substitution), - _ => { - let ctor = from_chalk(db, apply_ty.name); - let parameters = from_chalk(db, apply_ty.substitution); - Ty::Apply(ApplicationTy { ctor, parameters }) - } - }, - chalk_ir::TyData::Placeholder(idx) => { + match chalk.data(&Interner).kind.clone() { + chalk_ir::TyKind::Error => Ty::Unknown, + chalk_ir::TyKind::Array(ty, _size) => { + Ty::apply(TypeCtor::Array, Substs::single(from_chalk(db, ty))) + } + chalk_ir::TyKind::Placeholder(idx) => { assert_eq!(idx.ui, UniverseIndex::ROOT); let interned_id = crate::db::GlobalTypeParamId::from_intern_id( crate::salsa::InternId::from(idx.idx), ); Ty::Placeholder(db.lookup_intern_type_param_id(interned_id)) } - chalk_ir::TyData::Alias(chalk_ir::AliasTy::Projection(proj)) => { + chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { let associated_ty = from_chalk::(db, proj.associated_ty_id).0; let parameters = from_chalk(db, proj.substitution); Ty::Projection(ProjectionTy { associated_ty, parameters }) } - chalk_ir::TyData::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { + chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); let parameters = from_chalk(db, opaque_ty.substitution); Ty::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters }) } - chalk_ir::TyData::Function(chalk_ir::FnPointer { + chalk_ir::TyKind::Function(chalk_ir::FnPointer { num_binders, sig: chalk_ir::FnSig { variadic, .. }, substitution, @@ -145,9 +193,9 @@ impl ToChalk for Ty { parameters, }) } - chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx), - chalk_ir::TyData::InferenceVar(_iv, _kind) => Ty::Unknown, - chalk_ir::TyData::Dyn(where_clauses) => { + chalk_ir::TyKind::BoundVar(idx) => Ty::Bound(idx), + chalk_ir::TyKind::InferenceVar(_iv, _kind) => Ty::Unknown, + chalk_ir::TyKind::Dyn(where_clauses) => { assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); let predicates = where_clauses .bounds @@ -157,10 +205,76 @@ impl ToChalk for Ty { .collect(); Ty::Dyn(predicates) } + + chalk_ir::TyKind::Adt(struct_id, subst) => { + apply_ty_from_chalk(db, TypeCtor::Adt(struct_id.0), subst) + } + chalk_ir::TyKind::AssociatedType(type_id, subst) => apply_ty_from_chalk( + db, + TypeCtor::AssociatedType(from_chalk::(db, type_id).0), + subst, + ), + chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { + apply_ty_from_chalk(db, TypeCtor::OpaqueType(from_chalk(db, opaque_type_id)), subst) + } + + chalk_ir::TyKind::Scalar(Scalar::Bool) => Ty::simple(TypeCtor::Bool), + chalk_ir::TyKind::Scalar(Scalar::Char) => Ty::simple(TypeCtor::Char), + chalk_ir::TyKind::Scalar(Scalar::Int(int_ty)) => Ty::simple(TypeCtor::Int(IntTy { + signedness: Signedness::Signed, + bitness: bitness_from_chalk_int(int_ty), + })), + chalk_ir::TyKind::Scalar(Scalar::Uint(uint_ty)) => Ty::simple(TypeCtor::Int(IntTy { + signedness: Signedness::Unsigned, + bitness: bitness_from_chalk_uint(uint_ty), + })), + chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F32)) => { + Ty::simple(TypeCtor::Float(FloatTy { bitness: FloatBitness::X32 })) + } + chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F64)) => { + Ty::simple(TypeCtor::Float(FloatTy { bitness: FloatBitness::X64 })) + } + chalk_ir::TyKind::Tuple(cardinality, subst) => { + apply_ty_from_chalk(db, TypeCtor::Tuple { cardinality: cardinality as u16 }, subst) + } + chalk_ir::TyKind::Raw(mutability, ty) => { + Ty::apply_one(TypeCtor::RawPtr(from_chalk(db, mutability)), from_chalk(db, ty)) + } + chalk_ir::TyKind::Slice(ty) => Ty::apply_one(TypeCtor::Slice, from_chalk(db, ty)), + chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { + Ty::apply_one(TypeCtor::Ref(from_chalk(db, mutability)), from_chalk(db, ty)) + } + chalk_ir::TyKind::Str => Ty::simple(TypeCtor::Str), + chalk_ir::TyKind::Never => Ty::simple(TypeCtor::Never), + + chalk_ir::TyKind::FnDef(fn_def_id, subst) => { + let callable_def = from_chalk(db, fn_def_id); + apply_ty_from_chalk(db, TypeCtor::FnDef(callable_def), subst) + } + + chalk_ir::TyKind::Closure(id, subst) => { + let id: crate::db::ClosureId = id.into(); + let (def, expr) = db.lookup_intern_closure(id); + apply_ty_from_chalk(db, TypeCtor::Closure { def, expr }, subst) + } + + chalk_ir::TyKind::Foreign(foreign_def_id) => Ty::simple(TypeCtor::ForeignType( + from_chalk::(db, foreign_def_id).0, + )), + chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME + chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME } } } +fn apply_ty_from_chalk( + db: &dyn HirDatabase, + ctor: TypeCtor, + subst: chalk_ir::Substitution, +) -> Ty { + Ty::Apply(ApplicationTy { ctor, parameters: from_chalk(db, subst) }) +} + /// We currently don't model lifetimes, but Chalk does. So, we have to insert a /// fake lifetime here, because Chalks built-in logic may expect it to be there. fn ref_to_chalk( @@ -170,60 +284,21 @@ fn ref_to_chalk( ) -> chalk_ir::Ty { let arg = subst[0].clone().to_chalk(db); let lifetime = LifetimeData::Static.intern(&Interner); - chalk_ir::ApplicationTy { - name: TypeName::Ref(mutability.to_chalk(db)), - substitution: chalk_ir::Substitution::from_iter( - &Interner, - vec![lifetime.cast(&Interner), arg.cast(&Interner)], - ), - } - .intern(&Interner) -} - -/// Here we remove the lifetime from the type we got from Chalk. -fn ref_from_chalk( - db: &dyn HirDatabase, - mutability: chalk_ir::Mutability, - subst: chalk_ir::Substitution, -) -> Ty { - let tys = subst - .iter(&Interner) - .filter_map(|p| Some(from_chalk(db, p.ty(&Interner)?.clone()))) - .collect(); - Ty::apply(TypeCtor::Ref(from_chalk(db, mutability)), Substs(tys)) + chalk_ir::TyKind::Ref(mutability.to_chalk(db), lifetime, arg).intern(&Interner) } /// We currently don't model constants, but Chalk does. So, we have to insert a /// fake constant here, because Chalks built-in logic may expect it to be there. fn array_to_chalk(db: &dyn HirDatabase, subst: Substs) -> chalk_ir::Ty { let arg = subst[0].clone().to_chalk(db); - let usize_ty = chalk_ir::ApplicationTy { - name: TypeName::Scalar(Scalar::Uint(chalk_ir::UintTy::Usize)), - substitution: chalk_ir::Substitution::empty(&Interner), - } - .intern(&Interner); + let usize_ty = + chalk_ir::TyKind::Scalar(Scalar::Uint(chalk_ir::UintTy::Usize)).intern(&Interner); let const_ = chalk_ir::ConstData { ty: usize_ty, value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: () }), } .intern(&Interner); - chalk_ir::ApplicationTy { - name: TypeName::Array, - substitution: chalk_ir::Substitution::from_iter( - &Interner, - vec![arg.cast(&Interner), const_.cast(&Interner)], - ), - } - .intern(&Interner) -} - -/// Here we remove the const from the type we got from Chalk. -fn array_from_chalk(db: &dyn HirDatabase, subst: chalk_ir::Substitution) -> Ty { - let tys = subst - .iter(&Interner) - .filter_map(|p| Some(from_chalk(db, p.ty(&Interner)?.clone()))) - .collect(); - Ty::apply(TypeCtor::Array, Substs(tys)) + chalk_ir::TyKind::Array(arg, const_).intern(&Interner) } impl ToChalk for Substs { @@ -288,124 +363,6 @@ impl ToChalk for OpaqueTyId { } } -impl ToChalk for TypeCtor { - type Chalk = TypeName; - - fn to_chalk(self, db: &dyn HirDatabase) -> TypeName { - match self { - TypeCtor::AssociatedType(type_alias) => { - let assoc_type = TypeAliasAsAssocType(type_alias); - let assoc_type_id = assoc_type.to_chalk(db); - TypeName::AssociatedType(assoc_type_id) - } - - TypeCtor::OpaqueType(impl_trait_id) => { - let id = impl_trait_id.to_chalk(db); - TypeName::OpaqueType(id) - } - - TypeCtor::ForeignType(type_alias) => { - let foreign_type = TypeAliasAsForeignType(type_alias); - let foreign_type_id = foreign_type.to_chalk(db); - TypeName::Foreign(foreign_type_id) - } - - TypeCtor::Bool => TypeName::Scalar(Scalar::Bool), - TypeCtor::Char => TypeName::Scalar(Scalar::Char), - TypeCtor::Int(int_ty) => TypeName::Scalar(int_ty_to_chalk(int_ty)), - TypeCtor::Float(FloatTy { bitness: FloatBitness::X32 }) => { - TypeName::Scalar(Scalar::Float(chalk_ir::FloatTy::F32)) - } - TypeCtor::Float(FloatTy { bitness: FloatBitness::X64 }) => { - TypeName::Scalar(Scalar::Float(chalk_ir::FloatTy::F64)) - } - - TypeCtor::Tuple { cardinality } => TypeName::Tuple(cardinality.into()), - TypeCtor::RawPtr(mutability) => TypeName::Raw(mutability.to_chalk(db)), - TypeCtor::Slice => TypeName::Slice, - TypeCtor::Array => TypeName::Array, - TypeCtor::Ref(mutability) => TypeName::Ref(mutability.to_chalk(db)), - TypeCtor::Str => TypeName::Str, - TypeCtor::FnDef(callable_def) => { - let id = callable_def.to_chalk(db); - TypeName::FnDef(id) - } - TypeCtor::Never => TypeName::Never, - - TypeCtor::Closure { def, expr } => { - let closure_id = db.intern_closure((def, expr)); - TypeName::Closure(closure_id.into()) - } - - TypeCtor::Adt(adt_id) => TypeName::Adt(chalk_ir::AdtId(adt_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) => TypeCtor::Adt(struct_id.0), - TypeName::AssociatedType(type_id) => { - TypeCtor::AssociatedType(from_chalk::(db, type_id).0) - } - TypeName::OpaqueType(opaque_type_id) => { - TypeCtor::OpaqueType(from_chalk(db, opaque_type_id)) - } - - TypeName::Scalar(Scalar::Bool) => TypeCtor::Bool, - TypeName::Scalar(Scalar::Char) => TypeCtor::Char, - TypeName::Scalar(Scalar::Int(int_ty)) => TypeCtor::Int(IntTy { - signedness: Signedness::Signed, - bitness: bitness_from_chalk_int(int_ty), - }), - TypeName::Scalar(Scalar::Uint(uint_ty)) => TypeCtor::Int(IntTy { - signedness: Signedness::Unsigned, - bitness: bitness_from_chalk_uint(uint_ty), - }), - TypeName::Scalar(Scalar::Float(chalk_ir::FloatTy::F32)) => { - TypeCtor::Float(FloatTy { bitness: FloatBitness::X32 }) - } - TypeName::Scalar(Scalar::Float(chalk_ir::FloatTy::F64)) => { - TypeCtor::Float(FloatTy { bitness: FloatBitness::X64 }) - } - TypeName::Tuple(cardinality) => TypeCtor::Tuple { cardinality: cardinality as u16 }, - TypeName::Raw(mutability) => TypeCtor::RawPtr(from_chalk(db, mutability)), - TypeName::Slice => TypeCtor::Slice, - TypeName::Ref(mutability) => TypeCtor::Ref(from_chalk(db, mutability)), - TypeName::Str => TypeCtor::Str, - TypeName::Never => TypeCtor::Never, - - TypeName::FnDef(fn_def_id) => { - let callable_def = from_chalk(db, fn_def_id); - TypeCtor::FnDef(callable_def) - } - TypeName::Array => TypeCtor::Array, - - TypeName::Closure(id) => { - let id: crate::db::ClosureId = id.into(); - let (def, expr) = db.lookup_intern_closure(id); - TypeCtor::Closure { def, expr } - } - - TypeName::Foreign(foreign_def_id) => { - TypeCtor::ForeignType(from_chalk::(db, foreign_def_id).0) - } - - TypeName::Error => { - // this should not be reached, since we don't represent TypeName::Error with TypeCtor - unreachable!() - } - TypeName::Generator(_) => unimplemented!(), // FIXME - TypeName::GeneratorWitness(_) => unimplemented!(), // FIXME - } - } -} - fn bitness_from_chalk_uint(uint_ty: chalk_ir::UintTy) -> IntBitness { use chalk_ir::UintTy; @@ -677,9 +634,9 @@ where .kinds .iter() .map(|k| match k { - TyKind::General => chalk_ir::TyKind::General, - TyKind::Integer => chalk_ir::TyKind::Integer, - TyKind::Float => chalk_ir::TyKind::Float, + TyKind::General => chalk_ir::TyVariableKind::General, + TyKind::Integer => chalk_ir::TyVariableKind::Integer, + TyKind::Float => chalk_ir::TyVariableKind::Float, }) .map(|tk| { chalk_ir::CanonicalVarKind::new( @@ -700,9 +657,9 @@ where .iter(&Interner) .map(|k| match k.kind { chalk_ir::VariableKind::Ty(tk) => match tk { - chalk_ir::TyKind::General => TyKind::General, - chalk_ir::TyKind::Integer => TyKind::Integer, - chalk_ir::TyKind::Float => TyKind::Float, + chalk_ir::TyVariableKind::General => TyKind::General, + chalk_ir::TyVariableKind::Integer => TyKind::Integer, + chalk_ir::TyVariableKind::Float => TyKind::Float, }, chalk_ir::VariableKind::Lifetime => panic!("unexpected lifetime from Chalk"), chalk_ir::VariableKind::Const(_) => panic!("unexpected const from Chalk"), @@ -768,7 +725,8 @@ where chalk_ir::Binders::new( chalk_ir::VariableKinds::from_iter( &Interner, - std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)).take(num_vars), + std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General)) + .take(num_vars), ), value, ) diff --git a/crates/hir_ty/src/traits/chalk/tls.rs b/crates/hir_ty/src/traits/chalk/tls.rs index b4568cff6..3c9766550 100644 --- a/crates/hir_ty/src/traits/chalk/tls.rs +++ b/crates/hir_ty/src/traits/chalk/tls.rs @@ -1,12 +1,12 @@ //! Implementation of Chalk debug helper functions using TLS. use std::fmt; -use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication, TypeName}; +use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; use itertools::Itertools; use super::{from_chalk, Interner, TypeAliasAsAssocType}; -use crate::{db::HirDatabase, CallableDefId, TypeCtor}; -use hir_def::{AdtId, AssocContainerId, DefWithBodyId, Lookup, TypeAliasId}; +use crate::{db::HirDatabase, CallableDefId}; +use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; pub use unsafe_tls::{set_current_program, with_current_program}; @@ -18,94 +18,12 @@ impl DebugContext<'_> { id: super::AdtId, f: &mut fmt::Formatter<'_>, ) -> Result<(), fmt::Error> { - let type_ctor: TypeCtor = from_chalk(self.0, TypeName::Adt(id)); - match type_ctor { - TypeCtor::Bool => write!(f, "bool")?, - TypeCtor::Char => write!(f, "char")?, - TypeCtor::Int(t) => write!(f, "{}", t)?, - TypeCtor::Float(t) => write!(f, "{}", t)?, - TypeCtor::Str => write!(f, "str")?, - TypeCtor::Slice => write!(f, "slice")?, - TypeCtor::Array => write!(f, "array")?, - TypeCtor::RawPtr(m) => write!(f, "*{}", m.as_keyword_for_ptr())?, - TypeCtor::Ref(m) => write!(f, "&{}", m.as_keyword_for_ref())?, - TypeCtor::Never => write!(f, "!")?, - TypeCtor::Tuple { .. } => { - write!(f, "()")?; - } - TypeCtor::FnPtr { .. } => { - write!(f, "fn")?; - } - TypeCtor::FnDef(def) => { - let name = match def { - CallableDefId::FunctionId(ff) => self.0.function_data(ff).name.clone(), - CallableDefId::StructId(s) => self.0.struct_data(s).name.clone(), - CallableDefId::EnumVariantId(e) => { - let enum_data = self.0.enum_data(e.parent); - enum_data.variants[e.local_id].name.clone() - } - }; - match def { - CallableDefId::FunctionId(_) => write!(f, "{{fn {}}}", name)?, - CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => { - write!(f, "{{ctor {}}}", name)? - } - } - } - TypeCtor::Adt(def_id) => { - let name = match def_id { - AdtId::StructId(it) => self.0.struct_data(it).name.clone(), - AdtId::UnionId(it) => self.0.union_data(it).name.clone(), - AdtId::EnumId(it) => self.0.enum_data(it).name.clone(), - }; - write!(f, "{}", name)?; - } - TypeCtor::AssociatedType(type_alias) => { - let trait_ = match type_alias.lookup(self.0.upcast()).container { - AssocContainerId::TraitId(it) => it, - _ => panic!("not an associated type"), - }; - let trait_name = self.0.trait_data(trait_).name.clone(); - let name = self.0.type_alias_data(type_alias).name.clone(); - write!(f, "{}::{}", trait_name, name)?; - } - TypeCtor::OpaqueType(opaque_ty_id) => match opaque_ty_id { - crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => { - write!(f, "{{impl trait {} of {:?}}}", idx, func)?; - } - crate::OpaqueTyId::AsyncBlockTypeImplTrait(def, idx) => { - write!(f, "{{impl trait of async block {} of {:?}}}", idx.into_raw(), def)?; - } - }, - TypeCtor::ForeignType(type_alias) => { - let name = self.0.type_alias_data(type_alias).name.clone(); - write!(f, "{}", name)?; - } - TypeCtor::Closure { def, expr } => { - write!(f, "{{closure {:?} in ", expr.into_raw())?; - match def { - DefWithBodyId::FunctionId(func) => { - write!(f, "fn {}", self.0.function_data(func).name)? - } - DefWithBodyId::StaticId(s) => { - if let Some(name) = self.0.static_data(s).name.as_ref() { - write!(f, "body of static {}", name)?; - } else { - write!(f, "body of unnamed static {:?}", s)?; - } - } - DefWithBodyId::ConstId(c) => { - if let Some(name) = self.0.const_data(c).name.as_ref() { - write!(f, "body of const {}", name)?; - } else { - write!(f, "body of unnamed const {:?}", c)?; - } - } - }; - write!(f, "}}")?; - } - } - Ok(()) + let name = match id.0 { + AdtId::StructId(it) => self.0.struct_data(it).name.clone(), + AdtId::UnionId(it) => self.0.union_data(it).name.clone(), + AdtId::EnumId(it) => self.0.enum_data(it).name.clone(), + }; + write!(f, "{}", name) } pub fn debug_trait_id( @@ -234,14 +152,6 @@ impl DebugContext<'_> { write!(fmt, "{:?}", pci.debug(&Interner)) } - pub fn debug_application_ty( - &self, - application_ty: &chalk_ir::ApplicationTy, - fmt: &mut fmt::Formatter<'_>, - ) -> Result<(), fmt::Error> { - write!(fmt, "{:?}", application_ty.debug(&Interner)) - } - pub fn debug_substitution( &self, substitution: &chalk_ir::Substitution, -- cgit v1.2.3