From 06ed140fc7672466bc090fadd95bcf60ed6e82a4 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 22 May 2020 16:40:42 +0200 Subject: Update Chalk As always, this just makes compilation work, we don't use the newly available functionality yet. --- crates/ra_hir_ty/src/traits/chalk.rs | 119 +++++++++++++++++++------------ crates/ra_hir_ty/src/traits/chalk/tls.rs | 8 +-- 2 files changed, 78 insertions(+), 49 deletions(-) (limited to 'crates/ra_hir_ty/src/traits') diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 5870618a0..c2d7abd17 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -4,7 +4,7 @@ use std::{fmt, sync::Arc}; use log::debug; use chalk_ir::{ - cast::Cast, fold::shift::Shift, interner::HasInterner, Goal, GoalData, Parameter, + cast::Cast, fold::shift::Shift, interner::HasInterner, GenericArg, Goal, GoalData, PlaceholderIndex, TypeName, UniverseIndex, }; @@ -26,24 +26,24 @@ pub(super) mod tls; pub struct Interner; impl chalk_ir::interner::Interner for Interner { - type InternedType = Box>; + type InternedType = Box>; // FIXME use Arc? type InternedLifetime = chalk_ir::LifetimeData; - type InternedParameter = chalk_ir::ParameterData; + type InternedConst = Arc>; + type InternedConcreteConst = (); + type InternedGenericArg = chalk_ir::GenericArgData; type InternedGoal = Arc>; type InternedGoals = Vec>; - type InternedSubstitution = Vec>; + type InternedSubstitution = Vec>; type InternedProgramClause = chalk_ir::ProgramClauseData; type InternedProgramClauses = Arc<[chalk_ir::ProgramClause]>; type InternedQuantifiedWhereClauses = Vec>; - type InternedParameterKinds = Vec>; - type InternedCanonicalVarKinds = Vec>; - type Identifier = TypeAliasId; + type InternedVariableKinds = Vec>; + type InternedCanonicalVarKinds = Vec>; type DefId = InternId; + type InternedAdtId = InternId; + type Identifier = TypeAliasId; - fn debug_struct_id( - type_kind_id: StructId, - fmt: &mut fmt::Formatter<'_>, - ) -> Option { + fn debug_adt_id(type_kind_id: StructId, fmt: &mut fmt::Formatter<'_>) -> Option { tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt))) } @@ -94,11 +94,11 @@ impl chalk_ir::interner::Interner for Interner { tls::with_current_program(|prog| Some(prog?.debug_lifetime(lifetime, fmt))) } - fn debug_parameter( - parameter: &Parameter, + fn debug_generic_arg( + parameter: &GenericArg, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_parameter(parameter, fmt))) + tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt))) } fn debug_goal(goal: &Goal, fmt: &mut fmt::Formatter<'_>) -> Option { @@ -164,17 +164,32 @@ impl chalk_ir::interner::Interner for Interner { lifetime } - fn intern_parameter( + fn intern_const(&self, constant: chalk_ir::ConstData) -> Arc> { + Arc::new(constant) + } + + fn const_data<'a>( + &self, + constant: &'a Arc>, + ) -> &'a chalk_ir::ConstData { + constant + } + + fn const_eq(&self, _ty: &Box>, _c1: &(), _c2: &()) -> bool { + true + } + + fn intern_generic_arg( &self, - parameter: chalk_ir::ParameterData, - ) -> chalk_ir::ParameterData { + parameter: chalk_ir::GenericArgData, + ) -> chalk_ir::GenericArgData { parameter } - fn parameter_data<'a>( + fn generic_arg_data<'a>( &self, - parameter: &'a chalk_ir::ParameterData, - ) -> &'a chalk_ir::ParameterData { + parameter: &'a chalk_ir::GenericArgData, + ) -> &'a chalk_ir::GenericArgData { parameter } @@ -199,15 +214,15 @@ impl chalk_ir::interner::Interner for Interner { fn intern_substitution( &self, - data: impl IntoIterator, E>>, - ) -> Result>, E> { + data: impl IntoIterator, E>>, + ) -> Result>, E> { data.into_iter().collect() } fn substitution_data<'a>( &self, - substitution: &'a Vec>, - ) -> &'a [Parameter] { + substitution: &'a Vec>, + ) -> &'a [GenericArg] { substitution } @@ -253,23 +268,23 @@ impl chalk_ir::interner::Interner for Interner { clauses } - fn intern_parameter_kinds( + fn intern_generic_arg_kinds( &self, - data: impl IntoIterator, E>>, - ) -> Result { + data: impl IntoIterator, E>>, + ) -> Result { data.into_iter().collect() } - fn parameter_kinds_data<'a>( + fn variable_kinds_data<'a>( &self, - parameter_kinds: &'a Self::InternedParameterKinds, - ) -> &'a [chalk_ir::ParameterKind<()>] { + parameter_kinds: &'a Self::InternedVariableKinds, + ) -> &'a [chalk_ir::VariableKind] { ¶meter_kinds } fn intern_canonical_var_kinds( &self, - data: impl IntoIterator, E>>, + data: impl IntoIterator, E>>, ) -> Result { data.into_iter().collect() } @@ -277,7 +292,7 @@ impl chalk_ir::interner::Interner for Interner { fn canonical_var_kinds_data<'a>( &self, canonical_var_kinds: &'a Self::InternedCanonicalVarKinds, - ) -> &'a [chalk_ir::ParameterKind] { + ) -> &'a [chalk_ir::CanonicalVarKind] { &canonical_var_kinds } } @@ -290,8 +305,8 @@ pub type AssocTypeId = chalk_ir::AssocTypeId; pub type AssociatedTyDatum = chalk_rust_ir::AssociatedTyDatum; pub type TraitId = chalk_ir::TraitId; pub type TraitDatum = chalk_rust_ir::TraitDatum; -pub type StructId = chalk_ir::StructId; -pub type StructDatum = chalk_rust_ir::StructDatum; +pub type StructId = chalk_ir::AdtId; +pub type StructDatum = chalk_rust_ir::AdtDatum; pub type ImplId = chalk_ir::ImplId; pub type ImplDatum = chalk_rust_ir::ImplDatum; pub type AssociatedTyValueId = chalk_rust_ir::AssociatedTyValueId; @@ -453,14 +468,14 @@ impl ToChalk for TypeCtor { _ => { // other TypeCtors get interned and turned into a chalk StructId let struct_id = db.intern_type_ctor(self).into(); - TypeName::Struct(struct_id) + TypeName::Adt(struct_id) } } } fn from_chalk(db: &dyn HirDatabase, type_name: TypeName) -> TypeCtor { match type_name { - TypeName::Struct(struct_id) => db.lookup_intern_type_ctor(struct_id.into()), + TypeName::Adt(struct_id) => db.lookup_intern_type_ctor(struct_id.into()), TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)), TypeName::OpaqueType(_) => unreachable!(), @@ -471,6 +486,8 @@ impl ToChalk for TypeCtor { TypeName::Ref(_) => unreachable!(), TypeName::Str => unreachable!(), + TypeName::FnDef(_) => unreachable!(), + TypeName::Error => { // this should not be reached, since we don't represent TypeName::Error with TypeCtor unreachable!() @@ -622,7 +639,10 @@ where type Chalk = chalk_ir::Canonical; fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical { - let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT); + let parameter = chalk_ir::CanonicalVarKind::new( + chalk_ir::VariableKind::Ty, + chalk_ir::UniverseIndex::ROOT, + ); let value = self.value.to_chalk(db); chalk_ir::Canonical { value, @@ -738,9 +758,9 @@ where T: HasInterner, { chalk_ir::Binders::new( - chalk_ir::ParameterKinds::from( + chalk_ir::VariableKinds::from( &Interner, - std::iter::repeat(chalk_ir::ParameterKind::Ty(())).take(num_vars), + std::iter::repeat(chalk_ir::VariableKind::Ty).take(num_vars), ), value, ) @@ -819,16 +839,25 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { fn trait_datum(&self, trait_id: TraitId) -> Arc { self.db.trait_datum(self.krate, trait_id) } - fn struct_datum(&self, struct_id: StructId) -> Arc { + fn adt_datum(&self, struct_id: StructId) -> Arc { self.db.struct_datum(self.krate, struct_id) } fn impl_datum(&self, impl_id: ImplId) -> Arc { self.db.impl_datum(self.krate, impl_id) } + + fn fn_def_datum( + &self, + _fn_def_id: chalk_ir::FnDefId, + ) -> Arc> { + // We don't yet provide any FnDefs to Chalk + unimplemented!() + } + fn impls_for_trait( &self, trait_id: TraitId, - parameters: &[Parameter], + parameters: &[GenericArg], ) -> Vec { debug!("impls_for_trait {:?}", trait_id); let trait_: hir_def::TraitId = from_chalk(self.db, trait_id); @@ -1000,7 +1029,7 @@ pub(crate) fn struct_datum_query( struct_id: StructId, ) -> Arc { debug!("struct_datum {:?}", struct_id); - let type_ctor: TypeCtor = from_chalk(db, TypeName::Struct(struct_id)); + let type_ctor: TypeCtor = from_chalk(db, TypeName::Adt(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); @@ -1012,12 +1041,12 @@ pub(crate) fn struct_datum_query( convert_where_clauses(db, generic_def, &bound_vars) }) .unwrap_or_else(Vec::new); - let flags = chalk_rust_ir::StructFlags { + let flags = chalk_rust_ir::AdtFlags { upstream, // FIXME set fundamental flag correctly fundamental: false, }; - let struct_datum_bound = chalk_rust_ir::StructDatumBound { + let struct_datum_bound = chalk_rust_ir::AdtDatumBound { fields: Vec::new(), // FIXME add fields (only relevant for auto traits) where_clauses, }; @@ -1153,7 +1182,7 @@ impl From for crate::TypeCtorId { impl From for StructId { fn from(type_ctor_id: crate::TypeCtorId) -> Self { - chalk_ir::StructId(type_ctor_id.as_intern_id()) + chalk_ir::AdtId(type_ctor_id.as_intern_id()) } } diff --git a/crates/ra_hir_ty/src/traits/chalk/tls.rs b/crates/ra_hir_ty/src/traits/chalk/tls.rs index 4867cb17e..b7eb49d7b 100644 --- a/crates/ra_hir_ty/src/traits/chalk/tls.rs +++ b/crates/ra_hir_ty/src/traits/chalk/tls.rs @@ -1,7 +1,7 @@ //! Implementation of Chalk debug helper functions using TLS. use std::fmt; -use chalk_ir::{AliasTy, Goal, Goals, Lifetime, Parameter, ProgramClauseImplication, TypeName}; +use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication, TypeName}; use itertools::Itertools; use super::{from_chalk, Interner}; @@ -18,7 +18,7 @@ impl DebugContext<'_> { id: super::StructId, f: &mut fmt::Formatter<'_>, ) -> Result<(), fmt::Error> { - let type_ctor: TypeCtor = from_chalk(self.0, TypeName::Struct(id)); + let type_ctor: TypeCtor = from_chalk(self.0, TypeName::Adt(id)); match type_ctor { TypeCtor::Bool => write!(f, "bool")?, TypeCtor::Char => write!(f, "char")?, @@ -188,9 +188,9 @@ impl DebugContext<'_> { write!(fmt, "{:?}", lifetime.data(&Interner)) } - pub fn debug_parameter( + pub fn debug_generic_arg( &self, - parameter: &Parameter, + parameter: &GenericArg, fmt: &mut fmt::Formatter<'_>, ) -> Result<(), fmt::Error> { write!(fmt, "{:?}", parameter.data(&Interner).inner_debug()) -- cgit v1.2.3